Skip to content

Commit

Permalink
Merge pull request #326 from Prospress/revert-297-fix/296
Browse files Browse the repository at this point in the history
Fix marking actions with invalid schedules as failed
  • Loading branch information
rrennick authored Jul 30, 2019
2 parents 8aa3092 + d3a690d commit 0b64982
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
43 changes: 1 addition & 42 deletions classes/abstracts/ActionScheduler_Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Class ActionScheduler_Store
* @codeCoverageIgnore
*/
abstract class ActionScheduler_Store {
abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
const STATUS_COMPLETE = 'complete';
const STATUS_PENDING = 'pending';
const STATUS_RUNNING = 'in-progress';
Expand Down Expand Up @@ -239,55 +239,14 @@ public function has_pending_actions_due() {

public function init() {}

/**
* Mark an action that failed to fetch correctly as failed.
*
* @since 2.2.6
*
* @param int $action_id The ID of the action.
*/
public function mark_failed_fetch_action( $action_id ) {
self::$store->mark_failure( $action_id );
}

/**
* Add base hooks
*
* @since 2.2.6
*/
public static function hook() {
add_action( 'action_scheduler_failed_fetch_action', array( self::$store, 'mark_failed_fetch_action' ), 20 );
}

/**
* Remove base hooks
*
* @since 2.2.6
*/
public static function unhook() {
remove_action( 'action_scheduler_failed_fetch_action', array( self::$store, 'mark_failed_fetch_action' ), 20 );
}

/**
* @return ActionScheduler_Store
*/
public static function instance() {
if ( empty( self::$store ) ) {
$class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
self::$store = new $class();
self::hook();
}
return self::$store;
}

/**
* Get the site's local time.
*
* @deprecated 2.1.0
* @return DateTimeZone
*/
protected function get_local_timezone() {
_deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
return ActionScheduler_TimezoneHelper::get_local_timezone();
}
}
49 changes: 49 additions & 0 deletions deprecated/ActionScheduler_Store_Deprecated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* Class ActionScheduler_Store_Deprecated
* @codeCoverageIgnore
*/
abstract class ActionScheduler_Store_Deprecated {

/**
* Mark an action that failed to fetch correctly as failed.
*
* @since 2.2.6
*
* @param int $action_id The ID of the action.
*/
public function mark_failed_fetch_action( $action_id ) {
_deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' );
self::$store->mark_failure( $action_id );
}

/**
* Add base hooks
*
* @since 2.2.6
*/
protected static function hook() {
_deprecated_function( __METHOD__, '3.0.0' );
}

/**
* Remove base hooks
*
* @since 2.2.6
*/
protected static function unhook() {
_deprecated_function( __METHOD__, '3.0.0' );
}

/**
* Get the site's local time.
*
* @deprecated 2.1.0
* @return DateTimeZone
*/
protected function get_local_timezone() {
_deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
return ActionScheduler_TimezoneHelper::get_local_timezone();
}
}
2 changes: 0 additions & 2 deletions tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public function test_action_bad_args( $content ) {
'post_content' => $content,
) );

ActionScheduler_Store::unhook();
$fetched = $store->fetch_action( $post_id );
ActionScheduler_Store::hook();
$this->assertInstanceOf( 'ActionScheduler_NullSchedule', $fetched->get_schedule() );
}

Expand Down

0 comments on commit 0b64982

Please sign in to comment.