Skip to content

Commit

Permalink
Merge pull request #418 from x-team/issue-412
Browse files Browse the repository at this point in the history
Fixing auto purge cron that was not being created properly
  • Loading branch information
lukecarbis committed Apr 22, 2014
2 parents c6e95e3 + 6b6dc09 commit ca2d245
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -426,6 +426,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" );
Expand All @@ -447,7 +451,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' );
}
}

Expand Down
7 changes: 7 additions & 0 deletions includes/db-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
);

Expand Down

0 comments on commit ca2d245

Please sign in to comment.