mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
feature: plugin cronjobs (#215)
This commit is contained in:
parent
8a3986932d
commit
5f10773189
@ -12,7 +12,8 @@
|
||||
"erusev/parsedown": "^1.7",
|
||||
"nikic/fast-route": "^1.3",
|
||||
"matomo/device-detector": "^6.0",
|
||||
"illuminate/database": "^10.18"
|
||||
"illuminate/database": "^10.18",
|
||||
"peppeocchi/php-cron-scheduler": "4.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"filp/whoops": "^2.15"
|
||||
|
19
system/bin/cronjob.php
Normal file
19
system/bin/cronjob.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../common.php';
|
||||
require_once SYSTEM . 'functions.php';
|
||||
require_once SYSTEM . 'init.php';
|
||||
require_once SYSTEM . 'hooks.php';
|
||||
|
||||
$hooks = new Hooks();
|
||||
$hooks->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();
|
50
system/bin/install_cronjob.php
Normal file
50
system/bin/install_cronjob.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../common.php';
|
||||
require_once SYSTEM . 'functions.php';
|
||||
require_once SYSTEM . 'init.php';
|
||||
|
||||
if(!IS_CLI) {
|
||||
echo 'This script can be run only in command line mode.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (MYAAC_OS !== 'LINUX') {
|
||||
echo 'This script can be run only on linux.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$job = '* * * * * /usr/bin/php ' . SYSTEM . 'bin/cronjob.php >> ' . 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;
|
||||
}
|
@ -69,6 +69,7 @@ define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i);
|
||||
define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i);
|
||||
define('HOOK_ADMIN_ACCOUNTS_SAVE_POST', ++$i);
|
||||
define('HOOK_ADMIN_SETTINGS_BEFORE_SAVE', ++$i);
|
||||
define('HOOK_CRONJOB', ++$i);
|
||||
define('HOOK_EMAIL_CONFIRMED', ++$i);
|
||||
define('HOOK_GUILDS_BEFORE_GUILD_HEADER', ++$i);
|
||||
define('HOOK_GUILDS_AFTER_GUILD_HEADER', ++$i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user