Skip to content

Commit

Permalink
Merge pull request #208 from x-team/issue-61
Browse files Browse the repository at this point in the history
Issue 61: Fire cron event if auto-purge value is updated
  • Loading branch information
frankiejarrett committed Feb 4, 2014
2 parents a07425a + a86eb4d commit cbace1d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function load() {

// Auto purge setup
add_action( 'init', array( __CLASS__, 'purge_schedule_setup' ) );
add_action( 'stream_auto_purge', array( __CLASS__, 'purge_scheduled_action' ) );
add_action( 'wp_stream_auto_purge', array( __CLASS__, 'purge_scheduled_action' ) );

// Admin notices
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
Expand Down
23 changes: 22 additions & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public static function load() {
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );

// Check if we need to flush rewrites rules
add_action( 'update_option_' . self::KEY , array( __CLASS__, 'updated_option_trigger_flush_rules' ), 10, 2 );
add_action( 'update_option_' . self::KEY, array( __CLASS__, 'updated_option_trigger_flush_rules' ), 10, 2 );

// Remove records when records TTL is shortened
add_action( 'update_option_' . self::KEY, array( __CLASS__, 'updated_option_ttl_remove_records' ), 10, 2 );

add_filter( 'wp_stream_serialized_labels', array( __CLASS__, 'get_settings_translations' ) );
}
Expand Down Expand Up @@ -401,4 +404,22 @@ public static function get_settings_translations( $labels ) {

return $labels;
}

/**
* Remove records when records TTL is shortened
*
* @param array $old_value
* @param array $new_value
*
* @action update_option_wp_stream
* @return void
*/
public function updated_option_ttl_remove_records( $old_value, $new_value ) {
$ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : -1;
$ttl_after = isset( $new_value['general_records_ttl'] ) ? (int) $new_value['general_records_ttl'] : -1;

if ( $ttl_after < $ttl_before ) {
do_action( 'wp_stream_auto_purge' );
}
}
}
2 changes: 1 addition & 1 deletion tests/tests/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function test_constructor() {
array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_menu_css' ),
array( 'wp_ajax_wp_stream_reset', self::CLASSNAME, 'wp_ajax_reset' ),
array( 'init', self::CLASSNAME, 'purge_schedule_setup' ),
array( 'stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ),
array( 'wp_stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ),
);

$this->do_action_validation( $test_actions );
Expand Down

0 comments on commit cbace1d

Please sign in to comment.