security updates of unpatched modules
This commit is contained in:
@@ -126,7 +126,7 @@ You can use the "hook_cron_alter" function to edit cronapi data of other
|
||||
modules.
|
||||
|
||||
Example:
|
||||
function module_cron_alter($data) {
|
||||
function module_cron_alter(&$data) {
|
||||
$data['key']['rule'] = '0 */6 * * *';
|
||||
}
|
||||
|
||||
@@ -182,6 +182,19 @@ function phptemplate_elysia_cron_description($job) {
|
||||
Note: module default theme_elysia_cron_description($job) already contains
|
||||
some common tasks descriptions.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
DISABLE CRON JOBS VIA settings.php FILE
|
||||
-----------------------------------------------------------------------------
|
||||
If you have some instances for the project you can want to disable some cron
|
||||
jobs on different instances. For example you don't want to execute PROD cron
|
||||
jobs on DEV instance. There is no need to make it via interface or via SQL
|
||||
query. You can define variable for each cron job to manage it state. For more
|
||||
information please look at `_elysia_cron_is_job_disabled` and `_ec_get_name`
|
||||
functions.
|
||||
|
||||
For example, if you have cron job with name googleanalytics_cron, you can
|
||||
add this string to your settings.php file:
|
||||
$conf['ec_googleanalytics_cron_d'] = TRUE;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
OLD 1.x MODULE API (OBSOLETE)
|
||||
|
@@ -16,8 +16,7 @@ up and running.
|
||||
You can stop here if you don't need a great precision over task execution and
|
||||
you don't have to execute a task more often than once an hour.
|
||||
For example, if you need only the "Once a day", "Once a week" or "Once a month"
|
||||
schedule rules the basic install is fine. (For D6 users that want to stop here:
|
||||
you should have installed Drupal crontab as described in Drupal INSTALL guide).
|
||||
schedule rules the basic install is fine.
|
||||
|
||||
Instead, if you need:
|
||||
- to run some tasks more often than once an hour (eg: you have a function that
|
||||
@@ -41,8 +40,8 @@ The only difference is that you should use the "* * * * *" rule part instead of
|
||||
"0 * * * *" or "45 * * * *" as described in the guide.
|
||||
|
||||
While you're editing the system crontab, it's also recommended to replace the
|
||||
"/cron.php" part with "/sites/modules/elysia_cron/cron.php" (if you have
|
||||
installed elysia_cron in "sites/modules" directory).
|
||||
"/cron.php" part with "/sites/all/modules/elysia_cron/cron.php" (if you have
|
||||
installed elysia_cron in "sites/all/modules" directory).
|
||||
This is an optional step (you can leave "/cron.php" if you want), doing it will
|
||||
result in a better performance in bigger sites (elysia_cron's cron.php handles
|
||||
cache in a better way).
|
||||
@@ -78,6 +77,10 @@ red; font-weight: bold; }
|
||||
PERMISSIONS
|
||||
------------
|
||||
|
||||
You can also give 'administer elysia_cron' permission to all user roles that
|
||||
needs to administer cron jobs. You can do this with standard drupal users
|
||||
administration.
|
||||
There are three permission provided by module:
|
||||
* Administer elysia cron - Perform changes to cron jobs timings, disable cron
|
||||
or single jobs and access cron execution statistics;
|
||||
* Execute elysia cron jobs - Allow users to view statistics, execution status
|
||||
and do manually execute cron jobs;
|
||||
* View elysia cron stats - Allows users to view statistics and execution status
|
||||
of cron jobs;
|
||||
|
@@ -9,27 +9,27 @@ For module developers API documetation read API.TXT
|
||||
FEATURES
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Elysia Cron extends Drupal standard cron, allowing a fine grain control over
|
||||
Elysia Cron extends Drupal standard cron, allowing a fine grain control over
|
||||
each task and several ways to add custom cron jobs to your site.
|
||||
|
||||
- Set the timings and frequencies of each cron task (you can run some jobs every
|
||||
day at a specified hour, other only monthly and so on...).
|
||||
For each task you can simply choose between some frequently used options
|
||||
("once a day", "once a month" ...), or use a powerful "linux crontab"-like
|
||||
syntax to set the accurate timings. You can even define your frequently used
|
||||
For each task you can simply choose between some frequently used options
|
||||
("once a day", "once a month" ...), or use a powerful "linux crontab"-like
|
||||
syntax to set the accurate timings. You can even define your frequently used
|
||||
options to speed up site configuration.
|
||||
- Parallel execution of cron task: you can group jobs in channels and execute
|
||||
- Parallel execution of cron task: you can group jobs in channels and execute
|
||||
then simultaneously: so a task that takes a lot of time to execute won't block
|
||||
other tasks that need to be executed every 5 minutes...
|
||||
- You can disable all tasks, an entire channel or a single task.
|
||||
- Change the priority/order of task execution.
|
||||
- Manual force the execution of a cron tasks.
|
||||
- Detailed overview of cron status with time statistics for single tasks and
|
||||
- Detailed overview of cron status with time statistics for single tasks and
|
||||
channels.
|
||||
|
||||
- Powerful API for module developers: you can define extra cron tasks for your
|
||||
modules, each one with own default timings (site administrators can override
|
||||
them by configuration, other modules via hook_alter). Elysia Cron 2.0 gives a
|
||||
- Powerful API for module developers: you can define extra cron tasks for your
|
||||
modules, each one with own default timings (site administrators can override
|
||||
them by configuration, other modules via hook_alter). Elysia Cron 2.0 gives a
|
||||
brand new API support (compatible with 1.0 version) with a lot of features.
|
||||
- Administrators can define custom jobs (call to functions with parameters), via
|
||||
the "script" option.
|
||||
@@ -43,7 +43,7 @@ It also can be used in a Drupal install profile.
|
||||
3rd party integration:
|
||||
- Ping feature, for external tracking services like host-tracker to tell whether
|
||||
cron is functioning properly on your site.
|
||||
- Drush support: you can call "drush elysia-cron" to manually run extended cron.
|
||||
- Drush support: you can call "drush elysia-cron run" to manually run extended cron.
|
||||
- CTools support for exports/backup of task settings.
|
||||
- Features support.
|
||||
|
||||
@@ -53,35 +53,35 @@ USAGE EXAMPLES
|
||||
|
||||
Elysia cron is usually used in large sites that needs performance optimization.
|
||||
|
||||
- Avoid drupal peak loads by distributing heavy load tasks during quiet periods
|
||||
of the day: for example you may want to rebuild the XML Sitemap of your site
|
||||
at 2:00AM in the morning, where usually only a few people are visiting your
|
||||
site. You can even move some tasks to be executed only once a month (log
|
||||
- Avoid drupal peak loads by distributing heavy load tasks during quiet periods
|
||||
of the day: for example you may want to rebuild the XML Sitemap of your site
|
||||
at 2:00AM in the morning, where usually only a few people are visiting your
|
||||
site. You can even move some tasks to be executed only once a month (log
|
||||
rotation, old records expiry...).
|
||||
|
||||
- If you have tasks that should be executed very often, but don't want to
|
||||
execute ALL drupal cron tasks that often! For example, you may want to check
|
||||
for emails that needs to be sent to your users every 2 minutes. Standard cron
|
||||
is managed in a "monolithic" way, so even if you find out how to execute it
|
||||
- If you have tasks that should be executed very often, but don't want to
|
||||
execute ALL drupal cron tasks that often! For example, you may want to check
|
||||
for emails that needs to be sent to your users every 2 minutes. Standard cron
|
||||
is managed in a "monolithic" way, so even if you find out how to execute it
|
||||
every 2 minutes, you will end in having all cron tasks executed so often, with
|
||||
a lot of performance problems.
|
||||
|
||||
- Fine tune cron cache management : drupal cron will invalidate variable cache
|
||||
every cron run, and this is a great performance problem if you have a
|
||||
frequently called task. Elysia cron optimize cache management, and doesn't
|
||||
- Fine tune cron cache management : drupal cron will invalidate variable cache
|
||||
every cron run, and this is a great performance problem if you have a
|
||||
frequently called task. Elysia cron optimize cache management, and doesn't
|
||||
need to invalidate cache.
|
||||
|
||||
- Setup tasks that should be run at a precise time: for example if you want to
|
||||
- Setup tasks that should be run at a precise time: for example if you want to
|
||||
send a SimpleNews newsletter every monday at 9:00AM, you can do it.
|
||||
|
||||
- Parallel execution: if you have a task that takes a lot of time to execute,
|
||||
you can setup a different channel for it so it won't block other tasks that
|
||||
- Parallel execution: if you have a task that takes a lot of time to execute,
|
||||
you can setup a different channel for it so it won't block other tasks that
|
||||
need to be executed every 5 minutes.
|
||||
|
||||
- Turn off (disable) a cron task/feature you don't need.
|
||||
|
||||
- Debug system cron problems. If your cron does not terminate correctly you can
|
||||
use extended logging, see at each cron timings and disable task to track down
|
||||
use extended logging, see at each cron timings and disable task to track down
|
||||
the problem.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
@@ -93,11 +93,11 @@ Channels are groups of tasks. Each channel is a "parallel line" of execution
|
||||
Tasks inside a channel will be executed sequentially (if they should).
|
||||
|
||||
WARNING: It's not recommended to create more than 2 or 3 channels.
|
||||
Every channel will increase the delay between each cron check (of the same
|
||||
Every channel will increase the delay between each cron check (of the same
|
||||
channel), because each cron call will cycle between all channels.
|
||||
So, for example:
|
||||
If you have 1 channel it will be checked once a minute.
|
||||
If you have 2 channel each one will be checked every 2 minutes (almost usually,
|
||||
If you have 2 channel each one will be checked every 2 minutes (almost usually,
|
||||
when the other one is running it will be checked once a minute).
|
||||
It you have 10 channels there will be a check every 10 minutes... if you have
|
||||
a job that should be executed every 5 minutes it won't do so!
|
||||
@@ -106,10 +106,10 @@ a job that should be executed every 5 minutes it won't do so!
|
||||
EXPORT VIA CTOOLS/FEATURES MODULE
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
With 2.0 version of Elysia Cron you can use "Bulk Export" functionality of
|
||||
With 2.0 version of Elysia Cron you can use "Bulk Export" functionality of
|
||||
"Chaos Tools Suite" to export cron settings.
|
||||
To use it simply enable all modules, go to Structure > Bulk Exporter and
|
||||
select the tasks you want to export settings. You can also select all
|
||||
select the tasks you want to export settings. You can also select all
|
||||
"elysia_cron" prefixed variables to export global options.
|
||||
Than generate the module.
|
||||
|
||||
@@ -117,7 +117,7 @@ The generated code will set the new defaults of elysia cron settings. This way
|
||||
you can simply enable it to use them, but you are free to override them in
|
||||
the future using the normal settings page.
|
||||
Note that if you want to delete all overrides, and return to exported settings,
|
||||
you should do a "reset to defaults" from elysia cron settings page.
|
||||
you should do a "reset to defaults" from elysia cron settings page.
|
||||
|
||||
You can also use "Features" module to create a Feature module will the settings
|
||||
you need.
|
||||
@@ -133,7 +133,32 @@ DRUSH SUPPORT
|
||||
|
||||
Elysia Cron 2.0 adds a simple support for Drush module.
|
||||
|
||||
You can execute the "elysia-cron" command to run cron.
|
||||
Run all cron tasks in all active modules for specified site using elysia cron
|
||||
system. This replaces the standard "core-cron" drush handler.
|
||||
|
||||
Examples:
|
||||
elysia-cron run Run all cron tasks in all active
|
||||
modules (as the standard "core-cron")
|
||||
elysia-cron run --verbose Run all cron tasks in verbose mode
|
||||
elysia-cron run @channel Run all cron tasks in specified
|
||||
channel
|
||||
elysia-cron run search_cron --ignore-time Run only search index
|
||||
build task (force execution)
|
||||
elysia-cron list --elysia-cron-verbose List all channels/tasks
|
||||
in verbose mode
|
||||
elysia-cron disable search_cron Disable search index build task
|
||||
|
||||
Options:
|
||||
--elysia-cron-verbose enable extended output (the same as
|
||||
--verbose, but without enabling drush
|
||||
verbose mode)
|
||||
--ignore-disable run channels/tasks even if disabled
|
||||
--ignore-running run channels/tasks even
|
||||
if already running
|
||||
--ignore-time run channels/tasks even if not ready
|
||||
for execution
|
||||
--quiet suppress all output
|
||||
--verbose enable extended output
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
RULES AND SCRIPT SYNTAX
|
||||
@@ -150,17 +175,17 @@ RULES AND SCRIPT SYNTAX
|
||||
| | | | |
|
||||
* * * * *
|
||||
|
||||
Each of the patterns from the first five fields may be either * (an asterisk),
|
||||
which matches all legal values, or a list of elements separated by commas
|
||||
Each of the patterns from the first five fields may be either * (an asterisk),
|
||||
which matches all legal values, or a list of elements separated by commas
|
||||
(see below).
|
||||
|
||||
For "day of the week" (field 5), 0 is considered Sunday, 6 is Saturday (7 is
|
||||
For "day of the week" (field 5), 0 is considered Sunday, 6 is Saturday (7 is
|
||||
an illegal value)
|
||||
|
||||
A job is executed when the time/date specification fields all match the current
|
||||
time and date. There is one exception: if both "day of month" and "day of week"
|
||||
are restricted (not "*"), then either the "day of month" field (3) or the "day
|
||||
of week" field (5) must match the current day (even though the other of the two
|
||||
A job is executed when the time/date specification fields all match the current
|
||||
time and date. There is one exception: if both "day of month" and "day of week"
|
||||
are restricted (not "*"), then either the "day of month" field (3) or the "day
|
||||
of week" field (5) must match the current day (even though the other of the two
|
||||
fields need not match the current day).
|
||||
|
||||
2. FIELDS OPERATOR
|
||||
@@ -169,13 +194,13 @@ fields need not match the current day).
|
||||
There are several ways of specifying multiple date/time values in a field:
|
||||
|
||||
* The comma (',') operator specifies a list of values, for example: "1,3,4,7,8"
|
||||
* The dash ('-') operator specifies a range of values, for example: "1-6", which
|
||||
* The dash ('-') operator specifies a range of values, for example: "1-6", which
|
||||
is equivalent to "1,2,3,4,5,6"
|
||||
* The asterisk ('*') operator specifies all possible values for a field. For
|
||||
example, an asterisk in the hour time field would be equivalent to 'every hour'
|
||||
* The asterisk ('*') operator specifies all possible values for a field. For
|
||||
example, an asterisk in the hour time field would be equivalent to 'every hour'
|
||||
(subject to matching other specified fields).
|
||||
* The slash ('/') operator (called "step") can be used to skip a given number of
|
||||
values. For example, "*/3" in the hour time field is equivalent to
|
||||
* The slash ('/') operator (called "step") can be used to skip a given number of
|
||||
values. For example, "*/3" in the hour time field is equivalent to
|
||||
"0,3,6,9,12,15,18,21".
|
||||
|
||||
3. EXAMPLES
|
||||
@@ -190,10 +215,10 @@ There are several ways of specifying multiple date/time values in a field:
|
||||
4. SCRIPTS
|
||||
---------------------------------
|
||||
|
||||
You can use the script section to easily create new jobs (by calling a php
|
||||
You can use the script section to easily create new jobs (by calling a php
|
||||
function) or to change the scheduling of an existing job.
|
||||
|
||||
Every line of the script can be a comment (if it starts with #) or a job
|
||||
Every line of the script can be a comment (if it starts with #) or a job
|
||||
definition.
|
||||
|
||||
The syntax of a job definition is:
|
||||
@@ -207,10 +232,10 @@ The syntax of a job definition is:
|
||||
* [job]: could be the name of a supported job (for example: 'search_cron') or a
|
||||
function call, ending with ; (for example: 'process_queue();').
|
||||
|
||||
A comment on the line just preceding a job definition is considered the job
|
||||
A comment on the line just preceding a job definition is considered the job
|
||||
description.
|
||||
|
||||
Remember that script OVERRIDES all settings on single jobs sections or channel
|
||||
Remember that script OVERRIDES all settings on single jobs sections or channel
|
||||
sections of the configuration
|
||||
|
||||
5. EXAMPLE OF SCRIPT
|
||||
@@ -219,7 +244,7 @@ sections of the configuration
|
||||
# Search indexing every 2 hours (i'm setting this as the job description)
|
||||
0 */2 * * * search_cron
|
||||
|
||||
# I'll check for module status only on sunday nights
|
||||
# I'll check for module status only on sunday nights
|
||||
# (and this is will not be the job description, see the empty line below)
|
||||
|
||||
0 2 * * 0 update_status_cron
|
||||
|
@@ -8,9 +8,11 @@
|
||||
if (!file_exists('includes/bootstrap.inc')) {
|
||||
if (!empty($_SERVER['DOCUMENT_ROOT']) && file_exists($_SERVER['DOCUMENT_ROOT'] . '/includes/bootstrap.inc')) {
|
||||
chdir($_SERVER['DOCUMENT_ROOT']);
|
||||
} elseif (preg_match('@^(.*)[\\\\/]sites[\\\\/][^\\\\/]+[\\\\/]modules[\\\\/]([^\\\\/]+[\\\\/])?elysia(_cron)?$@', getcwd(), $r) && file_exists($r[1] . '/includes/bootstrap.inc')) {
|
||||
}
|
||||
elseif (preg_match('@^(.*)[\\\\/]sites[\\\\/][^\\\\/]+[\\\\/]modules[\\\\/]([^\\\\/]+[\\\\/])?elysia(_cron)?$@', getcwd(), $r) && file_exists($r[1] . '/includes/bootstrap.inc')) {
|
||||
chdir($r[1]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
die("Cron Fatal Error: Can't locate bootstrap.inc. Check cron.php position.");
|
||||
}
|
||||
}
|
||||
@@ -21,16 +23,14 @@ if (!file_exists('includes/bootstrap.inc')) {
|
||||
define('DRUPAL_ROOT', getcwd());
|
||||
|
||||
include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
|
||||
drupal_override_server_variables(array(
|
||||
'SCRIPT_NAME' => '/cron.php',
|
||||
));
|
||||
drupal_override_server_variables(array('SCRIPT_NAME' => '/cron.php'));
|
||||
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
|
||||
|
||||
if (!isset($_GET['cron_key']) || variable_get('cron_key', 'drupal') != $_GET['cron_key']) {
|
||||
if ((variable_get('cron_key') && empty($_GET['cron_key'])) || !empty($_GET['cron_key']) && variable_get('cron_key') != $_GET['cron_key']) {
|
||||
watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE);
|
||||
drupal_access_denied();
|
||||
}
|
||||
elseif (variable_get('maintenance_mode', 0)) {
|
||||
elseif (variable_get('maintenance_mode', 0) && !variable_get('elysia_cron_run_maintenance', FALSE)) {
|
||||
watchdog('cron', 'Cron could not run because the site is in maintenance mode.', array(), WATCHDOG_NOTICE);
|
||||
drupal_access_denied();
|
||||
}
|
||||
|
@@ -1,13 +0,0 @@
|
||||
diff --git a/elysia_cron.admin.inc b/elysia_cron.admin.inc
|
||||
index fa5c6de..4011d91 100644
|
||||
--- a/elysia_cron.admin.inc
|
||||
+++ b/elysia_cron.admin.inc
|
||||
@@ -42,7 +42,7 @@ function elysia_cron_admin_page() {
|
||||
|
||||
$rows = array();
|
||||
|
||||
- $ipath = url(drupal_get_path('module', 'elysia_cron') . '/images/icon_');
|
||||
+ $ipath = file_create_url(drupal_get_path('module', 'elysia_cron') . '/images/icon_');
|
||||
|
||||
foreach ($elysia_cron_settings_by_channel as $channel => $data) {
|
||||
$running = elysia_cron_is_channel_running($channel);
|
@@ -1,35 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************************
|
||||
* INTERFACE
|
||||
*
|
||||
* WARN: Below this point the word "context" should be avoided (use channel)
|
||||
* Disabled should always be referenced as "disabled" (in db is "disable" for
|
||||
* compatibility with Ctools )
|
||||
******************************************************************************/
|
||||
/**
|
||||
* @file
|
||||
* Admin page callbacks for the elysia cron module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page callback for 'admin/config/system/cron' path.
|
||||
*
|
||||
* @return array
|
||||
* Renderable array.
|
||||
*/
|
||||
function elysia_cron_admin_page() {
|
||||
$aoutput = array();
|
||||
$aoutput[] = drupal_get_form('elysia_cron_run_form');
|
||||
|
||||
$output = '';
|
||||
|
||||
elysia_cron_initialize();
|
||||
|
||||
global $elysia_cron_settings, $elysia_cron_settings_by_channel, $elysia_cron_current_channel, $cron_completed, $cron_completed_time;
|
||||
|
||||
$v = variable_get('elysia_cron_disabled', false);
|
||||
$output .= '<p>' . t('Global disable') . ': <i>' . ($v ? '<span class="warn">' . t('YES') . '</span>' : 'no') . '</i></p>';
|
||||
$output .= '<p>' . t('Last channel executed') . ': <i>' . (($c = elysia_cron_last_channel()) ? $c : t('n/a')) . '</i></p>';
|
||||
|
||||
if (EC_DRUPAL_VERSION < 7) {
|
||||
if (_ec_variable_get('elysia_cron_semaphore', 0)) {
|
||||
$output .= '<p><span class="warn">' . t('Global semaphore active since !date', array('!date' => elysia_cron_date(_ec_variable_get('elysia_cron_semaphore', 0)))) . '</span></p>';
|
||||
}
|
||||
if (elysia_cron_access('execute elysia_cron')) {
|
||||
$aoutput[] = drupal_get_form('elysia_cron_run_form');
|
||||
}
|
||||
|
||||
$output = '';
|
||||
elysia_cron_initialize();
|
||||
global $_elysia_cron_settings_by_channel;
|
||||
|
||||
$global_disabled = variable_get('elysia_cron_disabled', FALSE);
|
||||
$last_channel = elysia_cron_last_channel();
|
||||
$output .= '<p>' . t('Global disable') . ': <i>' . ($global_disabled ? '<span class="warn">' . t('YES') . '</span>' : t('no')) . '</i></p>';
|
||||
$output .= '<p>' . t('Last channel executed') . ': <i>' . ($last_channel ? $last_channel : t('n/a')) . '</i></p>';
|
||||
|
||||
$running = '';
|
||||
foreach ($elysia_cron_settings_by_channel as $channel => $data) {
|
||||
foreach ($_elysia_cron_settings_by_channel as $channel => $data) {
|
||||
if (elysia_cron_is_channel_running($channel)) {
|
||||
$running .= $channel . ' ';
|
||||
}
|
||||
@@ -39,19 +38,33 @@ function elysia_cron_admin_page() {
|
||||
}
|
||||
|
||||
$output .= '<p>' . t('Last run') . ': ' . elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0)) . '</p>';
|
||||
|
||||
$rows = array();
|
||||
|
||||
$ipath = file_create_url(drupal_get_path('module', 'elysia_cron') . '/images/icon_');
|
||||
|
||||
foreach ($elysia_cron_settings_by_channel as $channel => $data) {
|
||||
$ipath = drupal_get_path('module', 'elysia_cron') . '/images/icon_';
|
||||
|
||||
foreach ($_elysia_cron_settings_by_channel as $channel => $data) {
|
||||
$running = elysia_cron_is_channel_running($channel);
|
||||
$rows[] = array(
|
||||
array('data' => '<h3>' . t('Channel') . ': ' . $channel . ($data['#data']['disabled'] ? ' <span class="warn">(' . t('DISABLED') . ')</span>' : '') . '</h3>', 'colspan' => 2, 'header' => 'true'),
|
||||
array('data' => elysia_cron_date($data['#data']['last_run']), 'header' => 'true'),
|
||||
array('data' => $data['#data']['last_execution_time'] . 's ' . t('(Shutdown: !shutdown)', array('!shutdown' => $data['#data']['last_shutdown_time'] . 's')), 'header' => 'true'),
|
||||
array('data' => $data['#data']['execution_count'], 'header' => 'true'),
|
||||
array('data' => $data['#data']['avg_execution_time'] . 's / ' . $data['#data']['max_execution_time'] . 's', 'header' => 'true'),
|
||||
array(
|
||||
'data' => '<h3>' . t('Channel') . ': ' . $channel . ($data['#data']['disabled'] ? ' <span class="warn">(' . t('DISABLED') . ')</span>' : '') . '</h3>',
|
||||
'colspan' => 2,
|
||||
'header' => TRUE,
|
||||
),
|
||||
array(
|
||||
'data' => elysia_cron_date($data['#data']['last_run']),
|
||||
'header' => TRUE,
|
||||
),
|
||||
array(
|
||||
'data' => $data['#data']['last_execution_time'] . 's ' . t('(Shutdown: !shutdown)', array('!shutdown' => $data['#data']['last_shutdown_time'] . 's')),
|
||||
'header' => TRUE,
|
||||
),
|
||||
array(
|
||||
'data' => $data['#data']['execution_count'],
|
||||
'header' => TRUE,
|
||||
),
|
||||
array(
|
||||
'data' => $data['#data']['avg_execution_time'] . 's / ' . $data['#data']['max_execution_time'] . 's',
|
||||
'header' => TRUE,
|
||||
),
|
||||
);
|
||||
$messages = '';
|
||||
if ($running) {
|
||||
@@ -68,10 +81,14 @@ function elysia_cron_admin_page() {
|
||||
$messages .= implode(', ', $msg) . '<br />';
|
||||
}
|
||||
if ($messages) {
|
||||
$rows[] = array( '', '', array('data' => $messages, 'colspan' => 4, 'header' => true) );
|
||||
$rows[] = array( array('data' => '', 'colspan' => 6) );
|
||||
$rows[] = array(
|
||||
'',
|
||||
'',
|
||||
array('data' => $messages, 'colspan' => 4, 'header' => TRUE),
|
||||
);
|
||||
$rows[] = array(array('data' => '', 'colspan' => 6));
|
||||
}
|
||||
|
||||
|
||||
foreach ($data as $job => $conf) {
|
||||
$icon = 'idle';
|
||||
$caption = '<b>' . $job . '</b>';
|
||||
@@ -90,16 +107,25 @@ function elysia_cron_admin_page() {
|
||||
$icon = 'waiting';
|
||||
$tip = t('Waiting for execution');
|
||||
}
|
||||
|
||||
|
||||
if ($job != '#data') {
|
||||
$force_run = elysia_cron_access('execute elysia_cron')
|
||||
? l(t('Force run'), 'admin/config/system/cron/execute/' . $job, array('attributes' => array('onclick' => 'return confirm("' . t('Force execution of !job?', array('!job' => $job)) . '");')))
|
||||
: '';
|
||||
|
||||
$icon_image = theme('image', array(
|
||||
'path' => $ipath . $icon . '.png',
|
||||
'alt' => $tip,
|
||||
'title' => $tip,
|
||||
));
|
||||
$rows[] = array(
|
||||
array( 'data' => '<img src="' . $ipath . $icon . '.png" width="16" height="16" align="top" alt="' . $tip . '" title="' . $tip . '" />', 'align' => 'right' ),
|
||||
array( 'data' => $caption . ': <i>' . elysia_cron_description($job) . '</i> ', 'colspan' => 4 ),
|
||||
array( 'data' => _dco_l(t('Force run'), _dcf_internal_path('admin/config/system/cron/execute/') . $job, array('attributes' => array('onclick' => 'return confirm("' . t('Force execution of !job?', array('!job' => $job)) . '");'))), 'align' => 'right'),
|
||||
array('data' => $icon_image, 'align' => 'right'),
|
||||
array('data' => $caption . ': <i>' . elysia_cron_description($job) . '</i> ', 'colspan' => 4),
|
||||
array('data' => $force_run, 'align' => 'right'),
|
||||
);
|
||||
$rows[] = array(
|
||||
'',
|
||||
$conf['rule'] . (!empty($conf['weight']) ? ' <small>(' . t('Weight') . ': ' . $conf['weight'] . ')</small>' : ''),
|
||||
check_plain($conf['rule']) . (!empty($conf['weight']) ? ' <small>(' . t('Weight') . ': ' . $conf['weight'] . ')</small>' : ''),
|
||||
elysia_cron_date($conf['last_run']),
|
||||
$conf['last_execution_time'] . 's',
|
||||
$conf['execution_count'],
|
||||
@@ -107,21 +133,38 @@ function elysia_cron_admin_page() {
|
||||
);
|
||||
}
|
||||
}
|
||||
$rows[] = array(' ','','','','','');
|
||||
|
||||
$rows[] = array(' ', '', '', '', '', '');
|
||||
}
|
||||
|
||||
$output .= _dco_theme('table', array('header' => array('', t('Job / Rule'), t('Last run'), t('Last exec time'), t('Exec count'), t('Avg/Max Exec time')), 'rows' => $rows));
|
||||
|
||||
$output .= theme('table', array(
|
||||
'header' => array(
|
||||
'',
|
||||
t('Job / Rule'),
|
||||
t('Last run'),
|
||||
t('Last exec time'),
|
||||
t('Exec count'),
|
||||
t('Avg/Max Exec time'),
|
||||
),
|
||||
'rows' => $rows,
|
||||
));
|
||||
$output .= '<br />';
|
||||
|
||||
$output .= _dco_theme('table', array(
|
||||
|
||||
$legend_icons = array(
|
||||
'idle' => theme('image', array('path' => $ipath . 'idle.png')),
|
||||
'waiting' => theme('image', array('path' => $ipath . 'waiting.png')),
|
||||
'running' => theme('image', array('path' => $ipath . 'running.png')),
|
||||
'disabled' => theme('image', array('path' => $ipath . 'disabled.png')),
|
||||
);
|
||||
$output .= theme('table', array(
|
||||
'header' => array(t('Legend')),
|
||||
'rows' => array(
|
||||
array('<img src="' . $ipath . 'idle.png" width="16" height="16" align="top" alt="' . $tip . '" title="' . $tip . '" /> ' . t('Job shouldn\'t do anything right now')),
|
||||
array('<img src="' . $ipath . 'waiting.png" width="16" height="16" align="top" alt="' . $tip . '" title="' . $tip . '" /> ' . t('Job is ready to be executed, and is waiting for system cron call')),
|
||||
array('<img src="' . $ipath . 'running.png" width="16" height="16" align="top" alt="' . $tip . '" title="' . $tip . '" /> ' . t('Job is running right now')),
|
||||
array('<img src="' . $ipath . 'disabled.png" width="16" height="16" align="top" alt="' . $tip . '" title="' . $tip . '" /> ' . t('Job is disabled by settings, and won\'t run until enabled again')),
|
||||
array(t('Notes: job times don\'t include shutdown times (only shown on channel times).')),
|
||||
array(t('If an abort occours usually the job is not properly terminated, and so job timings can be inaccurate or wrong.')),
|
||||
array($legend_icons['idle'] . ' - ' . t("Job shouldn't do anything right now")),
|
||||
array($legend_icons['waiting'] . ' - ' . t('Job is ready to be executed, and is waiting for system cron call')),
|
||||
array($legend_icons['running'] . ' - ' . t('Job is running right now')),
|
||||
array($legend_icons['disabled'] . ' - ' . t("Job is disabled by settings, and won't run until enabled again")),
|
||||
array(t("Notes: job times don't include shutdown times (only shown on channel times).")),
|
||||
array(t('If an abort occurs usually the job is not properly terminated, and so job timings can be inaccurate or wrong.')),
|
||||
),
|
||||
));
|
||||
|
||||
@@ -130,11 +173,17 @@ function elysia_cron_admin_page() {
|
||||
'#markup' => $output,
|
||||
);
|
||||
|
||||
return _dcr_render_array($aoutput);
|
||||
return $aoutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder for general settings form.
|
||||
*
|
||||
* @return array
|
||||
* From API array.
|
||||
*/
|
||||
function elysia_cron_settings_form() {
|
||||
global $elysia_cron_settings, $elysia_cron_settings_by_channel;
|
||||
global $_elysia_cron_settings_by_channel;
|
||||
elysia_cron_initialize();
|
||||
|
||||
$form = array();
|
||||
@@ -142,8 +191,8 @@ function elysia_cron_settings_form() {
|
||||
$form['prefix_1'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Click for help and cron rules and script syntax'),
|
||||
'#collapsible' => true,
|
||||
'#collapsed' => true,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#description' => t(<<<EOT
|
||||
<h3>Fields order</h3>
|
||||
<pre>
|
||||
@@ -190,7 +239,7 @@ or to change the scheduling of an existing job.</p>
|
||||
<code>
|
||||
<-> [rule] <ch:CHANNEL> [job]
|
||||
</code>
|
||||
<p>(Tokens betweens [] are mandatory)</p>
|
||||
<p>(Tokens between [] are mandatory)</p>
|
||||
<ul>
|
||||
<li><->: a line starting with "-" means that the job is DISABLED.</li>
|
||||
<li>[rule]: a crontab schedule rule. See above.</li>
|
||||
@@ -216,13 +265,13 @@ or to change the scheduling of an existing job.</p>
|
||||
# Disable node_cron (i must set the cron rule even if disabled)
|
||||
- */15 * * * * node_cron
|
||||
|
||||
# Launch function send_summary_mail('test@test.com', false); every night
|
||||
# Launch function send_summary_mail('test@test.com', FALSE); every night
|
||||
# And set its description to "Send daily summary"
|
||||
# Send daily summary
|
||||
0 1 * * * send_summary_mail('test@test.com', false);
|
||||
0 1 * * * send_summary_mail('test@test.com', FALSE);
|
||||
</pre>
|
||||
EOT
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$form['prefix_2'] = array(
|
||||
@@ -232,54 +281,71 @@ EOT
|
||||
$form['main'] = array(
|
||||
'#title' => t('Main'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => false,
|
||||
'#collapsed' => false,
|
||||
'#collapsible' => FALSE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
$form['main']['elysia_cron_disabled'] = array(
|
||||
'#title' => t('Global disable'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => variable_get('elysia_cron_disabled', false),
|
||||
'#default_value' => variable_get('elysia_cron_disabled', FALSE),
|
||||
);
|
||||
$form['main']['elysia_cron_run_maintenance'] = array(
|
||||
'#title' => t('Run in maintenance'),
|
||||
'#description' => t('Allow to run cron in maintenance mode.'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => variable_get('elysia_cron_run_maintenance', FALSE),
|
||||
);
|
||||
|
||||
$form['installation'] = array(
|
||||
'#title' => t('Installation settings'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
'#collapsed' => true,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
|
||||
if (EC_DRUPAL_VERSION >= 7) {
|
||||
$form['installation']['cron_safe_threshold'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Run cron on visitor\'s requests, every'),
|
||||
'#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
|
||||
'#description' => t('Setting a time here will enable the "poormanscron" method, which runs the Drupal cron operation using normal browser/page requests instead of having to set up a crontab to request the cron.php script. This approach requires that your site gets regular traffic/visitors in order to trigger the cron request.') . '<br />' .
|
||||
t('This way is fine if you don\'t need a great control over job starting times and execution frequency.') . '<br />' .
|
||||
t('If you need a fine grained control over cron timings use the crontab metod, as <a href="!cron_url">described in Drupal installation guide</a>.', array('!cron_url' => url('http://drupal.org/cron'))) . '<br />' .
|
||||
t('If you have a very large site, or you need to execute some jobs very often (more than once an hour) refer to Elysia cron\'s INSTALL.TXT to improve main cron setup.'),
|
||||
'#options' => array(0 => t('Never / Use external crontab')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'),
|
||||
);
|
||||
}
|
||||
$options[0] = t('Never / Use external crontab');
|
||||
$options += drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval');
|
||||
$form['installation']['cron_safe_threshold'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t("Run cron on visitor's requests, every"),
|
||||
'#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
|
||||
'#description' => t('Setting a time here will enable the "poormanscron" method, which runs the Drupal cron operation using normal browser/page requests instead of having to set up a crontab to request the cron.php script. This approach requires that your site gets regular traffic/visitors in order to trigger the cron request.')
|
||||
. '<br>'
|
||||
. t("This way is fine if you don't need a great control over job starting times and execution frequency.")
|
||||
. '<br />'
|
||||
. t('If you need fine-grained control over cron timings use the crontab method, as <a href="!cron_url">described in Drupal installation guide</a>.', array('!cron_url' => url('http://drupal.org/cron')))
|
||||
. '<br />'
|
||||
. t("If you have a very large site, or you need to execute some jobs very often (more than once an hour) refer to Elysia cron's INSTALL.TXT to improve main cron setup."),
|
||||
'#options' => $options,
|
||||
);
|
||||
|
||||
$form['installation']['elysia_cron_queue_show_count'] = array(
|
||||
'#title' => t('Show the number of items in queues'),
|
||||
'#description' => t('Some queue backends may have performance issue related with counting items in queue. If you faced with it, just disable this option.'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => variable_get('elysia_cron_queue_show_count', TRUE),
|
||||
);
|
||||
|
||||
$form['installation']['cron_key'] = array(
|
||||
'#title' => t('Cron key'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('cron_key', ''),
|
||||
'#description' => t('This is used to avoid external cron calling. If you set this cron will by accessible only by calling http://site/cron.php?cron_key=XXX, so you\'ll need to modify system crontab to support this (Logged user with [administer elysia_cron] permission avoid this check).'),
|
||||
'#default_value' => variable_get('cron_key'),
|
||||
'#description' => t("This is used to avoid external cron calling. If you set this cron will by accessible only by calling <em>http://site/cron.php?cron_key=XXX</em>, so you'll need to modify system crontab to support this (Logged users with <em>execute elysia_cron</em> permission avoid this check).
|
||||
<br>If you left this field empty, you can run cron without cron_key parameter, like this <em>http://site/cron.php</em>, but it <b>HIGHLY NOT RECOMMENDED</b>."),
|
||||
);
|
||||
|
||||
$form['installation']['elysia_cron_allowed_hosts'] = array(
|
||||
'#title' => t('Allowed hosts'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('elysia_cron_allowed_hosts', ''),
|
||||
'#description' => t('Insert a list of ip addresses separated by , that can run cron.php (Logged user with [administer elysia_cron] permission avoid this check).'),
|
||||
'#description' => t('Insert a list of ip addresses separated by , that can run cron.php (Logged user with [execute elysia_cron] permission avoid this check).'),
|
||||
);
|
||||
|
||||
$form['installation']['elysia_cron_default_rule'] = array(
|
||||
'#title' => t('Default schedule rule'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('elysia_cron_default_rule', false),
|
||||
'#description' => t('If you don\'t specify a rule for a process, and if it has not a module specified one, this rule will apply'),
|
||||
'#default_value' => variable_get('elysia_cron_default_rule', FALSE),
|
||||
'#description' => t("If you don't specify a rule for a process, and if it has not a module specified one, this rule will apply"),
|
||||
);
|
||||
|
||||
if (!ini_get('safe_mode')) {
|
||||
@@ -309,25 +375,25 @@ EOT
|
||||
'#description' => t('Enable extended logging (in watchdog)'),
|
||||
);
|
||||
|
||||
$default_ruless = '';
|
||||
$default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']);
|
||||
$default_rules_human = '';
|
||||
$default_rules = variable_get('elysia_cron_default_rules', _elysia_cron_default_rules());
|
||||
foreach ($default_rules as $dk => $dr) {
|
||||
$default_ruless .= $dr . ' = ' . $dk . "\n";
|
||||
$default_rules_human .= $dr . ' = ' . $dk . PHP_EOL;
|
||||
}
|
||||
|
||||
$form['installation']['elysia_cron_default_rules'] = array(
|
||||
'#title' => t('Predefined rules'),
|
||||
'#type' => 'textarea',
|
||||
'#rows' => 5,
|
||||
'#default_value' => $default_ruless,
|
||||
'#default_value' => $default_rules_human,
|
||||
'#description' => t('You can put here standard rules used in your system, each one with its own caption. Put each rule in a separate line, in the form "caption = rule". For example: <i>"every 15 minutes = */15 * * * *"</i>.'),
|
||||
);
|
||||
|
||||
$form['installation']['elysia_cron_alert_fieldset'] = array(
|
||||
'#title' => t('External cron tracking'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
'#collapsed' => true,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#description' => t('This lets you use an external tracking system like <a href="http://www.host-tracker.com/">Host Tracker</a> to be used to monitor the health of cron on your site. Point the tracking service to <a href="!cron-ping-url">!cron-ping-url</a>. If Elysia cron has been called within the time interval specified below, the ping page will return HTTP 200. If not, the ping page will throw a 404 (page not found).', array('!cron-ping-url' => url('admin/build/cron/ping'))),
|
||||
);
|
||||
$form['installation']['elysia_cron_alert_fieldset']['elysia_cron_alert_interval'] = array(
|
||||
@@ -341,49 +407,46 @@ EOT
|
||||
$form['elysia_cron_script_fieldset'] = array(
|
||||
'#title' => t('Script'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => !variable_get('elysia_cron_script', ''),
|
||||
);
|
||||
$form['elysia_cron_script_fieldset']['elysia_cron_script'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#rows' => 20,
|
||||
'#default_value' => variable_get('elysia_cron_script', ''),
|
||||
'#description' => t('You can specify new cron jobs or modify existing schedules by adding lines to the script.<br>' .
|
||||
'<b>Warning</b> All rules specified in the script will OVERRIDE single job settings and channel settings (sections below).'),
|
||||
'#description' => t('You can specify new cron jobs or modify existing schedules by adding lines to the script.')
|
||||
. '<br />'
|
||||
. t('<b>Warning</b> All rules specified in the script will OVERRIDE single job settings and channel settings (sections below).'),
|
||||
);
|
||||
|
||||
|
||||
$form['single_job'] = array(
|
||||
'#title' => t('Single job settings'),
|
||||
'#description' =>
|
||||
'<b>'.t('Disabled').'</b>: '.t('Flag this to disable job execution').'<br />'.
|
||||
'<b>'.t('Schedule rule').'</b>: '.t('Timing rule for the job. Leave empty to use default rule (shown after the field in parenthesis)').'<br />'.
|
||||
'<b>'.t('Weight').'</b>: '.t('Use this to specify execution order: low weights are executed before high weights. Default value shown in parenthesis').'<br />'.
|
||||
'<b>'.t('Channel').'</b>: '.t('Specify a channel for the job (create the channel if not exists)').'<br /><br />',
|
||||
'#description' => '<b>' . t('Disabled') . '</b>: ' . t('Flag this to disable job execution') . '<br />'
|
||||
. '<b>' . t('Schedule rule') . '</b>: ' . t('Timing rule for the job. Leave empty to use default rule (shown after the field in parenthesis)') . '<br />'
|
||||
. '<b>' . t('Weight') . '</b>: ' . t('Use this to specify execution order: low weights are executed before high weights. Default value shown in parenthesis') . '<br />'
|
||||
. '<b>' . t('Channel') . '</b>: ' . t('Specify a channel for the job (create the channel if not exists)') . '<br /><br />',
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
//'#collapsed' => true,
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
|
||||
|
||||
$jobchannels = array(
|
||||
'#title' => t('Job channel associations'),
|
||||
'#description' => t('Leave empty for default channel'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
'#collapsed' => true,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
|
||||
foreach ($elysia_cron_settings_by_channel as $channel => $cconf) {
|
||||
foreach ($_elysia_cron_settings_by_channel as $channel => $cconf) {
|
||||
foreach ($cconf as $job => $conf) {
|
||||
if ($job != '#data' && empty($conf['expression'])) {
|
||||
$form['single_job']['elysia_cron_' . $job] = array(
|
||||
'#title' => $job, // t('Job !job', array('!job' => $job)),
|
||||
'#title' => $job,
|
||||
'#description' => elysia_cron_description($job),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => !elysia_cron_get_job_rule($job) && !elysia_cron_get_job_weight($job) && !elysia_cron_is_job_disabled($job) && !elysia_cron_get_job_channel($job),
|
||||
);
|
||||
//if (!$form['single_job']['elysia_cron_'.$job]['#collapsed'])
|
||||
// $form['single_job']['#collapsed'] = false;
|
||||
|
||||
$rule = elysia_cron_get_job_rule($job);
|
||||
$options = array_merge(array('default' => t('Default') . ' (' . (!empty($default_rules[$conf['default_rule']]) ? $default_rules[$conf['default_rule']] : $conf['default_rule']) . ')'), $default_rules);
|
||||
@@ -414,23 +477,18 @@ EOT
|
||||
'#description' => '(' . $conf['default_weight'] . ')',
|
||||
);
|
||||
|
||||
//$form['single_job']['elysia_cron_'.$job]['elysia_cron_'.$job.'_disabled'] = array(
|
||||
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_disabled_' . $job] = array(
|
||||
'#title' => t('Disabled'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => elysia_cron_is_job_disabled($job, false),
|
||||
'#default_value' => elysia_cron_is_job_disabled($job, FALSE),
|
||||
);
|
||||
|
||||
//$jobchannels['elysia_cron_'.$job.'_channel'] = array(
|
||||
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_channel_' . $job] = array(
|
||||
'#title' => t('Channel'), // t('Channel for !job', array('!job' => $job)),
|
||||
'#title' => t('Channel'),
|
||||
'#type' => 'textfield',
|
||||
'#size' => 20,
|
||||
'#default_value' => elysia_cron_get_job_channel($job),
|
||||
);
|
||||
|
||||
//if (elysia_cron_get_job_channel($job))
|
||||
// $jobchannels['#collapsed'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,13 +496,12 @@ EOT
|
||||
$form['channels'] = array(
|
||||
'#title' => t('Channels settings'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => true,
|
||||
//'#collapsed' => $jobchannels['#collapsed'],
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
|
||||
foreach ($elysia_cron_settings_by_channel as $channel => $conf) {
|
||||
foreach ($_elysia_cron_settings_by_channel as $channel => $conf) {
|
||||
$form['channels']['elysia_cron_ch_' . $channel] = array(
|
||||
'#title' => $channel, // t('Channel !channel', array('!channel' => $channel)),
|
||||
'#title' => $channel,
|
||||
'#type' => 'fieldset',
|
||||
);
|
||||
$form['channels']['elysia_cron_ch_' . $channel]['_elysia_cron_ch_disabled_' . $channel] = array(
|
||||
@@ -458,12 +515,8 @@ EOT
|
||||
'#size' => 20,
|
||||
'#default_value' => elysia_cron_get_channel_rule($channel),
|
||||
);
|
||||
//if (elysia_cron_is_channel_disabled($channel))
|
||||
// $form['channels']['#collapsed'] = false;
|
||||
}
|
||||
|
||||
//$form['channels']['jobchannels'] = $jobchannels;
|
||||
|
||||
$form['buttons'] = array('#type' => 'actions');
|
||||
$form['buttons']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
@@ -478,17 +531,22 @@ EOT
|
||||
elysia_cron_error('The settings have not been saved because of the errors.');
|
||||
}
|
||||
|
||||
return _dcr_form($form);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function theme_elysia_cron_settings_form($_dco_variables) {
|
||||
extract(_dcf_theme_form($_dco_variables));
|
||||
/**
|
||||
* Theme function for general settings form.
|
||||
*
|
||||
* @param array $variables
|
||||
* Theme vars.
|
||||
*
|
||||
* @return string
|
||||
* Ready for print HTML.
|
||||
*/
|
||||
function theme_elysia_cron_settings_form(array &$variables) {
|
||||
$form = &$variables['form'];
|
||||
|
||||
$output = '<script type="text/javascript"><!--' . "\n" .
|
||||
/*'function _ec_select(editid, select) { if (select.value == \'custom\') {'.
|
||||
'$ = jQuery; $(select).hide();$("#"+editid).show();$("#"+editid).focus();'.
|
||||
'}}'.*/
|
||||
'function _ec_select(key, select) { if (select.value == \'custom\') {' .
|
||||
'$ = jQuery; $("#_ec_select_"+key).hide();$("#_ec_custom_"+key).show();$("#_ec_custom_"+key).focus();' .
|
||||
'}}' .
|
||||
@@ -499,33 +557,28 @@ function theme_elysia_cron_settings_form($_dco_variables) {
|
||||
$i = 0;
|
||||
foreach (element_children($form['single_job']) as $c) {
|
||||
$key = substr($c, 12);
|
||||
//print_r($form['single_job'][$c]);
|
||||
if ($i++ == 0) {
|
||||
$coutput .= '<tr>' .
|
||||
'<th>' . $form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]['#title'] . '</th>' .
|
||||
'<th>' . $form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#title'] . '</th>' .
|
||||
'<th colspan="2">' . $form['single_job'][$c]['_elysia_cron_job_weight_' . $key]['#title'] . '</th>' .
|
||||
'<th>' . $form['single_job'][$c]['_elysia_cron_job_channel_' . $key]['#title'] . '</th>' .
|
||||
'</tr>';
|
||||
$coutput .= '<tr>'
|
||||
. '<th>' . $form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]['#title'] . '</th>'
|
||||
. '<th>' . $form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#title'] . '</th>'
|
||||
. '<th colspan="2">' . $form['single_job'][$c]['_elysia_cron_job_weight_' . $key]['#title'] . '</th>'
|
||||
. '<th>' . $form['single_job'][$c]['_elysia_cron_job_channel_' . $key]['#title'] . '</th>'
|
||||
. '</tr>';
|
||||
}
|
||||
|
||||
//$def_rule = $form['single_job'][$c]['_elysia_cron_job_rule_'.$key]['#description'];
|
||||
$def_weight = $form['single_job'][$c]['_elysia_cron_job_weight_' . $key]['#description'];
|
||||
|
||||
$posted_key = $form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]['#name'];
|
||||
$posted_val = !empty($_REQUEST[$posted_key]) ? $_REQUEST[$posted_key] : false;
|
||||
$posted_val = !empty($_REQUEST[$posted_key]) ? $_REQUEST[$posted_key] : FALSE;
|
||||
|
||||
$form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#prefix'] = '<span id="_ec_custom_' . $key . '" style="' . ($posted_val != 'custom' ? 'display: none;' : '') . '">';
|
||||
$form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#suffix'] = '</span>';
|
||||
$form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#title'] = NULL;
|
||||
$form['single_job'][$c]['_elysia_cron_job_rule_' . $key]['#description'] = NULL;
|
||||
//$form['single_job'][$c]['_elysia_cron_job_rule_'.$key]['#attributes']['style'] = ($posted_val != 'custom' ? 'display: none;' : '').'width: 20em; margin: 0';
|
||||
$form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]['#prefix'] = '<span id="_ec_select_' . $key . '" style="' . ($posted_val == 'custom' ? 'display: none;' : '') . '">';
|
||||
$form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]['#suffix'] = '</span>';
|
||||
$form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]['#title'] = NULL;
|
||||
$form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]['#description'] = NULL;
|
||||
//$form['single_job'][$c]['_elysia_cron_seljob_rule_'.$key]['#attributes']['style'] = ($posted_val == 'custom' ? 'display: none;' : '').'width: 20em; margin: 0';
|
||||
//$form['single_job'][$c]['_elysia_cron_seljob_rule_'.$key]['#attributes']['onchange'] = '_ec_select(\''.$form['single_job'][$c]['_elysia_cron_job_rule_'.$key]['#id'].'\', this)';
|
||||
$form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]['#attributes']['onchange'] = '_ec_select(\'' . $key . '\', this)';
|
||||
|
||||
$form['single_job'][$c]['_elysia_cron_job_weight_' . $key]['#title'] = NULL;
|
||||
@@ -536,32 +589,30 @@ function theme_elysia_cron_settings_form($_dco_variables) {
|
||||
$form['single_job'][$c]['_elysia_cron_job_channel_' . $key]['#title'] = NULL;
|
||||
$form['single_job'][$c]['_elysia_cron_job_channel_' . $key]['#attributes']['style'] = 'margin: 0';
|
||||
|
||||
$coutput .= '<tr><td colspan="6"><b>' . $form['single_job'][$c]['#title'] . '</b>' . (($d = $form['single_job'][$c]['#description']) && $d != '-' ? ' <i>(' . $d . ')</i>' : '' ) . '</td></tr>';
|
||||
$coutput .= '<tr>' .
|
||||
'<td align="center">' . drupal_render($form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]) . '</td>' .
|
||||
'<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]) . drupal_render($form['single_job'][$c]['_elysia_cron_job_rule_' . $key]) . '</td>' .//'<td><small>'.$def_rule.'</small></td>'.
|
||||
'<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_weight_' . $key]) . '</td><td><small>' . $def_weight . '</small></td>' .
|
||||
'<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_channel_' . $key]) . '</td>' .
|
||||
'</tr>';
|
||||
$coutput .= '<tr><td colspan="6"><b>' . $form['single_job'][$c]['#title'] . '</b>' . (($d = $form['single_job'][$c]['#description']) && $d != '-' ? ' <i>(' . $d . ')</i>' : '') . '</td></tr>';
|
||||
$coutput .= '<tr>'
|
||||
. '<td align="center">' . drupal_render($form['single_job'][$c]['_elysia_cron_job_disabled_' . $key]) . '</td>'
|
||||
. '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_seljob_rule_' . $key]) . drupal_render($form['single_job'][$c]['_elysia_cron_job_rule_' . $key]) . '</td>'
|
||||
. '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_weight_' . $key]) . '</td><td><small>' . $def_weight . '</small></td>'
|
||||
. '<td>' . drupal_render($form['single_job'][$c]['_elysia_cron_job_channel_' . $key]) . '</td>'
|
||||
. '</tr>';
|
||||
drupal_render($form['single_job'][$c]);
|
||||
}
|
||||
$coutput .= '</table>';
|
||||
|
||||
$form['single_job']['#children'] = $coutput;
|
||||
//$form['single_job'][] = array('#type' => 'markup', '#markup' => $output);
|
||||
|
||||
$coutput = '<table>';
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach (element_children($form['channels']) as $c) {
|
||||
$key = substr($c, 15);
|
||||
if ($i++ == 0) {
|
||||
$coutput .= '<tr>' .
|
||||
'<th>' . t('Name') . '</th>' .
|
||||
'<th>' . $form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]['#title'] . '</th>' .
|
||||
'<th>' . $form['channels'][$c]['_elysia_cron_ch_rule_' . $key]['#title'] . '</th>' .
|
||||
'</tr>';
|
||||
$coutput .= '<tr>'
|
||||
. '<th>' . t('Name') . '</th>'
|
||||
. '<th>' . $form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]['#title'] . '</th>'
|
||||
. '<th>' . $form['channels'][$c]['_elysia_cron_ch_rule_' . $key]['#title'] . '</th>'
|
||||
. '</tr>';
|
||||
}
|
||||
|
||||
$form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]['#title'] = NULL;
|
||||
@@ -569,11 +620,11 @@ function theme_elysia_cron_settings_form($_dco_variables) {
|
||||
$form['channels'][$c]['_elysia_cron_ch_rule_' . $key]['#title'] = NULL;
|
||||
$form['channels'][$c]['_elysia_cron_ch_rule_' . $key]['#attributes']['style'] = 'margin: 0';
|
||||
|
||||
$coutput .= '<tr>' .
|
||||
'<td><b>' . $form['channels'][$c]['#title'] . '</b></td>' .
|
||||
'<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]) . '</td>' .
|
||||
'<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_rule_' . $key]) . '</td>' .
|
||||
'</tr>';
|
||||
$coutput .= '<tr>'
|
||||
. '<td><b>' . $form['channels'][$c]['#title'] . '</b></td>'
|
||||
. '<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_disabled_' . $key]) . '</td>'
|
||||
. '<td>' . drupal_render($form['channels'][$c]['_elysia_cron_ch_rule_' . $key]) . '</td>'
|
||||
. '</tr>';
|
||||
drupal_render($form['channels'][$c]);
|
||||
}
|
||||
$coutput .= '</table>';
|
||||
@@ -581,33 +632,63 @@ function theme_elysia_cron_settings_form($_dco_variables) {
|
||||
$form['channels']['#children'] = $coutput;
|
||||
|
||||
return $output . drupal_render_children($form);
|
||||
//$form['channels'][] = array('#type' => 'markup', '#markup' => $output);
|
||||
//return drupal_render(_dcr_form($form));
|
||||
}
|
||||
|
||||
function elysia_cron_settings_form_validate($_dco_form, &$_dco_form_state) {
|
||||
extract(_dcf_form_validate($_dco_form, $_dco_form_state));
|
||||
global $elysia_cron_settings;
|
||||
/**
|
||||
* Validate handler for 'elysia_cron_settings_form' form.
|
||||
*
|
||||
* @param array $form
|
||||
* Form API array.
|
||||
* @param array $form_state
|
||||
* Filled form_state array with input values.
|
||||
*/
|
||||
function elysia_cron_settings_form_validate(array $form, array &$form_state) {
|
||||
$values = $form_state['values'];
|
||||
|
||||
$script = $form_state['values']['elysia_cron_script'];
|
||||
if ($script) {
|
||||
$errors = elysia_cron_decode_script($script, false);
|
||||
$errors = elysia_cron_decode_script($script, FALSE);
|
||||
if ($errors) {
|
||||
form_set_error('elysia_cron_script', t('Invalid lines:') . implode('<br>', $errors));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($form_state['values'] as $key => $value) {
|
||||
if ($value && preg_match('/^_elysia_cron_([^_]+_[^_]+)_(.*)$/', $key, $r) && ($r[1] == 'job_rule' || $r[1] == 'ch_rule')) {
|
||||
foreach ($values as $key => $value) {
|
||||
if ($value && ((preg_match('/^_elysia_cron_([^_]+_[^_]+)_(.*)$/', $key, $r) && ($r[1] == 'job_rule' || $r[1] == 'ch_rule')) || $key == 'elysia_cron_default_rule')) {
|
||||
if (!preg_match('/^\\s*([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)\\s*$/', $value)) {
|
||||
form_set_error($key, t('Invalid rule: !rule', array('!rule' => $value)));
|
||||
form_set_error($key, t('Invalid rule: %rule', array('%rule' => $value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($values['elysia_cron_default_rules'])) {
|
||||
$rules = explode(PHP_EOL, $values['elysia_cron_default_rules']);
|
||||
foreach ($rules as $rule) {
|
||||
$rule = trim($rule);
|
||||
if (empty($rule)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rule = explode('=', $rule);
|
||||
if (empty($rule[1])) {
|
||||
form_set_error('elysia_cron_default_rules', t('Invalid rule: %rule', array('%rule' => $rule[0])));
|
||||
}
|
||||
elseif (!preg_match('/^\\s*([0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+[ ]+[0-9*,\/-]+)\\s*$/', trim($rule[1]))) {
|
||||
form_set_error('elysia_cron_default_rules', t('Invalid rule: %rule', array('%rule' => $rule[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
extract(_dcf_form_validate($_dco_form, $_dco_form_state));
|
||||
/**
|
||||
* Submit handler for 'elysia_cron_settings_form' form.
|
||||
*
|
||||
* @param array $form
|
||||
* Form API array.
|
||||
* @param array $form_state
|
||||
* Filled form_state array with input values.
|
||||
*/
|
||||
function elysia_cron_settings_form_submit(array $form, array &$form_state) {
|
||||
$form_values = $form_state['values'];
|
||||
|
||||
$op = isset($form_values['op']) ? $form_values['op'] : '';
|
||||
@@ -616,7 +697,7 @@ function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
|
||||
|
||||
$elysia_cron_default_rules = array();
|
||||
$rules = explode("\n", $form_values['elysia_cron_default_rules']);
|
||||
$rules = explode(PHP_EOL, $form_values['elysia_cron_default_rules']);
|
||||
foreach ($rules as $r) {
|
||||
if (trim($r)) {
|
||||
$rr = explode("=", $r);
|
||||
@@ -641,24 +722,28 @@ function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
else {
|
||||
$nullvalue = $r[1] != 'job_weight' ? !$value : !$value && $value !== '0';
|
||||
|
||||
//dprint($r[1].' '.$r[1].' '.$r[2]);
|
||||
if ($op == t('Reset to defaults') || $nullvalue) {
|
||||
switch ($r[1]) {
|
||||
case 'job_channel':
|
||||
elysia_cron_reset_job_channel($r[2]);
|
||||
break;
|
||||
|
||||
case 'job_rule':
|
||||
elysia_cron_reset_job_rule($r[2]);
|
||||
break;
|
||||
|
||||
case 'job_weight':
|
||||
elysia_cron_reset_job_weight($r[2]);
|
||||
break;
|
||||
|
||||
case 'job_disabled':
|
||||
elysia_cron_reset_job_disabled($r[2]);
|
||||
break;
|
||||
|
||||
case 'ch_disabled':
|
||||
elysia_cron_reset_channel_disabled($r[2]);
|
||||
break;
|
||||
|
||||
case 'ch_rule':
|
||||
elysia_cron_reset_channel_rule($r[2]);
|
||||
break;
|
||||
@@ -669,11 +754,13 @@ function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
case 'job_channel':
|
||||
elysia_cron_set_job_channel($r[2], $value);
|
||||
break;
|
||||
|
||||
case 'job_rule':
|
||||
if ($form_values['_elysia_cron_seljob_rule_' . $r[2]] == 'custom') {
|
||||
elysia_cron_set_job_rule($r[2], $value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'seljob_rule':
|
||||
if ($value != 'custom') {
|
||||
if ($value == 'default') {
|
||||
@@ -684,15 +771,19 @@ function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'job_weight':
|
||||
elysia_cron_set_job_weight($r[2], $value);
|
||||
break;
|
||||
|
||||
case 'job_disabled':
|
||||
elysia_cron_set_job_disabled($r[2], $value);
|
||||
break;
|
||||
|
||||
case 'ch_disabled':
|
||||
elysia_cron_set_channel_disabled($r[2], $value);
|
||||
break;
|
||||
|
||||
case 'ch_rule':
|
||||
elysia_cron_set_channel_rule($r[2], $value);
|
||||
break;
|
||||
@@ -701,6 +792,7 @@ function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == t('Reset to defaults')) {
|
||||
elysia_cron_message('The configuration options have been reset to their default values.');
|
||||
}
|
||||
@@ -709,60 +801,89 @@ function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build time in "ago" format.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* Time of latest cron.
|
||||
*
|
||||
* @return string
|
||||
* Date in 'ago' format.
|
||||
*/
|
||||
function elysia_cron_date($timestamp) {
|
||||
return $timestamp > 0 ? format_date($timestamp, EC_DRUPAL_VERSION >= 7 ? 'short' : 'small') : t('n/a');
|
||||
//return date(variable_get('date_format_short', 'm/d/Y - H:i'), $timestamp);
|
||||
return $timestamp > 0 ? t('!time ago', array('!time' => format_interval(REQUEST_TIME - $timestamp, 2))) : t('n/a');
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder for cron run form.
|
||||
*
|
||||
* @return array
|
||||
* From API array.
|
||||
*/
|
||||
function elysia_cron_run_form() {
|
||||
$form = array();
|
||||
$form['runf'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#access' => elysia_cron_access('execute elysia_cron'),
|
||||
);
|
||||
$form['runf']['run'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Run cron'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function elysia_cron_run_form_submit($_dco_form, &$_dco_form_state) {
|
||||
/**
|
||||
* Submit handler for 'elysia_cron_run_form' form.
|
||||
*
|
||||
* @param array $form
|
||||
* Form API array.
|
||||
* @param array $form_state
|
||||
* Filled form_state array with input values.
|
||||
*/
|
||||
function elysia_cron_run_form_submit(array $form, array &$form_state) {
|
||||
// Run cron manually from Cron form.
|
||||
if (elysia_cron_run()) {
|
||||
if (elysia_cron_run(TRUE)) {
|
||||
elysia_cron_message('Cron run successfully.');
|
||||
}
|
||||
else {
|
||||
elysia_cron_error('Cron run failed.');
|
||||
}
|
||||
|
||||
drupal_goto(_dcf_internal_path('admin/config/system/cron'));
|
||||
drupal_goto('admin/config/system/cron');
|
||||
}
|
||||
|
||||
function elysia_cron_execute_page($job = false) {
|
||||
/**
|
||||
* Page callback for 'admin/config/system/cron/execute/%' path.
|
||||
*
|
||||
* @param string $job
|
||||
* Name of cron job to be executed.
|
||||
*/
|
||||
function elysia_cron_execute_page($job = '') {
|
||||
if (!$job) {
|
||||
elysia_cron_error('No job specified');
|
||||
drupal_goto(_dcf_internal_path('admin/config/system/cron'));
|
||||
drupal_goto('admin/config/system/cron');
|
||||
}
|
||||
|
||||
elysia_cron_run_job($job, true, true, false); // Run also if disabled or not ready (but not if it's already running)
|
||||
|
||||
drupal_goto(_dcf_internal_path('admin/config/system/cron'));
|
||||
}
|
||||
|
||||
function elysia_cron_maintenance_page() {
|
||||
$output = array();
|
||||
$output[] = drupal_get_form('elysia_cron_reset_statistics_form');
|
||||
|
||||
return _dcr_render_array($output);
|
||||
// Run also if disabled or not ready (but not if it's already running).
|
||||
elysia_cron_run_job($job, TRUE, TRUE, FALSE);
|
||||
|
||||
drupal_goto('admin/config/system/cron');
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder for statistic reset form.
|
||||
*
|
||||
* @return array
|
||||
* From API array.
|
||||
*/
|
||||
function elysia_cron_reset_statistics_form() {
|
||||
$form = array();
|
||||
$form['fieldset'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Reset statistics'),
|
||||
'#description' => t('Deletes all cron execution statistics (Last run, last exec time, exec count, avg/max exec time...). Do not touch cron settings.<br /><b>This operation could not be reverted</b><br />'),
|
||||
'#description' => t('Deletes all cron execution statistics (Last run, last exec time, exec count, avg/max exec time...). Do not touch cron settings.<br /><b>This operation can not be reverted</b><br />'),
|
||||
);
|
||||
|
||||
$form['fieldset']['reset'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Reset'),
|
||||
@@ -770,16 +891,21 @@ function elysia_cron_reset_statistics_form() {
|
||||
'onclick' => 'return confirm(\'' . htmlentities(t('Are you sure you want to reset statistics?')) . '\')',
|
||||
),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function elysia_cron_reset_statistics_form_submit($_dco_form, &$_dco_form_state) {
|
||||
/**
|
||||
* Submit handler for 'elysia_cron_reset_statistics_form' form.
|
||||
*
|
||||
* @param array $form
|
||||
* Form API array.
|
||||
* @param array $form_state
|
||||
* Filled form_state array with input values.
|
||||
*/
|
||||
function elysia_cron_reset_statistics_form_submit(array $form, array &$form_state) {
|
||||
elysia_cron_reset_stats();
|
||||
|
||||
elysia_cron_message('Reset done.');
|
||||
drupal_goto(_dcf_internal_path('admin/config/system/cron/maintenance'));
|
||||
}
|
||||
|
||||
function elysia_cron_reset_page() {
|
||||
elysia_cron_reset_statistics_form_submit(false, $res = array());
|
||||
elysia_cron_message('Reset done.');
|
||||
drupal_goto('admin/config/system/cron/maintenance');
|
||||
}
|
||||
|
134
sites/all/modules/contrib/dev/elysia_cron/elysia_cron.api.php
Normal file
134
sites/all/modules/contrib/dev/elysia_cron/elysia_cron.api.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the Elysia cron module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* You can extend cron functionality in you modules by using elysia_cron api.
|
||||
*
|
||||
* With it you can:
|
||||
* - have more than one cron job per module
|
||||
* - have a different schedule rule for each cron job defined
|
||||
* - set a description for each cron job.
|
||||
*
|
||||
* To do this you should add in you module a new hook. This is the syntax:
|
||||
*
|
||||
* - 'key' is the identifier for the task you are defining.
|
||||
* You can define a timing for the standard cron hook of the module by using
|
||||
* the "MODULENAME_cron" key. (See examples).
|
||||
*
|
||||
* - description:
|
||||
* a textual description of the job, used in elysia cron's status
|
||||
* page. Use the untranslated string, without the "t()" wrapper (elysia_cron
|
||||
* will apply it)
|
||||
*
|
||||
* - rule:
|
||||
* the crontab rule. For example: "0 * * * *" to execute the task every hour.
|
||||
*
|
||||
* - weight (optional):
|
||||
* a numerical value to define order of execution. (Default:0)
|
||||
*
|
||||
* - callback (optional):
|
||||
* you can define here a name of a PHP function that should
|
||||
* by called to execute the task. This is not mandatory: if you don't specify
|
||||
* it Elysia cron will search for a function called like the task KEY.
|
||||
* If this function is not found, Elysia cron will call the "hook_cronapi"
|
||||
* function with $op = 'execute' and $job = 'KEY' (the key of the task).
|
||||
* (See examples)
|
||||
*
|
||||
* - arguments (optional):
|
||||
* an array of arguments passed to callback (only if callback is defined).
|
||||
*
|
||||
* - file/file path:
|
||||
* the PHP file that contains the callback (hook_menu's syntax).
|
||||
*
|
||||
* @param string $op
|
||||
* Operation: "list" or "execute".
|
||||
* @param string|null $job
|
||||
* Name of current job or it is NULL if we define job list.
|
||||
*
|
||||
* @return array
|
||||
* Job list.
|
||||
*/
|
||||
function hook_cronapi($op, $job = NULL) {
|
||||
// General example of all parameters.
|
||||
$items['key'] = array(
|
||||
'description' => 'string',
|
||||
'rule' => 'string',
|
||||
'weight' => 1234,
|
||||
'callback' => 'function_name',
|
||||
'arguments' => array('first', 'second', 3),
|
||||
// External file, like in hook_menu.
|
||||
'file' => 'string',
|
||||
'file path' => 'string',
|
||||
);
|
||||
|
||||
// Run function example_sendmail_cron() every 2 hours.
|
||||
// Note: i don't need to define a callback, i'll use "example_sendmail_cron"
|
||||
// function.
|
||||
$items['example_sendmail_cron'] = array(
|
||||
'description' => 'Send mail with news',
|
||||
'rule' => '0 */2 * * *',
|
||||
);
|
||||
|
||||
// Run example_news_fetch('all') every 5 minutes.
|
||||
// Note: this function has argument.
|
||||
$items['example_news_cron'] = array(
|
||||
'description' => 'Send mail with news',
|
||||
'rule' => '*/5 * * * *',
|
||||
'callback' => 'example_news_fetch',
|
||||
'arguments' => array('all'),
|
||||
);
|
||||
|
||||
// Definition of rules list and embedded code.
|
||||
if ($op == 'list') {
|
||||
// Rules list.
|
||||
$items['job1'] = array(
|
||||
'description' => 'Send mail with news',
|
||||
'rule' => '0 */2 * * *',
|
||||
);
|
||||
|
||||
$items['job2'] = array(
|
||||
'description' => 'Send mail with news',
|
||||
'rule' => '*/5 * * * *',
|
||||
);
|
||||
}
|
||||
elseif ($op == 'execute') {
|
||||
// Embedded code.
|
||||
switch ($job) {
|
||||
case 'job1':
|
||||
// ... job1 code.
|
||||
break;
|
||||
|
||||
case 'job2':
|
||||
// ... job2 code.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Altering hook_cron definition.
|
||||
*
|
||||
* You can use the "hook_cron_alter" function to edit cronapi data of other
|
||||
* modules.
|
||||
*
|
||||
* @param array $data
|
||||
* Array of cron rules.
|
||||
*/
|
||||
function hook_cron_alter(&$data) {
|
||||
$data['key']['rule'] = '0 */6 * * *';
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
@@ -1,11 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************************
|
||||
* EXPORTABLES
|
||||
******************************************************************************/
|
||||
/**
|
||||
* @file
|
||||
* Ctools integration.
|
||||
*/
|
||||
|
||||
// WARN Features button "Revert components" will reset also statistics
|
||||
|
||||
/**
|
||||
* Get default cron jobs.
|
||||
*
|
||||
* @return array
|
||||
* Cron jobs.
|
||||
*/
|
||||
function elysia_cron_get_ctools_defaults() {
|
||||
if (module_exists('ctools') && function_exists('ctools_include')) {
|
||||
ctools_include('export');
|
||||
@@ -14,26 +19,34 @@ function elysia_cron_get_ctools_defaults() {
|
||||
return _ctools_export_get_defaults('elysia_cron', $export);
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctools load callback
|
||||
* Ctools does not support override of PARTIAL record, this is an elysia cron specific replacement to support it
|
||||
* Ctools load callback.
|
||||
*
|
||||
* Ctools does not support override of PARTIAL record,
|
||||
* this is an elysia cron specific replacement to support it.
|
||||
*
|
||||
* @param string $name
|
||||
* Cron job name.
|
||||
*
|
||||
* @return object|null
|
||||
* Object to export or NULL if nothing found.
|
||||
*/
|
||||
function elysia_cron_ctools_export_load($name) {
|
||||
$schema = ctools_export_get_schema('elysia_cron');
|
||||
if (!empty($schema)) {
|
||||
$export = $schema['export'];
|
||||
|
||||
if (EC_DRUPAL_VERSION >= 7) {
|
||||
$object = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = :name", array(':name' => $name))->fetch();
|
||||
}
|
||||
else {
|
||||
$object = db_fetch_object(db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron} where name = '%s'", $name));
|
||||
}
|
||||
|
||||
$object = db_select('elysia_cron', 'ec')
|
||||
->fields('ec', _elysia_cron_columns())
|
||||
->condition('name', $name)
|
||||
->execute()
|
||||
->fetch();
|
||||
$default_objects = _ctools_export_get_defaults('elysia_cron', $export);
|
||||
|
||||
|
||||
if ($object) {
|
||||
if (isset($default_objects[$name])) {
|
||||
return _elysia_cron_ctools_export_load_object_db_and_code($object, $default_objects[$name], $export);
|
||||
@@ -49,62 +62,84 @@ function elysia_cron_ctools_export_load($name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctools load all callback
|
||||
* Ctools does not support override of PARTIAL record, this is an elysia cron specific replacement to support it
|
||||
* Ctools load all callback.
|
||||
*
|
||||
* Ctools does not support override of PARTIAL record,
|
||||
* this is an elysia cron specific replacement to support it.
|
||||
*
|
||||
* @return array
|
||||
* Array of object to export.
|
||||
*/
|
||||
function elysia_cron_ctools_export_load_all() {
|
||||
$schema = ctools_export_get_schema('elysia_cron');
|
||||
if (empty($schema)) {
|
||||
return array();
|
||||
}
|
||||
$export = $schema['export'];
|
||||
|
||||
if (EC_DRUPAL_VERSION >= 7) {
|
||||
$objects = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron}")->fetchAll();
|
||||
}
|
||||
else {
|
||||
$objects = array();
|
||||
$rs = db_query("select " . implode(", ", $GLOBALS['_ec_columns']) . " from {elysia_cron}");
|
||||
while ($o = db_fetch_object($rs)) {
|
||||
$objects[] = $o;
|
||||
}
|
||||
}
|
||||
$default_objects = _ctools_export_get_defaults('elysia_cron', $export);
|
||||
|
||||
$result = array();
|
||||
$schema = ctools_export_get_schema('elysia_cron');
|
||||
|
||||
if (empty($schema)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$export = $schema['export'];
|
||||
|
||||
$objects = db_select('elysia_cron', 'ec')
|
||||
->fields('ec', _elysia_cron_columns())
|
||||
->execute()
|
||||
->fetchAll();
|
||||
$default_objects = _ctools_export_get_defaults('elysia_cron', $export);
|
||||
|
||||
foreach ($objects as $object) {
|
||||
$key = $object->{$export['key']};
|
||||
if (isset($default_objects[$key])) {
|
||||
$result[$key] = _elysia_cron_ctools_export_load_object_db_and_code($object, $default_objects[$key], $export);
|
||||
unset($default_objects[$key]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$result[$key] = _elysia_cron_ctools_export_load_object_db($object, $export);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($default_objects as $key => $object) {
|
||||
$result[$key] = _elysia_cron_ctools_export_load_object_code($object, $export);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function _elysia_cron_ctools_export_load_object_db_and_code($object, $code_object, $export) {
|
||||
$overridden = false;
|
||||
/**
|
||||
* @param object $object
|
||||
* @param object $code_object
|
||||
* @param array $export
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function _elysia_cron_ctools_export_load_object_db_and_code($object, $code_object, array $export) {
|
||||
$overridden = FALSE;
|
||||
|
||||
foreach ($code_object as $keyd => $value) {
|
||||
if (!isset($object->$keyd) || is_null($object->$keyd)) {
|
||||
$object->$keyd = $value;
|
||||
}
|
||||
else if ($object->$keyd !== $value) {
|
||||
$overridden = true;
|
||||
else {
|
||||
if ($object->$keyd !== $value) {
|
||||
$overridden = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$object->table = 'elysia_cron';
|
||||
$object->export_type = EXPORT_IN_DATABASE | EXPORT_IN_CODE;
|
||||
if (!empty($export['export type string'])) {
|
||||
$object->{$export['export type string']} = $overridden ? t('Overridden') : t('Normal');
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param array $export
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function _elysia_cron_ctools_export_load_object_db($object, $export) {
|
||||
$object->table = 'elysia_cron';
|
||||
$object->export_type = EXPORT_IN_DATABASE;
|
||||
@@ -114,6 +149,12 @@ function _elysia_cron_ctools_export_load_object_db($object, $export) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param array $export
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function _elysia_cron_ctools_export_load_object_code($object, $export) {
|
||||
$object->table = 'elysia_cron';
|
||||
$object->export_type = EXPORT_IN_CODE;
|
||||
@@ -125,12 +166,19 @@ function _elysia_cron_ctools_export_load_object_code($object, $export) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctools export object factory
|
||||
* Original ctools export factory (_ctools_export_unpack_object) does not handle NULL values correctly.
|
||||
* Ctools export object factory.
|
||||
*
|
||||
* Original ctools export factory (_ctools_export_unpack_object)
|
||||
* does not handle NULL values correctly.
|
||||
* This function does not support $schema['join'].
|
||||
*
|
||||
* @param array $schema
|
||||
* @param object $data
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function elysia_cron_ctools_export_object_factory($schema, $data) {
|
||||
$object = new stdClass;
|
||||
function elysia_cron_ctools_export_object_factory(array $schema, $data) {
|
||||
$object = new stdClass();
|
||||
|
||||
foreach ($schema['fields'] as $field => $info) {
|
||||
$object->$field = isset($data->$field) && !is_null($data->$field) ? (empty($info['serialize']) ? $data->$field : unserialize($data->$field)) : NULL;
|
||||
@@ -140,21 +188,28 @@ function elysia_cron_ctools_export_object_factory($schema, $data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctools export callback
|
||||
* Handles NULL value (it's not possible to do this with "field" export callback, because null values are rewritten before its call)
|
||||
* Ctools export callback.
|
||||
*
|
||||
* Handles NULL value (it's not possible to do this with "field"
|
||||
* export callback, because null values are rewritten before its call).
|
||||
*
|
||||
* @param object $object
|
||||
* @param string $indent
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function elysia_cron_ctools_export_callback($object, $indent) {
|
||||
$table = 'elysia_cron';
|
||||
$schema = ctools_export_get_schema($table);
|
||||
$identifier = $schema['export']['identifier'];
|
||||
|
||||
$output = $indent . '$' . $identifier . ' = new ' . get_class($object) . ";\n";
|
||||
$output = $indent . '$' . $identifier . ' = new ' . get_class($object) . ';' . PHP_EOL;
|
||||
|
||||
if ($schema['export']['can disable']) {
|
||||
$output .= $indent . '$' . $identifier . '->disabled = FALSE; /* Edit this to true to make a default ' . $identifier . ' disabled initially */' . "\n";
|
||||
$output .= $indent . '$' . $identifier . '->disabled = FALSE; /* Edit this to true to make a default ' . $identifier . ' disabled initially */' . PHP_EOL;
|
||||
}
|
||||
if (!empty($schema['export']['api']['current_version'])) {
|
||||
$output .= $indent . '$' . $identifier . '->api_version = ' . $schema['export']['api']['current_version'] . ";\n";
|
||||
$output .= $indent . '$' . $identifier . '->api_version = ' . $schema['export']['api']['current_version'] . ';' . PHP_EOL;
|
||||
}
|
||||
|
||||
$fields = $schema['fields'];
|
||||
@@ -167,36 +222,50 @@ function elysia_cron_ctools_export_callback($object, $indent) {
|
||||
if (!is_null($value) && $info['type'] == 'int') {
|
||||
$value = (isset($info['size']) && $info['size'] == 'tiny') ? (bool) $value : (int) $value;
|
||||
}
|
||||
$output .= $indent . '$' . $identifier . '->' . $field . ' = ' . ctools_var_export($value, $indent) . ";\n";
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctools export to hook code callback
|
||||
* Original "to hook code" callback doesn't support the replacement of "load/load all" callback (it simply ignores them, even if defined and supported elsewhere)
|
||||
* This code is equal to the original ctools one, but uses specific load callback
|
||||
*/
|
||||
function elysia_cron_ctools_to_hook_code($names, $name) {
|
||||
$table = 'elysia_cron';
|
||||
$schema = ctools_export_get_schema($table);
|
||||
$export = $schema['export'];
|
||||
$output = '';
|
||||
$objects = elysia_cron_ctools_export_load_all();
|
||||
$objects = array_intersect_key($objects, array_flip($names));
|
||||
if ($objects) {
|
||||
$output = "/**\n";
|
||||
$output .= " * Implementation of hook_{$export['default hook']}()\n";
|
||||
$output .= " */\n";
|
||||
$output .= "function " . $name . "_{$export['default hook']}() {\n";
|
||||
$output .= " \${$export['identifier']}s = array();\n\n";
|
||||
foreach ($objects as $object) {
|
||||
$output .= ctools_export_crud_export($table, $object, ' ');
|
||||
$output .= " \${$export['identifier']}s['" . check_plain($object->$export['key']) . "'] = \${$export['identifier']};\n\n";
|
||||
}
|
||||
$output .= " return \${$export['identifier']}s;\n";
|
||||
$output .= "}\n";
|
||||
$output .= $indent . '$' . $identifier . '->' . $field . ' = ' . ctools_var_export($value, $indent) . ';' . PHP_EOL;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctools export to hook code callback.
|
||||
*
|
||||
* Original "to hook code" callback does not support the replacement
|
||||
* of "load/load all" callback (it simply ignores them,
|
||||
* even if defined and supported elsewhere)
|
||||
* This code is equal to the original ctools one,
|
||||
* but uses specific load callback.
|
||||
*
|
||||
* @param array $names
|
||||
* @param string $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function elysia_cron_ctools_to_hook_code(array $names, $name) {
|
||||
$output = '';
|
||||
|
||||
$table = 'elysia_cron';
|
||||
$schema = ctools_export_get_schema($table);
|
||||
$export = $schema['export'];
|
||||
|
||||
$objects = elysia_cron_ctools_export_load_all();
|
||||
$objects = array_intersect_key($objects, array_flip($names));
|
||||
|
||||
if ($objects) {
|
||||
$output = '/**' . PHP_EOL;
|
||||
$output .= " * Implementation of hook_{$export['default hook']}()" . PHP_EOL;
|
||||
$output .= ' */' . PHP_EOL;
|
||||
$output .= "function " . $name . "_{$export['default hook']}() {" . PHP_EOL;
|
||||
$output .= " \${$export['identifier']}s = array();" . PHP_EOL . PHP_EOL;
|
||||
|
||||
foreach ($objects as $object) {
|
||||
$output .= ctools_export_crud_export($table, $object, ' ');
|
||||
$output .= " \${$export['identifier']}s['" . check_plain($object->{$export['key']}) . "'] = \${$export['identifier']};" . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
$output .= " return \${$export['identifier']}s;" . PHP_EOL;
|
||||
$output .= '}' . PHP_EOL;
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
@@ -1,47 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************************
|
||||
* DRUSH SUPPORT
|
||||
******************************************************************************/
|
||||
/**
|
||||
* @file
|
||||
* Drush integration for Elysia cron module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Detect, is it drush or not.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if code executed inside drush, FALSE otherwise.
|
||||
*/
|
||||
function elysia_cron_drush_detect() {
|
||||
return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))) && function_exists('drush_main');
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit from drush execution.
|
||||
*/
|
||||
function elysia_cron_drush_die() {
|
||||
if (function_exists('drush_bootstrap_finish')) {
|
||||
// Only in Drush5
|
||||
drush_bootstrap_finish();
|
||||
drush_die();
|
||||
} else {
|
||||
// Drush4
|
||||
drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE);
|
||||
exit();
|
||||
}
|
||||
drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);
|
||||
drupal_exit();
|
||||
}
|
||||
|
||||
function elysia_cron_drush_invoke($replace_core_cron = false) {
|
||||
/**
|
||||
* Wrapper for drush_invoke().
|
||||
*/
|
||||
function elysia_cron_drush_invoke($replace_core_cron = FALSE) {
|
||||
$args = drush_get_arguments();
|
||||
array_shift($args);
|
||||
|
||||
// If invoked like "core-cron" i do the same as that: execute "run"
|
||||
|
||||
// If invoked like 'core-cron' I do the same as that: execute 'run'.
|
||||
if ($replace_core_cron && empty($args)) {
|
||||
$args = array("run");
|
||||
$args = array('run');
|
||||
}
|
||||
|
||||
|
||||
call_user_func_array('drush_elysia_cron_run_wrapper', $args);
|
||||
elysia_cron_drush_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_drush_command().
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function elysia_cron_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$items['elysia-cron'] = array(
|
||||
'description' => "Run all cron tasks in all active modules for specified site using elysia cron system. This replaces the standard \"core-cron\" drush handler.", // TODO dt
|
||||
'callback' => 'drush_elysia_cron_run_wrapper',
|
||||
'description' => dt('Run all cron tasks in all active modules for specified site using elysia cron system. This replaces the standard "core-cron" drush handler.'),
|
||||
'callback' => 'drush_elysia_cron_run_wrapper',
|
||||
'arguments' => array(
|
||||
'op' => 'Operation: list, run, disable, enable',
|
||||
'target' => 'Target of operation (optional): usually a task name or a channel name starting with "@"',
|
||||
@@ -62,97 +66,97 @@ function elysia_cron_drush_command() {
|
||||
'ignore-time' => 'run channels/tasks even if not ready for execution',
|
||||
'ignore-running' => 'run channels/tasks even if already running',
|
||||
),
|
||||
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* A drush command callback.
|
||||
*
|
||||
* wraps the elysia_cron_run function, passing manual = true
|
||||
* Custom callback for 'elysia-cron' drush command.
|
||||
*/
|
||||
function drush_elysia_cron_run_wrapper($op = false, $target = false) {
|
||||
/*
|
||||
drush_log("test notice", "notice");
|
||||
drush_log("test ok", "ok");
|
||||
drush_log("test completed", "completed");
|
||||
drush_log("test warning", "warning");
|
||||
drush_log("test error", "error");
|
||||
drush_print("print");
|
||||
*/
|
||||
global $elysia_cron_drush;
|
||||
|
||||
$quiet = drush_get_option("quiet", false);
|
||||
$verbose = drush_get_option("verbose", false);
|
||||
if (!$verbose) {
|
||||
$verbose = drush_get_option("elysia-cron-verbose", false);
|
||||
function drush_elysia_cron_run_wrapper($op = FALSE, $target = FALSE) {
|
||||
global $_elysia_cron_drush;
|
||||
|
||||
if (variable_get('maintenance_mode', FALSE)) {
|
||||
if (!variable_get('elysia_cron_run_maintenance', FALSE)) {
|
||||
drush_set_error('Cron run is not allowed in maintenance mode');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$elysia_cron_drush = $quiet ? 1 : !$verbose ? 2 : 3;
|
||||
|
||||
|
||||
$quiet = drush_get_option('quiet', FALSE);
|
||||
$verbose = drush_get_option('verbose', FALSE);
|
||||
if (!$verbose) {
|
||||
$verbose = drush_get_option('elysia-cron-verbose', FALSE);
|
||||
}
|
||||
$_elysia_cron_drush = $quiet ? 1 : !$verbose ? 2 : 3;
|
||||
|
||||
switch ($op) {
|
||||
case 'list':
|
||||
global $elysia_cron_settings_by_channel;
|
||||
global $_elysia_cron_settings_by_channel;
|
||||
elysia_cron_initialize();
|
||||
foreach ($elysia_cron_settings_by_channel as $channel => $jobs) {
|
||||
|
||||
foreach ($_elysia_cron_settings_by_channel as $channel => $jobs) {
|
||||
$lines = array();
|
||||
if (!$verbose) {
|
||||
$line = array("@" . $channel);
|
||||
} else {
|
||||
$line = array("Channel: @" . $channel);
|
||||
$line = array('@' . $channel);
|
||||
}
|
||||
else {
|
||||
$line = array('Channel: @' . $channel);
|
||||
if ($running = elysia_cron_is_channel_running($channel)) {
|
||||
$line[] = "RUNNING NOW, since " . elysia_cron_date($running);
|
||||
$line[] = dt('Running, since !time', array('!time' => elysia_cron_date($running)));
|
||||
}
|
||||
if (!empty($jobs['#data']['disabled'])) {
|
||||
$line[] = "DISABLED";
|
||||
$line[] = dt('Disabled');
|
||||
}
|
||||
if (!$running) {
|
||||
$line[] = "Last run: " . elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0));
|
||||
$line[] = dt('Last run: !time', array('!time' => elysia_cron_date(_ec_variable_get('elysia_cron_last_run', 0))));
|
||||
}
|
||||
}
|
||||
drush_print(implode($line, ", "));
|
||||
foreach ($jobs as $job => $conf) if ($job{0} != '#') {
|
||||
if (!$verbose) {
|
||||
$line = array($job);
|
||||
} else {
|
||||
$line = array("- Job: " . $job);
|
||||
if (!empty($conf['running'])) {
|
||||
$line[] = "RUNNING NOW, since " . elysia_cron_date($conf['running']);
|
||||
drush_print(implode($line, ', '));
|
||||
|
||||
foreach ($jobs as $job => $conf) {
|
||||
$line = array();
|
||||
if (strpos($job, '#') !== 0) {
|
||||
if (!$verbose) {
|
||||
drush_print($job);
|
||||
}
|
||||
if (!empty($conf['disabled'])) {
|
||||
$line[] = "DISABLED";
|
||||
}
|
||||
if (empty($conf['running']) && elysia_cron_should_run($conf)) {
|
||||
$line[] = "Ready to run";
|
||||
}
|
||||
if (empty($conf['running'])) {
|
||||
$line[] = "Last run: " . elysia_cron_date($conf['last_run']);
|
||||
else {
|
||||
$line['name'] = $job;
|
||||
$line['status'] = empty($conf['disabled']) ? dt('Enabled') : dt('Disabled');
|
||||
$line['run_status'] = empty($conf['running']) && elysia_cron_should_run($conf) ? dt('Ready to run') : dt('Waiting');
|
||||
$line['run_status'] = !empty($conf['running']) ? dt('Running, since !time', array('!time' => elysia_cron_date($conf['running']))) : $line['run_status'];
|
||||
$line['last_run'] = !empty($conf['last_run']) ? dt('Last run: !time', array('!time' => elysia_cron_date($conf['last_run']))) : '';
|
||||
$lines[] = $line;
|
||||
}
|
||||
}
|
||||
drush_print(implode($line, ", "));
|
||||
}
|
||||
if ($lines) {
|
||||
drush_print_table($lines);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'run':
|
||||
if (empty($target)) {
|
||||
elysia_cron_run(true, drush_get_option("ignore-disable", false), drush_get_option("ignore-time", false), drush_get_option("ignore-running", false));
|
||||
//drush_log("Cron run complete", "completed");
|
||||
elysia_cron_run(FALSE, drush_get_option('ignore-disable', FALSE), drush_get_option('ignore-time', FALSE), drush_get_option('ignore-running', FALSE));
|
||||
}
|
||||
elseif ($target{0} == '@') {
|
||||
elseif (strpos($target, '@') === 0) {
|
||||
elysia_cron_initialize();
|
||||
if (elysia_cron_channel_exists(substr($target, 1))) {
|
||||
elysia_cron_run_channel(substr($target, 1), drush_get_option("ignore-disable", false), drush_get_option("ignore-time", false), drush_get_option("ignore-running", false));
|
||||
//drush_log("Cron run complete", "completed");
|
||||
} else {
|
||||
elysia_cron_run_channel(substr($target, 1), drush_get_option('ignore-disable', FALSE), drush_get_option('ignore-time', FALSE), drush_get_option('ignore-running', FALSE));
|
||||
}
|
||||
else {
|
||||
drush_set_error('Channel ' . substr($target, 1) . ' does not exists');
|
||||
}
|
||||
}
|
||||
else {
|
||||
elysia_cron_initialize();
|
||||
if (elysia_cron_job_exists($target)) {
|
||||
elysia_cron_run_job($target, drush_get_option("ignore-disable", false), drush_get_option("ignore-time", false), drush_get_option("ignore-running", false));
|
||||
//drush_log("Cron run complete", "completed");
|
||||
} else {
|
||||
elysia_cron_run_job($target, drush_get_option('ignore-disable', FALSE), drush_get_option('ignore-time', FALSE), drush_get_option('ignore-running', FALSE));
|
||||
}
|
||||
else {
|
||||
drush_set_error('Job ' . $target . ' does not exists');
|
||||
}
|
||||
}
|
||||
@@ -161,21 +165,21 @@ function drush_elysia_cron_run_wrapper($op = false, $target = false) {
|
||||
case 'disable':
|
||||
case 'enable':
|
||||
if (!empty($target)) {
|
||||
if ($target{0} == '@') {
|
||||
if (strpos($target, '@') === 0) {
|
||||
elysia_cron_set_channel_disabled(substr($target, 1), $op == 'disable');
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
elysia_cron_set_job_disabled($target, $op == 'disable');
|
||||
}
|
||||
drush_log("Done", "ok");
|
||||
} else {
|
||||
drush_log('Done', 'ok');
|
||||
}
|
||||
else {
|
||||
drush_set_error('Target not specified');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
drush_print_help(drush_get_command());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
name = "Elysia Cron"
|
||||
description = "Extended cron support with crontab-like scheduling and other features."
|
||||
core = 7.x
|
||||
files[] = elysia_cron_update.php
|
||||
files[] = elysia_drupalconv.php
|
||||
|
||||
configure = admin/config/system/cron
|
||||
; Information added by drupal.org packaging script on 2013-09-30
|
||||
version = "7.x-2.1+9-dev"
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-10-10
|
||||
version = "7.x-2.3"
|
||||
core = "7.x"
|
||||
project = "elysia_cron"
|
||||
datestamp = "1380576625"
|
||||
datestamp = "1476088169"
|
||||
|
||||
|
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the elysia_cron module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function elysia_cron_schema() {
|
||||
$schema['elysia_cron'] = array(
|
||||
'fields' => array(
|
||||
@@ -16,7 +24,7 @@ function elysia_cron_schema() {
|
||||
'rule' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
'length' => 32,
|
||||
'length' => 256,
|
||||
),
|
||||
'weight' => array(
|
||||
'type' => 'int',
|
||||
@@ -54,7 +62,7 @@ function elysia_cron_schema() {
|
||||
),
|
||||
'last_abort_function' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'length' => 128,
|
||||
'no export' => TRUE,
|
||||
),
|
||||
'last_execution_time' => array(
|
||||
@@ -97,11 +105,9 @@ function elysia_cron_schema() {
|
||||
'object factory' => 'elysia_cron_ctools_export_object_factory',
|
||||
'load callback' => 'elysia_cron_ctools_export_load',
|
||||
'load all callback' => 'elysia_cron_ctools_export_load_all',
|
||||
//'save callback' => 'elysia_cron_ctools_export_save',
|
||||
'export callback' => 'elysia_cron_ctools_export_callback',
|
||||
//'import callback' => 'elysia_cron_ctools_import_callback',
|
||||
'to hook code callback' => 'elysia_cron_ctools_to_hook_code',
|
||||
|
||||
|
||||
'default hook' => 'default_elysia_cron_rules',
|
||||
'api' => array(
|
||||
'owner' => 'elysia_cron',
|
||||
@@ -111,50 +117,93 @@ function elysia_cron_schema() {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function elysia_cron_install() {
|
||||
//drupal_install_schema('elysia_cron');
|
||||
|
||||
// elysia_cron MUST be the first returned by module_list
|
||||
// This is to ensure elysia_cron_cron is the first hook called by standard cron.php.
|
||||
$min = db_query("select min(weight) from {system}")->fetchField();
|
||||
|
||||
if ($min > -65535) {
|
||||
$min = -65535;
|
||||
}
|
||||
else {
|
||||
$min--;
|
||||
}
|
||||
db_update('system')->fields(array('weight' => $min))->condition('name', 'elysia_cron')->execute();
|
||||
|
||||
variable_set('elysia_cron_version', elysia_cron_version());
|
||||
|
||||
drupal_set_message('Elysia cron installed. Setup could be found at ' . l(t('Settings page'), 'admin/config/system/cron') . '. See INSTALL.TXT for more info.');
|
||||
// Elysia cron MUST be the first returned by module_list.
|
||||
// This is to ensure elysia_cron_cron is the first hook
|
||||
// called by standard cron.php.
|
||||
$query = db_select('system');
|
||||
$query->addExpression('MIN(weight)');
|
||||
$min = $query->execute()->fetchField();
|
||||
|
||||
$min = ($min > -65535) ? -65535 : --$min;
|
||||
|
||||
db_update('system')
|
||||
->fields(array('weight' => $min))
|
||||
->condition('name', 'elysia_cron')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function elysia_cron_uninstall() {
|
||||
$rs = db_query("select name from {variable} where name like 'elysia_cron_%%'");
|
||||
foreach ($rs as $o) {
|
||||
variable_del($o->name);
|
||||
$variables = db_select('variable', 'v')
|
||||
->fields('v', array('name'))
|
||||
->condition('v.name', 'elysia_cron_%', 'LIKE')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
|
||||
foreach ($variables as $name) {
|
||||
variable_del($name);
|
||||
}
|
||||
|
||||
//drupal_uninstall_schema('elysia_cron');
|
||||
|
||||
drupal_set_message('Elysia cron uninstalled.');
|
||||
}
|
||||
|
||||
function elysia_cron_update_1() {
|
||||
$cron_key = variable_get('elysia_cron_key', false);
|
||||
/**
|
||||
* Use default cron_key variable.
|
||||
*/
|
||||
function elysia_cron_update_7201() {
|
||||
$cron_key = variable_get('elysia_cron_key', FALSE);
|
||||
if ($cron_key) {
|
||||
variable_set('cron_key', $cron_key);
|
||||
}
|
||||
|
||||
variable_del('elysia_cron_key');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase elysia_cron last_abort_function size from 32 to 128 characters.
|
||||
*/
|
||||
function elysia_cron_update_7202() {
|
||||
db_change_field('elysia_cron', 'last_abort_function', 'last_abort_function', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'no export' => TRUE,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change length property of rule to 256 characters.
|
||||
*/
|
||||
function elysia_cron_update_7203() {
|
||||
$spec = array(
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
'length' => 256,
|
||||
);
|
||||
db_change_field('elysia_cron', 'rule', 'rule', $spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove unused variables.
|
||||
*/
|
||||
function elysia_cron_update_7204() {
|
||||
variable_del('elysia_cron_version');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename context variable to channel.
|
||||
*/
|
||||
function elysia_cron_update_7205() {
|
||||
if ($last = variable_get('elysia_cron_last_context')) {
|
||||
variable_set('elysia_cron_last_channel', $last);
|
||||
}
|
||||
|
||||
variable_del('elysia_cron_last_context');
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,33 +1,46 @@
|
||||
<?php
|
||||
|
||||
function elysia_cron_should_run($conf, $now = -1, $ignore_disable = false, $ignore_time = false) {
|
||||
$prev_rule_run = 0; // What time SHOULD the job be executed last time
|
||||
/**
|
||||
* @file
|
||||
* Schedules cron runs.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function for cron run schedule.
|
||||
*/
|
||||
function elysia_cron_should_run($conf, $now = -1, $ignore_disable = FALSE, $ignore_time = FALSE) {
|
||||
// What time SHOULD the job be executed last time.
|
||||
$prev_rule_run = 0;
|
||||
if (!$ignore_disable && $conf['disabled']) {
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
if ($ignore_time) {
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
if ($now < 0) {
|
||||
$now = time();
|
||||
}
|
||||
if ((!$conf['last_run']) || ($now - $conf['last_run'] > 365 * 86400)) {
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$next_run = _elysia_cron_next_run($conf);
|
||||
return $now >= $next_run;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for cron run schedule.
|
||||
*/
|
||||
function _elysia_cron_next_run($conf) {
|
||||
if (!isset($conf['rule'])) {
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
$ranges = array(
|
||||
array(0, 59),
|
||||
array(0, 23),
|
||||
array(1, 31), // TODO
|
||||
// TODO.
|
||||
array(1, 31),
|
||||
array(1, 12),
|
||||
array(0, 3000),
|
||||
array(0, 6),
|
||||
@@ -35,20 +48,21 @@ function _elysia_cron_next_run($conf) {
|
||||
|
||||
if (!preg_match('/^([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)$/', $conf['rule'], $rules)) {
|
||||
elysia_cron_warning('Invalid rule found: %rule', array('%rule' => $conf['rule']));
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rule = array($rules[1], $rules[2], array($rules[3], $rules[5]), $rules[4]);
|
||||
$ruledec = array();
|
||||
$date = __cronDecodeDate($conf['last_run'], 1);
|
||||
$expected_date = __cronDecodeDate(!empty($conf['last_run_expected']) ? $conf['last_run_expected'] : 0);
|
||||
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
if ($i != 2) {
|
||||
// Standard scheme for mins, hours, month
|
||||
// Standard scheme for mins, hours, month.
|
||||
$ruledec[$i] = __cronDecodeRule($rule[$i], $ranges[$i][0], $ranges[$i][1]);
|
||||
} else {
|
||||
// For mday+week we follow another scheme
|
||||
}
|
||||
else {
|
||||
// For mday+week we follow another scheme.
|
||||
$ruledec[$i] = __cronDecodeRuleMday($rule[2], $date[3], $date[4]);
|
||||
}
|
||||
$r = $ruledec[$i];
|
||||
@@ -82,10 +96,13 @@ function _elysia_cron_next_run($conf) {
|
||||
return __cronEncodeDate($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _elysia_cron_next_run().
|
||||
*/
|
||||
function __cronDecodeDate($timestamp, $min_diff = 0) {
|
||||
$time = floor($timestamp / 60);
|
||||
$time += $min_diff;
|
||||
|
||||
|
||||
$date = $time ? getdate($time * 60) : 0;
|
||||
$date = array(
|
||||
$time ? $date['minutes'] : 0,
|
||||
@@ -96,10 +113,17 @@ function __cronDecodeDate($timestamp, $min_diff = 0) {
|
||||
);
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _elysia_cron_next_run().
|
||||
*/
|
||||
function __cronEncodeDate($date) {
|
||||
return mktime($date[1], $date[0], 0, $date[3], $date[2], $date[4]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _elysia_cron_next_run().
|
||||
*/
|
||||
function __cronNextOrEqual($el, $arr, $range_start, $range_end) {
|
||||
if (empty($arr)) {
|
||||
return $el;
|
||||
@@ -112,6 +136,9 @@ function __cronNextOrEqual($el, $arr, $range_start, $range_end) {
|
||||
return $range_end + reset($arr) + 1 - $range_start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _elysia_cron_next_run().
|
||||
*/
|
||||
function __cronDecodeRule($rule, $min, $max) {
|
||||
if ($rule == '*') {
|
||||
return array('n' => array(), 'd' => 0);
|
||||
@@ -133,9 +160,12 @@ function __cronDecodeRule($rule, $min, $max) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _elysia_cron_next_run().
|
||||
*/
|
||||
function __cronDecodeRuleMday($rule, $month, $year) {
|
||||
$range_from = 1;
|
||||
$range_to = $month != 2 ? (in_array($month, array(4,6,9,11)) ? 30 : 31) : ($year % 4 == 0 ? 29 : 28);
|
||||
$range_to = $month != 2 ? (in_array($month, array(4, 6, 9, 11)) ? 30 : 31) : ($year % 4 == 0 ? 29 : 28);
|
||||
$r1 = __cronDecodeRule($rule[0], $range_from, $range_to);
|
||||
$r2 = __cronDecodeRule($rule[1], $range_from, $range_to);
|
||||
if ($r2['d']) {
|
||||
@@ -147,18 +177,21 @@ function __cronDecodeRuleMday($rule, $month, $year) {
|
||||
}
|
||||
if ($r2['n']) {
|
||||
$r2['n'] = array_unique($r2['n']);
|
||||
$r1['n'] = array_merge($r1['n'], __cronMonDaysFromWeekDays($year, $month, $r2['n']), __cronMonDaysFromWeekDays($year, $month + 1, $r2['n'], 31)); // Use always "31" and not $range_to, see http://drupal.org/node/1668302
|
||||
// Use always "31" and not $range_to, see http://drupal.org/node/1668302.
|
||||
$r1['n'] = array_merge($r1['n'], __cronMonDaysFromWeekDays($year, $month, $r2['n']), __cronMonDaysFromWeekDays($year, $month + 1, $r2['n'], 31));
|
||||
}
|
||||
return $r1;
|
||||
}
|
||||
|
||||
// Used by elysia_cron_should_run
|
||||
/**
|
||||
* Helper function for _elysia_cron_next_run().
|
||||
*/
|
||||
function __cronMonDaysFromWeekDays($year, $mon, $weekdays, $offset = 0) {
|
||||
if ($mon > 12) {
|
||||
$year ++;
|
||||
$year++;
|
||||
$mon = $mon - 12;
|
||||
}
|
||||
|
||||
|
||||
$result = array();
|
||||
for ($i = 1; checkdate($mon, $i, $year); $i++) {
|
||||
$w = date('w', mktime(12, 00, 00, $mon, $i, $year));
|
||||
@@ -173,76 +206,251 @@ function __cronMonDaysFromWeekDays($year, $mon, $weekdays, $offset = 0) {
|
||||
* TESTS
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Test function for elysia_cron_should_run().
|
||||
*/
|
||||
function test_elysia_cron_should_run() {
|
||||
dprint("Start test");
|
||||
$start = microtime(true);
|
||||
|
||||
//mktime: hr min sec mon day yr
|
||||
dprint(" 1." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 01, 0, 1, 2, 2008))));
|
||||
dprint(" 2." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(15, 00, 0, 1, 2, 2008))));
|
||||
dprint(" 3." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(11, 59, 0, 1, 3, 2008))));
|
||||
dprint(" 4." . (true == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 00, 0, 1, 3, 2008))));
|
||||
dprint(" 5." . (false == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 3, 2008))));
|
||||
dprint(" 6." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 3, 2008))));
|
||||
dprint(" 7." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 4, 2008))));
|
||||
dprint(" 8." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 2, 2008))));
|
||||
dprint(" 9." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(0, 0, 0, 1, 3, 2008))));
|
||||
dprint("10." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("11." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(0, 0, 0, 1, 6, 2008))));
|
||||
dprint("12." . (true == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("13." . (true == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(00, 00, 0, 1, 7, 2008))));
|
||||
dprint("14." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
|
||||
dprint("15." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("16." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("17." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 6, 2008))));
|
||||
dprint("18." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 28, 0, 1, 6, 2008))));
|
||||
dprint("19." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 5, 2008))));
|
||||
dprint("20." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 30, 0, 1, 5, 2008))));
|
||||
dprint("21." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("22." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
|
||||
$start = microtime(TRUE);
|
||||
|
||||
dprint("23." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 28, 2008))));
|
||||
dprint("24." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
|
||||
dprint("25." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
|
||||
// @mktime: hr min sec mon day yr.
|
||||
dprint(" 1." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '0 12 * * *',
|
||||
'last_run' => mktime(12, 0, 0, 1, 2, 2008),
|
||||
), mktime(12, 01, 0, 1, 2, 2008))));
|
||||
dprint(" 2." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '0 12 * * *',
|
||||
'last_run' => mktime(12, 0, 0, 1, 2, 2008),
|
||||
), mktime(15, 00, 0, 1, 2, 2008))));
|
||||
dprint(" 3." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '0 12 * * *',
|
||||
'last_run' => mktime(12, 0, 0, 1, 2, 2008),
|
||||
), mktime(11, 59, 0, 1, 3, 2008))));
|
||||
dprint(" 4." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '0 12 * * *',
|
||||
'last_run' => mktime(12, 0, 0, 1, 2, 2008),
|
||||
), mktime(12, 00, 0, 1, 3, 2008))));
|
||||
dprint(" 5." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 2, 2008),
|
||||
), mktime(0, 00, 0, 1, 3, 2008))));
|
||||
dprint(" 6." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 2, 2008),
|
||||
), mktime(23, 59, 0, 1, 3, 2008))));
|
||||
dprint(" 7." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 2, 2008),
|
||||
), mktime(0, 00, 0, 1, 4, 2008))));
|
||||
dprint(" 8." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * *',
|
||||
'last_run' => mktime(23, 58, 0, 1, 2, 2008),
|
||||
), mktime(23, 59, 0, 1, 2, 2008))));
|
||||
dprint(" 9." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * *',
|
||||
'last_run' => mktime(23, 58, 0, 1, 2, 2008),
|
||||
), mktime(0, 0, 0, 1, 3, 2008))));
|
||||
dprint("10." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("11." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(0, 0, 0, 1, 6, 2008))));
|
||||
dprint("12." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("13." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(00, 00, 0, 1, 7, 2008))));
|
||||
dprint("14." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 29, 0, 1, 6, 2008))));
|
||||
dprint("15." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("16." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("17." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 58, 0, 1, 6, 2008))));
|
||||
dprint("18." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 58, 0, 1, 5, 2008),
|
||||
), mktime(23, 28, 0, 1, 6, 2008))));
|
||||
dprint("19." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 28, 0, 1, 5, 2008),
|
||||
), mktime(23, 29, 0, 1, 5, 2008))));
|
||||
dprint("20." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 28, 0, 1, 5, 2008),
|
||||
), mktime(23, 30, 0, 1, 5, 2008))));
|
||||
dprint("21." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 28, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("22." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 0',
|
||||
'last_run' => mktime(23, 28, 0, 1, 5, 2008),
|
||||
), mktime(23, 29, 0, 1, 6, 2008))));
|
||||
|
||||
dprint("26." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 1, 2009))));
|
||||
dprint("27." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 7, 2009))));
|
||||
dprint("28." . (true == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(23, 59, 0, 1, 7, 2009))));
|
||||
dprint("23." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 22, 2008),
|
||||
), mktime(23, 59, 0, 2, 28, 2008))));
|
||||
dprint("24." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 22, 2008),
|
||||
), mktime(23, 59, 0, 2, 29, 2008))));
|
||||
dprint("25." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '29,59 23 * * 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 22, 2008),
|
||||
), mktime(0, 0, 0, 3, 1, 2008))));
|
||||
|
||||
dprint("29." . (true == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
|
||||
dprint("30." . (true == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
|
||||
dprint("31." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 3, 7, 2008))));
|
||||
dprint("32." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 58, 0, 2, 6, 2009))));
|
||||
dprint("33." . (true == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 2, 6, 2009))));
|
||||
dprint("34." . (true == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 58, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
|
||||
dprint("35." . (false == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 11, 2008))));
|
||||
dprint("36." . (true == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 20, 2008))));
|
||||
dprint("37." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("38." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("39." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("40." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 10, 2008))));
|
||||
dprint("41." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
|
||||
dprint("42." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 16, 2008))));
|
||||
dprint("26." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 3',
|
||||
'last_run' => mktime(23, 59, 0, 12, 31, 2008),
|
||||
), mktime(0, 0, 0, 1, 1, 2009))));
|
||||
dprint("27." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 3',
|
||||
'last_run' => mktime(23, 59, 0, 12, 31, 2008),
|
||||
), mktime(0, 0, 0, 1, 7, 2009))));
|
||||
dprint("28." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * * 3',
|
||||
'last_run' => mktime(23, 59, 0, 12, 31, 2008),
|
||||
), mktime(23, 59, 0, 1, 7, 2009))));
|
||||
|
||||
dprint("43." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("44." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("45." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 7, 2008))));
|
||||
dprint("46." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 13, 2008))));
|
||||
dprint("47." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 4, 2008)), mktime(23, 59, 0, 2, 5, 2008))));
|
||||
dprint("48." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 5, 2008)), mktime(23, 59, 0, 2, 10, 2008))));
|
||||
dprint("49." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 10, 2008)), mktime(23, 59, 0, 2, 17, 2008))));
|
||||
dprint("29." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * 2 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 22, 2008),
|
||||
), mktime(23, 59, 0, 2, 29, 2008))));
|
||||
dprint("30." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * 2 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 22, 2008),
|
||||
), mktime(0, 0, 0, 3, 1, 2008))));
|
||||
dprint("31." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * 2 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 29, 2008),
|
||||
), mktime(23, 59, 0, 3, 7, 2008))));
|
||||
dprint("32." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * 2 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 29, 2008),
|
||||
), mktime(23, 58, 0, 2, 6, 2009))));
|
||||
dprint("33." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 * 2 5',
|
||||
'last_run' => mktime(23, 59, 0, 2, 29, 2008),
|
||||
), mktime(23, 59, 0, 2, 6, 2009))));
|
||||
dprint("34." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 *' . '/10 * *',
|
||||
'last_run' => mktime(23, 58, 0, 1, 10, 2008),
|
||||
), mktime(23, 59, 0, 1, 10, 2008))));
|
||||
dprint("35." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 *' . '/10 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 10, 2008),
|
||||
), mktime(23, 59, 0, 1, 11, 2008))));
|
||||
dprint("36." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 *' . '/10 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 10, 2008),
|
||||
), mktime(23, 59, 0, 1, 20, 2008))));
|
||||
dprint("37." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5,10-15 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 4, 2008),
|
||||
), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("38." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5,10-15 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 4, 2008),
|
||||
), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("39." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5,10-15 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("40." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5,10-15 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 5, 2008),
|
||||
), mktime(23, 58, 0, 1, 10, 2008))));
|
||||
dprint("41." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5,10-15 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 10, 2008))));
|
||||
dprint("42." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5,10-15 * *',
|
||||
'last_run' => mktime(23, 59, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 16, 2008))));
|
||||
|
||||
dprint("49." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 58, 0, 2, 10, 2008)), mktime(8, 59, 0, 2, 10, 2008))));
|
||||
dprint("50." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(9, 00, 0, 2, 10, 2008))));
|
||||
dprint("51." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(17, 59, 0, 2, 10, 2008))));
|
||||
dprint("52." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(18, 00, 0, 2, 10, 2008))));
|
||||
dprint("53." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(18, 01, 0, 2, 10, 2008))));
|
||||
dprint("54." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(19, 0, 0, 2, 10, 2008))));
|
||||
dprint("55." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(9, 0, 0, 3, 10, 2008))));
|
||||
dprint("43." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 1, 4, 2008),
|
||||
), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("44." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 1, 5, 2008),
|
||||
), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("45." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 1, 6, 2008),
|
||||
), mktime(23, 59, 0, 1, 7, 2008))));
|
||||
dprint("46." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 1, 6, 2008),
|
||||
), mktime(23, 59, 0, 1, 13, 2008))));
|
||||
dprint("47." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 2, 4, 2008),
|
||||
), mktime(23, 59, 0, 2, 5, 2008))));
|
||||
dprint("48." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 2, 5, 2008),
|
||||
), mktime(23, 59, 0, 2, 10, 2008))));
|
||||
dprint("49." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '59 23 1-5 1 0',
|
||||
'last_run' => mktime(23, 59, 0, 2, 10, 2008),
|
||||
), mktime(23, 59, 0, 2, 17, 2008))));
|
||||
|
||||
dprint("56." . (true == elysia_cron_should_run(array('rule' => '* * * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(18, 01, 0, 2, 10, 2008))));
|
||||
dprint("49." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(8, 58, 0, 2, 10, 2008),
|
||||
), mktime(8, 59, 0, 2, 10, 2008))));
|
||||
dprint("50." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(8, 59, 0, 2, 10, 2008),
|
||||
), mktime(9, 00, 0, 2, 10, 2008))));
|
||||
dprint("51." . (FALSE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(8, 59, 0, 2, 10, 2008),
|
||||
), mktime(17, 59, 0, 2, 10, 2008))));
|
||||
dprint("52." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(8, 59, 0, 2, 10, 2008),
|
||||
), mktime(18, 00, 0, 2, 10, 2008))));
|
||||
dprint("53." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(18, 00, 0, 2, 10, 2008),
|
||||
), mktime(18, 01, 0, 2, 10, 2008))));
|
||||
dprint("54." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(18, 00, 0, 2, 10, 2008),
|
||||
), mktime(19, 0, 0, 2, 10, 2008))));
|
||||
dprint("55." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
|
||||
'last_run' => mktime(18, 00, 0, 2, 10, 2008),
|
||||
), mktime(9, 0, 0, 3, 10, 2008))));
|
||||
|
||||
dprint("End test (" . (microtime(true) - $start) . ")");
|
||||
dprint("56." . (TRUE == elysia_cron_should_run(array(
|
||||
'rule' => '* * * * *',
|
||||
'last_run' => mktime(18, 00, 0, 2, 10, 2008),
|
||||
), mktime(18, 01, 0, 2, 10, 2008))));
|
||||
|
||||
dprint("End test (" . (microtime(TRUE) - $start) . ")");
|
||||
}
|
||||
// Remove comment to run tests
|
||||
//test_elysia_cron_should_run();die();
|
||||
|
||||
// Remove comment to run tests.
|
||||
// test_elysia_cron_should_run();die();
|
||||
|
@@ -1,230 +0,0 @@
|
||||
<?php
|
||||
|
||||
function elysia_cron_should_run($conf, $now = -1) {
|
||||
if ($conf['disabled']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($now < 0) {
|
||||
$now = time();
|
||||
}
|
||||
|
||||
if ((!$conf['last_run']) || ($now - $conf['last_run'] > 365 * 86400)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!preg_match('/^([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)[ ]+([0-9*,\/-]+)$/', $conf['rule'], $rules)) {
|
||||
elysia_cron_warning('Invalid rule found: %rule', array('%rule' => $conf['rule']));
|
||||
return false;
|
||||
}
|
||||
|
||||
$weekdayspec = ($rules[5] != '*');
|
||||
$mondayspec = ($rules[3] != '*');
|
||||
|
||||
$rules[5] = _cronDecodeRule($rules[5], 0, 6);
|
||||
$rules[4] = _cronDecodeRule($rules[4], 1, 12);
|
||||
$rules[3] = _cronDecodeRule($rules[3], 1, 31);
|
||||
$rules[2] = _cronDecodeRule($rules[2], 0, 23);
|
||||
$rules[1] = _cronDecodeRule($rules[1], 0, 59);
|
||||
|
||||
$lastT = _cronT($conf['last_run'] + 30);
|
||||
$nowT = _cronT($now);
|
||||
$nowTDelta = $nowT - $lastT + ($lastT > $nowT ? 12 * 31 * 24 * 60 : 0);
|
||||
$year = date('Y', $conf['last_run']);
|
||||
|
||||
if ($mondayspec || (!$mondayspec && !$weekdayspec)) {
|
||||
$first = -1;
|
||||
foreach ($rules[4] as $mon) {
|
||||
foreach ($rules[3] as $d) {
|
||||
if (checkdate($mon, $d, $year)) {
|
||||
foreach ($rules[2] as $h) {
|
||||
foreach ($rules[1] as $m) {
|
||||
$t = _cronT($mon, $d, $h, $m);
|
||||
//dprint("* ".$t." L:".$lastT);
|
||||
if ($first < 0) {
|
||||
$first = $t;
|
||||
}
|
||||
if ($t > $lastT) {
|
||||
$nextT = $t;
|
||||
break 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//dprint("R: ".$nextT);
|
||||
if (!$nextT) {
|
||||
$nextT = $first;
|
||||
}
|
||||
|
||||
$nextTDelta = $nextT - $lastT + ($lastT > $nextT ? 12 * 31 * 24 * 60 : 0);
|
||||
|
||||
//dprint($nowT.' '.$nowTDelta.' '.$nextT.' '.$nextTDelta);
|
||||
if ($nowTDelta >= $nextTDelta) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($weekdayspec) {
|
||||
foreach ($rules[4] as $mon) {
|
||||
foreach (_cronMonDaysFromWeekDays($year, $mon, $rules[5]) as $d) {
|
||||
foreach ($rules[2] as $h) {
|
||||
foreach ($rules[1] as $m) {
|
||||
$t = _cronT($mon, $d, $h, $m);
|
||||
//dprint("* ".$t." L:".$lastT);
|
||||
if ($t > $lastT) {
|
||||
$nextT = $t;
|
||||
break 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//dprint("R: ".$nextT);
|
||||
if (!$nextT) {
|
||||
//Must get the first of following year (if day_of_week is specified it's not the same of previous one)
|
||||
foreach ($rules[4] as $mon) {
|
||||
foreach (_cronMonDaysFromWeekDays($year + 1, $mon, $rules[5]) as $d) {
|
||||
foreach ($rules[2] as $h) {
|
||||
foreach ($rules[1] as $m) {
|
||||
$nextT = _cronT($mon, $d, $h, $m);
|
||||
break 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nextTDelta = $nextT - $lastT + ($lastT > $nextT ? 12 * 31 * 24 * 60 : 0);
|
||||
|
||||
//dprint($nowT.' '.$nowTDelta.' '.$nextT.' '.$nextTDelta);
|
||||
if ($nowTDelta >= $nextTDelta) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Used by elysia_cron_should_run
|
||||
function _cronT($time, $d = -1, $h = -1, $m = -1) {
|
||||
if ($d < 0) {
|
||||
return date('n', $time) * 31 * 24 * 60 + date('j', $time) * 24 * 60 + date('H', $time) * 60 + date('i', $time);
|
||||
}
|
||||
else {
|
||||
return $time * 31 * 24 * 60 + $d * 24 * 60 + $h * 60 + $m;
|
||||
}
|
||||
}
|
||||
|
||||
// Used by elysia_cron_should_run
|
||||
function _cronMonDaysFromWeekDays($year, $mon, $weekdays) {
|
||||
$result = array();
|
||||
for ($i = 1; checkdate($mon, $i, $year); $i++) {
|
||||
$w = date('w', mktime(12, 00, 00, $mon, $i, $year));
|
||||
if (in_array($w, $weekdays)) {
|
||||
$result[] = $i;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Used by elysia_cron_should_run
|
||||
function _cronDecodeRule($rule, $min, $max) {
|
||||
if ($rule == '*') {
|
||||
return range($min, $max);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach (explode(',', $rule) as $token) {
|
||||
if (preg_match('/^([0-9]+)-([0-9]+)$/', $token, $r)) {
|
||||
$result = array_merge($result, range($r[1], $r[2]));
|
||||
}
|
||||
elseif (preg_match('/^\*\/([0-9]+)$/', $token, $r)) {
|
||||
for ($i = $min; $i <= $max; $i++) {
|
||||
if ($i % $r[1] == 0) {
|
||||
$result[] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (is_numeric($token)) {
|
||||
$result[] = $token;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* TESTS
|
||||
******************************************************************************/
|
||||
|
||||
function test_elysia_cron_should_run() {
|
||||
dprint("Start test");
|
||||
$start = microtime(true);
|
||||
|
||||
//mktime: hr min sec mon day yr
|
||||
dprint(" 1." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 01, 0, 1, 2, 2008))));
|
||||
dprint(" 2." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(15, 00, 0, 1, 2, 2008))));
|
||||
dprint(" 3." . (false == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(11, 59, 0, 1, 3, 2008))));
|
||||
dprint(" 4." . (true == elysia_cron_should_run(array('rule' => '0 12 * * *', 'last_run' => mktime(12, 0, 0, 1, 2, 2008)), mktime(12, 00, 0, 1, 3, 2008))));
|
||||
dprint(" 5." . (false == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 3, 2008))));
|
||||
dprint(" 6." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 3, 2008))));
|
||||
dprint(" 7." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 59, 0, 1, 2, 2008)), mktime(0, 00, 0, 1, 4, 2008))));
|
||||
dprint(" 8." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(23, 59, 0, 1, 2, 2008))));
|
||||
dprint(" 9." . (true == elysia_cron_should_run(array('rule' => '59 23 * * *', 'last_run' => mktime(23, 58, 0, 1, 2, 2008)), mktime(0, 0, 0, 1, 3, 2008))));
|
||||
dprint("10." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("11." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(0, 0, 0, 1, 6, 2008))));
|
||||
dprint("12." . (true == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("13." . (true == elysia_cron_should_run(array('rule' => '59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(00, 00, 0, 1, 7, 2008))));
|
||||
dprint("14." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
|
||||
dprint("15." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("16." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("17." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 6, 2008))));
|
||||
dprint("18." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 58, 0, 1, 5, 2008)), mktime(23, 28, 0, 1, 6, 2008))));
|
||||
dprint("19." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 5, 2008))));
|
||||
dprint("20." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 30, 0, 1, 5, 2008))));
|
||||
dprint("21." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("22." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 0', 'last_run' => mktime(23, 28, 0, 1, 5, 2008)), mktime(23, 29, 0, 1, 6, 2008))));
|
||||
|
||||
dprint("23." . (false == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 28, 2008))));
|
||||
dprint("24." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
|
||||
dprint("25." . (true == elysia_cron_should_run(array('rule' => '29,59 23 * * 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
|
||||
|
||||
dprint("26." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 1, 2009))));
|
||||
dprint("27." . (false == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(0, 0, 0, 1, 7, 2009))));
|
||||
dprint("28." . (true == elysia_cron_should_run(array('rule' => '59 23 * * 3', 'last_run' => mktime(23, 59, 0, 12, 31, 2008)), mktime(23, 59, 0, 1, 7, 2009))));
|
||||
|
||||
dprint("29." . (true == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(23, 59, 0, 2, 29, 2008))));
|
||||
dprint("30." . (true == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 22, 2008)), mktime(0, 0, 0, 3, 1, 2008))));
|
||||
dprint("31." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 3, 7, 2008))));
|
||||
dprint("32." . (false == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 58, 0, 2, 6, 2009))));
|
||||
dprint("33." . (true == elysia_cron_should_run(array('rule' => '59 23 * 2 5', 'last_run' => mktime(23, 59, 0, 2, 29, 2008)), mktime(23, 59, 0, 2, 6, 2009))));
|
||||
dprint("34." . (true == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 58, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
|
||||
dprint("35." . (false == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 11, 2008))));
|
||||
dprint("36." . (true == elysia_cron_should_run(array('rule' => '59 23 *' . '/10 * *', 'last_run' => mktime(23, 59, 0, 1, 10, 2008)), mktime(23, 59, 0, 1, 20, 2008))));
|
||||
dprint("37." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("38." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("39." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("40." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 58, 0, 1, 10, 2008))));
|
||||
dprint("41." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 10, 2008))));
|
||||
dprint("42." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5,10-15 * *', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 16, 2008))));
|
||||
|
||||
dprint("43." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 4, 2008)), mktime(23, 59, 0, 1, 5, 2008))));
|
||||
dprint("44." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 5, 2008)), mktime(23, 59, 0, 1, 6, 2008))));
|
||||
dprint("45." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 7, 2008))));
|
||||
dprint("46." . (true == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 1, 6, 2008)), mktime(23, 59, 0, 1, 13, 2008))));
|
||||
dprint("47." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 4, 2008)), mktime(23, 59, 0, 2, 5, 2008))));
|
||||
dprint("48." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 5, 2008)), mktime(23, 59, 0, 2, 10, 2008))));
|
||||
dprint("49." . (false == elysia_cron_should_run(array('rule' => '59 23 1-5 1 0', 'last_run' => mktime(23, 59, 0, 2, 10, 2008)), mktime(23, 59, 0, 2, 17, 2008))));
|
||||
|
||||
dprint("49." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 58, 0, 2, 10, 2008)), mktime(8, 59, 0, 2, 10, 2008))));
|
||||
dprint("50." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(9, 00, 0, 2, 10, 2008))));
|
||||
dprint("51." . (false == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(17, 59, 0, 2, 10, 2008))));
|
||||
dprint("52." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(8, 59, 0, 2, 10, 2008)), mktime(18, 00, 0, 2, 10, 2008))));
|
||||
dprint("53." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(18, 01, 0, 2, 10, 2008))));
|
||||
dprint("54." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(19, 0, 0, 2, 10, 2008))));
|
||||
dprint("55." . (true == elysia_cron_should_run(array('rule' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *', 'last_run' => mktime(18, 00, 0, 2, 10, 2008)), mktime(9, 0, 0, 3, 10, 2008))));
|
||||
|
||||
dprint("End test (" . (microtime(true) - $start) . ")");
|
||||
}
|
||||
// Remove comment to run tests
|
||||
//test_elysia_cron_should_run();die();
|
@@ -1,327 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************************
|
||||
* ELYSIA CRON VERSION UPDATE
|
||||
******************************************************************************/
|
||||
|
||||
function elysia_cron_check_version_update() {
|
||||
$ver = variable_get('elysia_cron_version', 0);
|
||||
if ($ver < 20111012) {
|
||||
$ver = _ec_variable_get('elysia_cron_version', 0);
|
||||
}
|
||||
|
||||
if (!$ver || $ver < 20090218) {
|
||||
|
||||
$unchanged = array(
|
||||
'elysia_cron_last_context',
|
||||
'elysia_cron_last_run',
|
||||
'elysia_cron_disabled',
|
||||
'elysia_cron_semaphore',
|
||||
'elysia_cron_key',
|
||||
'elysia_cron_allowed_hosts',
|
||||
'elysia_cron_default_rule',
|
||||
'elysia_cron_script',
|
||||
'elysia_cron_runtime_replacement',
|
||||
'elysia_cron_version',
|
||||
);
|
||||
|
||||
$rs = db_query("select * from {variable} where name like 'elysia_cron_%%'");
|
||||
while ($v = db_fetch_object($rs)) {
|
||||
if (!in_array($v->name, $unchanged)) {
|
||||
$vn = false;
|
||||
if (preg_match('/^elysia_cron_ctx_(.*)_(running|disabled|last_run|last_aborted|abort_count|execution_count|last_execution_time|avg_execution_time|max_execution_time|last_shutdown_time|last_abort_function)/', $v->name, $r)) {
|
||||
switch ($r[2]) {
|
||||
case 'running':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_r';
|
||||
break;
|
||||
case 'disabled':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_d';
|
||||
break;
|
||||
case 'last_run':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_lr';
|
||||
break;
|
||||
case 'last_aborted':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_la';
|
||||
break;
|
||||
case 'abort_count':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_ac';
|
||||
break;
|
||||
case 'execution_count':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_ec';
|
||||
break;
|
||||
case 'last_execution_time':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_let';
|
||||
break;
|
||||
case 'avg_execution_time':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_aet';
|
||||
break;
|
||||
case 'max_execution_time':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_met';
|
||||
break;
|
||||
case 'last_shutdown_time':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_lst';
|
||||
break;
|
||||
case 'last_abort_function':
|
||||
$vn = 'ecc_' . _ec_get_name($r[1]) . '_laf';
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif (preg_match('/^elysia_cron_(.*)_(rule|disabled|context|running|last_run|last_execution_time|execution_count|avg_execution_time|max_execution_time)/', $v->name, $r)) {
|
||||
switch ($r[2]) {
|
||||
case 'rule':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_rul';
|
||||
break;
|
||||
case 'disabled':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_d';
|
||||
break;
|
||||
case 'context':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_c';
|
||||
break;
|
||||
case 'running':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_r';
|
||||
break;
|
||||
case 'last_run':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_lr';
|
||||
break;
|
||||
case 'last_execution_time':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_let';
|
||||
break;
|
||||
case 'execution_count':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_ec';
|
||||
break;
|
||||
case 'avg_execution_time':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_aet';
|
||||
break;
|
||||
case 'max_execution_time':
|
||||
$vn = 'ec_' . _ec_get_name($r[1]) . '_met';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($vn) {
|
||||
variable_set($vn, unserialize($v->value));
|
||||
}
|
||||
else {
|
||||
elysia_cron_error('Error in update, cant convert %name (value: %value)', array('%name' => $v->name, '%value' => $v->value), true);
|
||||
}
|
||||
|
||||
variable_del($v->name);
|
||||
}
|
||||
}
|
||||
|
||||
variable_set('elysia_cron_version', 20090218);
|
||||
}
|
||||
if ($ver < 20090920) {
|
||||
variable_set('elysia_cron_version', 20090920);
|
||||
|
||||
}
|
||||
if ($ver < 20100507) {
|
||||
if (EC_DRUPAL_VERSION >= 6) {
|
||||
// D6
|
||||
drupal_install_schema('elysia_cron');
|
||||
|
||||
// In ver 20111020 disabled has been renamed to disable, revert it now
|
||||
if (EC_DRUPAL_VERSION >= 7) {
|
||||
// D7
|
||||
// Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
|
||||
db_change_field($v = 'elysia_cron', 'disable', 'disabled', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
|
||||
|
||||
}
|
||||
elseif (EC_DRUPAL_VERSION >= 6) {
|
||||
// D6
|
||||
$ret = array();
|
||||
db_change_field($ret, 'elysia_cron', 'disable', 'disabled', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// D5
|
||||
switch ($GLOBALS['db_type']) {
|
||||
case 'mysqli':
|
||||
case 'mysql':
|
||||
db_query("create table if not exists {elysia_cron} (
|
||||
name varchar(120) not null,
|
||||
disabled tinyint(1) not null default '0',
|
||||
rule varchar(32),
|
||||
weight int(11) not null default '0',
|
||||
context varchar(32),
|
||||
running int(11) not null default '0',
|
||||
last_run int(11) not null default '0',
|
||||
last_aborted tinyint(1) not null default '0',
|
||||
abort_count int(11) not null default '0',
|
||||
last_abort_function varchar(32),
|
||||
last_execution_time int(11) not null default '0',
|
||||
execution_count int(11) not null default '0',
|
||||
avg_execution_time float(5,2) not null default '0',
|
||||
max_execution_time int(11) not null default '0',
|
||||
last_shutdown_time int(11) not null default '0',
|
||||
primary key (name)
|
||||
)");
|
||||
break;
|
||||
case 'pgsql':
|
||||
db_query("create table {elysia_cron} (
|
||||
name varchar(120) not null,
|
||||
disabled smallint not null default '0',
|
||||
rule varchar(32),
|
||||
weight integer not null default '0',
|
||||
context varchar(32),
|
||||
running int not null default '0',
|
||||
last_run integer not null default '0',
|
||||
last_aborted smallint not null default '0',
|
||||
abort_count integer not null default '0',
|
||||
last_abort_function varchar(32),
|
||||
last_execution_time integer not null default '0',
|
||||
execution_count integer not null default '0',
|
||||
avg_execution_time float not null default '0',
|
||||
max_execution_time integer not null default '0',
|
||||
last_shutdown_time integer not null default '0',
|
||||
primary key (name)
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
$rs = db_query("select * from {variable} where name like 'ec_%%' or name like 'ecc_%%'");
|
||||
$data = array();
|
||||
$todelete = array();
|
||||
while ($v = db_fetch_object($rs)) {
|
||||
$name = false;
|
||||
if (preg_match('/^ecc_(.+)_(r|d|lr|la|ac|ec|let|aet|met|lst|laf)/', $v->name, $r)) {
|
||||
$name = ':' . $r[1];
|
||||
}
|
||||
elseif (preg_match('/^ec_(.+)_(rul|d|c|w|r|lr|let|ec|aet|met)/', $v->name, $r)) {
|
||||
$name = $r[1];
|
||||
}
|
||||
if ($name) {
|
||||
if (!isset($data[$name])) {
|
||||
$data[$name] = array('name' => $name);
|
||||
}
|
||||
switch ($r[2]) {
|
||||
case 'r':
|
||||
$f = 'running';
|
||||
break;
|
||||
case 'd':
|
||||
$f = 'disabled';
|
||||
break;
|
||||
case 'rul':
|
||||
$f = 'rule';
|
||||
break;
|
||||
case 'w':
|
||||
$f = 'weight';
|
||||
break;
|
||||
case 'c':
|
||||
$f = 'context';
|
||||
break;
|
||||
case 'lr':
|
||||
$f = 'last_run';
|
||||
break;
|
||||
case 'la':
|
||||
$f = 'last_aborted';
|
||||
break;
|
||||
case 'ac':
|
||||
$f = 'abort_count';
|
||||
break;
|
||||
case 'laf':
|
||||
$f = 'last_abort_function';
|
||||
break;
|
||||
case 'let':
|
||||
$f = 'last_execution_time';
|
||||
break;
|
||||
case 'ec':
|
||||
$f = 'execution_count';
|
||||
break;
|
||||
case 'aet':
|
||||
$f = 'avg_execution_time';
|
||||
break;
|
||||
case 'met':
|
||||
$f = 'max_execution_time';
|
||||
break;
|
||||
case 'lst':
|
||||
$f = 'last_shutdown_time';
|
||||
break;
|
||||
}
|
||||
$data[$name][$f] = unserialize($v->value);
|
||||
$todelete[] = $v->name;
|
||||
}
|
||||
}
|
||||
|
||||
$ifields = array('disabled', 'weight', 'running', 'last_run', 'last_aborted', 'abort_count', 'last_execution_time', 'execution_count', 'avg_execution_time', 'max_execution_time', 'last_shutdown_time');
|
||||
foreach ($data as $v) {
|
||||
foreach ($ifields as $f) {
|
||||
if (empty($v[$f])) {
|
||||
$v[$f] = 0;
|
||||
}
|
||||
}
|
||||
db_query("insert into {elysia_cron} (name, disabled, rule, weight, context, running, last_run, last_aborted, abort_count, last_abort_function, last_execution_time, execution_count, avg_execution_time, max_execution_time, last_shutdown_time)
|
||||
values ('%s', %d, '%s', %d, '%s', %d, %d, %d, %d, '%s', %d, %d, %f, %d, %d)",
|
||||
$v['name'], $v['disabled'], $v['rule'], $v['weight'], $v['context'], $v['running'], $v['last_run'], $v['last_aborted'], $v['abort_count'], $v['last_abort_function'], $v['last_execution_time'], $v['execution_count'], $v['avg_execution_time'], $v['max_execution_time'], $v['last_shutdown_time']
|
||||
);
|
||||
}
|
||||
|
||||
db_query("update {elysia_cron} set context = null where context = ''");
|
||||
db_query("update {elysia_cron} set rule = null where rule = ''");
|
||||
|
||||
foreach ($todelete as $v) {
|
||||
variable_del($v);
|
||||
db_query("DELETE FROM {variable} WHERE name = '%s'", $v);
|
||||
}
|
||||
|
||||
variable_set('elysia_cron_version', 20100507);
|
||||
|
||||
unset($GLOBALS['_ec_variables']);
|
||||
}
|
||||
// D7 VERSION FROM NOW ON...
|
||||
|
||||
if ($ver < 20110323) {
|
||||
if (EC_DRUPAL_VERSION >= 7) {
|
||||
// D7
|
||||
// Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
|
||||
db_change_field($v = 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE));
|
||||
|
||||
}
|
||||
elseif (EC_DRUPAL_VERSION >= 6) {
|
||||
// D6
|
||||
$ret = array();
|
||||
db_change_field($ret, 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE));
|
||||
}
|
||||
else {
|
||||
// D5
|
||||
db_query("alter table {elysia_cron} change weight weight int(11)");
|
||||
}
|
||||
|
||||
variable_set('elysia_cron_version', 20110323);
|
||||
}
|
||||
|
||||
if ($ver < 20111007) {
|
||||
$default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']);
|
||||
if (!empty($default_rules['*/6 * * * *']) && $default_rules['*/6 * * * *'] == 'Every 6 hours') {
|
||||
unset($default_rules['*/6 * * * *']);
|
||||
$default_rules['0 */6 * * *'] = 'Every 6 hours';
|
||||
variable_set('elysia_cron_default_rules', $default_rules);
|
||||
}
|
||||
variable_set('elysia_cron_version', 20111007);
|
||||
}
|
||||
|
||||
if ($ver < 20111012) {
|
||||
// I only need to rebuild variable cache, so i just set the new version
|
||||
variable_set('elysia_cron_version', 20111012);
|
||||
}
|
||||
|
||||
if ($ver < 20111020) {
|
||||
if (EC_DRUPAL_VERSION >= 7) {
|
||||
// D7
|
||||
// Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here)
|
||||
db_change_field($v = 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
|
||||
|
||||
}
|
||||
elseif (EC_DRUPAL_VERSION >= 6) {
|
||||
// D6
|
||||
$ret = array();
|
||||
db_change_field($ret, 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE));
|
||||
}
|
||||
else {
|
||||
// D5
|
||||
db_query("alter table {elysia_cron} change disabled disable tinyint(1)");
|
||||
}
|
||||
db_query("update {elysia_cron} set disable = NULL where disable = 0");
|
||||
|
||||
variable_set('elysia_cron_version', 20111020);
|
||||
}
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
define('EC_DRUPAL_VERSION', 7);
|
||||
|
||||
/***************************************************************
|
||||
* D7 VERSION
|
||||
***************************************************************/
|
||||
|
||||
function _dcf_hook_boot($module) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function _dcf_hook_init($module) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function _dcf_hook_menu($items, $maycache) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
function _dcr_render_array($output) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
function _dcr_form(&$form) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
function _dcf_internal_path($path) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
function _dcf_t($string) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
function _dco_watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { // WARN d7 changed WATCHDOG_ costants
|
||||
return watchdog($type, $message, $variables, $severity, $link);
|
||||
}
|
||||
|
||||
function _dco_l($text, $path, array $options = array()) {
|
||||
return l($text, $path, $options);
|
||||
}
|
||||
|
||||
function _dcf_form_validate(&$form, &$form_state) {
|
||||
return array('form' => &$form, 'form_state' => &$form_state);
|
||||
}
|
||||
|
||||
function _dco_theme($name, $args) {
|
||||
return theme($name, $args);
|
||||
}
|
||||
|
||||
function _dcf_theme_signature($args) {
|
||||
return array();
|
||||
}
|
||||
|
||||
function _dcr_hook_theme($specs) {
|
||||
return $specs;
|
||||
}
|
||||
|
||||
function _dcf_theme_form(&$args) {
|
||||
return array( 'variables' => $args );
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* D7 EXTRA FUNCTIONS
|
||||
***************************************************************/
|
||||
|
||||
function drupal_module_get_min_weight($except_module = false) {
|
||||
return !$except_module ? db_query("select min(weight) from {system}")->fetchField() :
|
||||
db_query("select min(weight) from {system} where name != :name", array(':name' => $except_module))->fetchField();
|
||||
}
|
||||
|
||||
function drupal_module_get_weight($name) {
|
||||
return db_query("select weight from {system} where name = :name", array(':name' => $name))->fetchField();
|
||||
}
|
||||
|
||||
function drupal_module_set_weight($name, $weight) {
|
||||
db_update('system')->fields(array('weight' => $weight))->condition('name', $name)->execute();
|
||||
}
|
||||
|
||||
function drupal_disable_standard_cron() {
|
||||
}
|
||||
|
||||
function drupal_clean_after_cron_run() {
|
||||
}
|
Reference in New Issue
Block a user