diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-09-14 15:04:44 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-09-14 15:04:44 +0000 |
| commit | b1d917d5d377c88241aa233d4c6403213afa05df (patch) | |
| tree | c2cbc61fa1ca5297a5dd065d8a6ef7c5a855061b /wp-includes/cron.php | |
| parent | 0594b4fefe09d84f0ed8ba46a6a0bb8f925027ea (diff) | |
WP Merge to rev #4191
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@753 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/cron.php')
| -rw-r--r-- | wp-includes/cron.php | 94 |
1 files changed, 69 insertions, 25 deletions
diff --git a/wp-includes/cron.php b/wp-includes/cron.php index 6f3d6b0..677fc3c 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -2,27 +2,30 @@ function wp_schedule_single_event( $timestamp, $hook ) {
$args = array_slice( func_get_args(), 2 );
- $crons = get_option( 'cron' );
- $crons[$timestamp][$hook] = array( 'schedule' => false, 'args' => $args );
+ $crons = _get_cron_array();
+ $key = md5(serialize($args));
+ $crons[$timestamp][$hook][$key] = array( 'schedule' => false, 'args' => $args );
ksort( $crons );
- update_option( 'cron', $crons );
+ _set_cron_array( $crons );
}
function wp_schedule_event( $timestamp, $recurrence, $hook ) {
$args = array_slice( func_get_args(), 3 );
- $crons = get_option( 'cron' );
+ $crons = _get_cron_array();
$schedules = wp_get_schedules();
+ $key = md5(serialize($args));
if ( !isset( $schedules[$recurrence] ) )
return false;
- $crons[$timestamp][$hook] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );
+ $crons[$timestamp][$hook][$key] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );
ksort( $crons );
- update_option( 'cron', $crons );
+ _set_cron_array( $crons );
}
function wp_reschedule_event( $timestamp, $recurrence, $hook ) {
$args = array_slice( func_get_args(), 3 );
- $crons = get_option( 'cron' );
+ $crons = _get_cron_array();
$schedules = wp_get_schedules();
+ $key = md5(serialize($args));
$interval = 0;
// First we try to get it from the schedule
@@ -30,7 +33,7 @@ function wp_reschedule_event( $timestamp, $recurrence, $hook ) { $interval = $schedules[$recurrence]['interval'];
// Now we try to get it from the saved interval in case the schedule disappears
if ( 0 == $interval )
- $interval = $crons[$timestamp][$hook]['interval'];
+ $interval = $crons[$timestamp][$hook][$key]['interval'];
// Now we assume something is wrong and fail to schedule
if ( 0 == $interval )
return false;
@@ -38,40 +41,41 @@ function wp_reschedule_event( $timestamp, $recurrence, $hook ) { while ( $timestamp < time() + 1 )
$timestamp += $interval;
- wp_schedule_event( $timestamp, $recurrence, $hook );
+ wp_schedule_event( $timestamp, $recurrence, $hook, $args );
}
-function wp_unschedule_event( $timestamp, $hook ) {
- $crons = get_option( 'cron' );
- unset( $crons[$timestamp][$hook] );
+function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
+ $crons = _get_cron_array();
+ $key = md5(serialize($args));
+ unset( $crons[$timestamp][$hook][$key] );
+ if ( empty($crons[$timestamp][$hook]) )
+ unset( $crons[$timestamp][$hook] );
if ( empty($crons[$timestamp]) )
unset( $crons[$timestamp] );
- update_option( 'cron', $crons );
+ _set_cron_array( $crons );
}
function wp_clear_scheduled_hook( $hook ) {
$args = array_slice( func_get_args(), 1 );
while ( $timestamp = wp_next_scheduled( $hook, $args ) )
- wp_unschedule_event( $timestamp, $hook );
+ wp_unschedule_event( $timestamp, $hook, $args );
}
-function wp_next_scheduled( $hook, $args = '' ) {
- $crons = get_option( 'cron' );
+function wp_next_scheduled( $hook, $args = array() ) {
+ $crons = _get_cron_array();
+ $key = md5(serialize($args));
if ( empty($crons) )
return false;
- foreach ( $crons as $timestamp => $cron )
- if ( isset( $cron[$hook] ) ) {
- if ( empty($args) )
- return $timestamp;
- if ( $args == $cron[$hook]['args'] )
- return $timestamp;
- }
+ foreach ( $crons as $timestamp => $cron ) {
+ if ( isset( $cron[$hook][$key] ) )
+ return $timestamp;
+ }
return false;
}
function spawn_cron() {
- $crons = get_option( 'cron' );
+ $crons = _get_cron_array();
if ( !is_array($crons) )
return;
@@ -92,7 +96,7 @@ function spawn_cron() { }
function wp_cron() {
- $crons = get_option( 'cron' );
+ $crons = _get_cron_array();
if ( !is_array($crons) )
return;
@@ -121,4 +125,44 @@ function wp_get_schedules() { return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
}
+//
+// Private functions
+//
+
+function _get_cron_array() {
+ $cron = get_option('cron');
+ if ( ! is_array($cron) )
+ return false;
+
+ if ( !isset($cron['version']) )
+ $cron = _upgrade_cron_array($cron);
+
+ unset($cron['version']);
+
+ return $cron;
+}
+
+function _set_cron_array($cron) {
+ $cron['version'] = 2;
+ update_option( 'cron', $cron );
+}
+
+function _upgrade_cron_array($cron) {
+ if ( isset($cron['version']) && 2 == $cron['version'])
+ return $cron;
+
+ $new_cron = array();
+
+ foreach ($cron as $timestamp => $hooks) {
+ foreach ( $hooks as $hook => $args ) {
+ $key = md5(serialize($args['args']));
+ $new_cron[$timestamp][$hook][$key] = $args;
+ }
+ }
+
+ $new_cron['version'] = 2;
+ update_option( 'cron', $new_cron );
+ return $new_cron;
+}
+
?>
|
