-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummyDataGeneratorPlugin.php
More file actions
134 lines (116 loc) · 3.57 KB
/
Copy pathDummyDataGeneratorPlugin.php
File metadata and controls
134 lines (116 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* @file DummyDataGeneratorPlugin.php
*
* Copyright (c) 2025 Munir Abbasi
* Distributed under the GNU GPL v3.
*
* @class DummyDataGeneratorPlugin
* @brief Generate dummy users, submissions, and issues for OJS development/testing
*
* @author Munir Abbasi <munir@syntaxhouse.com>
* @link https://github.com/munir-abbasi/dummyDataGenerator
* @since 3.5.0
*/
declare(strict_types=1);
namespace APP\plugins\generic\dummyDataGenerator;
use APP\core\Application;
use APP\plugins\generic\dummyDataGenerator\api\DummyDataAPIHandler;
use APP\template\TemplateManager;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\security\Role;
class DummyDataGeneratorPlugin extends GenericPlugin
{
/**
* @copydoc Plugin::getName()
*/
public function getName(): string
{
return 'dummyDataGenerator';
}
/**
* @copydoc Plugin::getPluginPath()
*/
public function getPluginPath(): string
{
return __DIR__;
}
/**
* @copydoc Plugin::getHideManagement()
*/
public function getHideManagement(): bool
{
// Keep plugin visible in management interface
return false;
}
/**
* @copydoc Plugin::register()
*/
public function register($category, $path, $mainContextId = null): bool
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)) {
$this->registerAPIHandler();
}
return $success;
}
/**
* Register custom API handler for dummy data operations
* Extends the users API endpoint with custom routes
*/
private function registerAPIHandler(): void
{
Hook::add('APIHandler::endpoints::users', function (string $hookName, array $args): bool {
$apiHandler = $args[1];
$controller = new DummyDataAPIHandler($this);
$apiHandler->addRoute(
'POST',
'generate-users',
[$controller, 'generateUsers'],
'dummyData.generateUsers',
[Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER]
);
$apiHandler->addRoute(
'POST',
'generate-submissions',
[$controller, 'generateSubmissions'],
'dummyData.generateSubmissions',
[Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER]
);
$apiHandler->addRoute(
'POST',
'generate-issue',
[$controller, 'generateIssue'],
'dummyData.generateIssue',
[Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER]
);
$apiHandler->addRoute(
'DELETE',
'cleanup',
[$controller, 'cleanup'],
'dummyData.cleanup',
[Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER]
);
return Hook::CONTINUE;
});
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName(): string
{
return __('plugins.generic.dummyDataGenerator.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription(): string
{
return __('plugins.generic.dummyDataGenerator.description');
}
}
// For backwards compatibility -- expect this to be removed approx. OJS/OMP/OPS 3.6
if (defined('PKP_STRICT_MODE') && !PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\dummyDataGenerator\DummyDataGeneratorPlugin', '\DummyDataGeneratorPlugin');
}