18 import(
'lib.pkp.classes.plugins.GenericPlugin');
19 import(
'lib.pkp.classes.scheduledTask.ScheduledTaskHelper');
34 function register($category, $path, $mainContextId =
null) {
35 $success = parent::register($category, $path, $mainContextId);
38 if (!
Config::getVar(
'general',
'installed') || defined(
'RUNNING_UPGRADE'))
return $success;
67 return __(
'plugins.generic.acron.name');
74 return __(
'plugins.generic.acron.description');
81 return PKP_LIB_PATH . DIRECTORY_SEPARATOR . $this->
getPluginPath() .
'/settings.xml';
88 import(
'lib.pkp.classes.linkAction.request.AjaxAction');
95 $router->url(
$request,
null,
null,
'manage',
null, array(
'verb' =>
'reload',
'plugin' => $this->
getName(),
'category' =>
'generic'))
97 __(
'plugins.generic.acron.reload'),
101 parent::getActions(
$request, $actionArgs)
109 switch(
$request->getUserVar(
'verb')) {
114 $notificationManager->createTrivialNotification(
115 $user->getId(), NOTIFICATION_TYPE_SUCCESS,
116 array(
'contents' => __(
'plugins.generic.acron.tasksReloaded'))
120 return parent::manage($args,
$request);
146 if (!is_a($router,
'PKPPageRouter'))
return false;
149 if (!empty($tasksToRun)) {
152 $this->_workingDir = getcwd();
155 $this->_tasksToRun = $tasksToRun;
165 register_shutdown_function(array(&$this,
'shutdownFunction'));
183 if (!is_a($plugin,
'LazyLoadPlugin'))
return false;
186 if ($verb !==
'enable' && $verb !==
'disable')
return false;
192 foreach ($hookPriorityList as $priority => $callback) {
193 if ($callback[0] == $plugin) {
211 header(
"Connection: close");
215 header(
"Content-Encoding: none");
216 header(
"Content-Length: " . ob_get_length());
224 chdir($this->_workingDir);
227 foreach($this->_tasksToRun as $task) {
229 $className = $task[
'className'];
230 $pos = strrpos($className,
'.');
231 if ($pos ===
false) {
232 $baseClassName = $className;
234 $baseClassName = substr($className, $pos+1);
237 if (isset($task[
'args'])) {
238 $taskArgs = $task[
'args'];
248 if (in_array($task, $tasksToRun,
true)) {
249 $updateResult = $taskDao->updateLastRunTime($className, time());
252 if ($updateResult ===
false || $updateResult === 1) {
256 $task =
new $baseClassName($taskArgs);
273 $taskFilesPath = array();
282 $taskFilesPath[] =
'registry/scheduledTasks.xml';
285 foreach ($taskFilesPath as $filePath) {
286 $tree = $xmlParser->parse($filePath);
289 fatalError(
'Error parsing scheduled tasks XML file: ' . $filePath);
292 foreach ($tree->getChildren() as $task) {
293 $frequency = $task->getChildByName(
'frequency');
300 $setDefaultFrequency =
true;
301 $minHoursRunPeriod = 24;
303 $frequencyAttributes = $frequency->getAttributes();
304 if (is_array($frequencyAttributes)) {
305 foreach($frequencyAttributes as $key => $value) {
307 $setDefaultFrequency =
false;
314 'className' => $task->getAttribute(
'class'),
315 'frequency' => $setDefaultFrequency ? array(
'hour' => $minHoursRunPeriod) : $frequencyAttributes,
330 $tasksToRun = array();
337 $scheduledTasks = $this->
getSetting(0,
'crontab');
338 if(is_null($scheduledTasks)) {
340 $scheduledTasks = $this->
getSetting(0,
'crontab');
343 foreach($scheduledTasks as $task) {
346 $frequency->setAttribute(key($task[
'frequency']), current($task[
'frequency']));
350 $tasksToRun[] = $task;