From 137ac2984d975f0ee2d7c278221e44134909379f Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Fri, 18 Apr 2014 11:26:34 -0500 Subject: [PATCH 1/2] Fixing auto purge cron that was not being created properly --- includes/admin.php | 8 ++++++-- includes/db-updates.php | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index 617a18fc6..9727933ee 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -49,7 +49,7 @@ public static function load() { add_action( 'wp_ajax_wp_stream_uninstall', array( __CLASS__, 'uninstall_plugin' ) ); // Auto purge setup - add_action( 'wp', array( __CLASS__, 'purge_schedule_setup' ) ); + add_action( 'wp_loaded', array( __CLASS__, 'purge_schedule_setup' ) ); add_action( 'wp_stream_auto_purge', array( __CLASS__, 'purge_scheduled_action' ) ); // Admin notices @@ -429,6 +429,10 @@ public static function uninstall_plugin() { // Deactivate the plugin deactivate_plugins( plugin_basename( WP_STREAM_DIR ) . '/stream.php' ); + // Delete scheduled cron event hooks + wp_clear_scheduled_hook( 'stream_auto_purge' ); // Deprecated hook + wp_clear_scheduled_hook( 'wp_stream_auto_purge' ); + // Delete all tables foreach ( WP_Stream_DB::get_instance()->get_table_names() as $table ) { $wpdb->query( "DROP TABLE $table" ); @@ -450,7 +454,7 @@ public static function uninstall_plugin() { public static function purge_schedule_setup() { if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) { - wp_schedule_event( time(), 'daily', 'wp_stream_auto_purge' ); + wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' ); } } diff --git a/includes/db-updates.php b/includes/db-updates.php index ade6c58cf..709773e49 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -49,6 +49,13 @@ function wp_stream_update_140( $db_version, $current_version ) { return esc_html__( 'Database Update Error', 'stream' ); } + // Clear an old cron event hook that is lingering, replaced by `wp_stream_auto_purge` + wp_clear_scheduled_hook( 'stream_auto_purge' ); + + // Clear out this cron event hook too since we're changing the interval in this release + // and want the new schedule to take affect immediately after updating. + wp_clear_scheduled_hook( 'wp_stream_auto_purge' ); + return $current_version; } From 6b6dc09f0bbc7178205d17a8851e95677764cb0d Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Fri, 18 Apr 2014 11:33:37 -0500 Subject: [PATCH 2/2] Updating tests --- tests/tests/test-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/test-admin.php b/tests/tests/test-admin.php index 8ae8a417a..cd883ad0c 100644 --- a/tests/tests/test-admin.php +++ b/tests/tests/test-admin.php @@ -48,7 +48,7 @@ public function test_constructor() { array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_enqueue_scripts' ), array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_menu_css' ), array( 'wp_ajax_wp_stream_reset', self::CLASSNAME, 'wp_ajax_reset' ), - array( 'wp', self::CLASSNAME, 'purge_schedule_setup' ), + array( 'wp_loaded', self::CLASSNAME, 'purge_schedule_setup' ), array( 'wp_stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ), );