-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExternalModule.php
154 lines (128 loc) · 3.66 KB
/
ExternalModule.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
namespace Marcus\StudyMetadataSearch\ExternalModule;
use ProjectService;
use SearchEngineService;
use CronService;
/**
* ExternalModule - (required) Abstract implementation of REDCap module
*/
class ExternalModule extends \ExternalModules\AbstractExternalModule {
/**
* __construct
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* getPrefix
*
* @return string
*/
public function getPrefix() : string {
return $this->getModuleInfo()["prefix"];
}
/**
* getModuleInfo
*
* @return array
*/
public function getModuleInfo() : array {
$directoryName = $this->getModuleDirectoryName();
list($prefix, $releaseVersion) = explode('_v', $directoryName);
list($releaseMajor, $releaseMinor) = explode('.', $version);
$directoryPath = $this->getModulePath();
$composer = json_decode(file_get_contents($directoryPath.'composer.json'), true);
list($composerMajor, $composerMinor) = explode('.', $composer['version']);
return [
'prefix' => $prefix,
'release' => [
'version' => $releaseVersion,
'major' => $releaseMajor,
'minor' => $releaseMinor,
],
'composer' => [
'version' => $composer['version'],
'major' => $composerMajor,
'minor' => $composerMinor
]
];
}
/**
* rebuild_search_engine_index
*
* @param mixed $cronInfo
* @return void
*/
public function rebuild_search_engine_index($cron)
{
require_once(__DIR__."/app/bootstrap.php");
$message = "";
// Set up Monolog and add the REDCap handler to it.
$logger = \Logging\Log::getLogger('php://output');
$logger->pushHandler(new \Logging\ExternalModuleLogHandler($this));
// Get the system setting for automatic-reindex.
$enabled = $this->getSystemSetting("autorebuild-enabled");
$logger->info("Automatic reindex is {$enabled}.");
// // If the automatic-reindex is not enabled then exit
if ($enabled !== "enabled")
{
return "Automatic reindex is not enabled.";
}
// Get the cron service
$cronService = new CronService($this, $logger);
// Get the details inclulding the cron pattern and schedule
$details = $cronService->getDetails();
$pattern = $this->getSystemSetting('autorebuild-pattern');
$schedule = $cronService->getSchedule($details['last_start_time'], $pattern);
$is_due = ($schedule['is_due'] === true) ? "true" : "false";
$logger->info("Automatic reindex scheduled for {$schedule['next_run_time']} (due={$is_due}).");
// if the schedule says we are due to run then
if ($schedule['is_due'] === true){
// Log the start of the cron job (in REDCap)
$cronService->logStart();
try
{
// Create the search engine service, and distory the current index
$searchService = new SearchEngineService($this, $logger);
$searchService->destroy();
// Get all updated projects.
$projectService = new ProjectService($this, $logger);
$projects = $projectService->getProjects();
// Update the search service using the new documents
$searchService->updateAll($projects);
$message = "The search engine index has been rebuilt.";
}
catch (\Exception $e)
{
$message = "The search engine index rebuild failed: ".$e->getMessage();
}
finally
{
$logger->info($message);
}
// Log the stop of the cron job (in REDCap)
$cronService->logStop();
}
return $message;
}
/**
* redcap_module_system_enable
*
* @param mixed $version
* @return void
*/
public function redcap_module_system_enable( $version )
{
}
/**
* redcap_project_home_page
*
* @param mixed $project_id
* @return void
*/
function redcap_project_home_page ($project_id)
{
}
}