-
Notifications
You must be signed in to change notification settings - Fork 1
/
APITestPlugin.php
78 lines (60 loc) · 2.3 KB
/
APITestPlugin.php
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
<?php
import('lib.pkp.classes.plugins.GenericPlugin');
import('plugins.generic.apiTest.classes.handler.DatasetFileUploadHandler');
class APITestPlugin extends GenericPlugin {
public function register($category, $path, $mainContextId = NULL) {
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
HookRegistry::register('LoadComponentHandler', array($this, 'setDatasetFileUploadHandler'));
HookRegistry::register('Dispatcher::dispatch', array($this, 'setupDatasetFileHandler'));
HookRegistry::register('Schema::get::datasetFile', array($this, 'loadDatasetFileSchema'));
$this->import('classes.datasetFile.DatasetFileDAO');
$datasetFileDAO = new DatasetFileDAO;
DAORegistry::registerDAO('DatasetFileDAO', $datasetFileDAO);
$this->import('classes.TemplateRewriter');
$templateRewriter = new TemplateRewriter($this);
}
return $success;
}
public function getDisplayName() {
return 'API Test';
}
public function getDescription() {
return 'API test plugin.';
}
public function setDatasetFileUploadHandler($hookname, $params) {
$component =& $params[0];
switch ($component) {
case 'plugins.generic.apiTest.classes.handler.DatasetFileUploadHandler':
return true;
break;
}
return false;
}
public function setupDatasetFileHandler($hookname, $request) {
$router = $request->getRouter();
if ($router instanceof \APIRouter && str_contains($request->getRequestPath(), 'api/v1/datasetFiles')) {
$this->import('api.v1.datasetFiles.DatasetFileHandler');
$handler = new DatasetFileHandler($this);
$router->setHandler($handler);
$handler->getApp()->run();
exit;
}
return false;
}
public function loadDatasetFileSchema($hookname, $params) {
$schema = &$params[0];
$datasetFileSchemaFile = BASE_SYS_DIR . '/plugins/generic/apiTest/schemas/datasetFile.json';
if (file_exists($datasetFileSchemaFile)) {
$schema = json_decode(file_get_contents($datasetFileSchemaFile));
if (!$schema) {
fatalError('Schema failed to decode. This usually means it is invalid JSON. Requested: ' . $datasetFileSchemaFile . '. Last JSON error: ' . json_last_error());
}
}
return false;
}
function getInstallMigration() {
$this->import('classes.migration.DatasetMigration');
return new DatasetMigration();
}
}