@@ -4,7 +4,7 @@ |
||
4 | 4 | * Class ActionScheduler_NullLogEntry |
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullLogEntry extends ActionScheduler_LogEntry { |
7 | - public function __construct( $action_id = '', $message = '' ) { |
|
7 | + public function __construct($action_id = '', $message = '') { |
|
8 | 8 | // nothing to see here |
9 | 9 | } |
10 | 10 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | * Class ActionScheduler_NullLogEntry |
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullLogEntry extends ActionScheduler_LogEntry { |
7 | - public function __construct( $action_id = '', $message = '' ) { |
|
8 | - // nothing to see here |
|
9 | - } |
|
7 | + public function __construct( $action_id = '', $message = '' ) { |
|
8 | + // nothing to see here |
|
9 | + } |
|
10 | 10 | } |
11 | 11 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param DateTime $date The date & time to run the action. |
24 | 24 | */ |
25 | - public function __construct( DateTime $date ) { |
|
25 | + public function __construct(DateTime $date) { |
|
26 | 26 | $this->scheduled_date = $date; |
27 | 27 | } |
28 | 28 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param DateTime $after |
40 | 40 | * @return DateTime |
41 | 41 | */ |
42 | - abstract protected function calculate_next( DateTime $after ); |
|
42 | + abstract protected function calculate_next(DateTime $after); |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Get the next date & time when this schedule should run after a given date & time. |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | * @param DateTime $after |
48 | 48 | * @return DateTime|null |
49 | 49 | */ |
50 | - public function get_next( DateTime $after ) { |
|
50 | + public function get_next(DateTime $after) { |
|
51 | 51 | $after = clone $after; |
52 | - if ( $after > $this->scheduled_date ) { |
|
53 | - $after = $this->calculate_next( $after ); |
|
52 | + if ($after > $this->scheduled_date) { |
|
53 | + $after = $this->calculate_next($after); |
|
54 | 54 | return $after; |
55 | 55 | } |
56 | 56 | return clone $this->scheduled_date; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | public function __wakeup() { |
80 | - $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp ); |
|
81 | - unset( $this->scheduled_timestamp ); |
|
80 | + $this->scheduled_date = as_get_datetime_object($this->scheduled_timestamp); |
|
81 | + unset($this->scheduled_timestamp); |
|
82 | 82 | } |
83 | 83 | } |
@@ -5,80 +5,80 @@ |
||
5 | 5 | */ |
6 | 6 | abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedule_Deprecated { |
7 | 7 | |
8 | - /** |
|
9 | - * The date & time the schedule is set to run. |
|
10 | - * |
|
11 | - * @var DateTime |
|
12 | - */ |
|
13 | - private $scheduled_date = null; |
|
8 | + /** |
|
9 | + * The date & time the schedule is set to run. |
|
10 | + * |
|
11 | + * @var DateTime |
|
12 | + */ |
|
13 | + private $scheduled_date = null; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Timestamp equivalent of @see $this->scheduled_date |
|
17 | - * |
|
18 | - * @var int |
|
19 | - */ |
|
20 | - protected $scheduled_timestamp = null; |
|
15 | + /** |
|
16 | + * Timestamp equivalent of @see $this->scheduled_date |
|
17 | + * |
|
18 | + * @var int |
|
19 | + */ |
|
20 | + protected $scheduled_timestamp = null; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param DateTime $date The date & time to run the action. |
|
24 | - */ |
|
25 | - public function __construct( DateTime $date ) { |
|
26 | - $this->scheduled_date = $date; |
|
27 | - } |
|
22 | + /** |
|
23 | + * @param DateTime $date The date & time to run the action. |
|
24 | + */ |
|
25 | + public function __construct( DateTime $date ) { |
|
26 | + $this->scheduled_date = $date; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Check if a schedule should recur. |
|
31 | - * |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - abstract public function is_recurring(); |
|
29 | + /** |
|
30 | + * Check if a schedule should recur. |
|
31 | + * |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + abstract public function is_recurring(); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Calculate when the next instance of this schedule would run based on a given date & time. |
|
38 | - * |
|
39 | - * @param DateTime $after |
|
40 | - * @return DateTime |
|
41 | - */ |
|
42 | - abstract protected function calculate_next( DateTime $after ); |
|
36 | + /** |
|
37 | + * Calculate when the next instance of this schedule would run based on a given date & time. |
|
38 | + * |
|
39 | + * @param DateTime $after |
|
40 | + * @return DateTime |
|
41 | + */ |
|
42 | + abstract protected function calculate_next( DateTime $after ); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Get the next date & time when this schedule should run after a given date & time. |
|
46 | - * |
|
47 | - * @param DateTime $after |
|
48 | - * @return DateTime|null |
|
49 | - */ |
|
50 | - public function get_next( DateTime $after ) { |
|
51 | - $after = clone $after; |
|
52 | - if ( $after > $this->scheduled_date ) { |
|
53 | - $after = $this->calculate_next( $after ); |
|
54 | - return $after; |
|
55 | - } |
|
56 | - return clone $this->scheduled_date; |
|
57 | - } |
|
44 | + /** |
|
45 | + * Get the next date & time when this schedule should run after a given date & time. |
|
46 | + * |
|
47 | + * @param DateTime $after |
|
48 | + * @return DateTime|null |
|
49 | + */ |
|
50 | + public function get_next( DateTime $after ) { |
|
51 | + $after = clone $after; |
|
52 | + if ( $after > $this->scheduled_date ) { |
|
53 | + $after = $this->calculate_next( $after ); |
|
54 | + return $after; |
|
55 | + } |
|
56 | + return clone $this->scheduled_date; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Get the date & time the schedule is set to run. |
|
61 | - * |
|
62 | - * @return DateTime|null |
|
63 | - */ |
|
64 | - public function get_date() { |
|
65 | - return $this->scheduled_date; |
|
66 | - } |
|
59 | + /** |
|
60 | + * Get the date & time the schedule is set to run. |
|
61 | + * |
|
62 | + * @return DateTime|null |
|
63 | + */ |
|
64 | + public function get_date() { |
|
65 | + return $this->scheduled_date; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * For PHP 5.2 compat, since DateTime objects can't be serialized |
|
70 | - * |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function __sleep() { |
|
74 | - $this->scheduled_timestamp = $this->scheduled_date->getTimestamp(); |
|
75 | - return array( |
|
76 | - 'scheduled_timestamp', |
|
77 | - ); |
|
78 | - } |
|
68 | + /** |
|
69 | + * For PHP 5.2 compat, since DateTime objects can't be serialized |
|
70 | + * |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function __sleep() { |
|
74 | + $this->scheduled_timestamp = $this->scheduled_date->getTimestamp(); |
|
75 | + return array( |
|
76 | + 'scheduled_timestamp', |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | - public function __wakeup() { |
|
81 | - $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp ); |
|
82 | - unset( $this->scheduled_timestamp ); |
|
83 | - } |
|
80 | + public function __wakeup() { |
|
81 | + $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp ); |
|
82 | + unset( $this->scheduled_timestamp ); |
|
83 | + } |
|
84 | 84 | } |
@@ -15,62 +15,62 @@ |
||
15 | 15 | * @group migration |
16 | 16 | */ |
17 | 17 | class Controller_Test extends ActionScheduler_UnitTestCase { |
18 | - /** |
|
19 | - * Test to ensure the Migration Controller will schedule the migration. |
|
20 | - */ |
|
21 | - public function test_schedules_migration() { |
|
22 | - as_unschedule_action( Scheduler::HOOK ); |
|
23 | - Controller::instance()->schedule_migration(); |
|
18 | + /** |
|
19 | + * Test to ensure the Migration Controller will schedule the migration. |
|
20 | + */ |
|
21 | + public function test_schedules_migration() { |
|
22 | + as_unschedule_action( Scheduler::HOOK ); |
|
23 | + Controller::instance()->schedule_migration(); |
|
24 | 24 | |
25 | - $this->assertTrue( |
|
26 | - as_next_scheduled_action( Scheduler::HOOK ) > 0, |
|
27 | - 'Confirm that the Migration Controller scheduled the migration.' |
|
28 | - ); |
|
25 | + $this->assertTrue( |
|
26 | + as_next_scheduled_action( Scheduler::HOOK ) > 0, |
|
27 | + 'Confirm that the Migration Controller scheduled the migration.' |
|
28 | + ); |
|
29 | 29 | |
30 | - as_unschedule_action( Scheduler::HOOK ); |
|
31 | - } |
|
30 | + as_unschedule_action( Scheduler::HOOK ); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Test to ensure that if an essential table is missing, the Migration |
|
35 | - * Controller will not schedule a migration. |
|
36 | - * |
|
37 | - * @see https://github.com/woocommerce/action-scheduler/issues/653 |
|
38 | - */ |
|
39 | - public function test_migration_not_scheduled_if_tables_are_missing() { |
|
40 | - as_unschedule_action( Scheduler::HOOK ); |
|
41 | - $this->rename_claims_table(); |
|
42 | - Controller::instance()->schedule_migration(); |
|
33 | + /** |
|
34 | + * Test to ensure that if an essential table is missing, the Migration |
|
35 | + * Controller will not schedule a migration. |
|
36 | + * |
|
37 | + * @see https://github.com/woocommerce/action-scheduler/issues/653 |
|
38 | + */ |
|
39 | + public function test_migration_not_scheduled_if_tables_are_missing() { |
|
40 | + as_unschedule_action( Scheduler::HOOK ); |
|
41 | + $this->rename_claims_table(); |
|
42 | + Controller::instance()->schedule_migration(); |
|
43 | 43 | |
44 | - $this->assertFalse( |
|
45 | - as_next_scheduled_action( Scheduler::HOOK ), |
|
46 | - 'When required tables are missing, the migration will not be scheduled.' |
|
47 | - ); |
|
44 | + $this->assertFalse( |
|
45 | + as_next_scheduled_action( Scheduler::HOOK ), |
|
46 | + 'When required tables are missing, the migration will not be scheduled.' |
|
47 | + ); |
|
48 | 48 | |
49 | - $this->restore_claims_table_name(); |
|
50 | - } |
|
49 | + $this->restore_claims_table_name(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Rename the claims table, so that it cannot be used by the library. |
|
54 | - */ |
|
55 | - private function rename_claims_table() { |
|
56 | - global $wpdb; |
|
57 | - $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
58 | - $modified_table_name = $normal_table_name . 'x'; |
|
52 | + /** |
|
53 | + * Rename the claims table, so that it cannot be used by the library. |
|
54 | + */ |
|
55 | + private function rename_claims_table() { |
|
56 | + global $wpdb; |
|
57 | + $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
58 | + $modified_table_name = $normal_table_name . 'x'; |
|
59 | 59 | |
60 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
61 | - $wpdb->query( "RENAME TABLE {$normal_table_name} TO {$modified_table_name}" ); |
|
62 | - } |
|
60 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
61 | + $wpdb->query( "RENAME TABLE {$normal_table_name} TO {$modified_table_name}" ); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Restore the expected name of the claims table, so that it can be used by the library |
|
66 | - * and any further tests. |
|
67 | - */ |
|
68 | - private function restore_claims_table_name() { |
|
69 | - global $wpdb; |
|
70 | - $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
71 | - $modified_table_name = $normal_table_name . 'x'; |
|
64 | + /** |
|
65 | + * Restore the expected name of the claims table, so that it can be used by the library |
|
66 | + * and any further tests. |
|
67 | + */ |
|
68 | + private function restore_claims_table_name() { |
|
69 | + global $wpdb; |
|
70 | + $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
71 | + $modified_table_name = $normal_table_name . 'x'; |
|
72 | 72 | |
73 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
74 | - $wpdb->query( "RENAME TABLE {$modified_table_name} TO {$normal_table_name}" ); |
|
75 | - } |
|
73 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
74 | + $wpdb->query( "RENAME TABLE {$modified_table_name} TO {$normal_table_name}" ); |
|
75 | + } |
|
76 | 76 | } |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | * Test to ensure the Migration Controller will schedule the migration. |
20 | 20 | */ |
21 | 21 | public function test_schedules_migration() { |
22 | - as_unschedule_action( Scheduler::HOOK ); |
|
22 | + as_unschedule_action(Scheduler::HOOK); |
|
23 | 23 | Controller::instance()->schedule_migration(); |
24 | 24 | |
25 | 25 | $this->assertTrue( |
26 | - as_next_scheduled_action( Scheduler::HOOK ) > 0, |
|
26 | + as_next_scheduled_action(Scheduler::HOOK) > 0, |
|
27 | 27 | 'Confirm that the Migration Controller scheduled the migration.' |
28 | 28 | ); |
29 | 29 | |
30 | - as_unschedule_action( Scheduler::HOOK ); |
|
30 | + as_unschedule_action(Scheduler::HOOK); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @see https://github.com/woocommerce/action-scheduler/issues/653 |
38 | 38 | */ |
39 | 39 | public function test_migration_not_scheduled_if_tables_are_missing() { |
40 | - as_unschedule_action( Scheduler::HOOK ); |
|
40 | + as_unschedule_action(Scheduler::HOOK); |
|
41 | 41 | $this->rename_claims_table(); |
42 | 42 | Controller::instance()->schedule_migration(); |
43 | 43 | |
44 | 44 | $this->assertFalse( |
45 | - as_next_scheduled_action( Scheduler::HOOK ), |
|
45 | + as_next_scheduled_action(Scheduler::HOOK), |
|
46 | 46 | 'When required tables are missing, the migration will not be scheduled.' |
47 | 47 | ); |
48 | 48 | |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | */ |
55 | 55 | private function rename_claims_table() { |
56 | 56 | global $wpdb; |
57 | - $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
58 | - $modified_table_name = $normal_table_name . 'x'; |
|
57 | + $normal_table_name = $wpdb->prefix.Schema::CLAIMS_TABLE; |
|
58 | + $modified_table_name = $normal_table_name.'x'; |
|
59 | 59 | |
60 | 60 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
61 | - $wpdb->query( "RENAME TABLE {$normal_table_name} TO {$modified_table_name}" ); |
|
61 | + $wpdb->query("RENAME TABLE {$normal_table_name} TO {$modified_table_name}"); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function restore_claims_table_name() { |
69 | 69 | global $wpdb; |
70 | - $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
71 | - $modified_table_name = $normal_table_name . 'x'; |
|
70 | + $normal_table_name = $wpdb->prefix.Schema::CLAIMS_TABLE; |
|
71 | + $modified_table_name = $normal_table_name.'x'; |
|
72 | 72 | |
73 | 73 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
74 | - $wpdb->query( "RENAME TABLE {$modified_table_name} TO {$normal_table_name}" ); |
|
74 | + $wpdb->query("RENAME TABLE {$modified_table_name} TO {$normal_table_name}"); |
|
75 | 75 | } |
76 | 76 | } |
@@ -5,41 +5,41 @@ |
||
5 | 5 | * @package test_cases\lock |
6 | 6 | */ |
7 | 7 | class ActionScheduler_OptionLock_Test extends ActionScheduler_UnitTestCase { |
8 | - public function test_instance() { |
|
9 | - $lock = ActionScheduler::lock(); |
|
10 | - $this->assertInstanceOf( 'ActionScheduler_Lock', $lock ); |
|
11 | - $this->assertInstanceOf( 'ActionScheduler_OptionLock', $lock ); |
|
12 | - } |
|
8 | + public function test_instance() { |
|
9 | + $lock = ActionScheduler::lock(); |
|
10 | + $this->assertInstanceOf( 'ActionScheduler_Lock', $lock ); |
|
11 | + $this->assertInstanceOf( 'ActionScheduler_OptionLock', $lock ); |
|
12 | + } |
|
13 | 13 | |
14 | - public function test_is_locked() { |
|
15 | - $lock = ActionScheduler::lock(); |
|
16 | - $lock_type = md5( rand() ); |
|
14 | + public function test_is_locked() { |
|
15 | + $lock = ActionScheduler::lock(); |
|
16 | + $lock_type = md5( rand() ); |
|
17 | 17 | |
18 | - $this->assertFalse( $lock->is_locked( $lock_type ) ); |
|
18 | + $this->assertFalse( $lock->is_locked( $lock_type ) ); |
|
19 | 19 | |
20 | - $lock->set( $lock_type ); |
|
21 | - $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
22 | - } |
|
20 | + $lock->set( $lock_type ); |
|
21 | + $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
22 | + } |
|
23 | 23 | |
24 | - public function test_set() { |
|
25 | - $lock = ActionScheduler::lock(); |
|
26 | - $lock_type = md5( rand() ); |
|
24 | + public function test_set() { |
|
25 | + $lock = ActionScheduler::lock(); |
|
26 | + $lock_type = md5( rand() ); |
|
27 | 27 | |
28 | - $lock->set( $lock_type ); |
|
29 | - $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
30 | - } |
|
28 | + $lock->set( $lock_type ); |
|
29 | + $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
30 | + } |
|
31 | 31 | |
32 | - public function test_get_expiration() { |
|
33 | - $lock = ActionScheduler::lock(); |
|
34 | - $lock_type = md5( rand() ); |
|
32 | + public function test_get_expiration() { |
|
33 | + $lock = ActionScheduler::lock(); |
|
34 | + $lock_type = md5( rand() ); |
|
35 | 35 | |
36 | - $lock->set( $lock_type ); |
|
36 | + $lock->set( $lock_type ); |
|
37 | 37 | |
38 | - $expiration = $lock->get_expiration( $lock_type ); |
|
39 | - $current_time = time(); |
|
38 | + $expiration = $lock->get_expiration( $lock_type ); |
|
39 | + $current_time = time(); |
|
40 | 40 | |
41 | - $this->assertGreaterThanOrEqual( 0, $expiration ); |
|
42 | - $this->assertGreaterThan( $current_time, $expiration ); |
|
43 | - $this->assertLessThan( $current_time + MINUTE_IN_SECONDS + 1, $expiration ); |
|
44 | - } |
|
41 | + $this->assertGreaterThanOrEqual( 0, $expiration ); |
|
42 | + $this->assertGreaterThan( $current_time, $expiration ); |
|
43 | + $this->assertLessThan( $current_time + MINUTE_IN_SECONDS + 1, $expiration ); |
|
44 | + } |
|
45 | 45 | } |
@@ -7,39 +7,39 @@ |
||
7 | 7 | class ActionScheduler_OptionLock_Test extends ActionScheduler_UnitTestCase { |
8 | 8 | public function test_instance() { |
9 | 9 | $lock = ActionScheduler::lock(); |
10 | - $this->assertInstanceOf( 'ActionScheduler_Lock', $lock ); |
|
11 | - $this->assertInstanceOf( 'ActionScheduler_OptionLock', $lock ); |
|
10 | + $this->assertInstanceOf('ActionScheduler_Lock', $lock); |
|
11 | + $this->assertInstanceOf('ActionScheduler_OptionLock', $lock); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function test_is_locked() { |
15 | 15 | $lock = ActionScheduler::lock(); |
16 | - $lock_type = md5( rand() ); |
|
16 | + $lock_type = md5(rand()); |
|
17 | 17 | |
18 | - $this->assertFalse( $lock->is_locked( $lock_type ) ); |
|
18 | + $this->assertFalse($lock->is_locked($lock_type)); |
|
19 | 19 | |
20 | - $lock->set( $lock_type ); |
|
21 | - $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
20 | + $lock->set($lock_type); |
|
21 | + $this->assertTrue($lock->is_locked($lock_type)); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function test_set() { |
25 | 25 | $lock = ActionScheduler::lock(); |
26 | - $lock_type = md5( rand() ); |
|
26 | + $lock_type = md5(rand()); |
|
27 | 27 | |
28 | - $lock->set( $lock_type ); |
|
29 | - $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
28 | + $lock->set($lock_type); |
|
29 | + $this->assertTrue($lock->is_locked($lock_type)); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function test_get_expiration() { |
33 | 33 | $lock = ActionScheduler::lock(); |
34 | - $lock_type = md5( rand() ); |
|
34 | + $lock_type = md5(rand()); |
|
35 | 35 | |
36 | - $lock->set( $lock_type ); |
|
36 | + $lock->set($lock_type); |
|
37 | 37 | |
38 | - $expiration = $lock->get_expiration( $lock_type ); |
|
38 | + $expiration = $lock->get_expiration($lock_type); |
|
39 | 39 | $current_time = time(); |
40 | 40 | |
41 | - $this->assertGreaterThanOrEqual( 0, $expiration ); |
|
42 | - $this->assertGreaterThan( $current_time, $expiration ); |
|
43 | - $this->assertLessThan( $current_time + MINUTE_IN_SECONDS + 1, $expiration ); |
|
41 | + $this->assertGreaterThanOrEqual(0, $expiration); |
|
42 | + $this->assertGreaterThan($current_time, $expiration); |
|
43 | + $this->assertLessThan($current_time + MINUTE_IN_SECONDS + 1, $expiration); |
|
44 | 44 | } |
45 | 45 | } |
@@ -18,99 +18,99 @@ |
||
18 | 18 | */ |
19 | 19 | class Sync_Background_Process { |
20 | 20 | |
21 | - const STATE_STARTED = 'started'; |
|
22 | - const STATE_STOPPED = 'stopped'; |
|
23 | - |
|
24 | - protected $action = 'wl_dataset__sync'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var Sync_Service |
|
28 | - */ |
|
29 | - private $sync_service; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var Sync_Object_Adapter_Factory |
|
33 | - */ |
|
34 | - private $sync_object_adapter_factory; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var \Wordlift_Log_Service |
|
38 | - */ |
|
39 | - private $log; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var Sync_Background_Process_State |
|
43 | - */ |
|
44 | - private $state; |
|
45 | - |
|
46 | - /** |
|
47 | - * Sync_Background_Process constructor. |
|
48 | - * |
|
49 | - * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
50 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
51 | - */ |
|
52 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
53 | - // parent::__construct(); |
|
54 | - |
|
55 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
56 | - |
|
57 | - $this->sync_service = $sync_service; |
|
58 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
59 | - |
|
60 | - // Set the current state. |
|
61 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
62 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
63 | - } else { |
|
64 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Transition to the started state. |
|
70 | - */ |
|
71 | - public function start() { |
|
72 | - $this->state->leave(); |
|
73 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
74 | - $this->state->enter(); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Transition to the stopped state. |
|
79 | - */ |
|
80 | - public function stop() { |
|
81 | - $this->state->leave(); |
|
82 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
83 | - $this->state->enter(); |
|
84 | - } |
|
85 | - |
|
86 | - public function resume() { |
|
87 | - $this->state->resume(); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get the current state. |
|
92 | - * |
|
93 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
94 | - */ |
|
95 | - public function get_state() { |
|
96 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Persist the current state. |
|
101 | - * |
|
102 | - * @param string $value |
|
103 | - * |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - public function set_state( $value ) { |
|
107 | - return null === $value |
|
108 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
109 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
110 | - } |
|
111 | - |
|
112 | - public function get_info() { |
|
113 | - return $this->state->get_info(); |
|
114 | - } |
|
21 | + const STATE_STARTED = 'started'; |
|
22 | + const STATE_STOPPED = 'stopped'; |
|
23 | + |
|
24 | + protected $action = 'wl_dataset__sync'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var Sync_Service |
|
28 | + */ |
|
29 | + private $sync_service; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var Sync_Object_Adapter_Factory |
|
33 | + */ |
|
34 | + private $sync_object_adapter_factory; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var \Wordlift_Log_Service |
|
38 | + */ |
|
39 | + private $log; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var Sync_Background_Process_State |
|
43 | + */ |
|
44 | + private $state; |
|
45 | + |
|
46 | + /** |
|
47 | + * Sync_Background_Process constructor. |
|
48 | + * |
|
49 | + * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
50 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
51 | + */ |
|
52 | + public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
53 | + // parent::__construct(); |
|
54 | + |
|
55 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
56 | + |
|
57 | + $this->sync_service = $sync_service; |
|
58 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
59 | + |
|
60 | + // Set the current state. |
|
61 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
62 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
63 | + } else { |
|
64 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Transition to the started state. |
|
70 | + */ |
|
71 | + public function start() { |
|
72 | + $this->state->leave(); |
|
73 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
74 | + $this->state->enter(); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Transition to the stopped state. |
|
79 | + */ |
|
80 | + public function stop() { |
|
81 | + $this->state->leave(); |
|
82 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
83 | + $this->state->enter(); |
|
84 | + } |
|
85 | + |
|
86 | + public function resume() { |
|
87 | + $this->state->resume(); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get the current state. |
|
92 | + * |
|
93 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
94 | + */ |
|
95 | + public function get_state() { |
|
96 | + return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Persist the current state. |
|
101 | + * |
|
102 | + * @param string $value |
|
103 | + * |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + public function set_state( $value ) { |
|
107 | + return null === $value |
|
108 | + ? delete_option( '_wl_sync_background_process_state' ) |
|
109 | + : update_option( '_wl_sync_background_process_state', $value, true ); |
|
110 | + } |
|
111 | + |
|
112 | + public function get_info() { |
|
113 | + return $this->state->get_info(); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -49,19 +49,19 @@ discard block |
||
49 | 49 | * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
50 | 50 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
51 | 51 | */ |
52 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
52 | + public function __construct($sync_service, $sync_object_adapter_factory) { |
|
53 | 53 | // parent::__construct(); |
54 | 54 | |
55 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
55 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
56 | 56 | |
57 | 57 | $this->sync_service = $sync_service; |
58 | 58 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
59 | 59 | |
60 | 60 | // Set the current state. |
61 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
62 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
61 | + if (self::STATE_STARTED === $this->get_state()) { |
|
62 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
63 | 63 | } else { |
64 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
64 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function start() { |
72 | 72 | $this->state->leave(); |
73 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
73 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
74 | 74 | $this->state->enter(); |
75 | 75 | } |
76 | 76 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function stop() { |
81 | 81 | $this->state->leave(); |
82 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
82 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
83 | 83 | $this->state->enter(); |
84 | 84 | } |
85 | 85 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
94 | 94 | */ |
95 | 95 | public function get_state() { |
96 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
96 | + return get_option('_wl_sync_background_process_state', self::STATE_STOPPED); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return bool |
105 | 105 | */ |
106 | - public function set_state( $value ) { |
|
106 | + public function set_state($value) { |
|
107 | 107 | return null === $value |
108 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
109 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
108 | + ? delete_option('_wl_sync_background_process_state') |
|
109 | + : update_option('_wl_sync_background_process_state', $value, true); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | public function get_info() { |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | interface Sync_Background_Process_State { |
6 | 6 | |
7 | - public function enter(); |
|
8 | - |
|
9 | - public function leave(); |
|
10 | - |
|
11 | - /** |
|
12 | - * Task |
|
13 | - * |
|
14 | - * Override this method to perform any actions required on each |
|
15 | - * queue item. Return the modified item for further processing |
|
16 | - * in the next pass through. Or, return false to remove the |
|
17 | - * item from the queue. |
|
18 | - * |
|
19 | - * @return mixed |
|
20 | - */ |
|
21 | - public function task(); |
|
22 | - |
|
23 | - public function get_info(); |
|
24 | - |
|
25 | - /** |
|
26 | - * Try to resume an interrupted task. |
|
27 | - */ |
|
28 | - public function resume(); |
|
7 | + public function enter(); |
|
8 | + |
|
9 | + public function leave(); |
|
10 | + |
|
11 | + /** |
|
12 | + * Task |
|
13 | + * |
|
14 | + * Override this method to perform any actions required on each |
|
15 | + * queue item. Return the modified item for further processing |
|
16 | + * in the next pass through. Or, return false to remove the |
|
17 | + * item from the queue. |
|
18 | + * |
|
19 | + * @return mixed |
|
20 | + */ |
|
21 | + public function task(); |
|
22 | + |
|
23 | + public function get_info(); |
|
24 | + |
|
25 | + /** |
|
26 | + * Try to resume an interrupted task. |
|
27 | + */ |
|
28 | + public function resume(); |
|
29 | 29 | |
30 | 30 | } |
@@ -4,28 +4,28 @@ |
||
4 | 4 | |
5 | 5 | class Sync_Background_Process_Stopped_State extends Abstract_Sync_Background_Process_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Sync_Background_Process |
|
9 | - */ |
|
10 | - private $context; |
|
7 | + /** |
|
8 | + * @var Sync_Background_Process |
|
9 | + */ |
|
10 | + private $context; |
|
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( Sync_Background_Process::STATE_STOPPED ); |
|
12 | + public function __construct( $context ) { |
|
13 | + parent::__construct( Sync_Background_Process::STATE_STOPPED ); |
|
14 | 14 | |
15 | - $this->context = $context; |
|
16 | - } |
|
15 | + $this->context = $context; |
|
16 | + } |
|
17 | 17 | |
18 | - public function enter() { |
|
19 | - $this->context->set_state( Sync_Background_Process::STATE_STOPPED ); |
|
20 | - } |
|
18 | + public function enter() { |
|
19 | + $this->context->set_state( Sync_Background_Process::STATE_STOPPED ); |
|
20 | + } |
|
21 | 21 | |
22 | - public function leave() { |
|
23 | - $this->context->set_state( null ); |
|
24 | - } |
|
22 | + public function leave() { |
|
23 | + $this->context->set_state( null ); |
|
24 | + } |
|
25 | 25 | |
26 | - public function task() { |
|
27 | - as_unschedule_action( 'wl_sync_data_task' ); |
|
28 | - return false; |
|
29 | - } |
|
26 | + public function task() { |
|
27 | + as_unschedule_action( 'wl_sync_data_task' ); |
|
28 | + return false; |
|
29 | + } |
|
30 | 30 | |
31 | 31 | } |
@@ -9,22 +9,22 @@ |
||
9 | 9 | */ |
10 | 10 | private $context; |
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( Sync_Background_Process::STATE_STOPPED ); |
|
12 | + public function __construct($context) { |
|
13 | + parent::__construct(Sync_Background_Process::STATE_STOPPED); |
|
14 | 14 | |
15 | 15 | $this->context = $context; |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function enter() { |
19 | - $this->context->set_state( Sync_Background_Process::STATE_STOPPED ); |
|
19 | + $this->context->set_state(Sync_Background_Process::STATE_STOPPED); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function leave() { |
23 | - $this->context->set_state( null ); |
|
23 | + $this->context->set_state(null); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function task() { |
27 | - as_unschedule_action( 'wl_sync_data_task' ); |
|
27 | + as_unschedule_action('wl_sync_data_task'); |
|
28 | 28 | return false; |
29 | 29 | } |
30 | 30 |
@@ -11,142 +11,142 @@ |
||
11 | 11 | |
12 | 12 | class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State { |
13 | 13 | |
14 | - /** |
|
15 | - * @var Sync_Background_Process |
|
16 | - */ |
|
17 | - private $context; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var Sync_Service |
|
21 | - */ |
|
22 | - private $sync_service; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Sync_Background_Process_Stage[] |
|
26 | - */ |
|
27 | - private $stages; |
|
28 | - |
|
29 | - private $batch_size = 5; |
|
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
33 | - private $reset; |
|
34 | - |
|
35 | - /** |
|
36 | - * Sync_Background_Process_Started_State constructor. |
|
37 | - * |
|
38 | - * @param Sync_Background_Process $context |
|
39 | - * @param Sync_Service $sync_service |
|
40 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
41 | - * @param bool $reset Whether to reset the counters |
|
42 | - */ |
|
43 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
44 | - public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
45 | - parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
46 | - |
|
47 | - $this->context = $context; |
|
48 | - $this->sync_service = $sync_service; |
|
49 | - |
|
50 | - $this->stages = array( |
|
51 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
52 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
53 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
54 | - ); |
|
55 | - |
|
56 | - as_enqueue_async_action( 'wl_sync_data_task' ); |
|
57 | - add_action( 'wl_sync_data_task', array( $this, 'task' ), 10, 0 ); |
|
58 | - } |
|
59 | - |
|
60 | - public function enter() { |
|
61 | - // Delete the KG contents. |
|
62 | - $this->sync_service->delete_all(); |
|
63 | - |
|
64 | - // Clear caches. |
|
65 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
66 | - |
|
67 | - $counts = array_map( |
|
68 | - function ( $item ) { |
|
69 | - return $item->count(); |
|
70 | - }, |
|
71 | - $this->stages |
|
72 | - ); |
|
73 | - |
|
74 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
75 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
76 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
77 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
78 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
79 | - |
|
80 | - $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
81 | - |
|
82 | - $this->resume(); |
|
83 | - } |
|
84 | - |
|
85 | - public function resume() { |
|
86 | - // TODO : Resume Functionality. |
|
87 | - // $this->context->push_to_queue( true ); |
|
88 | - // $this->context->save()->dispatch(); |
|
89 | - } |
|
90 | - |
|
91 | - public function leave() { |
|
92 | - $this->context->set_state( null ); |
|
93 | - } |
|
94 | - |
|
95 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
96 | - public function task() { |
|
97 | - |
|
98 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
99 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
100 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
101 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
102 | - |
|
103 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
104 | - try { |
|
105 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
106 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
107 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
108 | - } catch ( \Exception $e ) { |
|
109 | - // ignored. |
|
110 | - } |
|
111 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
112 | - |
|
113 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
114 | - |
|
115 | - // Increase the offset. |
|
116 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
117 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
118 | - |
|
119 | - return true; |
|
120 | - } |
|
121 | - |
|
122 | - // Increase the stage. |
|
123 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
124 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
125 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
126 | - |
|
127 | - return true; |
|
128 | - } |
|
129 | - |
|
130 | - // Stop processing. |
|
131 | - $this->context->stop(); |
|
132 | - |
|
133 | - return false; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Hook to provide a request to update the status on the server. |
|
138 | - * |
|
139 | - * @param array $args |
|
140 | - * |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function api_service__request( $args ) { |
|
144 | - |
|
145 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
146 | - |
|
147 | - $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
148 | - |
|
149 | - return $args; |
|
150 | - } |
|
14 | + /** |
|
15 | + * @var Sync_Background_Process |
|
16 | + */ |
|
17 | + private $context; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var Sync_Service |
|
21 | + */ |
|
22 | + private $sync_service; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Sync_Background_Process_Stage[] |
|
26 | + */ |
|
27 | + private $stages; |
|
28 | + |
|
29 | + private $batch_size = 5; |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | + private $reset; |
|
34 | + |
|
35 | + /** |
|
36 | + * Sync_Background_Process_Started_State constructor. |
|
37 | + * |
|
38 | + * @param Sync_Background_Process $context |
|
39 | + * @param Sync_Service $sync_service |
|
40 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
41 | + * @param bool $reset Whether to reset the counters |
|
42 | + */ |
|
43 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
44 | + public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
45 | + parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
46 | + |
|
47 | + $this->context = $context; |
|
48 | + $this->sync_service = $sync_service; |
|
49 | + |
|
50 | + $this->stages = array( |
|
51 | + new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
52 | + new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
53 | + new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
54 | + ); |
|
55 | + |
|
56 | + as_enqueue_async_action( 'wl_sync_data_task' ); |
|
57 | + add_action( 'wl_sync_data_task', array( $this, 'task' ), 10, 0 ); |
|
58 | + } |
|
59 | + |
|
60 | + public function enter() { |
|
61 | + // Delete the KG contents. |
|
62 | + $this->sync_service->delete_all(); |
|
63 | + |
|
64 | + // Clear caches. |
|
65 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
66 | + |
|
67 | + $counts = array_map( |
|
68 | + function ( $item ) { |
|
69 | + return $item->count(); |
|
70 | + }, |
|
71 | + $this->stages |
|
72 | + ); |
|
73 | + |
|
74 | + update_option( '_wl_sync_background_process_count', $counts, true ); |
|
75 | + update_option( '_wl_sync_background_process_stage', 0, true ); |
|
76 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
77 | + update_option( '_wl_sync_background_process_started', time(), true ); |
|
78 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
79 | + |
|
80 | + $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
81 | + |
|
82 | + $this->resume(); |
|
83 | + } |
|
84 | + |
|
85 | + public function resume() { |
|
86 | + // TODO : Resume Functionality. |
|
87 | + // $this->context->push_to_queue( true ); |
|
88 | + // $this->context->save()->dispatch(); |
|
89 | + } |
|
90 | + |
|
91 | + public function leave() { |
|
92 | + $this->context->set_state( null ); |
|
93 | + } |
|
94 | + |
|
95 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
96 | + public function task() { |
|
97 | + |
|
98 | + $offset = get_option( '_wl_sync_background_process_offset' ); |
|
99 | + $stage = get_option( '_wl_sync_background_process_stage' ); |
|
100 | + $counts = get_option( '_wl_sync_background_process_count' ); |
|
101 | + $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
102 | + |
|
103 | + add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
104 | + try { |
|
105 | + $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
106 | + $this->sync_service->sync_many( $object_adapters, true ); |
|
107 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
108 | + } catch ( \Exception $e ) { |
|
109 | + // ignored. |
|
110 | + } |
|
111 | + remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
112 | + |
|
113 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
114 | + |
|
115 | + // Increase the offset. |
|
116 | + if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
117 | + update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
118 | + |
|
119 | + return true; |
|
120 | + } |
|
121 | + |
|
122 | + // Increase the stage. |
|
123 | + if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
124 | + update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
125 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
126 | + |
|
127 | + return true; |
|
128 | + } |
|
129 | + |
|
130 | + // Stop processing. |
|
131 | + $this->context->stop(); |
|
132 | + |
|
133 | + return false; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Hook to provide a request to update the status on the server. |
|
138 | + * |
|
139 | + * @param array $args |
|
140 | + * |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function api_service__request( $args ) { |
|
144 | + |
|
145 | + $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
146 | + |
|
147 | + $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
148 | + |
|
149 | + return $args; |
|
150 | + } |
|
151 | 151 | |
152 | 152 | } |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | * @param bool $reset Whether to reset the counters |
42 | 42 | */ |
43 | 43 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
44 | - public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
45 | - parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
44 | + public function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) { |
|
45 | + parent::__construct(Sync_Background_Process::STATE_STARTED); |
|
46 | 46 | |
47 | 47 | $this->context = $context; |
48 | 48 | $this->sync_service = $sync_service; |
49 | 49 | |
50 | 50 | $this->stages = array( |
51 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
52 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
53 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
51 | + new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory), |
|
52 | + new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory), |
|
53 | + new Sync_Background_Process_Users_Stage($sync_object_adapter_factory), |
|
54 | 54 | ); |
55 | 55 | |
56 | - as_enqueue_async_action( 'wl_sync_data_task' ); |
|
57 | - add_action( 'wl_sync_data_task', array( $this, 'task' ), 10, 0 ); |
|
56 | + as_enqueue_async_action('wl_sync_data_task'); |
|
57 | + add_action('wl_sync_data_task', array($this, 'task'), 10, 0); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function enter() { |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | $this->sync_service->delete_all(); |
63 | 63 | |
64 | 64 | // Clear caches. |
65 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
65 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
66 | 66 | |
67 | 67 | $counts = array_map( |
68 | - function ( $item ) { |
|
68 | + function($item) { |
|
69 | 69 | return $item->count(); |
70 | 70 | }, |
71 | 71 | $this->stages |
72 | 72 | ); |
73 | 73 | |
74 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
75 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
76 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
77 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
78 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
74 | + update_option('_wl_sync_background_process_count', $counts, true); |
|
75 | + update_option('_wl_sync_background_process_stage', 0, true); |
|
76 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
77 | + update_option('_wl_sync_background_process_started', time(), true); |
|
78 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
79 | 79 | |
80 | - $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
80 | + $this->context->set_state(Sync_Background_Process::STATE_STARTED); |
|
81 | 81 | |
82 | 82 | $this->resume(); |
83 | 83 | } |
@@ -89,40 +89,40 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | public function leave() { |
92 | - $this->context->set_state( null ); |
|
92 | + $this->context->set_state(null); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
96 | 96 | public function task() { |
97 | 97 | |
98 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
99 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
100 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
101 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
98 | + $offset = get_option('_wl_sync_background_process_offset'); |
|
99 | + $stage = get_option('_wl_sync_background_process_stage'); |
|
100 | + $counts = get_option('_wl_sync_background_process_count'); |
|
101 | + $batch_size = min($counts[$stage] - $offset, $this->batch_size); |
|
102 | 102 | |
103 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
103 | + add_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
104 | 104 | try { |
105 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
106 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
105 | + $object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size); |
|
106 | + $this->sync_service->sync_many($object_adapters, true); |
|
107 | 107 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
108 | - } catch ( \Exception $e ) { |
|
108 | + } catch (\Exception $e) { |
|
109 | 109 | // ignored. |
110 | 110 | } |
111 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
111 | + remove_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
112 | 112 | |
113 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
113 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
114 | 114 | |
115 | 115 | // Increase the offset. |
116 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
117 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
116 | + if (($offset + $batch_size) < $counts[$stage]) { |
|
117 | + update_option('_wl_sync_background_process_offset', $offset + $batch_size, true); |
|
118 | 118 | |
119 | 119 | return true; |
120 | 120 | } |
121 | 121 | |
122 | 122 | // Increase the stage. |
123 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
124 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
125 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
123 | + if (($stage + 1) < count($this->stages)) { |
|
124 | + update_option('_wl_sync_background_process_stage', $stage + 1, true); |
|
125 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
126 | 126 | |
127 | 127 | return true; |
128 | 128 | } |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - public function api_service__request( $args ) { |
|
143 | + public function api_service__request($args) { |
|
144 | 144 | |
145 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
145 | + $state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info())); |
|
146 | 146 | |
147 | 147 | $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
148 | 148 |
@@ -6,72 +6,72 @@ |
||
6 | 6 | * @group schedules |
7 | 7 | */ |
8 | 8 | class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase { |
9 | - public function test_creation() { |
|
10 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
11 | - $cron = CronExpression::factory( '@daily' ); |
|
12 | - $start = clone $time; |
|
13 | - $start->modify( '-1 hour' ); |
|
14 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
15 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
16 | - $this->assertEquals( $start, $schedule->get_first_date() ); |
|
9 | + public function test_creation() { |
|
10 | + $time = as_get_datetime_object( 'tomorrow' ); |
|
11 | + $cron = CronExpression::factory( '@daily' ); |
|
12 | + $start = clone $time; |
|
13 | + $start->modify( '-1 hour' ); |
|
14 | + $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
15 | + $this->assertEquals( $time, $schedule->get_date() ); |
|
16 | + $this->assertEquals( $start, $schedule->get_first_date() ); |
|
17 | 17 | |
18 | - // Test delaying for a future start date |
|
19 | - $start->modify( '+1 week' ); |
|
20 | - $time->modify( '+1 week' ); |
|
18 | + // Test delaying for a future start date |
|
19 | + $start->modify( '+1 week' ); |
|
20 | + $time->modify( '+1 week' ); |
|
21 | 21 | |
22 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
23 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
24 | - $this->assertEquals( $start, $schedule->get_first_date() ); |
|
25 | - } |
|
22 | + $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
23 | + $this->assertEquals( $time, $schedule->get_date() ); |
|
24 | + $this->assertEquals( $start, $schedule->get_first_date() ); |
|
25 | + } |
|
26 | 26 | |
27 | - public function test_creation_with_first_date() { |
|
28 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
29 | - $cron = CronExpression::factory( '@daily' ); |
|
30 | - $start = clone $time; |
|
31 | - $start->modify( '-1 hour' ); |
|
32 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
33 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
34 | - $this->assertEquals( $start, $schedule->get_first_date() ); |
|
27 | + public function test_creation_with_first_date() { |
|
28 | + $time = as_get_datetime_object( 'tomorrow' ); |
|
29 | + $cron = CronExpression::factory( '@daily' ); |
|
30 | + $start = clone $time; |
|
31 | + $start->modify( '-1 hour' ); |
|
32 | + $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
33 | + $this->assertEquals( $time, $schedule->get_date() ); |
|
34 | + $this->assertEquals( $start, $schedule->get_first_date() ); |
|
35 | 35 | |
36 | - // Test delaying for a future start date |
|
37 | - $first = clone $time; |
|
38 | - $first->modify( '-1 day' ); |
|
39 | - $start->modify( '+1 week' ); |
|
40 | - $time->modify( '+1 week' ); |
|
36 | + // Test delaying for a future start date |
|
37 | + $first = clone $time; |
|
38 | + $first->modify( '-1 day' ); |
|
39 | + $start->modify( '+1 week' ); |
|
40 | + $time->modify( '+1 week' ); |
|
41 | 41 | |
42 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron, $first ); |
|
43 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
44 | - $this->assertEquals( $first, $schedule->get_first_date() ); |
|
45 | - } |
|
42 | + $schedule = new ActionScheduler_CronSchedule( $start, $cron, $first ); |
|
43 | + $this->assertEquals( $time, $schedule->get_date() ); |
|
44 | + $this->assertEquals( $first, $schedule->get_first_date() ); |
|
45 | + } |
|
46 | 46 | |
47 | - public function test_next() { |
|
48 | - $time = as_get_datetime_object( '2013-06-14' ); |
|
49 | - $cron = CronExpression::factory( '@daily' ); |
|
50 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
51 | - $this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) ); |
|
52 | - } |
|
47 | + public function test_next() { |
|
48 | + $time = as_get_datetime_object( '2013-06-14' ); |
|
49 | + $cron = CronExpression::factory( '@daily' ); |
|
50 | + $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
51 | + $this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) ); |
|
52 | + } |
|
53 | 53 | |
54 | - public function test_is_recurring() { |
|
55 | - $schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) ); |
|
56 | - $this->assertTrue( $schedule->is_recurring() ); |
|
57 | - } |
|
54 | + public function test_is_recurring() { |
|
55 | + $schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) ); |
|
56 | + $this->assertTrue( $schedule->is_recurring() ); |
|
57 | + } |
|
58 | 58 | |
59 | - public function test_cron_format() { |
|
60 | - $time = as_get_datetime_object( '2014-01-01' ); |
|
61 | - $cron = CronExpression::factory( '0 0 10 10 *' ); |
|
62 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
63 | - $this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() ); |
|
59 | + public function test_cron_format() { |
|
60 | + $time = as_get_datetime_object( '2014-01-01' ); |
|
61 | + $cron = CronExpression::factory( '0 0 10 10 *' ); |
|
62 | + $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
63 | + $this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() ); |
|
64 | 64 | |
65 | - $cron = CronExpression::factory( '0 0 L 1/2 *' ); |
|
66 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
67 | - $this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() ); |
|
68 | - $this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) ); |
|
69 | - $this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) ); |
|
65 | + $cron = CronExpression::factory( '0 0 L 1/2 *' ); |
|
66 | + $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
67 | + $this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() ); |
|
68 | + $this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) ); |
|
69 | + $this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) ); |
|
70 | 70 | |
71 | - $cron = CronExpression::factory( '30 14 * * MON#3 *' ); |
|
72 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
73 | - $this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() ); |
|
74 | - $this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) ); |
|
75 | - } |
|
71 | + $cron = CronExpression::factory( '30 14 * * MON#3 *' ); |
|
72 | + $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
73 | + $this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() ); |
|
74 | + $this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) ); |
|
75 | + } |
|
76 | 76 | } |
77 | 77 |
@@ -7,71 +7,71 @@ |
||
7 | 7 | */ |
8 | 8 | class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase { |
9 | 9 | public function test_creation() { |
10 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
11 | - $cron = CronExpression::factory( '@daily' ); |
|
10 | + $time = as_get_datetime_object('tomorrow'); |
|
11 | + $cron = CronExpression::factory('@daily'); |
|
12 | 12 | $start = clone $time; |
13 | - $start->modify( '-1 hour' ); |
|
14 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
15 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
16 | - $this->assertEquals( $start, $schedule->get_first_date() ); |
|
13 | + $start->modify('-1 hour'); |
|
14 | + $schedule = new ActionScheduler_CronSchedule($start, $cron); |
|
15 | + $this->assertEquals($time, $schedule->get_date()); |
|
16 | + $this->assertEquals($start, $schedule->get_first_date()); |
|
17 | 17 | |
18 | 18 | // Test delaying for a future start date |
19 | - $start->modify( '+1 week' ); |
|
20 | - $time->modify( '+1 week' ); |
|
19 | + $start->modify('+1 week'); |
|
20 | + $time->modify('+1 week'); |
|
21 | 21 | |
22 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
23 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
24 | - $this->assertEquals( $start, $schedule->get_first_date() ); |
|
22 | + $schedule = new ActionScheduler_CronSchedule($start, $cron); |
|
23 | + $this->assertEquals($time, $schedule->get_date()); |
|
24 | + $this->assertEquals($start, $schedule->get_first_date()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function test_creation_with_first_date() { |
28 | - $time = as_get_datetime_object( 'tomorrow' ); |
|
29 | - $cron = CronExpression::factory( '@daily' ); |
|
28 | + $time = as_get_datetime_object('tomorrow'); |
|
29 | + $cron = CronExpression::factory('@daily'); |
|
30 | 30 | $start = clone $time; |
31 | - $start->modify( '-1 hour' ); |
|
32 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron ); |
|
33 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
34 | - $this->assertEquals( $start, $schedule->get_first_date() ); |
|
31 | + $start->modify('-1 hour'); |
|
32 | + $schedule = new ActionScheduler_CronSchedule($start, $cron); |
|
33 | + $this->assertEquals($time, $schedule->get_date()); |
|
34 | + $this->assertEquals($start, $schedule->get_first_date()); |
|
35 | 35 | |
36 | 36 | // Test delaying for a future start date |
37 | 37 | $first = clone $time; |
38 | - $first->modify( '-1 day' ); |
|
39 | - $start->modify( '+1 week' ); |
|
40 | - $time->modify( '+1 week' ); |
|
38 | + $first->modify('-1 day'); |
|
39 | + $start->modify('+1 week'); |
|
40 | + $time->modify('+1 week'); |
|
41 | 41 | |
42 | - $schedule = new ActionScheduler_CronSchedule( $start, $cron, $first ); |
|
43 | - $this->assertEquals( $time, $schedule->get_date() ); |
|
44 | - $this->assertEquals( $first, $schedule->get_first_date() ); |
|
42 | + $schedule = new ActionScheduler_CronSchedule($start, $cron, $first); |
|
43 | + $this->assertEquals($time, $schedule->get_date()); |
|
44 | + $this->assertEquals($first, $schedule->get_first_date()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function test_next() { |
48 | - $time = as_get_datetime_object( '2013-06-14' ); |
|
49 | - $cron = CronExpression::factory( '@daily' ); |
|
50 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
51 | - $this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) ); |
|
48 | + $time = as_get_datetime_object('2013-06-14'); |
|
49 | + $cron = CronExpression::factory('@daily'); |
|
50 | + $schedule = new ActionScheduler_CronSchedule($time, $cron); |
|
51 | + $this->assertEquals(as_get_datetime_object('tomorrow'), $schedule->get_next(as_get_datetime_object())); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function test_is_recurring() { |
55 | - $schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) ); |
|
56 | - $this->assertTrue( $schedule->is_recurring() ); |
|
55 | + $schedule = new ActionScheduler_CronSchedule(as_get_datetime_object('2013-06-14'), CronExpression::factory('@daily')); |
|
56 | + $this->assertTrue($schedule->is_recurring()); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function test_cron_format() { |
60 | - $time = as_get_datetime_object( '2014-01-01' ); |
|
61 | - $cron = CronExpression::factory( '0 0 10 10 *' ); |
|
62 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
63 | - $this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() ); |
|
60 | + $time = as_get_datetime_object('2014-01-01'); |
|
61 | + $cron = CronExpression::factory('0 0 10 10 *'); |
|
62 | + $schedule = new ActionScheduler_CronSchedule($time, $cron); |
|
63 | + $this->assertEquals(as_get_datetime_object('2014-10-10'), $schedule->get_date()); |
|
64 | 64 | |
65 | - $cron = CronExpression::factory( '0 0 L 1/2 *' ); |
|
66 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
67 | - $this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() ); |
|
68 | - $this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) ); |
|
69 | - $this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) ); |
|
65 | + $cron = CronExpression::factory('0 0 L 1/2 *'); |
|
66 | + $schedule = new ActionScheduler_CronSchedule($time, $cron); |
|
67 | + $this->assertEquals(as_get_datetime_object('2014-01-31'), $schedule->get_date()); |
|
68 | + $this->assertEquals(as_get_datetime_object('2014-07-31'), $schedule->get_next(as_get_datetime_object('2014-06-01'))); |
|
69 | + $this->assertEquals(as_get_datetime_object('2028-11-30'), $schedule->get_next(as_get_datetime_object('2028-11-01'))); |
|
70 | 70 | |
71 | - $cron = CronExpression::factory( '30 14 * * MON#3 *' ); |
|
72 | - $schedule = new ActionScheduler_CronSchedule( $time, $cron ); |
|
73 | - $this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() ); |
|
74 | - $this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) ); |
|
71 | + $cron = CronExpression::factory('30 14 * * MON#3 *'); |
|
72 | + $schedule = new ActionScheduler_CronSchedule($time, $cron); |
|
73 | + $this->assertEquals(as_get_datetime_object('2014-01-20 14:30:00'), $schedule->get_date()); |
|
74 | + $this->assertEquals(as_get_datetime_object('2014-05-19 14:30:00'), $schedule->get_next(as_get_datetime_object('2014-05-01'))); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 |