Add "getCronFiles" method to the plugin class and change cron_single file to execute old cron files and new registered cron files
This commit is contained in:
@@ -566,7 +566,7 @@ function executePlugins()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($handle = opendir($pathCronPlugins)) {
|
if ($handle = opendir($pathCronPlugins)) {
|
||||||
setExecutionMessage('--- Executing cron files in bin/plugins directory in Workspace:' . SYS_SYS);
|
setExecutionMessage('Executing cron files in bin/plugins directory in Workspace: ' . SYS_SYS);
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
if (strpos($file, '.php',1) && is_file($pathCronPlugins . $file)) {
|
if (strpos($file, '.php',1) && is_file($pathCronPlugins . $file)) {
|
||||||
$filename = str_replace('.php' , '', $file);
|
$filename = str_replace('.php' , '', $file);
|
||||||
@@ -579,8 +579,22 @@ function executePlugins()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Executing registered cron files
|
// Executing registered cron files
|
||||||
|
|
||||||
// -> Get registered cron files
|
// -> Get registered cron files
|
||||||
|
Bootstrap::LoadClass( 'plugin' );
|
||||||
|
$oPluginRegistry =& PMPluginRegistry::getSingleton();
|
||||||
|
if (file_exists(PATH_DATA_SITE . 'plugin.singleton')) {
|
||||||
|
$oPluginRegistry->unSerializeInstance(file_get_contents(PATH_DATA_SITE . 'plugin.singleton'));
|
||||||
|
}
|
||||||
|
$cronFiles = $oPluginRegistry->getCronFiles();
|
||||||
|
|
||||||
// -> Execute functions
|
// -> Execute functions
|
||||||
|
if (!empty($cronFiles)) {
|
||||||
|
setExecutionMessage('Executing registered cron files for Workspace: ' . SYS_SYS);
|
||||||
|
foreach($cronFiles as $cronFile) {
|
||||||
|
executeCustomCronFunction(PATH_PLUGINS . $cronFile->namespace . PATH_SEP . 'bin' . PATH_SEP . $cronFile->cronFile . '.php', $cronFile->cronFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
function executeCustomCronFunction($pathFile, $className)
|
function executeCustomCronFunction($pathFile, $className)
|
||||||
@@ -596,14 +610,14 @@ function executeCustomCronFunction($pathFile, $className)
|
|||||||
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
||||||
|
|
||||||
//Try to execute Plugin Cron. If there is an error then continue with the next file
|
//Try to execute Plugin Cron. If there is an error then continue with the next file
|
||||||
setExecutionMessage("------ Executing cron file: $filename");
|
setExecutionMessage("\n--- Executing cron file: $pathFile");
|
||||||
try {
|
try {
|
||||||
$oPlugin->executeCron();
|
$oPlugin->executeCron();
|
||||||
setExecutionResultMessage('DONE');
|
setExecutionResultMessage('DONE');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
setExecutionResultMessage('FAILED', 'error');
|
setExecutionResultMessage('FAILED', 'error');
|
||||||
eprintln(" '-".$e->getMessage(), 'red');
|
eprintln(" '-".$e->getMessage(), 'red');
|
||||||
saveLog('executePlugins', 'error', 'Error executing Plugin ' . $filename . ': ' . $e->getMessage());
|
saveLog('executePlugins', 'error', 'Error executing cron file: ' . $pathFile . ' - ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -895,7 +909,12 @@ function saveLog($sSource, $sType, $sDescription)
|
|||||||
}
|
}
|
||||||
|
|
||||||
G::verifyPath(PATH_DATA . "log" . PATH_SEP, true);
|
G::verifyPath(PATH_DATA . "log" . PATH_SEP, true);
|
||||||
G::log(date("Y-m-d H:i:s") . " | $sObject | " . $sSource . " | $sType | " . $sDescription . "\n", PATH_DATA);
|
|
||||||
|
//setExecutionMessage( PATH_DATA."log".PATH_SEP);
|
||||||
|
|
||||||
|
$oFile = @fopen(PATH_DATA . "log" . PATH_SEP . "cron.log", "a+");
|
||||||
|
@fwrite($oFile, date("Y-m-d H:i:s") . " | $sObject | " . $sSource . " | $sType | " . $sDescription . "\n");
|
||||||
|
@fclose($oFile);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
//CONTINUE
|
//CONTINUE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1458,5 +1458,15 @@ class PMPluginRegistry
|
|||||||
$this->_aCronFiles[] = $cronFile;
|
$this->_aCronFiles[] = $cronFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all cron files registered
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCronFiles()
|
||||||
|
{
|
||||||
|
return $this->_aCronFiles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user