@@ -13,97 +13,97 @@ |
||
13 | 13 | * @codeCoverageIgnore |
14 | 14 | */ |
15 | 15 | class ActionMigrator { |
16 | - /** var ActionScheduler_Store */ |
|
17 | - private $source; |
|
18 | - |
|
19 | - /** var ActionScheduler_Store */ |
|
20 | - private $destination; |
|
21 | - |
|
22 | - /** var LogMigrator */ |
|
23 | - private $log_migrator; |
|
24 | - |
|
25 | - /** |
|
26 | - * ActionMigrator constructor. |
|
27 | - * |
|
28 | - * @param ActionScheduler_Store $source_store Source store object. |
|
29 | - * @param ActionScheduler_Store $destination_store Destination store object. |
|
30 | - * @param LogMigrator $log_migrator Log migrator object. |
|
31 | - */ |
|
32 | - public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
33 | - $this->source = $source_store; |
|
34 | - $this->destination = $destination_store; |
|
35 | - $this->log_migrator = $log_migrator; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Migrate an action. |
|
40 | - * |
|
41 | - * @param int $source_action_id Action ID. |
|
42 | - * |
|
43 | - * @return int 0|new action ID |
|
44 | - */ |
|
45 | - public function migrate( $source_action_id ) { |
|
46 | - try { |
|
47 | - $action = $this->source->fetch_action( $source_action_id ); |
|
48 | - $status = $this->source->get_status( $source_action_id ); |
|
49 | - } catch ( \Exception $e ) { |
|
50 | - $action = null; |
|
51 | - $status = ''; |
|
52 | - } |
|
53 | - |
|
54 | - if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
55 | - // null action or empty status means the fetch operation failed or the action didn't exist |
|
56 | - // null schedule means it's missing vital data |
|
57 | - // delete it and move on |
|
58 | - try { |
|
59 | - $this->source->delete_action( $source_action_id ); |
|
60 | - } catch ( \Exception $e ) { |
|
61 | - // nothing to do, it didn't exist in the first place |
|
62 | - } |
|
63 | - do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
64 | - |
|
65 | - return 0; |
|
66 | - } |
|
67 | - |
|
68 | - try { |
|
69 | - |
|
70 | - // Make sure the last attempt date is set correctly for completed and failed actions |
|
71 | - $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
72 | - |
|
73 | - $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
74 | - } catch ( \Exception $e ) { |
|
75 | - do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
76 | - |
|
77 | - return 0; // could not save the action in the new store |
|
78 | - } |
|
79 | - |
|
80 | - try { |
|
81 | - switch ( $status ) { |
|
82 | - case \ActionScheduler_Store::STATUS_FAILED : |
|
83 | - $this->destination->mark_failure( $destination_action_id ); |
|
84 | - break; |
|
85 | - case \ActionScheduler_Store::STATUS_CANCELED : |
|
86 | - $this->destination->cancel_action( $destination_action_id ); |
|
87 | - break; |
|
88 | - } |
|
89 | - |
|
90 | - $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
91 | - $this->source->delete_action( $source_action_id ); |
|
92 | - |
|
93 | - $test_action = $this->source->fetch_action( $source_action_id ); |
|
94 | - if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
95 | - throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) ); |
|
96 | - } |
|
97 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
98 | - |
|
99 | - return $destination_action_id; |
|
100 | - } catch ( \Exception $e ) { |
|
101 | - // could not delete from the old store |
|
102 | - $this->source->mark_migrated( $source_action_id ); |
|
103 | - do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
104 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
105 | - |
|
106 | - return $destination_action_id; |
|
107 | - } |
|
108 | - } |
|
16 | + /** var ActionScheduler_Store */ |
|
17 | + private $source; |
|
18 | + |
|
19 | + /** var ActionScheduler_Store */ |
|
20 | + private $destination; |
|
21 | + |
|
22 | + /** var LogMigrator */ |
|
23 | + private $log_migrator; |
|
24 | + |
|
25 | + /** |
|
26 | + * ActionMigrator constructor. |
|
27 | + * |
|
28 | + * @param ActionScheduler_Store $source_store Source store object. |
|
29 | + * @param ActionScheduler_Store $destination_store Destination store object. |
|
30 | + * @param LogMigrator $log_migrator Log migrator object. |
|
31 | + */ |
|
32 | + public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
33 | + $this->source = $source_store; |
|
34 | + $this->destination = $destination_store; |
|
35 | + $this->log_migrator = $log_migrator; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Migrate an action. |
|
40 | + * |
|
41 | + * @param int $source_action_id Action ID. |
|
42 | + * |
|
43 | + * @return int 0|new action ID |
|
44 | + */ |
|
45 | + public function migrate( $source_action_id ) { |
|
46 | + try { |
|
47 | + $action = $this->source->fetch_action( $source_action_id ); |
|
48 | + $status = $this->source->get_status( $source_action_id ); |
|
49 | + } catch ( \Exception $e ) { |
|
50 | + $action = null; |
|
51 | + $status = ''; |
|
52 | + } |
|
53 | + |
|
54 | + if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
55 | + // null action or empty status means the fetch operation failed or the action didn't exist |
|
56 | + // null schedule means it's missing vital data |
|
57 | + // delete it and move on |
|
58 | + try { |
|
59 | + $this->source->delete_action( $source_action_id ); |
|
60 | + } catch ( \Exception $e ) { |
|
61 | + // nothing to do, it didn't exist in the first place |
|
62 | + } |
|
63 | + do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
64 | + |
|
65 | + return 0; |
|
66 | + } |
|
67 | + |
|
68 | + try { |
|
69 | + |
|
70 | + // Make sure the last attempt date is set correctly for completed and failed actions |
|
71 | + $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
72 | + |
|
73 | + $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
74 | + } catch ( \Exception $e ) { |
|
75 | + do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
76 | + |
|
77 | + return 0; // could not save the action in the new store |
|
78 | + } |
|
79 | + |
|
80 | + try { |
|
81 | + switch ( $status ) { |
|
82 | + case \ActionScheduler_Store::STATUS_FAILED : |
|
83 | + $this->destination->mark_failure( $destination_action_id ); |
|
84 | + break; |
|
85 | + case \ActionScheduler_Store::STATUS_CANCELED : |
|
86 | + $this->destination->cancel_action( $destination_action_id ); |
|
87 | + break; |
|
88 | + } |
|
89 | + |
|
90 | + $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
91 | + $this->source->delete_action( $source_action_id ); |
|
92 | + |
|
93 | + $test_action = $this->source->fetch_action( $source_action_id ); |
|
94 | + if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
95 | + throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) ); |
|
96 | + } |
|
97 | + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
98 | + |
|
99 | + return $destination_action_id; |
|
100 | + } catch ( \Exception $e ) { |
|
101 | + // could not delete from the old store |
|
102 | + $this->source->mark_migrated( $source_action_id ); |
|
103 | + do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
104 | + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
105 | + |
|
106 | + return $destination_action_id; |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param ActionScheduler_Store $destination_store Destination store object. |
30 | 30 | * @param LogMigrator $log_migrator Log migrator object. |
31 | 31 | */ |
32 | - public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
32 | + public function __construct(\ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator) { |
|
33 | 33 | $this->source = $source_store; |
34 | 34 | $this->destination = $destination_store; |
35 | 35 | $this->log_migrator = $log_migrator; |
@@ -42,25 +42,25 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return int 0|new action ID |
44 | 44 | */ |
45 | - public function migrate( $source_action_id ) { |
|
45 | + public function migrate($source_action_id) { |
|
46 | 46 | try { |
47 | - $action = $this->source->fetch_action( $source_action_id ); |
|
48 | - $status = $this->source->get_status( $source_action_id ); |
|
49 | - } catch ( \Exception $e ) { |
|
47 | + $action = $this->source->fetch_action($source_action_id); |
|
48 | + $status = $this->source->get_status($source_action_id); |
|
49 | + } catch (\Exception $e) { |
|
50 | 50 | $action = null; |
51 | 51 | $status = ''; |
52 | 52 | } |
53 | 53 | |
54 | - if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
54 | + if (is_null($action) || empty($status) || !$action->get_schedule()->get_date()) { |
|
55 | 55 | // null action or empty status means the fetch operation failed or the action didn't exist |
56 | 56 | // null schedule means it's missing vital data |
57 | 57 | // delete it and move on |
58 | 58 | try { |
59 | - $this->source->delete_action( $source_action_id ); |
|
60 | - } catch ( \Exception $e ) { |
|
59 | + $this->source->delete_action($source_action_id); |
|
60 | + } catch (\Exception $e) { |
|
61 | 61 | // nothing to do, it didn't exist in the first place |
62 | 62 | } |
63 | - do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
63 | + do_action('action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination); |
|
64 | 64 | |
65 | 65 | return 0; |
66 | 66 | } |
@@ -68,40 +68,40 @@ discard block |
||
68 | 68 | try { |
69 | 69 | |
70 | 70 | // Make sure the last attempt date is set correctly for completed and failed actions |
71 | - $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
71 | + $last_attempt_date = ($status !== \ActionScheduler_Store::STATUS_PENDING) ? $this->source->get_date($source_action_id) : null; |
|
72 | 72 | |
73 | - $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
74 | - } catch ( \Exception $e ) { |
|
75 | - do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
73 | + $destination_action_id = $this->destination->save_action($action, null, $last_attempt_date); |
|
74 | + } catch (\Exception $e) { |
|
75 | + do_action('action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination); |
|
76 | 76 | |
77 | 77 | return 0; // could not save the action in the new store |
78 | 78 | } |
79 | 79 | |
80 | 80 | try { |
81 | - switch ( $status ) { |
|
81 | + switch ($status) { |
|
82 | 82 | case \ActionScheduler_Store::STATUS_FAILED : |
83 | - $this->destination->mark_failure( $destination_action_id ); |
|
83 | + $this->destination->mark_failure($destination_action_id); |
|
84 | 84 | break; |
85 | 85 | case \ActionScheduler_Store::STATUS_CANCELED : |
86 | - $this->destination->cancel_action( $destination_action_id ); |
|
86 | + $this->destination->cancel_action($destination_action_id); |
|
87 | 87 | break; |
88 | 88 | } |
89 | 89 | |
90 | - $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
91 | - $this->source->delete_action( $source_action_id ); |
|
90 | + $this->log_migrator->migrate($source_action_id, $destination_action_id); |
|
91 | + $this->source->delete_action($source_action_id); |
|
92 | 92 | |
93 | - $test_action = $this->source->fetch_action( $source_action_id ); |
|
94 | - if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
95 | - throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) ); |
|
93 | + $test_action = $this->source->fetch_action($source_action_id); |
|
94 | + if (!is_a($test_action, 'ActionScheduler_NullAction')) { |
|
95 | + throw new \RuntimeException(sprintf(__('Unable to remove source migrated action %s', 'action-scheduler'), $source_action_id)); |
|
96 | 96 | } |
97 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
97 | + do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
98 | 98 | |
99 | 99 | return $destination_action_id; |
100 | - } catch ( \Exception $e ) { |
|
100 | + } catch (\Exception $e) { |
|
101 | 101 | // could not delete from the old store |
102 | - $this->source->mark_migrated( $source_action_id ); |
|
103 | - do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
104 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
102 | + $this->source->mark_migrated($source_action_id); |
|
103 | + do_action('action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
104 | + do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
105 | 105 | |
106 | 106 | return $destination_action_id; |
107 | 107 | } |
@@ -5,77 +5,77 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_IntervalSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Deprecated property @see $this->__wakeup() for details. |
|
10 | - **/ |
|
11 | - private $start_timestamp = NULL; |
|
8 | + /** |
|
9 | + * Deprecated property @see $this->__wakeup() for details. |
|
10 | + **/ |
|
11 | + private $start_timestamp = NULL; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Deprecated property @see $this->__wakeup() for details. |
|
15 | - **/ |
|
16 | - private $interval_in_seconds = NULL; |
|
13 | + /** |
|
14 | + * Deprecated property @see $this->__wakeup() for details. |
|
15 | + **/ |
|
16 | + private $interval_in_seconds = NULL; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Calculate when this schedule should start after a given date & time using |
|
20 | - * the number of seconds between recurrences. |
|
21 | - * |
|
22 | - * @param DateTime $after |
|
23 | - * @return DateTime |
|
24 | - */ |
|
25 | - protected function calculate_next( DateTime $after ) { |
|
26 | - $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' ); |
|
27 | - return $after; |
|
28 | - } |
|
18 | + /** |
|
19 | + * Calculate when this schedule should start after a given date & time using |
|
20 | + * the number of seconds between recurrences. |
|
21 | + * |
|
22 | + * @param DateTime $after |
|
23 | + * @return DateTime |
|
24 | + */ |
|
25 | + protected function calculate_next( DateTime $after ) { |
|
26 | + $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' ); |
|
27 | + return $after; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return int |
|
32 | - */ |
|
33 | - public function interval_in_seconds() { |
|
34 | - _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' ); |
|
35 | - return (int) $this->get_recurrence(); |
|
36 | - } |
|
30 | + /** |
|
31 | + * @return int |
|
32 | + */ |
|
33 | + public function interval_in_seconds() { |
|
34 | + _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' ); |
|
35 | + return (int) $this->get_recurrence(); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Serialize interval schedules with data required prior to AS 3.0.0 |
|
40 | - * |
|
41 | - * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to |
|
42 | - * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
43 | - * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
44 | - * aligned properties and property names for better inheritance. To guard against the |
|
45 | - * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to |
|
46 | - * also store the data with the old property names so if it's unserialized in AS < 3.0, |
|
47 | - * the schedule doesn't end up with a null/false/0 recurrence. |
|
48 | - * |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function __sleep() { |
|
38 | + /** |
|
39 | + * Serialize interval schedules with data required prior to AS 3.0.0 |
|
40 | + * |
|
41 | + * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to |
|
42 | + * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
43 | + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
44 | + * aligned properties and property names for better inheritance. To guard against the |
|
45 | + * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to |
|
46 | + * also store the data with the old property names so if it's unserialized in AS < 3.0, |
|
47 | + * the schedule doesn't end up with a null/false/0 recurrence. |
|
48 | + * |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function __sleep() { |
|
52 | 52 | |
53 | - $sleep_params = parent::__sleep(); |
|
53 | + $sleep_params = parent::__sleep(); |
|
54 | 54 | |
55 | - $this->start_timestamp = $this->scheduled_timestamp; |
|
56 | - $this->interval_in_seconds = $this->recurrence; |
|
55 | + $this->start_timestamp = $this->scheduled_timestamp; |
|
56 | + $this->interval_in_seconds = $this->recurrence; |
|
57 | 57 | |
58 | - return array_merge( $sleep_params, array( |
|
59 | - 'start_timestamp', |
|
60 | - 'interval_in_seconds' |
|
61 | - ) ); |
|
62 | - } |
|
58 | + return array_merge( $sleep_params, array( |
|
59 | + 'start_timestamp', |
|
60 | + 'interval_in_seconds' |
|
61 | + ) ); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Unserialize interval schedules serialized/stored prior to AS 3.0.0 |
|
66 | - * |
|
67 | - * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
|
68 | - */ |
|
69 | - public function __wakeup() { |
|
70 | - if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
|
71 | - $this->scheduled_timestamp = $this->start_timestamp; |
|
72 | - unset( $this->start_timestamp ); |
|
73 | - } |
|
64 | + /** |
|
65 | + * Unserialize interval schedules serialized/stored prior to AS 3.0.0 |
|
66 | + * |
|
67 | + * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
|
68 | + */ |
|
69 | + public function __wakeup() { |
|
70 | + if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
|
71 | + $this->scheduled_timestamp = $this->start_timestamp; |
|
72 | + unset( $this->start_timestamp ); |
|
73 | + } |
|
74 | 74 | |
75 | - if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) { |
|
76 | - $this->recurrence = $this->interval_in_seconds; |
|
77 | - unset( $this->interval_in_seconds ); |
|
78 | - } |
|
79 | - parent::__wakeup(); |
|
80 | - } |
|
75 | + if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) { |
|
76 | + $this->recurrence = $this->interval_in_seconds; |
|
77 | + unset( $this->interval_in_seconds ); |
|
78 | + } |
|
79 | + parent::__wakeup(); |
|
80 | + } |
|
81 | 81 | } |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * @param DateTime $after |
23 | 23 | * @return DateTime |
24 | 24 | */ |
25 | - protected function calculate_next( DateTime $after ) { |
|
26 | - $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' ); |
|
25 | + protected function calculate_next(DateTime $after) { |
|
26 | + $after->modify('+' . (int) $this->get_recurrence() . ' seconds'); |
|
27 | 27 | return $after; |
28 | 28 | } |
29 | 29 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @return int |
32 | 32 | */ |
33 | 33 | public function interval_in_seconds() { |
34 | - _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' ); |
|
34 | + _deprecated_function(__METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()'); |
|
35 | 35 | return (int) $this->get_recurrence(); |
36 | 36 | } |
37 | 37 | |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | $this->start_timestamp = $this->scheduled_timestamp; |
56 | 56 | $this->interval_in_seconds = $this->recurrence; |
57 | 57 | |
58 | - return array_merge( $sleep_params, array( |
|
58 | + return array_merge($sleep_params, array( |
|
59 | 59 | 'start_timestamp', |
60 | 60 | 'interval_in_seconds' |
61 | - ) ); |
|
61 | + )); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
68 | 68 | */ |
69 | 69 | public function __wakeup() { |
70 | - if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
|
70 | + if (is_null($this->scheduled_timestamp) && !is_null($this->start_timestamp)) { |
|
71 | 71 | $this->scheduled_timestamp = $this->start_timestamp; |
72 | - unset( $this->start_timestamp ); |
|
72 | + unset($this->start_timestamp); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) { |
|
75 | + if (is_null($this->recurrence) && !is_null($this->interval_in_seconds)) { |
|
76 | 76 | $this->recurrence = $this->interval_in_seconds; |
77 | - unset( $this->interval_in_seconds ); |
|
77 | + unset($this->interval_in_seconds); |
|
78 | 78 | } |
79 | 79 | parent::__wakeup(); |
80 | 80 | } |
@@ -5,67 +5,67 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_SimpleSchedule extends ActionScheduler_Abstract_Schedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Deprecated property @see $this->__wakeup() for details. |
|
10 | - **/ |
|
11 | - private $timestamp = NULL; |
|
8 | + /** |
|
9 | + * Deprecated property @see $this->__wakeup() for details. |
|
10 | + **/ |
|
11 | + private $timestamp = NULL; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @param DateTime $after |
|
15 | - * |
|
16 | - * @return DateTime|null |
|
17 | - */ |
|
18 | - public function calculate_next( DateTime $after ) { |
|
19 | - return null; |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param DateTime $after |
|
15 | + * |
|
16 | + * @return DateTime|null |
|
17 | + */ |
|
18 | + public function calculate_next( DateTime $after ) { |
|
19 | + return null; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - public function is_recurring() { |
|
26 | - return false; |
|
27 | - } |
|
22 | + /** |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + public function is_recurring() { |
|
26 | + return false; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Serialize schedule with data required prior to AS 3.0.0 |
|
31 | - * |
|
32 | - * Prior to Action Scheduler 3.0.0, schedules used different property names to refer |
|
33 | - * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
34 | - * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
35 | - * aligned properties and property names for better inheritance. To guard against the |
|
36 | - * scheduled date for single actions always being seen as "now" if downgrading to |
|
37 | - * Action Scheduler < 3.0.0, we need to also store the data with the old property names |
|
38 | - * so if it's unserialized in AS < 3.0, the schedule doesn't end up with a null recurrence. |
|
39 | - * |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function __sleep() { |
|
29 | + /** |
|
30 | + * Serialize schedule with data required prior to AS 3.0.0 |
|
31 | + * |
|
32 | + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer |
|
33 | + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
34 | + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
35 | + * aligned properties and property names for better inheritance. To guard against the |
|
36 | + * scheduled date for single actions always being seen as "now" if downgrading to |
|
37 | + * Action Scheduler < 3.0.0, we need to also store the data with the old property names |
|
38 | + * so if it's unserialized in AS < 3.0, the schedule doesn't end up with a null recurrence. |
|
39 | + * |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function __sleep() { |
|
43 | 43 | |
44 | - $sleep_params = parent::__sleep(); |
|
44 | + $sleep_params = parent::__sleep(); |
|
45 | 45 | |
46 | - $this->timestamp = $this->scheduled_timestamp; |
|
46 | + $this->timestamp = $this->scheduled_timestamp; |
|
47 | 47 | |
48 | - return array_merge( $sleep_params, array( |
|
49 | - 'timestamp', |
|
50 | - ) ); |
|
51 | - } |
|
48 | + return array_merge( $sleep_params, array( |
|
49 | + 'timestamp', |
|
50 | + ) ); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 |
|
55 | - * |
|
56 | - * Prior to Action Scheduler 3.0.0, schedules used different property names to refer |
|
57 | - * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
58 | - * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
59 | - * aligned properties and property names for better inheritance. To maintain backward |
|
60 | - * compatibility with schedules serialized and stored prior to 3.0, we need to correctly |
|
61 | - * map the old property names with matching visibility. |
|
62 | - */ |
|
63 | - public function __wakeup() { |
|
53 | + /** |
|
54 | + * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 |
|
55 | + * |
|
56 | + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer |
|
57 | + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
58 | + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
59 | + * aligned properties and property names for better inheritance. To maintain backward |
|
60 | + * compatibility with schedules serialized and stored prior to 3.0, we need to correctly |
|
61 | + * map the old property names with matching visibility. |
|
62 | + */ |
|
63 | + public function __wakeup() { |
|
64 | 64 | |
65 | - if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) { |
|
66 | - $this->scheduled_timestamp = $this->timestamp; |
|
67 | - unset( $this->timestamp ); |
|
68 | - } |
|
69 | - parent::__wakeup(); |
|
70 | - } |
|
65 | + if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) { |
|
66 | + $this->scheduled_timestamp = $this->timestamp; |
|
67 | + unset( $this->timestamp ); |
|
68 | + } |
|
69 | + parent::__wakeup(); |
|
70 | + } |
|
71 | 71 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return DateTime|null |
17 | 17 | */ |
18 | - public function calculate_next( DateTime $after ) { |
|
18 | + public function calculate_next(DateTime $after) { |
|
19 | 19 | return null; |
20 | 20 | } |
21 | 21 | |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | $this->timestamp = $this->scheduled_timestamp; |
47 | 47 | |
48 | - return array_merge( $sleep_params, array( |
|
48 | + return array_merge($sleep_params, array( |
|
49 | 49 | 'timestamp', |
50 | - ) ); |
|
50 | + )); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function __wakeup() { |
64 | 64 | |
65 | - if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) { |
|
65 | + if (is_null($this->scheduled_timestamp) && !is_null($this->timestamp)) { |
|
66 | 66 | $this->scheduled_timestamp = $this->timestamp; |
67 | - unset( $this->timestamp ); |
|
67 | + unset($this->timestamp); |
|
68 | 68 | } |
69 | 69 | parent::__wakeup(); |
70 | 70 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | * Class ActionScheduler_Schedule |
5 | 5 | */ |
6 | 6 | interface ActionScheduler_Schedule { |
7 | - /** |
|
8 | - * @param DateTime $after |
|
9 | - * @return DateTime|null |
|
10 | - */ |
|
11 | - public function next( DateTime $after = NULL ); |
|
7 | + /** |
|
8 | + * @param DateTime $after |
|
9 | + * @return DateTime|null |
|
10 | + */ |
|
11 | + public function next( DateTime $after = NULL ); |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return bool |
|
15 | - */ |
|
16 | - public function is_recurring(); |
|
13 | + /** |
|
14 | + * @return bool |
|
15 | + */ |
|
16 | + public function is_recurring(); |
|
17 | 17 | } |
18 | - |
|
19 | 18 | \ No newline at end of file |
19 | + |
|
20 | 20 | \ No newline at end of file |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @param DateTime $after |
9 | 9 | * @return DateTime|null |
10 | 10 | */ |
11 | - public function next( DateTime $after = NULL ); |
|
11 | + public function next(DateTime $after = NULL); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @return bool |
@@ -5,24 +5,24 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullSchedule extends ActionScheduler_SimpleSchedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Make the $date param optional and default to null. |
|
10 | - * |
|
11 | - * @param null $date The date & time to run the action. |
|
12 | - */ |
|
13 | - public function __construct( DateTime $date = null ) { |
|
14 | - $this->scheduled_date = null; |
|
15 | - } |
|
8 | + /** |
|
9 | + * Make the $date param optional and default to null. |
|
10 | + * |
|
11 | + * @param null $date The date & time to run the action. |
|
12 | + */ |
|
13 | + public function __construct( DateTime $date = null ) { |
|
14 | + $this->scheduled_date = null; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * This schedule has no scheduled DateTime, so we need to override the parent __sleep() |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function __sleep() { |
|
22 | - return array(); |
|
23 | - } |
|
17 | + /** |
|
18 | + * This schedule has no scheduled DateTime, so we need to override the parent __sleep() |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function __sleep() { |
|
22 | + return array(); |
|
23 | + } |
|
24 | 24 | |
25 | - public function __wakeup() { |
|
26 | - $this->scheduled_date = null; |
|
27 | - } |
|
25 | + public function __wakeup() { |
|
26 | + $this->scheduled_date = null; |
|
27 | + } |
|
28 | 28 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * @param null $date The date & time to run the action. |
12 | 12 | */ |
13 | - public function __construct( DateTime $date = null ) { |
|
13 | + public function __construct(DateTime $date = null) { |
|
14 | 14 | $this->scheduled_date = null; |
15 | 15 | } |
16 | 16 |
@@ -5,53 +5,53 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_CanceledSchedule extends ActionScheduler_SimpleSchedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Deprecated property @see $this->__wakeup() for details. |
|
10 | - **/ |
|
11 | - private $timestamp = NULL; |
|
8 | + /** |
|
9 | + * Deprecated property @see $this->__wakeup() for details. |
|
10 | + **/ |
|
11 | + private $timestamp = NULL; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @param DateTime $after |
|
15 | - * |
|
16 | - * @return DateTime|null |
|
17 | - */ |
|
18 | - public function calculate_next( DateTime $after ) { |
|
19 | - return null; |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param DateTime $after |
|
15 | + * |
|
16 | + * @return DateTime|null |
|
17 | + */ |
|
18 | + public function calculate_next( DateTime $after ) { |
|
19 | + return null; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Cancelled actions should never have a next schedule, even if get_next() |
|
24 | - * is called with $after < $this->scheduled_date. |
|
25 | - * |
|
26 | - * @param DateTime $after |
|
27 | - * @return DateTime|null |
|
28 | - */ |
|
29 | - public function get_next( DateTime $after ) { |
|
30 | - return null; |
|
31 | - } |
|
22 | + /** |
|
23 | + * Cancelled actions should never have a next schedule, even if get_next() |
|
24 | + * is called with $after < $this->scheduled_date. |
|
25 | + * |
|
26 | + * @param DateTime $after |
|
27 | + * @return DateTime|null |
|
28 | + */ |
|
29 | + public function get_next( DateTime $after ) { |
|
30 | + return null; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_recurring() { |
|
37 | - return false; |
|
38 | - } |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_recurring() { |
|
37 | + return false; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 |
|
42 | - * |
|
43 | - * Prior to Action Scheduler 3.0.0, schedules used different property names to refer |
|
44 | - * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
45 | - * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
46 | - * aligned properties and property names for better inheritance. To maintain backward |
|
47 | - * compatibility with schedules serialized and stored prior to 3.0, we need to correctly |
|
48 | - * map the old property names with matching visibility. |
|
49 | - */ |
|
50 | - public function __wakeup() { |
|
51 | - if ( ! is_null( $this->timestamp ) ) { |
|
52 | - $this->scheduled_timestamp = $this->timestamp; |
|
53 | - unset( $this->timestamp ); |
|
54 | - } |
|
55 | - parent::__wakeup(); |
|
56 | - } |
|
40 | + /** |
|
41 | + * Unserialize recurring schedules serialized/stored prior to AS 3.0.0 |
|
42 | + * |
|
43 | + * Prior to Action Scheduler 3.0.0, schedules used different property names to refer |
|
44 | + * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
45 | + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
46 | + * aligned properties and property names for better inheritance. To maintain backward |
|
47 | + * compatibility with schedules serialized and stored prior to 3.0, we need to correctly |
|
48 | + * map the old property names with matching visibility. |
|
49 | + */ |
|
50 | + public function __wakeup() { |
|
51 | + if ( ! is_null( $this->timestamp ) ) { |
|
52 | + $this->scheduled_timestamp = $this->timestamp; |
|
53 | + unset( $this->timestamp ); |
|
54 | + } |
|
55 | + parent::__wakeup(); |
|
56 | + } |
|
57 | 57 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return DateTime|null |
17 | 17 | */ |
18 | - public function calculate_next( DateTime $after ) { |
|
18 | + public function calculate_next(DateTime $after) { |
|
19 | 19 | return null; |
20 | 20 | } |
21 | 21 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param DateTime $after |
27 | 27 | * @return DateTime|null |
28 | 28 | */ |
29 | - public function get_next( DateTime $after ) { |
|
29 | + public function get_next(DateTime $after) { |
|
30 | 30 | return null; |
31 | 31 | } |
32 | 32 | |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * map the old property names with matching visibility. |
49 | 49 | */ |
50 | 50 | public function __wakeup() { |
51 | - if ( ! is_null( $this->timestamp ) ) { |
|
51 | + if (!is_null($this->timestamp)) { |
|
52 | 52 | $this->scheduled_timestamp = $this->timestamp; |
53 | - unset( $this->timestamp ); |
|
53 | + unset($this->timestamp); |
|
54 | 54 | } |
55 | 55 | parent::__wakeup(); |
56 | 56 | } |
@@ -5,98 +5,98 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_CronSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Deprecated property @see $this->__wakeup() for details. |
|
10 | - **/ |
|
11 | - private $start_timestamp = NULL; |
|
12 | - |
|
13 | - /** |
|
14 | - * Deprecated property @see $this->__wakeup() for details. |
|
15 | - **/ |
|
16 | - private $cron = NULL; |
|
17 | - |
|
18 | - /** |
|
19 | - * Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this |
|
20 | - * objects $recurrence property. |
|
21 | - * |
|
22 | - * @param DateTime $start The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used. |
|
23 | - * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance. |
|
24 | - * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance. |
|
25 | - */ |
|
26 | - public function __construct( DateTime $start, $recurrence, DateTime $first = null ) { |
|
27 | - if ( ! is_a( $recurrence, 'CronExpression' ) ) { |
|
28 | - $recurrence = CronExpression::factory( $recurrence ); |
|
29 | - } |
|
30 | - |
|
31 | - // For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method. |
|
32 | - $date = $recurrence->getNextRunDate( $start, 0, true ); |
|
33 | - |
|
34 | - // parent::__construct() will set this to $date by default, but that may be different to $start now. |
|
35 | - $first = empty( $first ) ? $start : $first; |
|
36 | - |
|
37 | - parent::__construct( $date, $recurrence, $first ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Calculate when an instance of this schedule would start based on a given |
|
42 | - * date & time using its the CronExpression. |
|
43 | - * |
|
44 | - * @param DateTime $after |
|
45 | - * @return DateTime |
|
46 | - */ |
|
47 | - protected function calculate_next( DateTime $after ) { |
|
48 | - return $this->recurrence->getNextRunDate( $after, 0, false ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function get_recurrence() { |
|
55 | - return strval( $this->recurrence ); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Serialize cron schedules with data required prior to AS 3.0.0 |
|
60 | - * |
|
61 | - * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to |
|
62 | - * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
63 | - * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
64 | - * aligned properties and property names for better inheritance. To guard against the |
|
65 | - * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to |
|
66 | - * also store the data with the old property names so if it's unserialized in AS < 3.0, |
|
67 | - * the schedule doesn't end up with a null recurrence. |
|
68 | - * |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function __sleep() { |
|
72 | - |
|
73 | - $sleep_params = parent::__sleep(); |
|
74 | - |
|
75 | - $this->start_timestamp = $this->scheduled_timestamp; |
|
76 | - $this->cron = $this->recurrence; |
|
77 | - |
|
78 | - return array_merge( $sleep_params, array( |
|
79 | - 'start_timestamp', |
|
80 | - 'cron' |
|
81 | - ) ); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Unserialize cron schedules serialized/stored prior to AS 3.0.0 |
|
86 | - * |
|
87 | - * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
|
88 | - */ |
|
89 | - public function __wakeup() { |
|
90 | - if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
|
91 | - $this->scheduled_timestamp = $this->start_timestamp; |
|
92 | - unset( $this->start_timestamp ); |
|
93 | - } |
|
94 | - |
|
95 | - if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) { |
|
96 | - $this->recurrence = $this->cron; |
|
97 | - unset( $this->cron ); |
|
98 | - } |
|
99 | - parent::__wakeup(); |
|
100 | - } |
|
8 | + /** |
|
9 | + * Deprecated property @see $this->__wakeup() for details. |
|
10 | + **/ |
|
11 | + private $start_timestamp = NULL; |
|
12 | + |
|
13 | + /** |
|
14 | + * Deprecated property @see $this->__wakeup() for details. |
|
15 | + **/ |
|
16 | + private $cron = NULL; |
|
17 | + |
|
18 | + /** |
|
19 | + * Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this |
|
20 | + * objects $recurrence property. |
|
21 | + * |
|
22 | + * @param DateTime $start The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used. |
|
23 | + * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance. |
|
24 | + * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance. |
|
25 | + */ |
|
26 | + public function __construct( DateTime $start, $recurrence, DateTime $first = null ) { |
|
27 | + if ( ! is_a( $recurrence, 'CronExpression' ) ) { |
|
28 | + $recurrence = CronExpression::factory( $recurrence ); |
|
29 | + } |
|
30 | + |
|
31 | + // For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method. |
|
32 | + $date = $recurrence->getNextRunDate( $start, 0, true ); |
|
33 | + |
|
34 | + // parent::__construct() will set this to $date by default, but that may be different to $start now. |
|
35 | + $first = empty( $first ) ? $start : $first; |
|
36 | + |
|
37 | + parent::__construct( $date, $recurrence, $first ); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Calculate when an instance of this schedule would start based on a given |
|
42 | + * date & time using its the CronExpression. |
|
43 | + * |
|
44 | + * @param DateTime $after |
|
45 | + * @return DateTime |
|
46 | + */ |
|
47 | + protected function calculate_next( DateTime $after ) { |
|
48 | + return $this->recurrence->getNextRunDate( $after, 0, false ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function get_recurrence() { |
|
55 | + return strval( $this->recurrence ); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Serialize cron schedules with data required prior to AS 3.0.0 |
|
60 | + * |
|
61 | + * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to |
|
62 | + * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp |
|
63 | + * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0 |
|
64 | + * aligned properties and property names for better inheritance. To guard against the |
|
65 | + * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to |
|
66 | + * also store the data with the old property names so if it's unserialized in AS < 3.0, |
|
67 | + * the schedule doesn't end up with a null recurrence. |
|
68 | + * |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function __sleep() { |
|
72 | + |
|
73 | + $sleep_params = parent::__sleep(); |
|
74 | + |
|
75 | + $this->start_timestamp = $this->scheduled_timestamp; |
|
76 | + $this->cron = $this->recurrence; |
|
77 | + |
|
78 | + return array_merge( $sleep_params, array( |
|
79 | + 'start_timestamp', |
|
80 | + 'cron' |
|
81 | + ) ); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Unserialize cron schedules serialized/stored prior to AS 3.0.0 |
|
86 | + * |
|
87 | + * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
|
88 | + */ |
|
89 | + public function __wakeup() { |
|
90 | + if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
|
91 | + $this->scheduled_timestamp = $this->start_timestamp; |
|
92 | + unset( $this->start_timestamp ); |
|
93 | + } |
|
94 | + |
|
95 | + if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) { |
|
96 | + $this->recurrence = $this->cron; |
|
97 | + unset( $this->cron ); |
|
98 | + } |
|
99 | + parent::__wakeup(); |
|
100 | + } |
|
101 | 101 | } |
102 | 102 |
@@ -23,18 +23,18 @@ discard block |
||
23 | 23 | * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance. |
24 | 24 | * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance. |
25 | 25 | */ |
26 | - public function __construct( DateTime $start, $recurrence, DateTime $first = null ) { |
|
27 | - if ( ! is_a( $recurrence, 'CronExpression' ) ) { |
|
28 | - $recurrence = CronExpression::factory( $recurrence ); |
|
26 | + public function __construct(DateTime $start, $recurrence, DateTime $first = null) { |
|
27 | + if (!is_a($recurrence, 'CronExpression')) { |
|
28 | + $recurrence = CronExpression::factory($recurrence); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | // For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method. |
32 | - $date = $recurrence->getNextRunDate( $start, 0, true ); |
|
32 | + $date = $recurrence->getNextRunDate($start, 0, true); |
|
33 | 33 | |
34 | 34 | // parent::__construct() will set this to $date by default, but that may be different to $start now. |
35 | - $first = empty( $first ) ? $start : $first; |
|
35 | + $first = empty($first) ? $start : $first; |
|
36 | 36 | |
37 | - parent::__construct( $date, $recurrence, $first ); |
|
37 | + parent::__construct($date, $recurrence, $first); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | * @param DateTime $after |
45 | 45 | * @return DateTime |
46 | 46 | */ |
47 | - protected function calculate_next( DateTime $after ) { |
|
48 | - return $this->recurrence->getNextRunDate( $after, 0, false ); |
|
47 | + protected function calculate_next(DateTime $after) { |
|
48 | + return $this->recurrence->getNextRunDate($after, 0, false); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return string |
53 | 53 | */ |
54 | 54 | public function get_recurrence() { |
55 | - return strval( $this->recurrence ); |
|
55 | + return strval($this->recurrence); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | $this->start_timestamp = $this->scheduled_timestamp; |
76 | 76 | $this->cron = $this->recurrence; |
77 | 77 | |
78 | - return array_merge( $sleep_params, array( |
|
78 | + return array_merge($sleep_params, array( |
|
79 | 79 | 'start_timestamp', |
80 | 80 | 'cron' |
81 | - ) ); |
|
81 | + )); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup(). |
88 | 88 | */ |
89 | 89 | public function __wakeup() { |
90 | - if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) { |
|
90 | + if (is_null($this->scheduled_timestamp) && !is_null($this->start_timestamp)) { |
|
91 | 91 | $this->scheduled_timestamp = $this->start_timestamp; |
92 | - unset( $this->start_timestamp ); |
|
92 | + unset($this->start_timestamp); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) { |
|
95 | + if (is_null($this->recurrence) && !is_null($this->cron)) { |
|
96 | 96 | $this->recurrence = $this->cron; |
97 | - unset( $this->cron ); |
|
97 | + unset($this->cron); |
|
98 | 98 | } |
99 | 99 | parent::__wakeup(); |
100 | 100 | } |
@@ -6,606 +6,606 @@ |
||
6 | 6 | */ |
7 | 7 | class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable { |
8 | 8 | |
9 | - /** |
|
10 | - * The package name. |
|
11 | - * |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $package = 'action-scheduler'; |
|
15 | - |
|
16 | - /** |
|
17 | - * Columns to show (name => label). |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $columns = array(); |
|
22 | - |
|
23 | - /** |
|
24 | - * Actions (name => label). |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $row_actions = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * The active data stores |
|
32 | - * |
|
33 | - * @var ActionScheduler_Store |
|
34 | - */ |
|
35 | - protected $store; |
|
36 | - |
|
37 | - /** |
|
38 | - * A logger to use for getting action logs to display |
|
39 | - * |
|
40 | - * @var ActionScheduler_Logger |
|
41 | - */ |
|
42 | - protected $logger; |
|
43 | - |
|
44 | - /** |
|
45 | - * A ActionScheduler_QueueRunner runner instance (or child class) |
|
46 | - * |
|
47 | - * @var ActionScheduler_QueueRunner |
|
48 | - */ |
|
49 | - protected $runner; |
|
50 | - |
|
51 | - /** |
|
52 | - * Bulk actions. The key of the array is the method name of the implementation: |
|
53 | - * |
|
54 | - * bulk_<key>(array $ids, string $sql_in). |
|
55 | - * |
|
56 | - * See the comments in the parent class for further details |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $bulk_actions = array(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Flag variable to render our notifications, if any, once. |
|
64 | - * |
|
65 | - * @var bool |
|
66 | - */ |
|
67 | - protected static $did_notification = false; |
|
68 | - |
|
69 | - /** |
|
70 | - * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days" |
|
71 | - * |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - private static $time_periods; |
|
75 | - |
|
76 | - /** |
|
77 | - * Sets the current data store object into `store->action` and initialises the object. |
|
78 | - * |
|
79 | - * @param ActionScheduler_Store $store |
|
80 | - * @param ActionScheduler_Logger $logger |
|
81 | - * @param ActionScheduler_QueueRunner $runner |
|
82 | - */ |
|
83 | - public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { |
|
84 | - |
|
85 | - $this->store = $store; |
|
86 | - $this->logger = $logger; |
|
87 | - $this->runner = $runner; |
|
88 | - |
|
89 | - $this->table_header = __( 'Scheduled Actions', 'action-scheduler' ); |
|
90 | - |
|
91 | - $this->bulk_actions = array( |
|
92 | - 'delete' => __( 'Delete', 'action-scheduler' ), |
|
93 | - ); |
|
94 | - |
|
95 | - $this->columns = array( |
|
96 | - 'hook' => __( 'Hook', 'action-scheduler' ), |
|
97 | - 'status' => __( 'Status', 'action-scheduler' ), |
|
98 | - 'args' => __( 'Arguments', 'action-scheduler' ), |
|
99 | - 'group' => __( 'Group', 'action-scheduler' ), |
|
100 | - 'recurrence' => __( 'Recurrence', 'action-scheduler' ), |
|
101 | - 'schedule' => __( 'Scheduled Date', 'action-scheduler' ), |
|
102 | - 'log_entries' => __( 'Log', 'action-scheduler' ), |
|
103 | - ); |
|
104 | - |
|
105 | - $this->sort_by = array( |
|
106 | - 'schedule', |
|
107 | - 'hook', |
|
108 | - 'group', |
|
109 | - ); |
|
110 | - |
|
111 | - $this->search_by = array( |
|
112 | - 'hook', |
|
113 | - 'args', |
|
114 | - 'claim_id', |
|
115 | - ); |
|
116 | - |
|
117 | - $request_status = $this->get_request_status(); |
|
118 | - |
|
119 | - if ( empty( $request_status ) ) { |
|
120 | - $this->sort_by[] = 'status'; |
|
121 | - } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { |
|
122 | - $this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) ); |
|
123 | - $this->sort_by[] = 'claim_id'; |
|
124 | - } |
|
125 | - |
|
126 | - $this->row_actions = array( |
|
127 | - 'hook' => array( |
|
128 | - 'run' => array( |
|
129 | - 'name' => __( 'Run', 'action-scheduler' ), |
|
130 | - 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ), |
|
131 | - ), |
|
132 | - 'cancel' => array( |
|
133 | - 'name' => __( 'Cancel', 'action-scheduler' ), |
|
134 | - 'desc' => __( 'Cancel the action now to avoid it being run in future', 'action-scheduler' ), |
|
135 | - 'class' => 'cancel trash', |
|
136 | - ), |
|
137 | - ), |
|
138 | - ); |
|
139 | - |
|
140 | - self::$time_periods = array( |
|
141 | - array( |
|
142 | - 'seconds' => YEAR_IN_SECONDS, |
|
143 | - /* translators: %s: amount of time */ |
|
144 | - 'names' => _n_noop( '%s year', '%s years', 'action-scheduler' ), |
|
145 | - ), |
|
146 | - array( |
|
147 | - 'seconds' => MONTH_IN_SECONDS, |
|
148 | - /* translators: %s: amount of time */ |
|
149 | - 'names' => _n_noop( '%s month', '%s months', 'action-scheduler' ), |
|
150 | - ), |
|
151 | - array( |
|
152 | - 'seconds' => WEEK_IN_SECONDS, |
|
153 | - /* translators: %s: amount of time */ |
|
154 | - 'names' => _n_noop( '%s week', '%s weeks', 'action-scheduler' ), |
|
155 | - ), |
|
156 | - array( |
|
157 | - 'seconds' => DAY_IN_SECONDS, |
|
158 | - /* translators: %s: amount of time */ |
|
159 | - 'names' => _n_noop( '%s day', '%s days', 'action-scheduler' ), |
|
160 | - ), |
|
161 | - array( |
|
162 | - 'seconds' => HOUR_IN_SECONDS, |
|
163 | - /* translators: %s: amount of time */ |
|
164 | - 'names' => _n_noop( '%s hour', '%s hours', 'action-scheduler' ), |
|
165 | - ), |
|
166 | - array( |
|
167 | - 'seconds' => MINUTE_IN_SECONDS, |
|
168 | - /* translators: %s: amount of time */ |
|
169 | - 'names' => _n_noop( '%s minute', '%s minutes', 'action-scheduler' ), |
|
170 | - ), |
|
171 | - array( |
|
172 | - 'seconds' => 1, |
|
173 | - /* translators: %s: amount of time */ |
|
174 | - 'names' => _n_noop( '%s second', '%s seconds', 'action-scheduler' ), |
|
175 | - ), |
|
176 | - ); |
|
177 | - |
|
178 | - parent::__construct( array( |
|
179 | - 'singular' => 'action-scheduler', |
|
180 | - 'plural' => 'action-scheduler', |
|
181 | - 'ajax' => false, |
|
182 | - ) ); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Convert an interval of seconds into a two part human friendly string. |
|
187 | - * |
|
188 | - * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning |
|
189 | - * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step |
|
190 | - * further to display two degrees of accuracy. |
|
191 | - * |
|
192 | - * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ |
|
193 | - * |
|
194 | - * @param int $interval A interval in seconds. |
|
195 | - * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. |
|
196 | - * @return string A human friendly string representation of the interval. |
|
197 | - */ |
|
198 | - private static function human_interval( $interval, $periods_to_include = 2 ) { |
|
199 | - |
|
200 | - if ( $interval <= 0 ) { |
|
201 | - return __( 'Now!', 'action-scheduler' ); |
|
202 | - } |
|
203 | - |
|
204 | - $output = ''; |
|
205 | - |
|
206 | - for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { |
|
207 | - |
|
208 | - $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); |
|
209 | - |
|
210 | - if ( $periods_in_interval > 0 ) { |
|
211 | - if ( ! empty( $output ) ) { |
|
212 | - $output .= ' '; |
|
213 | - } |
|
214 | - $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'action-scheduler' ), $periods_in_interval ); |
|
215 | - $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
|
216 | - $periods_included++; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - return $output; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Returns the recurrence of an action or 'Non-repeating'. The output is human readable. |
|
225 | - * |
|
226 | - * @param ActionScheduler_Action $action |
|
227 | - * |
|
228 | - * @return string |
|
229 | - */ |
|
230 | - protected function get_recurrence( $action ) { |
|
231 | - $schedule = $action->get_schedule(); |
|
232 | - if ( $schedule->is_recurring() ) { |
|
233 | - $recurrence = $schedule->get_recurrence(); |
|
234 | - |
|
235 | - if ( is_numeric( $recurrence ) ) { |
|
236 | - /* translators: %s: time interval */ |
|
237 | - return sprintf( __( 'Every %s', 'action-scheduler' ), self::human_interval( $recurrence ) ); |
|
238 | - } else { |
|
239 | - return $recurrence; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - return __( 'Non-repeating', 'action-scheduler' ); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Serializes the argument of an action to render it in a human friendly format. |
|
248 | - * |
|
249 | - * @param array $row The array representation of the current row of the table |
|
250 | - * |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function column_args( array $row ) { |
|
254 | - if ( empty( $row['args'] ) ) { |
|
255 | - return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); |
|
256 | - } |
|
257 | - |
|
258 | - $row_html = '<ul>'; |
|
259 | - foreach ( $row['args'] as $key => $value ) { |
|
260 | - $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); |
|
261 | - } |
|
262 | - $row_html .= '</ul>'; |
|
263 | - |
|
264 | - return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
269 | - * |
|
270 | - * @param array $row Action array. |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - public function column_log_entries( array $row ) { |
|
274 | - |
|
275 | - $log_entries_html = '<ol>'; |
|
276 | - |
|
277 | - $timezone = new DateTimezone( 'UTC' ); |
|
278 | - |
|
279 | - foreach ( $row['log_entries'] as $log_entry ) { |
|
280 | - $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); |
|
281 | - } |
|
282 | - |
|
283 | - $log_entries_html .= '</ol>'; |
|
284 | - |
|
285 | - return $log_entries_html; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
290 | - * |
|
291 | - * @param ActionScheduler_LogEntry $log_entry |
|
292 | - * @param DateTimezone $timezone |
|
293 | - * @return string |
|
294 | - */ |
|
295 | - protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { |
|
296 | - $date = $log_entry->get_date(); |
|
297 | - $date->setTimezone( $timezone ); |
|
298 | - return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Only display row actions for pending actions. |
|
303 | - * |
|
304 | - * @param array $row Row to render |
|
305 | - * @param string $column_name Current row |
|
306 | - * |
|
307 | - * @return string |
|
308 | - */ |
|
309 | - protected function maybe_render_actions( $row, $column_name ) { |
|
310 | - if ( 'pending' === strtolower( $row['status'] ) ) { |
|
311 | - return parent::maybe_render_actions( $row, $column_name ); |
|
312 | - } |
|
313 | - |
|
314 | - return ''; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Renders admin notifications |
|
319 | - * |
|
320 | - * Notifications: |
|
321 | - * 1. When the maximum number of tasks are being executed simultaneously. |
|
322 | - * 2. Notifications when a task is manually executed. |
|
323 | - * 3. Tables are missing. |
|
324 | - */ |
|
325 | - public function display_admin_notices() { |
|
326 | - global $wpdb; |
|
327 | - |
|
328 | - if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { |
|
329 | - $table_list = array( |
|
330 | - 'actionscheduler_actions', |
|
331 | - 'actionscheduler_logs', |
|
332 | - 'actionscheduler_groups', |
|
333 | - 'actionscheduler_claims', |
|
334 | - ); |
|
335 | - |
|
336 | - $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
337 | - foreach ( $table_list as $table_name ) { |
|
338 | - if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { |
|
339 | - $this->admin_notices[] = array( |
|
340 | - 'class' => 'error', |
|
341 | - 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ), |
|
342 | - ); |
|
343 | - $this->recreate_tables(); |
|
344 | - parent::display_admin_notices(); |
|
345 | - |
|
346 | - return; |
|
347 | - } |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - if ( $this->runner->has_maximum_concurrent_batches() ) { |
|
352 | - $claim_count = $this->store->get_claim_count(); |
|
353 | - $this->admin_notices[] = array( |
|
354 | - 'class' => 'updated', |
|
355 | - 'message' => sprintf( |
|
356 | - /* translators: %s: amount of claims */ |
|
357 | - _n( |
|
358 | - 'Maximum simultaneous queues already in progress (%s queue). No additional queues will begin processing until the current queues are complete.', |
|
359 | - 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', |
|
360 | - $claim_count, |
|
361 | - 'action-scheduler' |
|
362 | - ), |
|
363 | - $claim_count |
|
364 | - ), |
|
365 | - ); |
|
366 | - } elseif ( $this->store->has_pending_actions_due() ) { |
|
367 | - |
|
368 | - $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
|
369 | - |
|
370 | - // No lock set or lock expired |
|
371 | - if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
|
372 | - $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); |
|
373 | - /* translators: %s: process URL */ |
|
374 | - $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'action-scheduler' ), esc_url( $in_progress_url ) ); |
|
375 | - } else { |
|
376 | - /* translators: %d: seconds */ |
|
377 | - $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'action-scheduler' ), $async_request_lock_expiration - time() ); |
|
378 | - } |
|
379 | - |
|
380 | - $this->admin_notices[] = array( |
|
381 | - 'class' => 'notice notice-info', |
|
382 | - 'message' => $async_request_message, |
|
383 | - ); |
|
384 | - } |
|
385 | - |
|
386 | - $notification = get_transient( 'action_scheduler_admin_notice' ); |
|
387 | - |
|
388 | - if ( is_array( $notification ) ) { |
|
389 | - delete_transient( 'action_scheduler_admin_notice' ); |
|
390 | - |
|
391 | - $action = $this->store->fetch_action( $notification['action_id'] ); |
|
392 | - $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
|
393 | - if ( 1 == $notification['success'] ) { |
|
394 | - $class = 'updated'; |
|
395 | - switch ( $notification['row_action_type'] ) { |
|
396 | - case 'run' : |
|
397 | - /* translators: %s: action HTML */ |
|
398 | - $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html ); |
|
399 | - break; |
|
400 | - case 'cancel' : |
|
401 | - /* translators: %s: action HTML */ |
|
402 | - $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html ); |
|
403 | - break; |
|
404 | - default : |
|
405 | - /* translators: %s: action HTML */ |
|
406 | - $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html ); |
|
407 | - break; |
|
408 | - } |
|
409 | - } else { |
|
410 | - $class = 'error'; |
|
411 | - /* translators: 1: action HTML 2: action ID 3: error message */ |
|
412 | - $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'action-scheduler' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); |
|
413 | - } |
|
414 | - |
|
415 | - $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); |
|
416 | - |
|
417 | - $this->admin_notices[] = array( |
|
418 | - 'class' => $class, |
|
419 | - 'message' => $action_message_html, |
|
420 | - ); |
|
421 | - } |
|
422 | - |
|
423 | - parent::display_admin_notices(); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Prints the scheduled date in a human friendly format. |
|
428 | - * |
|
429 | - * @param array $row The array representation of the current row of the table |
|
430 | - * |
|
431 | - * @return string |
|
432 | - */ |
|
433 | - public function column_schedule( $row ) { |
|
434 | - return $this->get_schedule_display_string( $row['schedule'] ); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Get the scheduled date in a human friendly format. |
|
439 | - * |
|
440 | - * @param ActionScheduler_Schedule $schedule |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
|
444 | - |
|
445 | - $schedule_display_string = ''; |
|
446 | - |
|
447 | - if ( ! $schedule->get_date() ) { |
|
448 | - return '0000-00-00 00:00:00'; |
|
449 | - } |
|
450 | - |
|
451 | - $next_timestamp = $schedule->get_date()->getTimestamp(); |
|
452 | - |
|
453 | - $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); |
|
454 | - $schedule_display_string .= '<br/>'; |
|
455 | - |
|
456 | - if ( gmdate( 'U' ) > $next_timestamp ) { |
|
457 | - /* translators: %s: date interval */ |
|
458 | - $schedule_display_string .= sprintf( __( ' (%s ago)', 'action-scheduler' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); |
|
459 | - } else { |
|
460 | - /* translators: %s: date interval */ |
|
461 | - $schedule_display_string .= sprintf( __( ' (%s)', 'action-scheduler' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); |
|
462 | - } |
|
463 | - |
|
464 | - return $schedule_display_string; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Bulk delete |
|
469 | - * |
|
470 | - * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data |
|
471 | - * properly validated by the callee and it will delete the actions without any extra validation. |
|
472 | - * |
|
473 | - * @param array $ids |
|
474 | - * @param string $ids_sql Inherited and unused |
|
475 | - */ |
|
476 | - protected function bulk_delete( array $ids, $ids_sql ) { |
|
477 | - foreach ( $ids as $id ) { |
|
478 | - $this->store->delete_action( $id ); |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
484 | - * parameters are valid. |
|
485 | - * |
|
486 | - * @param int $action_id |
|
487 | - */ |
|
488 | - protected function row_action_cancel( $action_id ) { |
|
489 | - $this->process_row_action( $action_id, 'cancel' ); |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
494 | - * parameters are valid. |
|
495 | - * |
|
496 | - * @param int $action_id |
|
497 | - */ |
|
498 | - protected function row_action_run( $action_id ) { |
|
499 | - $this->process_row_action( $action_id, 'run' ); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Force the data store schema updates. |
|
504 | - */ |
|
505 | - protected function recreate_tables() { |
|
506 | - if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { |
|
507 | - $store = $this->store; |
|
508 | - } else { |
|
509 | - $store = new ActionScheduler_HybridStore(); |
|
510 | - } |
|
511 | - add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); |
|
512 | - |
|
513 | - $store_schema = new ActionScheduler_StoreSchema(); |
|
514 | - $logger_schema = new ActionScheduler_LoggerSchema(); |
|
515 | - $store_schema->register_tables( true ); |
|
516 | - $logger_schema->register_tables( true ); |
|
517 | - |
|
518 | - remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); |
|
519 | - } |
|
520 | - /** |
|
521 | - * Implements the logic behind processing an action once an action link is clicked on the list table. |
|
522 | - * |
|
523 | - * @param int $action_id |
|
524 | - * @param string $row_action_type The type of action to perform on the action. |
|
525 | - */ |
|
526 | - protected function process_row_action( $action_id, $row_action_type ) { |
|
527 | - try { |
|
528 | - switch ( $row_action_type ) { |
|
529 | - case 'run' : |
|
530 | - $this->runner->process_action( $action_id, 'Admin List Table' ); |
|
531 | - break; |
|
532 | - case 'cancel' : |
|
533 | - $this->store->cancel_action( $action_id ); |
|
534 | - break; |
|
535 | - } |
|
536 | - $success = 1; |
|
537 | - $error_message = ''; |
|
538 | - } catch ( Exception $e ) { |
|
539 | - $success = 0; |
|
540 | - $error_message = $e->getMessage(); |
|
541 | - } |
|
542 | - |
|
543 | - set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * {@inheritDoc} |
|
548 | - */ |
|
549 | - public function prepare_items() { |
|
550 | - $this->prepare_column_headers(); |
|
551 | - |
|
552 | - $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); |
|
553 | - $query = array( |
|
554 | - 'per_page' => $per_page, |
|
555 | - 'offset' => $this->get_items_offset(), |
|
556 | - 'status' => $this->get_request_status(), |
|
557 | - 'orderby' => $this->get_request_orderby(), |
|
558 | - 'order' => $this->get_request_order(), |
|
559 | - 'search' => $this->get_request_search_query(), |
|
560 | - ); |
|
561 | - |
|
562 | - $this->items = array(); |
|
563 | - |
|
564 | - $total_items = $this->store->query_actions( $query, 'count' ); |
|
565 | - |
|
566 | - $status_labels = $this->store->get_status_labels(); |
|
567 | - |
|
568 | - foreach ( $this->store->query_actions( $query ) as $action_id ) { |
|
569 | - try { |
|
570 | - $action = $this->store->fetch_action( $action_id ); |
|
571 | - } catch ( Exception $e ) { |
|
572 | - continue; |
|
573 | - } |
|
574 | - if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { |
|
575 | - continue; |
|
576 | - } |
|
577 | - $this->items[ $action_id ] = array( |
|
578 | - 'ID' => $action_id, |
|
579 | - 'hook' => $action->get_hook(), |
|
580 | - 'status' => $status_labels[ $this->store->get_status( $action_id ) ], |
|
581 | - 'args' => $action->get_args(), |
|
582 | - 'group' => $action->get_group(), |
|
583 | - 'log_entries' => $this->logger->get_logs( $action_id ), |
|
584 | - 'claim_id' => $this->store->get_claim_id( $action_id ), |
|
585 | - 'recurrence' => $this->get_recurrence( $action ), |
|
586 | - 'schedule' => $action->get_schedule(), |
|
587 | - ); |
|
588 | - } |
|
589 | - |
|
590 | - $this->set_pagination_args( array( |
|
591 | - 'total_items' => $total_items, |
|
592 | - 'per_page' => $per_page, |
|
593 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
594 | - ) ); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Prints the available statuses so the user can click to filter. |
|
599 | - */ |
|
600 | - protected function display_filter_by_status() { |
|
601 | - $this->status_counts = $this->store->action_counts(); |
|
602 | - parent::display_filter_by_status(); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Get the text to display in the search box on the list table. |
|
607 | - */ |
|
608 | - protected function get_search_box_button_text() { |
|
609 | - return __( 'Search hook, args and claim ID', 'action-scheduler' ); |
|
610 | - } |
|
9 | + /** |
|
10 | + * The package name. |
|
11 | + * |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $package = 'action-scheduler'; |
|
15 | + |
|
16 | + /** |
|
17 | + * Columns to show (name => label). |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $columns = array(); |
|
22 | + |
|
23 | + /** |
|
24 | + * Actions (name => label). |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $row_actions = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * The active data stores |
|
32 | + * |
|
33 | + * @var ActionScheduler_Store |
|
34 | + */ |
|
35 | + protected $store; |
|
36 | + |
|
37 | + /** |
|
38 | + * A logger to use for getting action logs to display |
|
39 | + * |
|
40 | + * @var ActionScheduler_Logger |
|
41 | + */ |
|
42 | + protected $logger; |
|
43 | + |
|
44 | + /** |
|
45 | + * A ActionScheduler_QueueRunner runner instance (or child class) |
|
46 | + * |
|
47 | + * @var ActionScheduler_QueueRunner |
|
48 | + */ |
|
49 | + protected $runner; |
|
50 | + |
|
51 | + /** |
|
52 | + * Bulk actions. The key of the array is the method name of the implementation: |
|
53 | + * |
|
54 | + * bulk_<key>(array $ids, string $sql_in). |
|
55 | + * |
|
56 | + * See the comments in the parent class for further details |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $bulk_actions = array(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Flag variable to render our notifications, if any, once. |
|
64 | + * |
|
65 | + * @var bool |
|
66 | + */ |
|
67 | + protected static $did_notification = false; |
|
68 | + |
|
69 | + /** |
|
70 | + * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days" |
|
71 | + * |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + private static $time_periods; |
|
75 | + |
|
76 | + /** |
|
77 | + * Sets the current data store object into `store->action` and initialises the object. |
|
78 | + * |
|
79 | + * @param ActionScheduler_Store $store |
|
80 | + * @param ActionScheduler_Logger $logger |
|
81 | + * @param ActionScheduler_QueueRunner $runner |
|
82 | + */ |
|
83 | + public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { |
|
84 | + |
|
85 | + $this->store = $store; |
|
86 | + $this->logger = $logger; |
|
87 | + $this->runner = $runner; |
|
88 | + |
|
89 | + $this->table_header = __( 'Scheduled Actions', 'action-scheduler' ); |
|
90 | + |
|
91 | + $this->bulk_actions = array( |
|
92 | + 'delete' => __( 'Delete', 'action-scheduler' ), |
|
93 | + ); |
|
94 | + |
|
95 | + $this->columns = array( |
|
96 | + 'hook' => __( 'Hook', 'action-scheduler' ), |
|
97 | + 'status' => __( 'Status', 'action-scheduler' ), |
|
98 | + 'args' => __( 'Arguments', 'action-scheduler' ), |
|
99 | + 'group' => __( 'Group', 'action-scheduler' ), |
|
100 | + 'recurrence' => __( 'Recurrence', 'action-scheduler' ), |
|
101 | + 'schedule' => __( 'Scheduled Date', 'action-scheduler' ), |
|
102 | + 'log_entries' => __( 'Log', 'action-scheduler' ), |
|
103 | + ); |
|
104 | + |
|
105 | + $this->sort_by = array( |
|
106 | + 'schedule', |
|
107 | + 'hook', |
|
108 | + 'group', |
|
109 | + ); |
|
110 | + |
|
111 | + $this->search_by = array( |
|
112 | + 'hook', |
|
113 | + 'args', |
|
114 | + 'claim_id', |
|
115 | + ); |
|
116 | + |
|
117 | + $request_status = $this->get_request_status(); |
|
118 | + |
|
119 | + if ( empty( $request_status ) ) { |
|
120 | + $this->sort_by[] = 'status'; |
|
121 | + } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { |
|
122 | + $this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) ); |
|
123 | + $this->sort_by[] = 'claim_id'; |
|
124 | + } |
|
125 | + |
|
126 | + $this->row_actions = array( |
|
127 | + 'hook' => array( |
|
128 | + 'run' => array( |
|
129 | + 'name' => __( 'Run', 'action-scheduler' ), |
|
130 | + 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ), |
|
131 | + ), |
|
132 | + 'cancel' => array( |
|
133 | + 'name' => __( 'Cancel', 'action-scheduler' ), |
|
134 | + 'desc' => __( 'Cancel the action now to avoid it being run in future', 'action-scheduler' ), |
|
135 | + 'class' => 'cancel trash', |
|
136 | + ), |
|
137 | + ), |
|
138 | + ); |
|
139 | + |
|
140 | + self::$time_periods = array( |
|
141 | + array( |
|
142 | + 'seconds' => YEAR_IN_SECONDS, |
|
143 | + /* translators: %s: amount of time */ |
|
144 | + 'names' => _n_noop( '%s year', '%s years', 'action-scheduler' ), |
|
145 | + ), |
|
146 | + array( |
|
147 | + 'seconds' => MONTH_IN_SECONDS, |
|
148 | + /* translators: %s: amount of time */ |
|
149 | + 'names' => _n_noop( '%s month', '%s months', 'action-scheduler' ), |
|
150 | + ), |
|
151 | + array( |
|
152 | + 'seconds' => WEEK_IN_SECONDS, |
|
153 | + /* translators: %s: amount of time */ |
|
154 | + 'names' => _n_noop( '%s week', '%s weeks', 'action-scheduler' ), |
|
155 | + ), |
|
156 | + array( |
|
157 | + 'seconds' => DAY_IN_SECONDS, |
|
158 | + /* translators: %s: amount of time */ |
|
159 | + 'names' => _n_noop( '%s day', '%s days', 'action-scheduler' ), |
|
160 | + ), |
|
161 | + array( |
|
162 | + 'seconds' => HOUR_IN_SECONDS, |
|
163 | + /* translators: %s: amount of time */ |
|
164 | + 'names' => _n_noop( '%s hour', '%s hours', 'action-scheduler' ), |
|
165 | + ), |
|
166 | + array( |
|
167 | + 'seconds' => MINUTE_IN_SECONDS, |
|
168 | + /* translators: %s: amount of time */ |
|
169 | + 'names' => _n_noop( '%s minute', '%s minutes', 'action-scheduler' ), |
|
170 | + ), |
|
171 | + array( |
|
172 | + 'seconds' => 1, |
|
173 | + /* translators: %s: amount of time */ |
|
174 | + 'names' => _n_noop( '%s second', '%s seconds', 'action-scheduler' ), |
|
175 | + ), |
|
176 | + ); |
|
177 | + |
|
178 | + parent::__construct( array( |
|
179 | + 'singular' => 'action-scheduler', |
|
180 | + 'plural' => 'action-scheduler', |
|
181 | + 'ajax' => false, |
|
182 | + ) ); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Convert an interval of seconds into a two part human friendly string. |
|
187 | + * |
|
188 | + * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning |
|
189 | + * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step |
|
190 | + * further to display two degrees of accuracy. |
|
191 | + * |
|
192 | + * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ |
|
193 | + * |
|
194 | + * @param int $interval A interval in seconds. |
|
195 | + * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. |
|
196 | + * @return string A human friendly string representation of the interval. |
|
197 | + */ |
|
198 | + private static function human_interval( $interval, $periods_to_include = 2 ) { |
|
199 | + |
|
200 | + if ( $interval <= 0 ) { |
|
201 | + return __( 'Now!', 'action-scheduler' ); |
|
202 | + } |
|
203 | + |
|
204 | + $output = ''; |
|
205 | + |
|
206 | + for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { |
|
207 | + |
|
208 | + $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); |
|
209 | + |
|
210 | + if ( $periods_in_interval > 0 ) { |
|
211 | + if ( ! empty( $output ) ) { |
|
212 | + $output .= ' '; |
|
213 | + } |
|
214 | + $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'action-scheduler' ), $periods_in_interval ); |
|
215 | + $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
|
216 | + $periods_included++; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + return $output; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Returns the recurrence of an action or 'Non-repeating'. The output is human readable. |
|
225 | + * |
|
226 | + * @param ActionScheduler_Action $action |
|
227 | + * |
|
228 | + * @return string |
|
229 | + */ |
|
230 | + protected function get_recurrence( $action ) { |
|
231 | + $schedule = $action->get_schedule(); |
|
232 | + if ( $schedule->is_recurring() ) { |
|
233 | + $recurrence = $schedule->get_recurrence(); |
|
234 | + |
|
235 | + if ( is_numeric( $recurrence ) ) { |
|
236 | + /* translators: %s: time interval */ |
|
237 | + return sprintf( __( 'Every %s', 'action-scheduler' ), self::human_interval( $recurrence ) ); |
|
238 | + } else { |
|
239 | + return $recurrence; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + return __( 'Non-repeating', 'action-scheduler' ); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Serializes the argument of an action to render it in a human friendly format. |
|
248 | + * |
|
249 | + * @param array $row The array representation of the current row of the table |
|
250 | + * |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function column_args( array $row ) { |
|
254 | + if ( empty( $row['args'] ) ) { |
|
255 | + return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); |
|
256 | + } |
|
257 | + |
|
258 | + $row_html = '<ul>'; |
|
259 | + foreach ( $row['args'] as $key => $value ) { |
|
260 | + $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); |
|
261 | + } |
|
262 | + $row_html .= '</ul>'; |
|
263 | + |
|
264 | + return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
269 | + * |
|
270 | + * @param array $row Action array. |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + public function column_log_entries( array $row ) { |
|
274 | + |
|
275 | + $log_entries_html = '<ol>'; |
|
276 | + |
|
277 | + $timezone = new DateTimezone( 'UTC' ); |
|
278 | + |
|
279 | + foreach ( $row['log_entries'] as $log_entry ) { |
|
280 | + $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); |
|
281 | + } |
|
282 | + |
|
283 | + $log_entries_html .= '</ol>'; |
|
284 | + |
|
285 | + return $log_entries_html; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
290 | + * |
|
291 | + * @param ActionScheduler_LogEntry $log_entry |
|
292 | + * @param DateTimezone $timezone |
|
293 | + * @return string |
|
294 | + */ |
|
295 | + protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { |
|
296 | + $date = $log_entry->get_date(); |
|
297 | + $date->setTimezone( $timezone ); |
|
298 | + return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Only display row actions for pending actions. |
|
303 | + * |
|
304 | + * @param array $row Row to render |
|
305 | + * @param string $column_name Current row |
|
306 | + * |
|
307 | + * @return string |
|
308 | + */ |
|
309 | + protected function maybe_render_actions( $row, $column_name ) { |
|
310 | + if ( 'pending' === strtolower( $row['status'] ) ) { |
|
311 | + return parent::maybe_render_actions( $row, $column_name ); |
|
312 | + } |
|
313 | + |
|
314 | + return ''; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Renders admin notifications |
|
319 | + * |
|
320 | + * Notifications: |
|
321 | + * 1. When the maximum number of tasks are being executed simultaneously. |
|
322 | + * 2. Notifications when a task is manually executed. |
|
323 | + * 3. Tables are missing. |
|
324 | + */ |
|
325 | + public function display_admin_notices() { |
|
326 | + global $wpdb; |
|
327 | + |
|
328 | + if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { |
|
329 | + $table_list = array( |
|
330 | + 'actionscheduler_actions', |
|
331 | + 'actionscheduler_logs', |
|
332 | + 'actionscheduler_groups', |
|
333 | + 'actionscheduler_claims', |
|
334 | + ); |
|
335 | + |
|
336 | + $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
337 | + foreach ( $table_list as $table_name ) { |
|
338 | + if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { |
|
339 | + $this->admin_notices[] = array( |
|
340 | + 'class' => 'error', |
|
341 | + 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ), |
|
342 | + ); |
|
343 | + $this->recreate_tables(); |
|
344 | + parent::display_admin_notices(); |
|
345 | + |
|
346 | + return; |
|
347 | + } |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + if ( $this->runner->has_maximum_concurrent_batches() ) { |
|
352 | + $claim_count = $this->store->get_claim_count(); |
|
353 | + $this->admin_notices[] = array( |
|
354 | + 'class' => 'updated', |
|
355 | + 'message' => sprintf( |
|
356 | + /* translators: %s: amount of claims */ |
|
357 | + _n( |
|
358 | + 'Maximum simultaneous queues already in progress (%s queue). No additional queues will begin processing until the current queues are complete.', |
|
359 | + 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', |
|
360 | + $claim_count, |
|
361 | + 'action-scheduler' |
|
362 | + ), |
|
363 | + $claim_count |
|
364 | + ), |
|
365 | + ); |
|
366 | + } elseif ( $this->store->has_pending_actions_due() ) { |
|
367 | + |
|
368 | + $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
|
369 | + |
|
370 | + // No lock set or lock expired |
|
371 | + if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
|
372 | + $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); |
|
373 | + /* translators: %s: process URL */ |
|
374 | + $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'action-scheduler' ), esc_url( $in_progress_url ) ); |
|
375 | + } else { |
|
376 | + /* translators: %d: seconds */ |
|
377 | + $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'action-scheduler' ), $async_request_lock_expiration - time() ); |
|
378 | + } |
|
379 | + |
|
380 | + $this->admin_notices[] = array( |
|
381 | + 'class' => 'notice notice-info', |
|
382 | + 'message' => $async_request_message, |
|
383 | + ); |
|
384 | + } |
|
385 | + |
|
386 | + $notification = get_transient( 'action_scheduler_admin_notice' ); |
|
387 | + |
|
388 | + if ( is_array( $notification ) ) { |
|
389 | + delete_transient( 'action_scheduler_admin_notice' ); |
|
390 | + |
|
391 | + $action = $this->store->fetch_action( $notification['action_id'] ); |
|
392 | + $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
|
393 | + if ( 1 == $notification['success'] ) { |
|
394 | + $class = 'updated'; |
|
395 | + switch ( $notification['row_action_type'] ) { |
|
396 | + case 'run' : |
|
397 | + /* translators: %s: action HTML */ |
|
398 | + $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html ); |
|
399 | + break; |
|
400 | + case 'cancel' : |
|
401 | + /* translators: %s: action HTML */ |
|
402 | + $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html ); |
|
403 | + break; |
|
404 | + default : |
|
405 | + /* translators: %s: action HTML */ |
|
406 | + $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html ); |
|
407 | + break; |
|
408 | + } |
|
409 | + } else { |
|
410 | + $class = 'error'; |
|
411 | + /* translators: 1: action HTML 2: action ID 3: error message */ |
|
412 | + $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'action-scheduler' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); |
|
413 | + } |
|
414 | + |
|
415 | + $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); |
|
416 | + |
|
417 | + $this->admin_notices[] = array( |
|
418 | + 'class' => $class, |
|
419 | + 'message' => $action_message_html, |
|
420 | + ); |
|
421 | + } |
|
422 | + |
|
423 | + parent::display_admin_notices(); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Prints the scheduled date in a human friendly format. |
|
428 | + * |
|
429 | + * @param array $row The array representation of the current row of the table |
|
430 | + * |
|
431 | + * @return string |
|
432 | + */ |
|
433 | + public function column_schedule( $row ) { |
|
434 | + return $this->get_schedule_display_string( $row['schedule'] ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Get the scheduled date in a human friendly format. |
|
439 | + * |
|
440 | + * @param ActionScheduler_Schedule $schedule |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
|
444 | + |
|
445 | + $schedule_display_string = ''; |
|
446 | + |
|
447 | + if ( ! $schedule->get_date() ) { |
|
448 | + return '0000-00-00 00:00:00'; |
|
449 | + } |
|
450 | + |
|
451 | + $next_timestamp = $schedule->get_date()->getTimestamp(); |
|
452 | + |
|
453 | + $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); |
|
454 | + $schedule_display_string .= '<br/>'; |
|
455 | + |
|
456 | + if ( gmdate( 'U' ) > $next_timestamp ) { |
|
457 | + /* translators: %s: date interval */ |
|
458 | + $schedule_display_string .= sprintf( __( ' (%s ago)', 'action-scheduler' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); |
|
459 | + } else { |
|
460 | + /* translators: %s: date interval */ |
|
461 | + $schedule_display_string .= sprintf( __( ' (%s)', 'action-scheduler' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); |
|
462 | + } |
|
463 | + |
|
464 | + return $schedule_display_string; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Bulk delete |
|
469 | + * |
|
470 | + * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data |
|
471 | + * properly validated by the callee and it will delete the actions without any extra validation. |
|
472 | + * |
|
473 | + * @param array $ids |
|
474 | + * @param string $ids_sql Inherited and unused |
|
475 | + */ |
|
476 | + protected function bulk_delete( array $ids, $ids_sql ) { |
|
477 | + foreach ( $ids as $id ) { |
|
478 | + $this->store->delete_action( $id ); |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
484 | + * parameters are valid. |
|
485 | + * |
|
486 | + * @param int $action_id |
|
487 | + */ |
|
488 | + protected function row_action_cancel( $action_id ) { |
|
489 | + $this->process_row_action( $action_id, 'cancel' ); |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
494 | + * parameters are valid. |
|
495 | + * |
|
496 | + * @param int $action_id |
|
497 | + */ |
|
498 | + protected function row_action_run( $action_id ) { |
|
499 | + $this->process_row_action( $action_id, 'run' ); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Force the data store schema updates. |
|
504 | + */ |
|
505 | + protected function recreate_tables() { |
|
506 | + if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { |
|
507 | + $store = $this->store; |
|
508 | + } else { |
|
509 | + $store = new ActionScheduler_HybridStore(); |
|
510 | + } |
|
511 | + add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); |
|
512 | + |
|
513 | + $store_schema = new ActionScheduler_StoreSchema(); |
|
514 | + $logger_schema = new ActionScheduler_LoggerSchema(); |
|
515 | + $store_schema->register_tables( true ); |
|
516 | + $logger_schema->register_tables( true ); |
|
517 | + |
|
518 | + remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); |
|
519 | + } |
|
520 | + /** |
|
521 | + * Implements the logic behind processing an action once an action link is clicked on the list table. |
|
522 | + * |
|
523 | + * @param int $action_id |
|
524 | + * @param string $row_action_type The type of action to perform on the action. |
|
525 | + */ |
|
526 | + protected function process_row_action( $action_id, $row_action_type ) { |
|
527 | + try { |
|
528 | + switch ( $row_action_type ) { |
|
529 | + case 'run' : |
|
530 | + $this->runner->process_action( $action_id, 'Admin List Table' ); |
|
531 | + break; |
|
532 | + case 'cancel' : |
|
533 | + $this->store->cancel_action( $action_id ); |
|
534 | + break; |
|
535 | + } |
|
536 | + $success = 1; |
|
537 | + $error_message = ''; |
|
538 | + } catch ( Exception $e ) { |
|
539 | + $success = 0; |
|
540 | + $error_message = $e->getMessage(); |
|
541 | + } |
|
542 | + |
|
543 | + set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * {@inheritDoc} |
|
548 | + */ |
|
549 | + public function prepare_items() { |
|
550 | + $this->prepare_column_headers(); |
|
551 | + |
|
552 | + $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); |
|
553 | + $query = array( |
|
554 | + 'per_page' => $per_page, |
|
555 | + 'offset' => $this->get_items_offset(), |
|
556 | + 'status' => $this->get_request_status(), |
|
557 | + 'orderby' => $this->get_request_orderby(), |
|
558 | + 'order' => $this->get_request_order(), |
|
559 | + 'search' => $this->get_request_search_query(), |
|
560 | + ); |
|
561 | + |
|
562 | + $this->items = array(); |
|
563 | + |
|
564 | + $total_items = $this->store->query_actions( $query, 'count' ); |
|
565 | + |
|
566 | + $status_labels = $this->store->get_status_labels(); |
|
567 | + |
|
568 | + foreach ( $this->store->query_actions( $query ) as $action_id ) { |
|
569 | + try { |
|
570 | + $action = $this->store->fetch_action( $action_id ); |
|
571 | + } catch ( Exception $e ) { |
|
572 | + continue; |
|
573 | + } |
|
574 | + if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { |
|
575 | + continue; |
|
576 | + } |
|
577 | + $this->items[ $action_id ] = array( |
|
578 | + 'ID' => $action_id, |
|
579 | + 'hook' => $action->get_hook(), |
|
580 | + 'status' => $status_labels[ $this->store->get_status( $action_id ) ], |
|
581 | + 'args' => $action->get_args(), |
|
582 | + 'group' => $action->get_group(), |
|
583 | + 'log_entries' => $this->logger->get_logs( $action_id ), |
|
584 | + 'claim_id' => $this->store->get_claim_id( $action_id ), |
|
585 | + 'recurrence' => $this->get_recurrence( $action ), |
|
586 | + 'schedule' => $action->get_schedule(), |
|
587 | + ); |
|
588 | + } |
|
589 | + |
|
590 | + $this->set_pagination_args( array( |
|
591 | + 'total_items' => $total_items, |
|
592 | + 'per_page' => $per_page, |
|
593 | + 'total_pages' => ceil( $total_items / $per_page ), |
|
594 | + ) ); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Prints the available statuses so the user can click to filter. |
|
599 | + */ |
|
600 | + protected function display_filter_by_status() { |
|
601 | + $this->status_counts = $this->store->action_counts(); |
|
602 | + parent::display_filter_by_status(); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Get the text to display in the search box on the list table. |
|
607 | + */ |
|
608 | + protected function get_search_box_button_text() { |
|
609 | + return __( 'Search hook, args and claim ID', 'action-scheduler' ); |
|
610 | + } |
|
611 | 611 | } |
@@ -80,26 +80,26 @@ discard block |
||
80 | 80 | * @param ActionScheduler_Logger $logger |
81 | 81 | * @param ActionScheduler_QueueRunner $runner |
82 | 82 | */ |
83 | - public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { |
|
83 | + public function __construct(ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner) { |
|
84 | 84 | |
85 | 85 | $this->store = $store; |
86 | 86 | $this->logger = $logger; |
87 | 87 | $this->runner = $runner; |
88 | 88 | |
89 | - $this->table_header = __( 'Scheduled Actions', 'action-scheduler' ); |
|
89 | + $this->table_header = __('Scheduled Actions', 'action-scheduler'); |
|
90 | 90 | |
91 | 91 | $this->bulk_actions = array( |
92 | - 'delete' => __( 'Delete', 'action-scheduler' ), |
|
92 | + 'delete' => __('Delete', 'action-scheduler'), |
|
93 | 93 | ); |
94 | 94 | |
95 | 95 | $this->columns = array( |
96 | - 'hook' => __( 'Hook', 'action-scheduler' ), |
|
97 | - 'status' => __( 'Status', 'action-scheduler' ), |
|
98 | - 'args' => __( 'Arguments', 'action-scheduler' ), |
|
99 | - 'group' => __( 'Group', 'action-scheduler' ), |
|
100 | - 'recurrence' => __( 'Recurrence', 'action-scheduler' ), |
|
101 | - 'schedule' => __( 'Scheduled Date', 'action-scheduler' ), |
|
102 | - 'log_entries' => __( 'Log', 'action-scheduler' ), |
|
96 | + 'hook' => __('Hook', 'action-scheduler'), |
|
97 | + 'status' => __('Status', 'action-scheduler'), |
|
98 | + 'args' => __('Arguments', 'action-scheduler'), |
|
99 | + 'group' => __('Group', 'action-scheduler'), |
|
100 | + 'recurrence' => __('Recurrence', 'action-scheduler'), |
|
101 | + 'schedule' => __('Scheduled Date', 'action-scheduler'), |
|
102 | + 'log_entries' => __('Log', 'action-scheduler'), |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | $this->sort_by = array( |
@@ -116,22 +116,22 @@ discard block |
||
116 | 116 | |
117 | 117 | $request_status = $this->get_request_status(); |
118 | 118 | |
119 | - if ( empty( $request_status ) ) { |
|
119 | + if (empty($request_status)) { |
|
120 | 120 | $this->sort_by[] = 'status'; |
121 | - } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { |
|
122 | - $this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) ); |
|
121 | + } elseif (in_array($request_status, array('in-progress', 'failed'))) { |
|
122 | + $this->columns += array('claim_id' => __('Claim ID', 'action-scheduler')); |
|
123 | 123 | $this->sort_by[] = 'claim_id'; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $this->row_actions = array( |
127 | 127 | 'hook' => array( |
128 | 128 | 'run' => array( |
129 | - 'name' => __( 'Run', 'action-scheduler' ), |
|
130 | - 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ), |
|
129 | + 'name' => __('Run', 'action-scheduler'), |
|
130 | + 'desc' => __('Process the action now as if it were run as part of a queue', 'action-scheduler'), |
|
131 | 131 | ), |
132 | 132 | 'cancel' => array( |
133 | - 'name' => __( 'Cancel', 'action-scheduler' ), |
|
134 | - 'desc' => __( 'Cancel the action now to avoid it being run in future', 'action-scheduler' ), |
|
133 | + 'name' => __('Cancel', 'action-scheduler'), |
|
134 | + 'desc' => __('Cancel the action now to avoid it being run in future', 'action-scheduler'), |
|
135 | 135 | 'class' => 'cancel trash', |
136 | 136 | ), |
137 | 137 | ), |
@@ -141,45 +141,45 @@ discard block |
||
141 | 141 | array( |
142 | 142 | 'seconds' => YEAR_IN_SECONDS, |
143 | 143 | /* translators: %s: amount of time */ |
144 | - 'names' => _n_noop( '%s year', '%s years', 'action-scheduler' ), |
|
144 | + 'names' => _n_noop('%s year', '%s years', 'action-scheduler'), |
|
145 | 145 | ), |
146 | 146 | array( |
147 | 147 | 'seconds' => MONTH_IN_SECONDS, |
148 | 148 | /* translators: %s: amount of time */ |
149 | - 'names' => _n_noop( '%s month', '%s months', 'action-scheduler' ), |
|
149 | + 'names' => _n_noop('%s month', '%s months', 'action-scheduler'), |
|
150 | 150 | ), |
151 | 151 | array( |
152 | 152 | 'seconds' => WEEK_IN_SECONDS, |
153 | 153 | /* translators: %s: amount of time */ |
154 | - 'names' => _n_noop( '%s week', '%s weeks', 'action-scheduler' ), |
|
154 | + 'names' => _n_noop('%s week', '%s weeks', 'action-scheduler'), |
|
155 | 155 | ), |
156 | 156 | array( |
157 | 157 | 'seconds' => DAY_IN_SECONDS, |
158 | 158 | /* translators: %s: amount of time */ |
159 | - 'names' => _n_noop( '%s day', '%s days', 'action-scheduler' ), |
|
159 | + 'names' => _n_noop('%s day', '%s days', 'action-scheduler'), |
|
160 | 160 | ), |
161 | 161 | array( |
162 | 162 | 'seconds' => HOUR_IN_SECONDS, |
163 | 163 | /* translators: %s: amount of time */ |
164 | - 'names' => _n_noop( '%s hour', '%s hours', 'action-scheduler' ), |
|
164 | + 'names' => _n_noop('%s hour', '%s hours', 'action-scheduler'), |
|
165 | 165 | ), |
166 | 166 | array( |
167 | 167 | 'seconds' => MINUTE_IN_SECONDS, |
168 | 168 | /* translators: %s: amount of time */ |
169 | - 'names' => _n_noop( '%s minute', '%s minutes', 'action-scheduler' ), |
|
169 | + 'names' => _n_noop('%s minute', '%s minutes', 'action-scheduler'), |
|
170 | 170 | ), |
171 | 171 | array( |
172 | 172 | 'seconds' => 1, |
173 | 173 | /* translators: %s: amount of time */ |
174 | - 'names' => _n_noop( '%s second', '%s seconds', 'action-scheduler' ), |
|
174 | + 'names' => _n_noop('%s second', '%s seconds', 'action-scheduler'), |
|
175 | 175 | ), |
176 | 176 | ); |
177 | 177 | |
178 | - parent::__construct( array( |
|
178 | + parent::__construct(array( |
|
179 | 179 | 'singular' => 'action-scheduler', |
180 | 180 | 'plural' => 'action-scheduler', |
181 | 181 | 'ajax' => false, |
182 | - ) ); |
|
182 | + )); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -195,24 +195,24 @@ discard block |
||
195 | 195 | * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. |
196 | 196 | * @return string A human friendly string representation of the interval. |
197 | 197 | */ |
198 | - private static function human_interval( $interval, $periods_to_include = 2 ) { |
|
198 | + private static function human_interval($interval, $periods_to_include = 2) { |
|
199 | 199 | |
200 | - if ( $interval <= 0 ) { |
|
201 | - return __( 'Now!', 'action-scheduler' ); |
|
200 | + if ($interval <= 0) { |
|
201 | + return __('Now!', 'action-scheduler'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | $output = ''; |
205 | 205 | |
206 | - for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { |
|
206 | + for ($time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count(self::$time_periods) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++) { |
|
207 | 207 | |
208 | - $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); |
|
208 | + $periods_in_interval = floor($seconds_remaining / self::$time_periods[$time_period_index]['seconds']); |
|
209 | 209 | |
210 | - if ( $periods_in_interval > 0 ) { |
|
211 | - if ( ! empty( $output ) ) { |
|
210 | + if ($periods_in_interval > 0) { |
|
211 | + if (!empty($output)) { |
|
212 | 212 | $output .= ' '; |
213 | 213 | } |
214 | - $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'action-scheduler' ), $periods_in_interval ); |
|
215 | - $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
|
214 | + $output .= sprintf(_n(self::$time_periods[$time_period_index]['names'][0], self::$time_periods[$time_period_index]['names'][1], $periods_in_interval, 'action-scheduler'), $periods_in_interval); |
|
215 | + $seconds_remaining -= $periods_in_interval * self::$time_periods[$time_period_index]['seconds']; |
|
216 | 216 | $periods_included++; |
217 | 217 | } |
218 | 218 | } |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @return string |
229 | 229 | */ |
230 | - protected function get_recurrence( $action ) { |
|
230 | + protected function get_recurrence($action) { |
|
231 | 231 | $schedule = $action->get_schedule(); |
232 | - if ( $schedule->is_recurring() ) { |
|
232 | + if ($schedule->is_recurring()) { |
|
233 | 233 | $recurrence = $schedule->get_recurrence(); |
234 | 234 | |
235 | - if ( is_numeric( $recurrence ) ) { |
|
235 | + if (is_numeric($recurrence)) { |
|
236 | 236 | /* translators: %s: time interval */ |
237 | - return sprintf( __( 'Every %s', 'action-scheduler' ), self::human_interval( $recurrence ) ); |
|
237 | + return sprintf(__('Every %s', 'action-scheduler'), self::human_interval($recurrence)); |
|
238 | 238 | } else { |
239 | 239 | return $recurrence; |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - return __( 'Non-repeating', 'action-scheduler' ); |
|
243 | + return __('Non-repeating', 'action-scheduler'); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -250,18 +250,18 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @return string |
252 | 252 | */ |
253 | - public function column_args( array $row ) { |
|
254 | - if ( empty( $row['args'] ) ) { |
|
255 | - return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); |
|
253 | + public function column_args(array $row) { |
|
254 | + if (empty($row['args'])) { |
|
255 | + return apply_filters('action_scheduler_list_table_column_args', '', $row); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | $row_html = '<ul>'; |
259 | - foreach ( $row['args'] as $key => $value ) { |
|
260 | - $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); |
|
259 | + foreach ($row['args'] as $key => $value) { |
|
260 | + $row_html .= sprintf('<li><code>%s => %s</code></li>', esc_html(var_export($key, true)), esc_html(var_export($value, true))); |
|
261 | 261 | } |
262 | 262 | $row_html .= '</ul>'; |
263 | 263 | |
264 | - return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
|
264 | + return apply_filters('action_scheduler_list_table_column_args', $row_html, $row); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -270,14 +270,14 @@ discard block |
||
270 | 270 | * @param array $row Action array. |
271 | 271 | * @return string |
272 | 272 | */ |
273 | - public function column_log_entries( array $row ) { |
|
273 | + public function column_log_entries(array $row) { |
|
274 | 274 | |
275 | 275 | $log_entries_html = '<ol>'; |
276 | 276 | |
277 | - $timezone = new DateTimezone( 'UTC' ); |
|
277 | + $timezone = new DateTimezone('UTC'); |
|
278 | 278 | |
279 | - foreach ( $row['log_entries'] as $log_entry ) { |
|
280 | - $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); |
|
279 | + foreach ($row['log_entries'] as $log_entry) { |
|
280 | + $log_entries_html .= $this->get_log_entry_html($log_entry, $timezone); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | $log_entries_html .= '</ol>'; |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | * @param DateTimezone $timezone |
293 | 293 | * @return string |
294 | 294 | */ |
295 | - protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { |
|
295 | + protected function get_log_entry_html(ActionScheduler_LogEntry $log_entry, DateTimezone $timezone) { |
|
296 | 296 | $date = $log_entry->get_date(); |
297 | - $date->setTimezone( $timezone ); |
|
298 | - return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); |
|
297 | + $date->setTimezone($timezone); |
|
298 | + return sprintf('<li><strong>%s</strong><br/>%s</li>', esc_html($date->format('Y-m-d H:i:s O')), esc_html($log_entry->get_message())); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - protected function maybe_render_actions( $row, $column_name ) { |
|
310 | - if ( 'pending' === strtolower( $row['status'] ) ) { |
|
311 | - return parent::maybe_render_actions( $row, $column_name ); |
|
309 | + protected function maybe_render_actions($row, $column_name) { |
|
310 | + if ('pending' === strtolower($row['status'])) { |
|
311 | + return parent::maybe_render_actions($row, $column_name); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | return ''; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | public function display_admin_notices() { |
326 | 326 | global $wpdb; |
327 | 327 | |
328 | - if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { |
|
328 | + if ((is_a($this->store, 'ActionScheduler_HybridStore') || is_a($this->store, 'ActionScheduler_DBStore')) && apply_filters('action_scheduler_enable_recreate_data_store', true)) { |
|
329 | 329 | $table_list = array( |
330 | 330 | 'actionscheduler_actions', |
331 | 331 | 'actionscheduler_logs', |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | 'actionscheduler_claims', |
334 | 334 | ); |
335 | 335 | |
336 | - $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
337 | - foreach ( $table_list as $table_name ) { |
|
338 | - if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { |
|
336 | + $found_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
337 | + foreach ($table_list as $table_name) { |
|
338 | + if (!in_array($wpdb->prefix . $table_name, $found_tables)) { |
|
339 | 339 | $this->admin_notices[] = array( |
340 | 340 | 'class' => 'error', |
341 | - 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ), |
|
341 | + 'message' => __('It appears one or more database tables were missing. Attempting to re-create the missing table(s).', 'action-scheduler'), |
|
342 | 342 | ); |
343 | 343 | $this->recreate_tables(); |
344 | 344 | parent::display_admin_notices(); |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | } |
349 | 349 | } |
350 | 350 | |
351 | - if ( $this->runner->has_maximum_concurrent_batches() ) { |
|
351 | + if ($this->runner->has_maximum_concurrent_batches()) { |
|
352 | 352 | $claim_count = $this->store->get_claim_count(); |
353 | 353 | $this->admin_notices[] = array( |
354 | 354 | 'class' => 'updated', |
@@ -363,18 +363,18 @@ discard block |
||
363 | 363 | $claim_count |
364 | 364 | ), |
365 | 365 | ); |
366 | - } elseif ( $this->store->has_pending_actions_due() ) { |
|
366 | + } elseif ($this->store->has_pending_actions_due()) { |
|
367 | 367 | |
368 | - $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
|
368 | + $async_request_lock_expiration = ActionScheduler::lock()->get_expiration('async-request-runner'); |
|
369 | 369 | |
370 | 370 | // No lock set or lock expired |
371 | - if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
|
372 | - $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); |
|
371 | + if (false === $async_request_lock_expiration || $async_request_lock_expiration < time()) { |
|
372 | + $in_progress_url = add_query_arg('status', 'in-progress', remove_query_arg('status')); |
|
373 | 373 | /* translators: %s: process URL */ |
374 | - $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'action-scheduler' ), esc_url( $in_progress_url ) ); |
|
374 | + $async_request_message = sprintf(__('A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'action-scheduler'), esc_url($in_progress_url)); |
|
375 | 375 | } else { |
376 | 376 | /* translators: %d: seconds */ |
377 | - $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'action-scheduler' ), $async_request_lock_expiration - time() ); |
|
377 | + $async_request_message = sprintf(__('The next queue will begin processing in approximately %d seconds.', 'action-scheduler'), $async_request_lock_expiration - time()); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | $this->admin_notices[] = array( |
@@ -383,36 +383,36 @@ discard block |
||
383 | 383 | ); |
384 | 384 | } |
385 | 385 | |
386 | - $notification = get_transient( 'action_scheduler_admin_notice' ); |
|
386 | + $notification = get_transient('action_scheduler_admin_notice'); |
|
387 | 387 | |
388 | - if ( is_array( $notification ) ) { |
|
389 | - delete_transient( 'action_scheduler_admin_notice' ); |
|
388 | + if (is_array($notification)) { |
|
389 | + delete_transient('action_scheduler_admin_notice'); |
|
390 | 390 | |
391 | - $action = $this->store->fetch_action( $notification['action_id'] ); |
|
391 | + $action = $this->store->fetch_action($notification['action_id']); |
|
392 | 392 | $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
393 | - if ( 1 == $notification['success'] ) { |
|
393 | + if (1 == $notification['success']) { |
|
394 | 394 | $class = 'updated'; |
395 | - switch ( $notification['row_action_type'] ) { |
|
395 | + switch ($notification['row_action_type']) { |
|
396 | 396 | case 'run' : |
397 | 397 | /* translators: %s: action HTML */ |
398 | - $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html ); |
|
398 | + $action_message_html = sprintf(__('Successfully executed action: %s', 'action-scheduler'), $action_hook_html); |
|
399 | 399 | break; |
400 | 400 | case 'cancel' : |
401 | 401 | /* translators: %s: action HTML */ |
402 | - $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html ); |
|
402 | + $action_message_html = sprintf(__('Successfully canceled action: %s', 'action-scheduler'), $action_hook_html); |
|
403 | 403 | break; |
404 | 404 | default : |
405 | 405 | /* translators: %s: action HTML */ |
406 | - $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html ); |
|
406 | + $action_message_html = sprintf(__('Successfully processed change for action: %s', 'action-scheduler'), $action_hook_html); |
|
407 | 407 | break; |
408 | 408 | } |
409 | 409 | } else { |
410 | 410 | $class = 'error'; |
411 | 411 | /* translators: 1: action HTML 2: action ID 3: error message */ |
412 | - $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'action-scheduler' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); |
|
412 | + $action_message_html = sprintf(__('Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'action-scheduler'), $action_hook_html, esc_html($notification['action_id']), esc_html($notification['error_message'])); |
|
413 | 413 | } |
414 | 414 | |
415 | - $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); |
|
415 | + $action_message_html = apply_filters('action_scheduler_admin_notice_html', $action_message_html, $action, $notification); |
|
416 | 416 | |
417 | 417 | $this->admin_notices[] = array( |
418 | 418 | 'class' => $class, |
@@ -430,8 +430,8 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @return string |
432 | 432 | */ |
433 | - public function column_schedule( $row ) { |
|
434 | - return $this->get_schedule_display_string( $row['schedule'] ); |
|
433 | + public function column_schedule($row) { |
|
434 | + return $this->get_schedule_display_string($row['schedule']); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -440,25 +440,25 @@ discard block |
||
440 | 440 | * @param ActionScheduler_Schedule $schedule |
441 | 441 | * @return string |
442 | 442 | */ |
443 | - protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
|
443 | + protected function get_schedule_display_string(ActionScheduler_Schedule $schedule) { |
|
444 | 444 | |
445 | 445 | $schedule_display_string = ''; |
446 | 446 | |
447 | - if ( ! $schedule->get_date() ) { |
|
447 | + if (!$schedule->get_date()) { |
|
448 | 448 | return '0000-00-00 00:00:00'; |
449 | 449 | } |
450 | 450 | |
451 | 451 | $next_timestamp = $schedule->get_date()->getTimestamp(); |
452 | 452 | |
453 | - $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); |
|
453 | + $schedule_display_string .= $schedule->get_date()->format('Y-m-d H:i:s O'); |
|
454 | 454 | $schedule_display_string .= '<br/>'; |
455 | 455 | |
456 | - if ( gmdate( 'U' ) > $next_timestamp ) { |
|
456 | + if (gmdate('U') > $next_timestamp) { |
|
457 | 457 | /* translators: %s: date interval */ |
458 | - $schedule_display_string .= sprintf( __( ' (%s ago)', 'action-scheduler' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); |
|
458 | + $schedule_display_string .= sprintf(__(' (%s ago)', 'action-scheduler'), self::human_interval(gmdate('U') - $next_timestamp)); |
|
459 | 459 | } else { |
460 | 460 | /* translators: %s: date interval */ |
461 | - $schedule_display_string .= sprintf( __( ' (%s)', 'action-scheduler' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); |
|
461 | + $schedule_display_string .= sprintf(__(' (%s)', 'action-scheduler'), self::human_interval($next_timestamp - gmdate('U'))); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | return $schedule_display_string; |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | * @param array $ids |
474 | 474 | * @param string $ids_sql Inherited and unused |
475 | 475 | */ |
476 | - protected function bulk_delete( array $ids, $ids_sql ) { |
|
477 | - foreach ( $ids as $id ) { |
|
478 | - $this->store->delete_action( $id ); |
|
476 | + protected function bulk_delete(array $ids, $ids_sql) { |
|
477 | + foreach ($ids as $id) { |
|
478 | + $this->store->delete_action($id); |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
@@ -485,8 +485,8 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @param int $action_id |
487 | 487 | */ |
488 | - protected function row_action_cancel( $action_id ) { |
|
489 | - $this->process_row_action( $action_id, 'cancel' ); |
|
488 | + protected function row_action_cancel($action_id) { |
|
489 | + $this->process_row_action($action_id, 'cancel'); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
@@ -495,27 +495,27 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @param int $action_id |
497 | 497 | */ |
498 | - protected function row_action_run( $action_id ) { |
|
499 | - $this->process_row_action( $action_id, 'run' ); |
|
498 | + protected function row_action_run($action_id) { |
|
499 | + $this->process_row_action($action_id, 'run'); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
503 | 503 | * Force the data store schema updates. |
504 | 504 | */ |
505 | 505 | protected function recreate_tables() { |
506 | - if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { |
|
506 | + if (is_a($this->store, 'ActionScheduler_HybridStore')) { |
|
507 | 507 | $store = $this->store; |
508 | 508 | } else { |
509 | 509 | $store = new ActionScheduler_HybridStore(); |
510 | 510 | } |
511 | - add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); |
|
511 | + add_action('action_scheduler/created_table', array($store, 'set_autoincrement'), 10, 2); |
|
512 | 512 | |
513 | 513 | $store_schema = new ActionScheduler_StoreSchema(); |
514 | 514 | $logger_schema = new ActionScheduler_LoggerSchema(); |
515 | - $store_schema->register_tables( true ); |
|
516 | - $logger_schema->register_tables( true ); |
|
515 | + $store_schema->register_tables(true); |
|
516 | + $logger_schema->register_tables(true); |
|
517 | 517 | |
518 | - remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); |
|
518 | + remove_action('action_scheduler/created_table', array($store, 'set_autoincrement'), 10); |
|
519 | 519 | } |
520 | 520 | /** |
521 | 521 | * Implements the logic behind processing an action once an action link is clicked on the list table. |
@@ -523,24 +523,24 @@ discard block |
||
523 | 523 | * @param int $action_id |
524 | 524 | * @param string $row_action_type The type of action to perform on the action. |
525 | 525 | */ |
526 | - protected function process_row_action( $action_id, $row_action_type ) { |
|
526 | + protected function process_row_action($action_id, $row_action_type) { |
|
527 | 527 | try { |
528 | - switch ( $row_action_type ) { |
|
528 | + switch ($row_action_type) { |
|
529 | 529 | case 'run' : |
530 | - $this->runner->process_action( $action_id, 'Admin List Table' ); |
|
530 | + $this->runner->process_action($action_id, 'Admin List Table'); |
|
531 | 531 | break; |
532 | 532 | case 'cancel' : |
533 | - $this->store->cancel_action( $action_id ); |
|
533 | + $this->store->cancel_action($action_id); |
|
534 | 534 | break; |
535 | 535 | } |
536 | 536 | $success = 1; |
537 | 537 | $error_message = ''; |
538 | - } catch ( Exception $e ) { |
|
538 | + } catch (Exception $e) { |
|
539 | 539 | $success = 0; |
540 | 540 | $error_message = $e->getMessage(); |
541 | 541 | } |
542 | 542 | |
543 | - set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
|
543 | + set_transient('action_scheduler_admin_notice', compact('action_id', 'success', 'error_message', 'row_action_type'), 30); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | public function prepare_items() { |
550 | 550 | $this->prepare_column_headers(); |
551 | 551 | |
552 | - $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); |
|
552 | + $per_page = $this->get_items_per_page($this->package . '_items_per_page', $this->items_per_page); |
|
553 | 553 | $query = array( |
554 | 554 | 'per_page' => $per_page, |
555 | 555 | 'offset' => $this->get_items_offset(), |
@@ -561,37 +561,37 @@ discard block |
||
561 | 561 | |
562 | 562 | $this->items = array(); |
563 | 563 | |
564 | - $total_items = $this->store->query_actions( $query, 'count' ); |
|
564 | + $total_items = $this->store->query_actions($query, 'count'); |
|
565 | 565 | |
566 | 566 | $status_labels = $this->store->get_status_labels(); |
567 | 567 | |
568 | - foreach ( $this->store->query_actions( $query ) as $action_id ) { |
|
568 | + foreach ($this->store->query_actions($query) as $action_id) { |
|
569 | 569 | try { |
570 | - $action = $this->store->fetch_action( $action_id ); |
|
571 | - } catch ( Exception $e ) { |
|
570 | + $action = $this->store->fetch_action($action_id); |
|
571 | + } catch (Exception $e) { |
|
572 | 572 | continue; |
573 | 573 | } |
574 | - if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { |
|
574 | + if (is_a($action, 'ActionScheduler_NullAction')) { |
|
575 | 575 | continue; |
576 | 576 | } |
577 | - $this->items[ $action_id ] = array( |
|
577 | + $this->items[$action_id] = array( |
|
578 | 578 | 'ID' => $action_id, |
579 | 579 | 'hook' => $action->get_hook(), |
580 | - 'status' => $status_labels[ $this->store->get_status( $action_id ) ], |
|
580 | + 'status' => $status_labels[$this->store->get_status($action_id)], |
|
581 | 581 | 'args' => $action->get_args(), |
582 | 582 | 'group' => $action->get_group(), |
583 | - 'log_entries' => $this->logger->get_logs( $action_id ), |
|
584 | - 'claim_id' => $this->store->get_claim_id( $action_id ), |
|
585 | - 'recurrence' => $this->get_recurrence( $action ), |
|
583 | + 'log_entries' => $this->logger->get_logs($action_id), |
|
584 | + 'claim_id' => $this->store->get_claim_id($action_id), |
|
585 | + 'recurrence' => $this->get_recurrence($action), |
|
586 | 586 | 'schedule' => $action->get_schedule(), |
587 | 587 | ); |
588 | 588 | } |
589 | 589 | |
590 | - $this->set_pagination_args( array( |
|
590 | + $this->set_pagination_args(array( |
|
591 | 591 | 'total_items' => $total_items, |
592 | 592 | 'per_page' => $per_page, |
593 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
594 | - ) ); |
|
593 | + 'total_pages' => ceil($total_items / $per_page), |
|
594 | + )); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -606,6 +606,6 @@ discard block |
||
606 | 606 | * Get the text to display in the search box on the list table. |
607 | 607 | */ |
608 | 608 | protected function get_search_box_button_text() { |
609 | - return __( 'Search hook, args and claim ID', 'action-scheduler' ); |
|
609 | + return __('Search hook, args and claim ID', 'action-scheduler'); |
|
610 | 610 | } |
611 | 611 | } |
@@ -17,103 +17,103 @@ |
||
17 | 17 | */ |
18 | 18 | class ProgressBar { |
19 | 19 | |
20 | - /** @var integer */ |
|
21 | - protected $total_ticks; |
|
22 | - |
|
23 | - /** @var integer */ |
|
24 | - protected $count; |
|
25 | - |
|
26 | - /** @var integer */ |
|
27 | - protected $interval; |
|
28 | - |
|
29 | - /** @var string */ |
|
30 | - protected $message; |
|
31 | - |
|
32 | - /** @var \cli\progress\Bar */ |
|
33 | - protected $progress_bar; |
|
34 | - |
|
35 | - /** |
|
36 | - * ProgressBar constructor. |
|
37 | - * |
|
38 | - * @param string $message Text to display before the progress bar. |
|
39 | - * @param integer $count Total number of ticks to be performed. |
|
40 | - * @param integer $interval Optional. The interval in milliseconds between updates. Default 100. |
|
41 | - * |
|
42 | - * @throws Exception When this is not run within WP CLI |
|
43 | - */ |
|
44 | - public function __construct( $message, $count, $interval = 100 ) { |
|
45 | - if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
46 | - /* translators: %s php class name */ |
|
47 | - throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) ); |
|
48 | - } |
|
49 | - |
|
50 | - $this->total_ticks = 0; |
|
51 | - $this->message = $message; |
|
52 | - $this->count = $count; |
|
53 | - $this->interval = $interval; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Increment the progress bar ticks. |
|
58 | - */ |
|
59 | - public function tick() { |
|
60 | - if ( null === $this->progress_bar ) { |
|
61 | - $this->setup_progress_bar(); |
|
62 | - } |
|
63 | - |
|
64 | - $this->progress_bar->tick(); |
|
65 | - $this->total_ticks++; |
|
66 | - |
|
67 | - do_action( 'action_scheduler/progress_tick', $this->total_ticks ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Get the progress bar tick count. |
|
72 | - * |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - public function current() { |
|
76 | - return $this->progress_bar ? $this->progress_bar->current() : 0; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Finish the current progress bar. |
|
81 | - */ |
|
82 | - public function finish() { |
|
83 | - if ( null !== $this->progress_bar ) { |
|
84 | - $this->progress_bar->finish(); |
|
85 | - } |
|
86 | - |
|
87 | - $this->progress_bar = null; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Set the message used when creating the progress bar. |
|
92 | - * |
|
93 | - * @param string $message The message to be used when the next progress bar is created. |
|
94 | - */ |
|
95 | - public function set_message( $message ) { |
|
96 | - $this->message = $message; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Set the count for a new progress bar. |
|
101 | - * |
|
102 | - * @param integer $count The total number of ticks expected to complete. |
|
103 | - */ |
|
104 | - public function set_count( $count ) { |
|
105 | - $this->count = $count; |
|
106 | - $this->finish(); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Set up the progress bar. |
|
111 | - */ |
|
112 | - protected function setup_progress_bar() { |
|
113 | - $this->progress_bar = \WP_CLI\Utils\make_progress_bar( |
|
114 | - $this->message, |
|
115 | - $this->count, |
|
116 | - $this->interval |
|
117 | - ); |
|
118 | - } |
|
20 | + /** @var integer */ |
|
21 | + protected $total_ticks; |
|
22 | + |
|
23 | + /** @var integer */ |
|
24 | + protected $count; |
|
25 | + |
|
26 | + /** @var integer */ |
|
27 | + protected $interval; |
|
28 | + |
|
29 | + /** @var string */ |
|
30 | + protected $message; |
|
31 | + |
|
32 | + /** @var \cli\progress\Bar */ |
|
33 | + protected $progress_bar; |
|
34 | + |
|
35 | + /** |
|
36 | + * ProgressBar constructor. |
|
37 | + * |
|
38 | + * @param string $message Text to display before the progress bar. |
|
39 | + * @param integer $count Total number of ticks to be performed. |
|
40 | + * @param integer $interval Optional. The interval in milliseconds between updates. Default 100. |
|
41 | + * |
|
42 | + * @throws Exception When this is not run within WP CLI |
|
43 | + */ |
|
44 | + public function __construct( $message, $count, $interval = 100 ) { |
|
45 | + if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
46 | + /* translators: %s php class name */ |
|
47 | + throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) ); |
|
48 | + } |
|
49 | + |
|
50 | + $this->total_ticks = 0; |
|
51 | + $this->message = $message; |
|
52 | + $this->count = $count; |
|
53 | + $this->interval = $interval; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Increment the progress bar ticks. |
|
58 | + */ |
|
59 | + public function tick() { |
|
60 | + if ( null === $this->progress_bar ) { |
|
61 | + $this->setup_progress_bar(); |
|
62 | + } |
|
63 | + |
|
64 | + $this->progress_bar->tick(); |
|
65 | + $this->total_ticks++; |
|
66 | + |
|
67 | + do_action( 'action_scheduler/progress_tick', $this->total_ticks ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Get the progress bar tick count. |
|
72 | + * |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + public function current() { |
|
76 | + return $this->progress_bar ? $this->progress_bar->current() : 0; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Finish the current progress bar. |
|
81 | + */ |
|
82 | + public function finish() { |
|
83 | + if ( null !== $this->progress_bar ) { |
|
84 | + $this->progress_bar->finish(); |
|
85 | + } |
|
86 | + |
|
87 | + $this->progress_bar = null; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Set the message used when creating the progress bar. |
|
92 | + * |
|
93 | + * @param string $message The message to be used when the next progress bar is created. |
|
94 | + */ |
|
95 | + public function set_message( $message ) { |
|
96 | + $this->message = $message; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Set the count for a new progress bar. |
|
101 | + * |
|
102 | + * @param integer $count The total number of ticks expected to complete. |
|
103 | + */ |
|
104 | + public function set_count( $count ) { |
|
105 | + $this->count = $count; |
|
106 | + $this->finish(); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Set up the progress bar. |
|
111 | + */ |
|
112 | + protected function setup_progress_bar() { |
|
113 | + $this->progress_bar = \WP_CLI\Utils\make_progress_bar( |
|
114 | + $this->message, |
|
115 | + $this->count, |
|
116 | + $this->interval |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @throws Exception When this is not run within WP CLI |
43 | 43 | */ |
44 | - public function __construct( $message, $count, $interval = 100 ) { |
|
45 | - if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
44 | + public function __construct($message, $count, $interval = 100) { |
|
45 | + if (!(defined('WP_CLI') && WP_CLI)) { |
|
46 | 46 | /* translators: %s php class name */ |
47 | - throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) ); |
|
47 | + throw new \Exception(sprintf(__('The %s class can only be run within WP CLI.', 'action-scheduler'), __CLASS__)); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $this->total_ticks = 0; |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | * Increment the progress bar ticks. |
58 | 58 | */ |
59 | 59 | public function tick() { |
60 | - if ( null === $this->progress_bar ) { |
|
60 | + if (null === $this->progress_bar) { |
|
61 | 61 | $this->setup_progress_bar(); |
62 | 62 | } |
63 | 63 | |
64 | 64 | $this->progress_bar->tick(); |
65 | 65 | $this->total_ticks++; |
66 | 66 | |
67 | - do_action( 'action_scheduler/progress_tick', $this->total_ticks ); |
|
67 | + do_action('action_scheduler/progress_tick', $this->total_ticks); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * Finish the current progress bar. |
81 | 81 | */ |
82 | 82 | public function finish() { |
83 | - if ( null !== $this->progress_bar ) { |
|
83 | + if (null !== $this->progress_bar) { |
|
84 | 84 | $this->progress_bar->finish(); |
85 | 85 | } |
86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @param string $message The message to be used when the next progress bar is created. |
94 | 94 | */ |
95 | - public function set_message( $message ) { |
|
95 | + public function set_message($message) { |
|
96 | 96 | $this->message = $message; |
97 | 97 | } |
98 | 98 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @param integer $count The total number of ticks expected to complete. |
103 | 103 | */ |
104 | - public function set_count( $count ) { |
|
104 | + public function set_count($count) { |
|
105 | 105 | $this->count = $count; |
106 | 106 | $this->finish(); |
107 | 107 | } |