diff --git a/composer.json b/composer.json index 90179c29..5c13b68d 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "composer/semver": "^3.2", "twig/twig": "^2.0", "erusev/parsedown": "^1.7", - "nikic/fast-route": "^1.3" + "nikic/fast-route": "^1.3", + "peppeocchi/php-cron-scheduler": "4.*" } } diff --git a/system/bin/cronjob.php b/system/bin/cronjob.php new file mode 100644 index 00000000..0bea2b03 --- /dev/null +++ b/system/bin/cronjob.php @@ -0,0 +1,19 @@ +load(); + +use GO\Scheduler; + +// Create a new scheduler +$scheduler = new Scheduler(); + +$hooks->trigger(HOOK_CRONJOB, ['scheduler' => $scheduler]); + +// Let the scheduler execute jobs which are due. +$scheduler->run(); diff --git a/system/bin/install_cronjob.php b/system/bin/install_cronjob.php new file mode 100644 index 00000000..dff2604a --- /dev/null +++ b/system/bin/install_cronjob.php @@ -0,0 +1,50 @@ +> ' . SYSTEM . 'logs/cron.log 2>&1'; + +if (cronjob_exists($job)) { + echo 'MyAAC cronjob already installed.' . PHP_EOL; + exit(0); +} + +exec ('crontab -l', $content); + +$content = implode(' ', $content); +$content .= PHP_EOL . $job; + +file_put_contents(CACHE . 'cronjob', $content . PHP_EOL); +exec('crontab ' . CACHE. 'cronjob'); + +echo 'Installed crontab successfully.' . PHP_EOL; + +function cronjob_exists($command) +{ + $cronjob_exists=false; + + exec('crontab -l', $crontab); + if(isset($crontab)&&is_array($crontab)) { + + $crontab = array_flip($crontab); + + if(isset($crontab[$command])){ + $cronjob_exists = true; + } + + } + + return $cronjob_exists; +} diff --git a/system/hooks.php b/system/hooks.php index 3201880d..e177a5b0 100644 --- a/system/hooks.php +++ b/system/hooks.php @@ -64,6 +64,7 @@ define('HOOK_ADMIN_MENU', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_ACCOUNT', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i); +define('HOOK_CRONJOB', ++$i); define('HOOK_EMAIL_CONFIRMED', ++$i); const HOOK_FIRST = HOOK_STARTUP; const HOOK_LAST = HOOK_EMAIL_CONFIRMED;