@@ -7,56 +7,56 @@ |
||
7 | 7 | */ |
8 | 8 | class CronExpression_MonthField extends CronExpression_AbstractField { |
9 | 9 | |
10 | - /** |
|
11 | - * {@inheritdoc} |
|
12 | - */ |
|
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - // Convert text month values to integers |
|
15 | - $value = str_ireplace( |
|
16 | - array( |
|
17 | - 'JAN', |
|
18 | - 'FEB', |
|
19 | - 'MAR', |
|
20 | - 'APR', |
|
21 | - 'MAY', |
|
22 | - 'JUN', |
|
23 | - 'JUL', |
|
24 | - 'AUG', |
|
25 | - 'SEP', |
|
26 | - 'OCT', |
|
27 | - 'NOV', |
|
28 | - 'DEC', |
|
29 | - ), |
|
30 | - range( 1, 12 ), |
|
31 | - $value |
|
32 | - ); |
|
10 | + /** |
|
11 | + * {@inheritdoc} |
|
12 | + */ |
|
13 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | + // Convert text month values to integers |
|
15 | + $value = str_ireplace( |
|
16 | + array( |
|
17 | + 'JAN', |
|
18 | + 'FEB', |
|
19 | + 'MAR', |
|
20 | + 'APR', |
|
21 | + 'MAY', |
|
22 | + 'JUN', |
|
23 | + 'JUL', |
|
24 | + 'AUG', |
|
25 | + 'SEP', |
|
26 | + 'OCT', |
|
27 | + 'NOV', |
|
28 | + 'DEC', |
|
29 | + ), |
|
30 | + range( 1, 12 ), |
|
31 | + $value |
|
32 | + ); |
|
33 | 33 | |
34 | - return $this->isSatisfied( $date->format( 'm' ), $value ); |
|
35 | - } |
|
34 | + return $this->isSatisfied( $date->format( 'm' ), $value ); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * {@inheritdoc} |
|
39 | - */ |
|
40 | - public function increment( DateTime $date, $invert = false ) { |
|
41 | - if ( $invert ) { |
|
42 | - // $date->modify('last day of previous month'); // remove for php 5.2 compat |
|
43 | - $date->modify( 'previous month' ); |
|
44 | - $date->modify( $date->format( 'Y-m-t' ) ); |
|
45 | - $date->setTime( 23, 59 ); |
|
46 | - } else { |
|
47 | - // $date->modify('first day of next month'); // remove for php 5.2 compat |
|
48 | - $date->modify( 'next month' ); |
|
49 | - $date->modify( $date->format( 'Y-m-01' ) ); |
|
50 | - $date->setTime( 0, 0 ); |
|
51 | - } |
|
37 | + /** |
|
38 | + * {@inheritdoc} |
|
39 | + */ |
|
40 | + public function increment( DateTime $date, $invert = false ) { |
|
41 | + if ( $invert ) { |
|
42 | + // $date->modify('last day of previous month'); // remove for php 5.2 compat |
|
43 | + $date->modify( 'previous month' ); |
|
44 | + $date->modify( $date->format( 'Y-m-t' ) ); |
|
45 | + $date->setTime( 23, 59 ); |
|
46 | + } else { |
|
47 | + // $date->modify('first day of next month'); // remove for php 5.2 compat |
|
48 | + $date->modify( 'next month' ); |
|
49 | + $date->modify( $date->format( 'Y-m-01' ) ); |
|
50 | + $date->setTime( 0, 0 ); |
|
51 | + } |
|
52 | 52 | |
53 | - return $this; |
|
54 | - } |
|
53 | + return $this; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function validate( $value ) { |
|
60 | - return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
61 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function validate( $value ) { |
|
60 | + return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
61 | + } |
|
62 | 62 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * {@inheritdoc} |
12 | 12 | */ |
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
13 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
14 | 14 | // Convert text month values to integers |
15 | 15 | $value = str_ireplace( |
16 | 16 | array( |
@@ -27,27 +27,27 @@ discard block |
||
27 | 27 | 'NOV', |
28 | 28 | 'DEC', |
29 | 29 | ), |
30 | - range( 1, 12 ), |
|
30 | + range(1, 12), |
|
31 | 31 | $value |
32 | 32 | ); |
33 | 33 | |
34 | - return $this->isSatisfied( $date->format( 'm' ), $value ); |
|
34 | + return $this->isSatisfied($date->format('m'), $value); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * {@inheritdoc} |
39 | 39 | */ |
40 | - public function increment( DateTime $date, $invert = false ) { |
|
41 | - if ( $invert ) { |
|
40 | + public function increment(DateTime $date, $invert = false) { |
|
41 | + if ($invert) { |
|
42 | 42 | // $date->modify('last day of previous month'); // remove for php 5.2 compat |
43 | - $date->modify( 'previous month' ); |
|
44 | - $date->modify( $date->format( 'Y-m-t' ) ); |
|
45 | - $date->setTime( 23, 59 ); |
|
43 | + $date->modify('previous month'); |
|
44 | + $date->modify($date->format('Y-m-t')); |
|
45 | + $date->setTime(23, 59); |
|
46 | 46 | } else { |
47 | 47 | // $date->modify('first day of next month'); // remove for php 5.2 compat |
48 | - $date->modify( 'next month' ); |
|
49 | - $date->modify( $date->format( 'Y-m-01' ) ); |
|
50 | - $date->setTime( 0, 0 ); |
|
48 | + $date->modify('next month'); |
|
49 | + $date->modify($date->format('Y-m-01')); |
|
50 | + $date->setTime(0, 0); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return $this; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * {@inheritdoc} |
58 | 58 | */ |
59 | - public function validate( $value ) { |
|
60 | - return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
59 | + public function validate($value) { |
|
60 | + return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value); |
|
61 | 61 | } |
62 | 62 | } |
@@ -7,33 +7,33 @@ |
||
7 | 7 | */ |
8 | 8 | interface CronExpression_FieldInterface { |
9 | 9 | |
10 | - /** |
|
11 | - * Check if the respective value of a DateTime field satisfies a CRON exp |
|
12 | - * |
|
13 | - * @param DateTime $date DateTime object to check |
|
14 | - * @param string $value CRON expression to test against |
|
15 | - * |
|
16 | - * @return bool Returns TRUE if satisfied, FALSE otherwise |
|
17 | - */ |
|
18 | - public function isSatisfiedBy( DateTime $date, $value); |
|
10 | + /** |
|
11 | + * Check if the respective value of a DateTime field satisfies a CRON exp |
|
12 | + * |
|
13 | + * @param DateTime $date DateTime object to check |
|
14 | + * @param string $value CRON expression to test against |
|
15 | + * |
|
16 | + * @return bool Returns TRUE if satisfied, FALSE otherwise |
|
17 | + */ |
|
18 | + public function isSatisfiedBy( DateTime $date, $value); |
|
19 | 19 | |
20 | - /** |
|
21 | - * When a CRON expression is not satisfied, this method is used to increment |
|
22 | - * or decrement a DateTime object by the unit of the cron field |
|
23 | - * |
|
24 | - * @param DateTime $date DateTime object to change |
|
25 | - * @param bool $invert (optional) Set to TRUE to decrement |
|
26 | - * |
|
27 | - * @return CronExpression_FieldInterface |
|
28 | - */ |
|
29 | - public function increment( DateTime $date, $invert = false); |
|
20 | + /** |
|
21 | + * When a CRON expression is not satisfied, this method is used to increment |
|
22 | + * or decrement a DateTime object by the unit of the cron field |
|
23 | + * |
|
24 | + * @param DateTime $date DateTime object to change |
|
25 | + * @param bool $invert (optional) Set to TRUE to decrement |
|
26 | + * |
|
27 | + * @return CronExpression_FieldInterface |
|
28 | + */ |
|
29 | + public function increment( DateTime $date, $invert = false); |
|
30 | 30 | |
31 | - /** |
|
32 | - * Validates a CRON expression for a given field |
|
33 | - * |
|
34 | - * @param string $value CRON expression value to validate |
|
35 | - * |
|
36 | - * @return bool Returns TRUE if valid, FALSE otherwise |
|
37 | - */ |
|
38 | - public function validate( $value); |
|
31 | + /** |
|
32 | + * Validates a CRON expression for a given field |
|
33 | + * |
|
34 | + * @param string $value CRON expression value to validate |
|
35 | + * |
|
36 | + * @return bool Returns TRUE if valid, FALSE otherwise |
|
37 | + */ |
|
38 | + public function validate( $value); |
|
39 | 39 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return bool Returns TRUE if satisfied, FALSE otherwise |
17 | 17 | */ |
18 | - public function isSatisfiedBy( DateTime $date, $value); |
|
18 | + public function isSatisfiedBy(DateTime $date, $value); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * When a CRON expression is not satisfied, this method is used to increment |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return CronExpression_FieldInterface |
28 | 28 | */ |
29 | - public function increment( DateTime $date, $invert = false); |
|
29 | + public function increment(DateTime $date, $invert = false); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Validates a CRON expression for a given field |
@@ -35,5 +35,5 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return bool Returns TRUE if valid, FALSE otherwise |
37 | 37 | */ |
38 | - public function validate( $value); |
|
38 | + public function validate($value); |
|
39 | 39 | } |
@@ -8,47 +8,47 @@ |
||
8 | 8 | */ |
9 | 9 | class CronExpression_FieldFactory { |
10 | 10 | |
11 | - /** |
|
12 | - * @var array Cache of instantiated fields |
|
13 | - */ |
|
14 | - private $fields = array(); |
|
11 | + /** |
|
12 | + * @var array Cache of instantiated fields |
|
13 | + */ |
|
14 | + private $fields = array(); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Get an instance of a field object for a cron expression position |
|
18 | - * |
|
19 | - * @param int $position CRON expression position value to retrieve |
|
20 | - * |
|
21 | - * @return CronExpression_FieldInterface |
|
22 | - * @throws InvalidArgumentException if a position is not valid |
|
23 | - */ |
|
24 | - public function getField( $position ) { |
|
25 | - if ( ! isset( $this->fields[ $position ] ) ) { |
|
26 | - switch ( $position ) { |
|
27 | - case 0: |
|
28 | - $this->fields[ $position ] = new CronExpression_MinutesField(); |
|
29 | - break; |
|
30 | - case 1: |
|
31 | - $this->fields[ $position ] = new CronExpression_HoursField(); |
|
32 | - break; |
|
33 | - case 2: |
|
34 | - $this->fields[ $position ] = new CronExpression_DayOfMonthField(); |
|
35 | - break; |
|
36 | - case 3: |
|
37 | - $this->fields[ $position ] = new CronExpression_MonthField(); |
|
38 | - break; |
|
39 | - case 4: |
|
40 | - $this->fields[ $position ] = new CronExpression_DayOfWeekField(); |
|
41 | - break; |
|
42 | - case 5: |
|
43 | - $this->fields[ $position ] = new CronExpression_YearField(); |
|
44 | - break; |
|
45 | - default: |
|
46 | - throw new InvalidArgumentException( |
|
47 | - $position . ' is not a valid position' |
|
48 | - ); |
|
49 | - } |
|
50 | - } |
|
16 | + /** |
|
17 | + * Get an instance of a field object for a cron expression position |
|
18 | + * |
|
19 | + * @param int $position CRON expression position value to retrieve |
|
20 | + * |
|
21 | + * @return CronExpression_FieldInterface |
|
22 | + * @throws InvalidArgumentException if a position is not valid |
|
23 | + */ |
|
24 | + public function getField( $position ) { |
|
25 | + if ( ! isset( $this->fields[ $position ] ) ) { |
|
26 | + switch ( $position ) { |
|
27 | + case 0: |
|
28 | + $this->fields[ $position ] = new CronExpression_MinutesField(); |
|
29 | + break; |
|
30 | + case 1: |
|
31 | + $this->fields[ $position ] = new CronExpression_HoursField(); |
|
32 | + break; |
|
33 | + case 2: |
|
34 | + $this->fields[ $position ] = new CronExpression_DayOfMonthField(); |
|
35 | + break; |
|
36 | + case 3: |
|
37 | + $this->fields[ $position ] = new CronExpression_MonthField(); |
|
38 | + break; |
|
39 | + case 4: |
|
40 | + $this->fields[ $position ] = new CronExpression_DayOfWeekField(); |
|
41 | + break; |
|
42 | + case 5: |
|
43 | + $this->fields[ $position ] = new CronExpression_YearField(); |
|
44 | + break; |
|
45 | + default: |
|
46 | + throw new InvalidArgumentException( |
|
47 | + $position . ' is not a valid position' |
|
48 | + ); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - return $this->fields[ $position ]; |
|
53 | - } |
|
52 | + return $this->fields[ $position ]; |
|
53 | + } |
|
54 | 54 | } |
@@ -21,34 +21,34 @@ |
||
21 | 21 | * @return CronExpression_FieldInterface |
22 | 22 | * @throws InvalidArgumentException if a position is not valid |
23 | 23 | */ |
24 | - public function getField( $position ) { |
|
25 | - if ( ! isset( $this->fields[ $position ] ) ) { |
|
26 | - switch ( $position ) { |
|
24 | + public function getField($position) { |
|
25 | + if ( ! isset($this->fields[$position])) { |
|
26 | + switch ($position) { |
|
27 | 27 | case 0: |
28 | - $this->fields[ $position ] = new CronExpression_MinutesField(); |
|
28 | + $this->fields[$position] = new CronExpression_MinutesField(); |
|
29 | 29 | break; |
30 | 30 | case 1: |
31 | - $this->fields[ $position ] = new CronExpression_HoursField(); |
|
31 | + $this->fields[$position] = new CronExpression_HoursField(); |
|
32 | 32 | break; |
33 | 33 | case 2: |
34 | - $this->fields[ $position ] = new CronExpression_DayOfMonthField(); |
|
34 | + $this->fields[$position] = new CronExpression_DayOfMonthField(); |
|
35 | 35 | break; |
36 | 36 | case 3: |
37 | - $this->fields[ $position ] = new CronExpression_MonthField(); |
|
37 | + $this->fields[$position] = new CronExpression_MonthField(); |
|
38 | 38 | break; |
39 | 39 | case 4: |
40 | - $this->fields[ $position ] = new CronExpression_DayOfWeekField(); |
|
40 | + $this->fields[$position] = new CronExpression_DayOfWeekField(); |
|
41 | 41 | break; |
42 | 42 | case 5: |
43 | - $this->fields[ $position ] = new CronExpression_YearField(); |
|
43 | + $this->fields[$position] = new CronExpression_YearField(); |
|
44 | 44 | break; |
45 | 45 | default: |
46 | 46 | throw new InvalidArgumentException( |
47 | - $position . ' is not a valid position' |
|
47 | + $position.' is not a valid position' |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - return $this->fields[ $position ]; |
|
52 | + return $this->fields[$position]; |
|
53 | 53 | } |
54 | 54 | } |
@@ -15,293 +15,293 @@ |
||
15 | 15 | */ |
16 | 16 | class CronExpression { |
17 | 17 | |
18 | - const MINUTE = 0; |
|
19 | - const HOUR = 1; |
|
20 | - const DAY = 2; |
|
21 | - const MONTH = 3; |
|
22 | - const WEEKDAY = 4; |
|
23 | - const YEAR = 5; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array CRON expression parts |
|
27 | - */ |
|
28 | - private $cronParts; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var CronExpression_FieldFactory CRON field factory |
|
32 | - */ |
|
33 | - private $fieldFactory; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array Order in which to test of cron parts |
|
37 | - */ |
|
38 | - private static $order = array( self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE ); |
|
39 | - |
|
40 | - /** |
|
41 | - * Factory method to create a new CronExpression. |
|
42 | - * |
|
43 | - * @param string $expression The CRON expression to create. There are |
|
44 | - * several special predefined values which can be used to substitute the |
|
45 | - * CRON expression: |
|
46 | - * |
|
47 | - * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 * |
|
48 | - * @monthly - Run once a month, midnight, first of month - 0 0 1 * * |
|
49 | - * @weekly - Run once a week, midnight on Sun - 0 0 * * 0 |
|
50 | - * @daily - Run once a day, midnight - 0 0 * * * |
|
51 | - * @hourly - Run once an hour, first minute - 0 * * * * |
|
52 | - * |
|
53 | - * @param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use |
|
54 | - * |
|
55 | - * @return CronExpression |
|
56 | - */ |
|
57 | - public static function factory( $expression, CronExpression_FieldFactory $fieldFactory = null ) { |
|
58 | - $mappings = array( |
|
59 | - '@yearly' => '0 0 1 1 *', |
|
60 | - '@annually' => '0 0 1 1 *', |
|
61 | - '@monthly' => '0 0 1 * *', |
|
62 | - '@weekly' => '0 0 * * 0', |
|
63 | - '@daily' => '0 0 * * *', |
|
64 | - '@hourly' => '0 * * * *', |
|
65 | - ); |
|
66 | - |
|
67 | - if ( isset( $mappings[ $expression ] ) ) { |
|
68 | - $expression = $mappings[ $expression ]; |
|
69 | - } |
|
70 | - |
|
71 | - return new self( $expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory() ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Parse a CRON expression |
|
76 | - * |
|
77 | - * @param string $expression CRON expression (e.g. '8 * * * *') |
|
78 | - * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields |
|
79 | - */ |
|
80 | - public function __construct( $expression, CronExpression_FieldFactory $fieldFactory ) { |
|
81 | - $this->fieldFactory = $fieldFactory; |
|
82 | - $this->setExpression( $expression ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Set or change the CRON expression |
|
87 | - * |
|
88 | - * @param string $value CRON expression (e.g. 8 * * * *) |
|
89 | - * |
|
90 | - * @return CronExpression |
|
91 | - * @throws InvalidArgumentException if not a valid CRON expression |
|
92 | - */ |
|
93 | - public function setExpression( $value ) { |
|
94 | - $this->cronParts = preg_split( '/\s/', $value, -1, PREG_SPLIT_NO_EMPTY ); |
|
95 | - if ( count( $this->cronParts ) < 5 ) { |
|
96 | - throw new InvalidArgumentException( |
|
97 | - $value . ' is not a valid CRON expression' |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - foreach ( $this->cronParts as $position => $part ) { |
|
102 | - $this->setPart( $position, $part ); |
|
103 | - } |
|
104 | - |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Set part of the CRON expression |
|
110 | - * |
|
111 | - * @param int $position The position of the CRON expression to set |
|
112 | - * @param string $value The value to set |
|
113 | - * |
|
114 | - * @return CronExpression |
|
115 | - * @throws InvalidArgumentException if the value is not valid for the part |
|
116 | - */ |
|
117 | - public function setPart( $position, $value ) { |
|
118 | - if ( ! $this->fieldFactory->getField( $position )->validate( $value ) ) { |
|
119 | - throw new InvalidArgumentException( |
|
120 | - 'Invalid CRON field value ' . $value . ' as position ' . $position |
|
121 | - ); |
|
122 | - } |
|
123 | - |
|
124 | - $this->cronParts[ $position ] = $value; |
|
125 | - |
|
126 | - return $this; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Get a next run date relative to the current date or a specific date |
|
131 | - * |
|
132 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
133 | - * @param int $nth (optional) Number of matches to skip before returning a |
|
134 | - * matching next run date. 0, the default, will return the current |
|
135 | - * date and time if the next run date falls on the current date and |
|
136 | - * time. Setting this value to 1 will skip the first match and go to |
|
137 | - * the second match. Setting this value to 2 will skip the first 2 |
|
138 | - * matches and so on. |
|
139 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
140 | - * current date if it matches the cron expression |
|
141 | - * |
|
142 | - * @return DateTime |
|
143 | - * @throws RuntimeException on too many iterations |
|
144 | - */ |
|
145 | - public function getNextRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
146 | - return $this->getRunDate( $currentTime, $nth, false, $allowCurrentDate ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Get a previous run date relative to the current date or a specific date |
|
151 | - * |
|
152 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
153 | - * @param int $nth (optional) Number of matches to skip before returning |
|
154 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
155 | - * current date if it matches the cron expression |
|
156 | - * |
|
157 | - * @return DateTime |
|
158 | - * @throws RuntimeException on too many iterations |
|
159 | - * @see CronExpression::getNextRunDate |
|
160 | - */ |
|
161 | - public function getPreviousRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
162 | - return $this->getRunDate( $currentTime, $nth, true, $allowCurrentDate ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get multiple run dates starting at the current date or a specific date |
|
167 | - * |
|
168 | - * @param int $total Set the total number of dates to calculate |
|
169 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
170 | - * @param bool $invert (optional) Set to TRUE to retrieve previous dates |
|
171 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
172 | - * current date if it matches the cron expression |
|
173 | - * |
|
174 | - * @return array Returns an array of run dates |
|
175 | - */ |
|
176 | - public function getMultipleRunDates( $total, $currentTime = 'now', $invert = false, $allowCurrentDate = false ) { |
|
177 | - $matches = array(); |
|
178 | - for ( $i = 0; $i < max( 0, $total ); $i++ ) { |
|
179 | - $matches[] = $this->getRunDate( $currentTime, $i, $invert, $allowCurrentDate ); |
|
180 | - } |
|
181 | - |
|
182 | - return $matches; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Get all or part of the CRON expression |
|
187 | - * |
|
188 | - * @param string $part (optional) Specify the part to retrieve or NULL to |
|
189 | - * get the full cron schedule string. |
|
190 | - * |
|
191 | - * @return string|null Returns the CRON expression, a part of the |
|
192 | - * CRON expression, or NULL if the part was specified but not found |
|
193 | - */ |
|
194 | - public function getExpression( $part = null ) { |
|
195 | - if ( null === $part ) { |
|
196 | - return implode( ' ', $this->cronParts ); |
|
197 | - } elseif ( array_key_exists( $part, $this->cronParts ) ) { |
|
198 | - return $this->cronParts[ $part ]; |
|
199 | - } |
|
200 | - |
|
201 | - return null; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Helper method to output the full expression. |
|
206 | - * |
|
207 | - * @return string Full CRON expression |
|
208 | - */ |
|
209 | - public function __toString() { |
|
210 | - return $this->getExpression(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Determine if the cron is due to run based on the current date or a |
|
215 | - * specific date. This method assumes that the current number of |
|
216 | - * seconds are irrelevant, and should be called once per minute. |
|
217 | - * |
|
218 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
219 | - * |
|
220 | - * @return bool Returns TRUE if the cron is due to run or FALSE if not |
|
221 | - */ |
|
222 | - public function isDue( $currentTime = 'now' ) { |
|
223 | - if ( 'now' === $currentTime ) { |
|
224 | - $currentDate = date( 'Y-m-d H:i' ); |
|
225 | - $currentTime = strtotime( $currentDate ); |
|
226 | - } elseif ( $currentTime instanceof DateTime ) { |
|
227 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
228 | - $currentTime = strtotime( $currentDate ); |
|
229 | - } else { |
|
230 | - $currentTime = new DateTime( $currentTime ); |
|
231 | - $currentTime->setTime( $currentTime->format( 'H' ), $currentTime->format( 'i' ), 0 ); |
|
232 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
233 | - $currentTime = (int) ( $currentTime->getTimestamp() ); |
|
234 | - } |
|
235 | - |
|
236 | - return $this->getNextRunDate( $currentDate, 0, true )->getTimestamp() == $currentTime; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Get the next or previous run date of the expression relative to a date |
|
241 | - * |
|
242 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
243 | - * @param int $nth (optional) Number of matches to skip before returning |
|
244 | - * @param bool $invert (optional) Set to TRUE to go backwards in time |
|
245 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
246 | - * current date if it matches the cron expression |
|
247 | - * |
|
248 | - * @return DateTime |
|
249 | - * @throws RuntimeException on too many iterations |
|
250 | - */ |
|
251 | - protected function getRunDate( $currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false ) { |
|
252 | - if ( $currentTime instanceof DateTime ) { |
|
253 | - $currentDate = $currentTime; |
|
254 | - } else { |
|
255 | - $currentDate = new DateTime( $currentTime ? $currentTime : 'now' ); |
|
256 | - $currentDate->setTimezone( new DateTimeZone( date_default_timezone_get() ) ); |
|
257 | - } |
|
258 | - |
|
259 | - $currentDate->setTime( $currentDate->format( 'H' ), $currentDate->format( 'i' ), 0 ); |
|
260 | - $nextRun = clone $currentDate; |
|
261 | - $nth = (int) $nth; |
|
262 | - |
|
263 | - // Set a hard limit to bail on an impossible date |
|
264 | - for ( $i = 0; $i < 1000; $i++ ) { |
|
265 | - |
|
266 | - foreach ( self::$order as $position ) { |
|
267 | - $part = $this->getExpression( $position ); |
|
268 | - if ( null === $part ) { |
|
269 | - continue; |
|
270 | - } |
|
271 | - |
|
272 | - $satisfied = false; |
|
273 | - // Get the field object used to validate this part |
|
274 | - $field = $this->fieldFactory->getField( $position ); |
|
275 | - // Check if this is singular or a list |
|
276 | - if ( strpos( $part, ',' ) === false ) { |
|
277 | - $satisfied = $field->isSatisfiedBy( $nextRun, $part ); |
|
278 | - } else { |
|
279 | - foreach ( array_map( 'trim', explode( ',', $part ) ) as $listPart ) { |
|
280 | - if ( $field->isSatisfiedBy( $nextRun, $listPart ) ) { |
|
281 | - $satisfied = true; |
|
282 | - break; |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - // If the field is not satisfied, then start over |
|
288 | - if ( ! $satisfied ) { |
|
289 | - $field->increment( $nextRun, $invert ); |
|
290 | - continue 2; |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - // Skip this match if needed |
|
295 | - if ( ( ! $allowCurrentDate && $nextRun == $currentDate ) || --$nth > -1 ) { |
|
296 | - $this->fieldFactory->getField( 0 )->increment( $nextRun, $invert ); |
|
297 | - continue; |
|
298 | - } |
|
299 | - |
|
300 | - return $nextRun; |
|
301 | - } |
|
302 | - |
|
303 | - // @codeCoverageIgnoreStart |
|
304 | - throw new RuntimeException( 'Impossible CRON expression' ); |
|
305 | - // @codeCoverageIgnoreEnd |
|
306 | - } |
|
18 | + const MINUTE = 0; |
|
19 | + const HOUR = 1; |
|
20 | + const DAY = 2; |
|
21 | + const MONTH = 3; |
|
22 | + const WEEKDAY = 4; |
|
23 | + const YEAR = 5; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array CRON expression parts |
|
27 | + */ |
|
28 | + private $cronParts; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var CronExpression_FieldFactory CRON field factory |
|
32 | + */ |
|
33 | + private $fieldFactory; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array Order in which to test of cron parts |
|
37 | + */ |
|
38 | + private static $order = array( self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE ); |
|
39 | + |
|
40 | + /** |
|
41 | + * Factory method to create a new CronExpression. |
|
42 | + * |
|
43 | + * @param string $expression The CRON expression to create. There are |
|
44 | + * several special predefined values which can be used to substitute the |
|
45 | + * CRON expression: |
|
46 | + * |
|
47 | + * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 * |
|
48 | + * @monthly - Run once a month, midnight, first of month - 0 0 1 * * |
|
49 | + * @weekly - Run once a week, midnight on Sun - 0 0 * * 0 |
|
50 | + * @daily - Run once a day, midnight - 0 0 * * * |
|
51 | + * @hourly - Run once an hour, first minute - 0 * * * * |
|
52 | + * |
|
53 | + * @param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use |
|
54 | + * |
|
55 | + * @return CronExpression |
|
56 | + */ |
|
57 | + public static function factory( $expression, CronExpression_FieldFactory $fieldFactory = null ) { |
|
58 | + $mappings = array( |
|
59 | + '@yearly' => '0 0 1 1 *', |
|
60 | + '@annually' => '0 0 1 1 *', |
|
61 | + '@monthly' => '0 0 1 * *', |
|
62 | + '@weekly' => '0 0 * * 0', |
|
63 | + '@daily' => '0 0 * * *', |
|
64 | + '@hourly' => '0 * * * *', |
|
65 | + ); |
|
66 | + |
|
67 | + if ( isset( $mappings[ $expression ] ) ) { |
|
68 | + $expression = $mappings[ $expression ]; |
|
69 | + } |
|
70 | + |
|
71 | + return new self( $expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory() ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Parse a CRON expression |
|
76 | + * |
|
77 | + * @param string $expression CRON expression (e.g. '8 * * * *') |
|
78 | + * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields |
|
79 | + */ |
|
80 | + public function __construct( $expression, CronExpression_FieldFactory $fieldFactory ) { |
|
81 | + $this->fieldFactory = $fieldFactory; |
|
82 | + $this->setExpression( $expression ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Set or change the CRON expression |
|
87 | + * |
|
88 | + * @param string $value CRON expression (e.g. 8 * * * *) |
|
89 | + * |
|
90 | + * @return CronExpression |
|
91 | + * @throws InvalidArgumentException if not a valid CRON expression |
|
92 | + */ |
|
93 | + public function setExpression( $value ) { |
|
94 | + $this->cronParts = preg_split( '/\s/', $value, -1, PREG_SPLIT_NO_EMPTY ); |
|
95 | + if ( count( $this->cronParts ) < 5 ) { |
|
96 | + throw new InvalidArgumentException( |
|
97 | + $value . ' is not a valid CRON expression' |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + foreach ( $this->cronParts as $position => $part ) { |
|
102 | + $this->setPart( $position, $part ); |
|
103 | + } |
|
104 | + |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Set part of the CRON expression |
|
110 | + * |
|
111 | + * @param int $position The position of the CRON expression to set |
|
112 | + * @param string $value The value to set |
|
113 | + * |
|
114 | + * @return CronExpression |
|
115 | + * @throws InvalidArgumentException if the value is not valid for the part |
|
116 | + */ |
|
117 | + public function setPart( $position, $value ) { |
|
118 | + if ( ! $this->fieldFactory->getField( $position )->validate( $value ) ) { |
|
119 | + throw new InvalidArgumentException( |
|
120 | + 'Invalid CRON field value ' . $value . ' as position ' . $position |
|
121 | + ); |
|
122 | + } |
|
123 | + |
|
124 | + $this->cronParts[ $position ] = $value; |
|
125 | + |
|
126 | + return $this; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Get a next run date relative to the current date or a specific date |
|
131 | + * |
|
132 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
133 | + * @param int $nth (optional) Number of matches to skip before returning a |
|
134 | + * matching next run date. 0, the default, will return the current |
|
135 | + * date and time if the next run date falls on the current date and |
|
136 | + * time. Setting this value to 1 will skip the first match and go to |
|
137 | + * the second match. Setting this value to 2 will skip the first 2 |
|
138 | + * matches and so on. |
|
139 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
140 | + * current date if it matches the cron expression |
|
141 | + * |
|
142 | + * @return DateTime |
|
143 | + * @throws RuntimeException on too many iterations |
|
144 | + */ |
|
145 | + public function getNextRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
146 | + return $this->getRunDate( $currentTime, $nth, false, $allowCurrentDate ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Get a previous run date relative to the current date or a specific date |
|
151 | + * |
|
152 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
153 | + * @param int $nth (optional) Number of matches to skip before returning |
|
154 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
155 | + * current date if it matches the cron expression |
|
156 | + * |
|
157 | + * @return DateTime |
|
158 | + * @throws RuntimeException on too many iterations |
|
159 | + * @see CronExpression::getNextRunDate |
|
160 | + */ |
|
161 | + public function getPreviousRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
162 | + return $this->getRunDate( $currentTime, $nth, true, $allowCurrentDate ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get multiple run dates starting at the current date or a specific date |
|
167 | + * |
|
168 | + * @param int $total Set the total number of dates to calculate |
|
169 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
170 | + * @param bool $invert (optional) Set to TRUE to retrieve previous dates |
|
171 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
172 | + * current date if it matches the cron expression |
|
173 | + * |
|
174 | + * @return array Returns an array of run dates |
|
175 | + */ |
|
176 | + public function getMultipleRunDates( $total, $currentTime = 'now', $invert = false, $allowCurrentDate = false ) { |
|
177 | + $matches = array(); |
|
178 | + for ( $i = 0; $i < max( 0, $total ); $i++ ) { |
|
179 | + $matches[] = $this->getRunDate( $currentTime, $i, $invert, $allowCurrentDate ); |
|
180 | + } |
|
181 | + |
|
182 | + return $matches; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Get all or part of the CRON expression |
|
187 | + * |
|
188 | + * @param string $part (optional) Specify the part to retrieve or NULL to |
|
189 | + * get the full cron schedule string. |
|
190 | + * |
|
191 | + * @return string|null Returns the CRON expression, a part of the |
|
192 | + * CRON expression, or NULL if the part was specified but not found |
|
193 | + */ |
|
194 | + public function getExpression( $part = null ) { |
|
195 | + if ( null === $part ) { |
|
196 | + return implode( ' ', $this->cronParts ); |
|
197 | + } elseif ( array_key_exists( $part, $this->cronParts ) ) { |
|
198 | + return $this->cronParts[ $part ]; |
|
199 | + } |
|
200 | + |
|
201 | + return null; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Helper method to output the full expression. |
|
206 | + * |
|
207 | + * @return string Full CRON expression |
|
208 | + */ |
|
209 | + public function __toString() { |
|
210 | + return $this->getExpression(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Determine if the cron is due to run based on the current date or a |
|
215 | + * specific date. This method assumes that the current number of |
|
216 | + * seconds are irrelevant, and should be called once per minute. |
|
217 | + * |
|
218 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
219 | + * |
|
220 | + * @return bool Returns TRUE if the cron is due to run or FALSE if not |
|
221 | + */ |
|
222 | + public function isDue( $currentTime = 'now' ) { |
|
223 | + if ( 'now' === $currentTime ) { |
|
224 | + $currentDate = date( 'Y-m-d H:i' ); |
|
225 | + $currentTime = strtotime( $currentDate ); |
|
226 | + } elseif ( $currentTime instanceof DateTime ) { |
|
227 | + $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
228 | + $currentTime = strtotime( $currentDate ); |
|
229 | + } else { |
|
230 | + $currentTime = new DateTime( $currentTime ); |
|
231 | + $currentTime->setTime( $currentTime->format( 'H' ), $currentTime->format( 'i' ), 0 ); |
|
232 | + $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
233 | + $currentTime = (int) ( $currentTime->getTimestamp() ); |
|
234 | + } |
|
235 | + |
|
236 | + return $this->getNextRunDate( $currentDate, 0, true )->getTimestamp() == $currentTime; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Get the next or previous run date of the expression relative to a date |
|
241 | + * |
|
242 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
243 | + * @param int $nth (optional) Number of matches to skip before returning |
|
244 | + * @param bool $invert (optional) Set to TRUE to go backwards in time |
|
245 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
246 | + * current date if it matches the cron expression |
|
247 | + * |
|
248 | + * @return DateTime |
|
249 | + * @throws RuntimeException on too many iterations |
|
250 | + */ |
|
251 | + protected function getRunDate( $currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false ) { |
|
252 | + if ( $currentTime instanceof DateTime ) { |
|
253 | + $currentDate = $currentTime; |
|
254 | + } else { |
|
255 | + $currentDate = new DateTime( $currentTime ? $currentTime : 'now' ); |
|
256 | + $currentDate->setTimezone( new DateTimeZone( date_default_timezone_get() ) ); |
|
257 | + } |
|
258 | + |
|
259 | + $currentDate->setTime( $currentDate->format( 'H' ), $currentDate->format( 'i' ), 0 ); |
|
260 | + $nextRun = clone $currentDate; |
|
261 | + $nth = (int) $nth; |
|
262 | + |
|
263 | + // Set a hard limit to bail on an impossible date |
|
264 | + for ( $i = 0; $i < 1000; $i++ ) { |
|
265 | + |
|
266 | + foreach ( self::$order as $position ) { |
|
267 | + $part = $this->getExpression( $position ); |
|
268 | + if ( null === $part ) { |
|
269 | + continue; |
|
270 | + } |
|
271 | + |
|
272 | + $satisfied = false; |
|
273 | + // Get the field object used to validate this part |
|
274 | + $field = $this->fieldFactory->getField( $position ); |
|
275 | + // Check if this is singular or a list |
|
276 | + if ( strpos( $part, ',' ) === false ) { |
|
277 | + $satisfied = $field->isSatisfiedBy( $nextRun, $part ); |
|
278 | + } else { |
|
279 | + foreach ( array_map( 'trim', explode( ',', $part ) ) as $listPart ) { |
|
280 | + if ( $field->isSatisfiedBy( $nextRun, $listPart ) ) { |
|
281 | + $satisfied = true; |
|
282 | + break; |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + // If the field is not satisfied, then start over |
|
288 | + if ( ! $satisfied ) { |
|
289 | + $field->increment( $nextRun, $invert ); |
|
290 | + continue 2; |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + // Skip this match if needed |
|
295 | + if ( ( ! $allowCurrentDate && $nextRun == $currentDate ) || --$nth > -1 ) { |
|
296 | + $this->fieldFactory->getField( 0 )->increment( $nextRun, $invert ); |
|
297 | + continue; |
|
298 | + } |
|
299 | + |
|
300 | + return $nextRun; |
|
301 | + } |
|
302 | + |
|
303 | + // @codeCoverageIgnoreStart |
|
304 | + throw new RuntimeException( 'Impossible CRON expression' ); |
|
305 | + // @codeCoverageIgnoreEnd |
|
306 | + } |
|
307 | 307 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @var array Order in which to test of cron parts |
37 | 37 | */ |
38 | - private static $order = array( self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE ); |
|
38 | + private static $order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Factory method to create a new CronExpression. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return CronExpression |
56 | 56 | */ |
57 | - public static function factory( $expression, CronExpression_FieldFactory $fieldFactory = null ) { |
|
57 | + public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null) { |
|
58 | 58 | $mappings = array( |
59 | 59 | '@yearly' => '0 0 1 1 *', |
60 | 60 | '@annually' => '0 0 1 1 *', |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | '@hourly' => '0 * * * *', |
65 | 65 | ); |
66 | 66 | |
67 | - if ( isset( $mappings[ $expression ] ) ) { |
|
68 | - $expression = $mappings[ $expression ]; |
|
67 | + if (isset($mappings[$expression])) { |
|
68 | + $expression = $mappings[$expression]; |
|
69 | 69 | } |
70 | 70 | |
71 | - return new self( $expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory() ); |
|
71 | + return new self($expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory()); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param string $expression CRON expression (e.g. '8 * * * *') |
78 | 78 | * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields |
79 | 79 | */ |
80 | - public function __construct( $expression, CronExpression_FieldFactory $fieldFactory ) { |
|
80 | + public function __construct($expression, CronExpression_FieldFactory $fieldFactory) { |
|
81 | 81 | $this->fieldFactory = $fieldFactory; |
82 | - $this->setExpression( $expression ); |
|
82 | + $this->setExpression($expression); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | * @return CronExpression |
91 | 91 | * @throws InvalidArgumentException if not a valid CRON expression |
92 | 92 | */ |
93 | - public function setExpression( $value ) { |
|
94 | - $this->cronParts = preg_split( '/\s/', $value, -1, PREG_SPLIT_NO_EMPTY ); |
|
95 | - if ( count( $this->cronParts ) < 5 ) { |
|
93 | + public function setExpression($value) { |
|
94 | + $this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY); |
|
95 | + if (count($this->cronParts) < 5) { |
|
96 | 96 | throw new InvalidArgumentException( |
97 | - $value . ' is not a valid CRON expression' |
|
97 | + $value.' is not a valid CRON expression' |
|
98 | 98 | ); |
99 | 99 | } |
100 | 100 | |
101 | - foreach ( $this->cronParts as $position => $part ) { |
|
102 | - $this->setPart( $position, $part ); |
|
101 | + foreach ($this->cronParts as $position => $part) { |
|
102 | + $this->setPart($position, $part); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $this; |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @return CronExpression |
115 | 115 | * @throws InvalidArgumentException if the value is not valid for the part |
116 | 116 | */ |
117 | - public function setPart( $position, $value ) { |
|
118 | - if ( ! $this->fieldFactory->getField( $position )->validate( $value ) ) { |
|
117 | + public function setPart($position, $value) { |
|
118 | + if ( ! $this->fieldFactory->getField($position)->validate($value)) { |
|
119 | 119 | throw new InvalidArgumentException( |
120 | - 'Invalid CRON field value ' . $value . ' as position ' . $position |
|
120 | + 'Invalid CRON field value '.$value.' as position '.$position |
|
121 | 121 | ); |
122 | 122 | } |
123 | 123 | |
124 | - $this->cronParts[ $position ] = $value; |
|
124 | + $this->cronParts[$position] = $value; |
|
125 | 125 | |
126 | 126 | return $this; |
127 | 127 | } |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * @return DateTime |
143 | 143 | * @throws RuntimeException on too many iterations |
144 | 144 | */ |
145 | - public function getNextRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
146 | - return $this->getRunDate( $currentTime, $nth, false, $allowCurrentDate ); |
|
145 | + public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) { |
|
146 | + return $this->getRunDate($currentTime, $nth, false, $allowCurrentDate); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @throws RuntimeException on too many iterations |
159 | 159 | * @see CronExpression::getNextRunDate |
160 | 160 | */ |
161 | - public function getPreviousRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
162 | - return $this->getRunDate( $currentTime, $nth, true, $allowCurrentDate ); |
|
161 | + public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) { |
|
162 | + return $this->getRunDate($currentTime, $nth, true, $allowCurrentDate); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return array Returns an array of run dates |
175 | 175 | */ |
176 | - public function getMultipleRunDates( $total, $currentTime = 'now', $invert = false, $allowCurrentDate = false ) { |
|
176 | + public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false) { |
|
177 | 177 | $matches = array(); |
178 | - for ( $i = 0; $i < max( 0, $total ); $i++ ) { |
|
179 | - $matches[] = $this->getRunDate( $currentTime, $i, $invert, $allowCurrentDate ); |
|
178 | + for ($i = 0; $i < max(0, $total); $i++) { |
|
179 | + $matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | return $matches; |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | * @return string|null Returns the CRON expression, a part of the |
192 | 192 | * CRON expression, or NULL if the part was specified but not found |
193 | 193 | */ |
194 | - public function getExpression( $part = null ) { |
|
195 | - if ( null === $part ) { |
|
196 | - return implode( ' ', $this->cronParts ); |
|
197 | - } elseif ( array_key_exists( $part, $this->cronParts ) ) { |
|
198 | - return $this->cronParts[ $part ]; |
|
194 | + public function getExpression($part = null) { |
|
195 | + if (null === $part) { |
|
196 | + return implode(' ', $this->cronParts); |
|
197 | + } elseif (array_key_exists($part, $this->cronParts)) { |
|
198 | + return $this->cronParts[$part]; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return null; |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return bool Returns TRUE if the cron is due to run or FALSE if not |
221 | 221 | */ |
222 | - public function isDue( $currentTime = 'now' ) { |
|
223 | - if ( 'now' === $currentTime ) { |
|
224 | - $currentDate = date( 'Y-m-d H:i' ); |
|
225 | - $currentTime = strtotime( $currentDate ); |
|
226 | - } elseif ( $currentTime instanceof DateTime ) { |
|
227 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
228 | - $currentTime = strtotime( $currentDate ); |
|
222 | + public function isDue($currentTime = 'now') { |
|
223 | + if ('now' === $currentTime) { |
|
224 | + $currentDate = date('Y-m-d H:i'); |
|
225 | + $currentTime = strtotime($currentDate); |
|
226 | + } elseif ($currentTime instanceof DateTime) { |
|
227 | + $currentDate = $currentTime->format('Y-m-d H:i'); |
|
228 | + $currentTime = strtotime($currentDate); |
|
229 | 229 | } else { |
230 | - $currentTime = new DateTime( $currentTime ); |
|
231 | - $currentTime->setTime( $currentTime->format( 'H' ), $currentTime->format( 'i' ), 0 ); |
|
232 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
233 | - $currentTime = (int) ( $currentTime->getTimestamp() ); |
|
230 | + $currentTime = new DateTime($currentTime); |
|
231 | + $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0); |
|
232 | + $currentDate = $currentTime->format('Y-m-d H:i'); |
|
233 | + $currentTime = (int) ($currentTime->getTimestamp()); |
|
234 | 234 | } |
235 | 235 | |
236 | - return $this->getNextRunDate( $currentDate, 0, true )->getTimestamp() == $currentTime; |
|
236 | + return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -248,36 +248,36 @@ discard block |
||
248 | 248 | * @return DateTime |
249 | 249 | * @throws RuntimeException on too many iterations |
250 | 250 | */ |
251 | - protected function getRunDate( $currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false ) { |
|
252 | - if ( $currentTime instanceof DateTime ) { |
|
251 | + protected function getRunDate($currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false) { |
|
252 | + if ($currentTime instanceof DateTime) { |
|
253 | 253 | $currentDate = $currentTime; |
254 | 254 | } else { |
255 | - $currentDate = new DateTime( $currentTime ? $currentTime : 'now' ); |
|
256 | - $currentDate->setTimezone( new DateTimeZone( date_default_timezone_get() ) ); |
|
255 | + $currentDate = new DateTime($currentTime ? $currentTime : 'now'); |
|
256 | + $currentDate->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
257 | 257 | } |
258 | 258 | |
259 | - $currentDate->setTime( $currentDate->format( 'H' ), $currentDate->format( 'i' ), 0 ); |
|
259 | + $currentDate->setTime($currentDate->format('H'), $currentDate->format('i'), 0); |
|
260 | 260 | $nextRun = clone $currentDate; |
261 | 261 | $nth = (int) $nth; |
262 | 262 | |
263 | 263 | // Set a hard limit to bail on an impossible date |
264 | - for ( $i = 0; $i < 1000; $i++ ) { |
|
264 | + for ($i = 0; $i < 1000; $i++) { |
|
265 | 265 | |
266 | - foreach ( self::$order as $position ) { |
|
267 | - $part = $this->getExpression( $position ); |
|
268 | - if ( null === $part ) { |
|
266 | + foreach (self::$order as $position) { |
|
267 | + $part = $this->getExpression($position); |
|
268 | + if (null === $part) { |
|
269 | 269 | continue; |
270 | 270 | } |
271 | 271 | |
272 | 272 | $satisfied = false; |
273 | 273 | // Get the field object used to validate this part |
274 | - $field = $this->fieldFactory->getField( $position ); |
|
274 | + $field = $this->fieldFactory->getField($position); |
|
275 | 275 | // Check if this is singular or a list |
276 | - if ( strpos( $part, ',' ) === false ) { |
|
277 | - $satisfied = $field->isSatisfiedBy( $nextRun, $part ); |
|
276 | + if (strpos($part, ',') === false) { |
|
277 | + $satisfied = $field->isSatisfiedBy($nextRun, $part); |
|
278 | 278 | } else { |
279 | - foreach ( array_map( 'trim', explode( ',', $part ) ) as $listPart ) { |
|
280 | - if ( $field->isSatisfiedBy( $nextRun, $listPart ) ) { |
|
279 | + foreach (array_map('trim', explode(',', $part)) as $listPart) { |
|
280 | + if ($field->isSatisfiedBy($nextRun, $listPart)) { |
|
281 | 281 | $satisfied = true; |
282 | 282 | break; |
283 | 283 | } |
@@ -285,15 +285,15 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | // If the field is not satisfied, then start over |
288 | - if ( ! $satisfied ) { |
|
289 | - $field->increment( $nextRun, $invert ); |
|
288 | + if ( ! $satisfied) { |
|
289 | + $field->increment($nextRun, $invert); |
|
290 | 290 | continue 2; |
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | 294 | // Skip this match if needed |
295 | - if ( ( ! $allowCurrentDate && $nextRun == $currentDate ) || --$nth > -1 ) { |
|
296 | - $this->fieldFactory->getField( 0 )->increment( $nextRun, $invert ); |
|
295 | + if (( ! $allowCurrentDate && $nextRun == $currentDate) || --$nth > -1) { |
|
296 | + $this->fieldFactory->getField(0)->increment($nextRun, $invert); |
|
297 | 297 | continue; |
298 | 298 | } |
299 | 299 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | // @codeCoverageIgnoreStart |
304 | - throw new RuntimeException( 'Impossible CRON expression' ); |
|
304 | + throw new RuntimeException('Impossible CRON expression'); |
|
305 | 305 | // @codeCoverageIgnoreEnd |
306 | 306 | } |
307 | 307 | } |
@@ -28,40 +28,40 @@ |
||
28 | 28 | |
29 | 29 | if ( ! function_exists( 'action_scheduler_register_3_dot_5_dot_3' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION. |
30 | 30 | |
31 | - if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { |
|
32 | - require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; |
|
33 | - add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
34 | - } |
|
31 | + if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { |
|
32 | + require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; |
|
33 | + add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
34 | + } |
|
35 | 35 | |
36 | - add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0 ); // WRCS: DEFINED_VERSION. |
|
36 | + add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0 ); // WRCS: DEFINED_VERSION. |
|
37 | 37 | |
38 | - /** |
|
39 | - * Registers this version of Action Scheduler. |
|
40 | - */ |
|
41 | - function action_scheduler_register_3_dot_5_dot_3() { |
|
42 | - // WRCS: DEFINED_VERSION. |
|
43 | - $versions = ActionScheduler_Versions::instance(); |
|
44 | - $versions->register( '3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3' ); // WRCS: DEFINED_VERSION. |
|
45 | - } |
|
38 | + /** |
|
39 | + * Registers this version of Action Scheduler. |
|
40 | + */ |
|
41 | + function action_scheduler_register_3_dot_5_dot_3() { |
|
42 | + // WRCS: DEFINED_VERSION. |
|
43 | + $versions = ActionScheduler_Versions::instance(); |
|
44 | + $versions->register( '3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3' ); // WRCS: DEFINED_VERSION. |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Initializes this version of Action Scheduler. |
|
49 | - */ |
|
50 | - function action_scheduler_initialize_3_dot_5_dot_3() { |
|
51 | - // WRCS: DEFINED_VERSION. |
|
52 | - // A final safety check is required even here, because historic versions of Action Scheduler |
|
53 | - // followed a different pattern (in some unusual cases, we could reach this point and the |
|
54 | - // ActionScheduler class is already defined—so we need to guard against that). |
|
55 | - if ( ! class_exists( 'ActionScheduler', false ) ) { |
|
56 | - require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; |
|
57 | - ActionScheduler::init( __FILE__ ); |
|
58 | - } |
|
59 | - } |
|
47 | + /** |
|
48 | + * Initializes this version of Action Scheduler. |
|
49 | + */ |
|
50 | + function action_scheduler_initialize_3_dot_5_dot_3() { |
|
51 | + // WRCS: DEFINED_VERSION. |
|
52 | + // A final safety check is required even here, because historic versions of Action Scheduler |
|
53 | + // followed a different pattern (in some unusual cases, we could reach this point and the |
|
54 | + // ActionScheduler class is already defined—so we need to guard against that). |
|
55 | + if ( ! class_exists( 'ActionScheduler', false ) ) { |
|
56 | + require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; |
|
57 | + ActionScheduler::init( __FILE__ ); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - // Support usage in themes - load this version if no plugin has loaded a version yet. |
|
62 | - if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { |
|
63 | - action_scheduler_initialize_3_dot_5_dot_3(); // WRCS: DEFINED_VERSION. |
|
64 | - do_action( 'action_scheduler_pre_theme_init' ); |
|
65 | - ActionScheduler_Versions::initialize_latest_version(); |
|
66 | - } |
|
61 | + // Support usage in themes - load this version if no plugin has loaded a version yet. |
|
62 | + if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { |
|
63 | + action_scheduler_initialize_3_dot_5_dot_3(); // WRCS: DEFINED_VERSION. |
|
64 | + do_action( 'action_scheduler_pre_theme_init' ); |
|
65 | + ActionScheduler_Versions::initialize_latest_version(); |
|
66 | + } |
|
67 | 67 | } |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * @package ActionScheduler |
27 | 27 | */ |
28 | 28 | |
29 | -if ( ! function_exists( 'action_scheduler_register_3_dot_5_dot_3' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION. |
|
29 | +if ( ! function_exists('action_scheduler_register_3_dot_5_dot_3') && function_exists('add_action')) { // WRCS: DEFINED_VERSION. |
|
30 | 30 | |
31 | - if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { |
|
32 | - require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; |
|
33 | - add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
31 | + if ( ! class_exists('ActionScheduler_Versions', false)) { |
|
32 | + require_once __DIR__.'/classes/ActionScheduler_Versions.php'; |
|
33 | + add_action('plugins_loaded', array('ActionScheduler_Versions', 'initialize_latest_version'), 1, 0); |
|
34 | 34 | } |
35 | 35 | |
36 | - add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0 ); // WRCS: DEFINED_VERSION. |
|
36 | + add_action('plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0); // WRCS: DEFINED_VERSION. |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Registers this version of Action Scheduler. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | function action_scheduler_register_3_dot_5_dot_3() { |
42 | 42 | // WRCS: DEFINED_VERSION. |
43 | 43 | $versions = ActionScheduler_Versions::instance(); |
44 | - $versions->register( '3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3' ); // WRCS: DEFINED_VERSION. |
|
44 | + $versions->register('3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3'); // WRCS: DEFINED_VERSION. |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -52,16 +52,16 @@ discard block |
||
52 | 52 | // A final safety check is required even here, because historic versions of Action Scheduler |
53 | 53 | // followed a different pattern (in some unusual cases, we could reach this point and the |
54 | 54 | // ActionScheduler class is already defined—so we need to guard against that). |
55 | - if ( ! class_exists( 'ActionScheduler', false ) ) { |
|
56 | - require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; |
|
57 | - ActionScheduler::init( __FILE__ ); |
|
55 | + if ( ! class_exists('ActionScheduler', false)) { |
|
56 | + require_once __DIR__.'/classes/abstracts/ActionScheduler.php'; |
|
57 | + ActionScheduler::init(__FILE__); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Support usage in themes - load this version if no plugin has loaded a version yet. |
62 | - if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { |
|
62 | + if (did_action('plugins_loaded') && ! doing_action('plugins_loaded') && ! class_exists('ActionScheduler', false)) { |
|
63 | 63 | action_scheduler_initialize_3_dot_5_dot_3(); // WRCS: DEFINED_VERSION. |
64 | - do_action( 'action_scheduler_pre_theme_init' ); |
|
64 | + do_action('action_scheduler_pre_theme_init'); |
|
65 | 65 | ActionScheduler_Versions::initialize_latest_version(); |
66 | 66 | } |
67 | 67 | } |
@@ -9,102 +9,102 @@ |
||
9 | 9 | |
10 | 10 | class Sync_Background_Process extends Action_Scheduler_Background_Process { |
11 | 11 | |
12 | - const STATE_STARTED = 'started'; |
|
13 | - const STATE_STOPPED = 'stopped'; |
|
14 | - |
|
15 | - const HOOK_NAME = 'wl_dataset__sync'; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var Sync_Service |
|
19 | - */ |
|
20 | - private $sync_service; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var Sync_Object_Adapter_Factory |
|
24 | - */ |
|
25 | - private $sync_object_adapter_factory; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var Sync_Background_Process_State |
|
29 | - */ |
|
30 | - private $state; |
|
31 | - |
|
32 | - /** |
|
33 | - * Sync_Background_Process constructor. |
|
34 | - * |
|
35 | - * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
36 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
37 | - */ |
|
38 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
39 | - parent::__construct( self::HOOK_NAME, 'wordlift' ); |
|
40 | - $this->sync_service = $sync_service; |
|
41 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
42 | - |
|
43 | - // Set the current state. |
|
44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
46 | - } else { |
|
47 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function start() { |
|
52 | - $this->state->leave(); |
|
53 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
54 | - $this->state->enter(); |
|
55 | - $this->schedule(); |
|
56 | - } |
|
57 | - |
|
58 | - public function stop() { |
|
59 | - $this->state->leave(); |
|
60 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
61 | - $this->state->enter(); |
|
62 | - } |
|
63 | - |
|
64 | - public function resume() { |
|
65 | - $this->schedule(); |
|
66 | - $this->state->resume(); |
|
67 | - } |
|
68 | - |
|
69 | - public function do_task( $args ) { |
|
70 | - |
|
71 | - // Action scheduler might have pending tasks which can call this method. |
|
72 | - // So we need to check if the task should run or not |
|
73 | - if ( self::STATE_STOPPED === $this->get_state() ) { |
|
74 | - return State::complete(); |
|
75 | - } |
|
76 | - |
|
77 | - $result = $this->state->task( $args ); |
|
78 | - if ( ! $result->has_next() ) { |
|
79 | - $this->stop(); |
|
80 | - } |
|
81 | - return $result; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get the current state. |
|
86 | - * |
|
87 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
88 | - */ |
|
89 | - public function get_state() { |
|
90 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Persist the current state. |
|
95 | - * |
|
96 | - * @param string $value |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function set_state( $value ) { |
|
101 | - return null === $value |
|
102 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
103 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
104 | - } |
|
105 | - |
|
106 | - public function get_info() { |
|
107 | - return $this->state->get_info(); |
|
108 | - } |
|
12 | + const STATE_STARTED = 'started'; |
|
13 | + const STATE_STOPPED = 'stopped'; |
|
14 | + |
|
15 | + const HOOK_NAME = 'wl_dataset__sync'; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var Sync_Service |
|
19 | + */ |
|
20 | + private $sync_service; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var Sync_Object_Adapter_Factory |
|
24 | + */ |
|
25 | + private $sync_object_adapter_factory; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var Sync_Background_Process_State |
|
29 | + */ |
|
30 | + private $state; |
|
31 | + |
|
32 | + /** |
|
33 | + * Sync_Background_Process constructor. |
|
34 | + * |
|
35 | + * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
36 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
37 | + */ |
|
38 | + public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
39 | + parent::__construct( self::HOOK_NAME, 'wordlift' ); |
|
40 | + $this->sync_service = $sync_service; |
|
41 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
42 | + |
|
43 | + // Set the current state. |
|
44 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
46 | + } else { |
|
47 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function start() { |
|
52 | + $this->state->leave(); |
|
53 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
54 | + $this->state->enter(); |
|
55 | + $this->schedule(); |
|
56 | + } |
|
57 | + |
|
58 | + public function stop() { |
|
59 | + $this->state->leave(); |
|
60 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
61 | + $this->state->enter(); |
|
62 | + } |
|
63 | + |
|
64 | + public function resume() { |
|
65 | + $this->schedule(); |
|
66 | + $this->state->resume(); |
|
67 | + } |
|
68 | + |
|
69 | + public function do_task( $args ) { |
|
70 | + |
|
71 | + // Action scheduler might have pending tasks which can call this method. |
|
72 | + // So we need to check if the task should run or not |
|
73 | + if ( self::STATE_STOPPED === $this->get_state() ) { |
|
74 | + return State::complete(); |
|
75 | + } |
|
76 | + |
|
77 | + $result = $this->state->task( $args ); |
|
78 | + if ( ! $result->has_next() ) { |
|
79 | + $this->stop(); |
|
80 | + } |
|
81 | + return $result; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get the current state. |
|
86 | + * |
|
87 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
88 | + */ |
|
89 | + public function get_state() { |
|
90 | + return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Persist the current state. |
|
95 | + * |
|
96 | + * @param string $value |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function set_state( $value ) { |
|
101 | + return null === $value |
|
102 | + ? delete_option( '_wl_sync_background_process_state' ) |
|
103 | + : update_option( '_wl_sync_background_process_state', $value, true ); |
|
104 | + } |
|
105 | + |
|
106 | + public function get_info() { |
|
107 | + return $this->state->get_info(); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
@@ -35,29 +35,29 @@ discard block |
||
35 | 35 | * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
36 | 36 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
37 | 37 | */ |
38 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
39 | - parent::__construct( self::HOOK_NAME, 'wordlift' ); |
|
38 | + public function __construct($sync_service, $sync_object_adapter_factory) { |
|
39 | + parent::__construct(self::HOOK_NAME, 'wordlift'); |
|
40 | 40 | $this->sync_service = $sync_service; |
41 | 41 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
42 | 42 | |
43 | 43 | // Set the current state. |
44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
44 | + if (self::STATE_STARTED === $this->get_state()) { |
|
45 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
46 | 46 | } else { |
47 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
47 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | public function start() { |
52 | 52 | $this->state->leave(); |
53 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
53 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
54 | 54 | $this->state->enter(); |
55 | 55 | $this->schedule(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | public function stop() { |
59 | 59 | $this->state->leave(); |
60 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
60 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
61 | 61 | $this->state->enter(); |
62 | 62 | } |
63 | 63 | |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | $this->state->resume(); |
67 | 67 | } |
68 | 68 | |
69 | - public function do_task( $args ) { |
|
69 | + public function do_task($args) { |
|
70 | 70 | |
71 | 71 | // Action scheduler might have pending tasks which can call this method. |
72 | 72 | // So we need to check if the task should run or not |
73 | - if ( self::STATE_STOPPED === $this->get_state() ) { |
|
73 | + if (self::STATE_STOPPED === $this->get_state()) { |
|
74 | 74 | return State::complete(); |
75 | 75 | } |
76 | 76 | |
77 | - $result = $this->state->task( $args ); |
|
78 | - if ( ! $result->has_next() ) { |
|
77 | + $result = $this->state->task($args); |
|
78 | + if ( ! $result->has_next()) { |
|
79 | 79 | $this->stop(); |
80 | 80 | } |
81 | 81 | return $result; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
88 | 88 | */ |
89 | 89 | public function get_state() { |
90 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
90 | + return get_option('_wl_sync_background_process_state', self::STATE_STOPPED); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return bool |
99 | 99 | */ |
100 | - public function set_state( $value ) { |
|
100 | + public function set_state($value) { |
|
101 | 101 | return null === $value |
102 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
103 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
102 | + ? delete_option('_wl_sync_background_process_state') |
|
103 | + : update_option('_wl_sync_background_process_state', $value, true); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | public function get_info() { |
@@ -4,44 +4,44 @@ |
||
4 | 4 | |
5 | 5 | abstract class Action_Scheduler_Background_Process { |
6 | 6 | |
7 | - /** |
|
8 | - * @var string Hook name used for invoking the task method. |
|
9 | - */ |
|
10 | - private $hook; |
|
11 | - /** |
|
12 | - * @var string Group which would be used when |
|
13 | - */ |
|
14 | - private $group; |
|
15 | - |
|
16 | - public function __construct( $hook, $group ) { |
|
17 | - $this->hook = $hook; |
|
18 | - $this->group = $group; |
|
19 | - add_action( $this->hook, array( $this, 'task' ) ); |
|
20 | - } |
|
21 | - |
|
22 | - public function schedule( $args = array() ) { |
|
23 | - |
|
24 | - as_enqueue_async_action( $this->hook, $args, $this->group ); |
|
25 | - |
|
26 | - } |
|
27 | - |
|
28 | - public function unschedule() { |
|
29 | - as_unschedule_all_actions( $this->hook ); |
|
30 | - } |
|
31 | - |
|
32 | - public function task( $args = array() ) { |
|
33 | - $state = $this->do_task( $args ); |
|
34 | - if ( $state->has_next() ) { |
|
35 | - $this->schedule( $state->get_args() ); |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @param $args |
|
41 | - * |
|
42 | - * @return State The state object provides necessary information about |
|
43 | - * whether to schedule next event or stop processing. |
|
44 | - */ |
|
45 | - abstract public function do_task( $args ); |
|
7 | + /** |
|
8 | + * @var string Hook name used for invoking the task method. |
|
9 | + */ |
|
10 | + private $hook; |
|
11 | + /** |
|
12 | + * @var string Group which would be used when |
|
13 | + */ |
|
14 | + private $group; |
|
15 | + |
|
16 | + public function __construct( $hook, $group ) { |
|
17 | + $this->hook = $hook; |
|
18 | + $this->group = $group; |
|
19 | + add_action( $this->hook, array( $this, 'task' ) ); |
|
20 | + } |
|
21 | + |
|
22 | + public function schedule( $args = array() ) { |
|
23 | + |
|
24 | + as_enqueue_async_action( $this->hook, $args, $this->group ); |
|
25 | + |
|
26 | + } |
|
27 | + |
|
28 | + public function unschedule() { |
|
29 | + as_unschedule_all_actions( $this->hook ); |
|
30 | + } |
|
31 | + |
|
32 | + public function task( $args = array() ) { |
|
33 | + $state = $this->do_task( $args ); |
|
34 | + if ( $state->has_next() ) { |
|
35 | + $this->schedule( $state->get_args() ); |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @param $args |
|
41 | + * |
|
42 | + * @return State The state object provides necessary information about |
|
43 | + * whether to schedule next event or stop processing. |
|
44 | + */ |
|
45 | + abstract public function do_task( $args ); |
|
46 | 46 | |
47 | 47 | } |
@@ -13,26 +13,26 @@ discard block |
||
13 | 13 | */ |
14 | 14 | private $group; |
15 | 15 | |
16 | - public function __construct( $hook, $group ) { |
|
16 | + public function __construct($hook, $group) { |
|
17 | 17 | $this->hook = $hook; |
18 | 18 | $this->group = $group; |
19 | - add_action( $this->hook, array( $this, 'task' ) ); |
|
19 | + add_action($this->hook, array($this, 'task')); |
|
20 | 20 | } |
21 | 21 | |
22 | - public function schedule( $args = array() ) { |
|
22 | + public function schedule($args = array()) { |
|
23 | 23 | |
24 | - as_enqueue_async_action( $this->hook, $args, $this->group ); |
|
24 | + as_enqueue_async_action($this->hook, $args, $this->group); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
28 | 28 | public function unschedule() { |
29 | - as_unschedule_all_actions( $this->hook ); |
|
29 | + as_unschedule_all_actions($this->hook); |
|
30 | 30 | } |
31 | 31 | |
32 | - public function task( $args = array() ) { |
|
33 | - $state = $this->do_task( $args ); |
|
34 | - if ( $state->has_next() ) { |
|
35 | - $this->schedule( $state->get_args() ); |
|
32 | + public function task($args = array()) { |
|
33 | + $state = $this->do_task($args); |
|
34 | + if ($state->has_next()) { |
|
35 | + $this->schedule($state->get_args()); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -42,6 +42,6 @@ discard block |
||
42 | 42 | * @return State The state object provides necessary information about |
43 | 43 | * whether to schedule next event or stop processing. |
44 | 44 | */ |
45 | - abstract public function do_task( $args ); |
|
45 | + abstract public function do_task($args); |
|
46 | 46 | |
47 | 47 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | // If this file is called directly, abort. |
34 | 34 | if ( ! defined( 'WPINC' ) ) { |
35 | - die; |
|
35 | + die; |
|
36 | 36 | } |
37 | 37 | define( |
38 | - 'WORDLIFT_PLUGIN_FILE', |
|
39 | - __FILE__ |
|
38 | + 'WORDLIFT_PLUGIN_FILE', |
|
39 | + __FILE__ |
|
40 | 40 | ); |
41 | 41 | define( 'WORDLIFT_VERSION', '3.40.3' ); |
42 | 42 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @since 3.33.6 |
51 | 51 | */ |
52 | 52 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
53 | - return; |
|
53 | + return; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -79,33 +79,33 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function activate_wordlift() { |
81 | 81 | |
82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
82 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
83 | 83 | |
84 | - $log->info( 'Activating WordLift...' ); |
|
84 | + $log->info( 'Activating WordLift...' ); |
|
85 | 85 | |
86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
87 | - Wordlift_Activator::activate(); |
|
86 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
87 | + Wordlift_Activator::activate(); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
91 | - * |
|
92 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
93 | - * @since 3.19.2 |
|
94 | - */ |
|
95 | - Wordlift_Http_Api::activate(); |
|
96 | - |
|
97 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
98 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
99 | - flush_rewrite_rules(); |
|
100 | - /** |
|
101 | - * @since 3.27.7 |
|
102 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
103 | - */ |
|
104 | - Top_Entities::activate(); |
|
89 | + /** |
|
90 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
91 | + * |
|
92 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
93 | + * @since 3.19.2 |
|
94 | + */ |
|
95 | + Wordlift_Http_Api::activate(); |
|
96 | + |
|
97 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
98 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
99 | + flush_rewrite_rules(); |
|
100 | + /** |
|
101 | + * @since 3.27.7 |
|
102 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
103 | + */ |
|
104 | + Top_Entities::activate(); |
|
105 | 105 | |
106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
108 | - } |
|
106 | + if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | + wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | |
@@ -115,23 +115,23 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function deactivate_wordlift() { |
117 | 117 | |
118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
119 | - Wordlift_Deactivator::deactivate(); |
|
120 | - Wordlift_Http_Api::deactivate(); |
|
121 | - Ttl_Cache_Cleaner::deactivate(); |
|
122 | - /** |
|
123 | - * @since 3.27.7 |
|
124 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
125 | - */ |
|
126 | - Top_Entities::deactivate(); |
|
127 | - /** |
|
128 | - * @since 3.27.8 |
|
129 | - * Remove notification flag on deactivation. |
|
130 | - */ |
|
131 | - Key_Validation_Notice::remove_notification_flag(); |
|
132 | - flush_rewrite_rules(); |
|
133 | - |
|
134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
118 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
119 | + Wordlift_Deactivator::deactivate(); |
|
120 | + Wordlift_Http_Api::deactivate(); |
|
121 | + Ttl_Cache_Cleaner::deactivate(); |
|
122 | + /** |
|
123 | + * @since 3.27.7 |
|
124 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
125 | + */ |
|
126 | + Top_Entities::deactivate(); |
|
127 | + /** |
|
128 | + * @since 3.27.8 |
|
129 | + * Remove notification flag on deactivation. |
|
130 | + */ |
|
131 | + Key_Validation_Notice::remove_notification_flag(); |
|
132 | + flush_rewrite_rules(); |
|
133 | + |
|
134 | + wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | |
@@ -154,84 +154,84 @@ discard block |
||
154 | 154 | * @since 1.0.0 |
155 | 155 | */ |
156 | 156 | function run_wordlift() { |
157 | - /** |
|
158 | - * Filter: wl_feature__enable__widgets. |
|
159 | - * |
|
160 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - * @since 3.27.6 |
|
164 | - */ |
|
165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
169 | - } |
|
170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Filter: wl_feature__enable__analysis |
|
174 | - * |
|
175 | - * @param bool Whether to send api request to analysis or not |
|
176 | - * |
|
177 | - * @return bool |
|
178 | - * @since 3.27.6 |
|
179 | - */ |
|
180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
182 | - } else { |
|
183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
184 | - } |
|
185 | - |
|
186 | - $plugin = new Wordlift(); |
|
187 | - $plugin->run(); |
|
188 | - |
|
189 | - // Initialize the TTL Cache Cleaner. |
|
190 | - new Ttl_Cache_Cleaner(); |
|
191 | - |
|
192 | - // Load the new Post Adapter. |
|
193 | - new Post_Adapter(); |
|
194 | - |
|
195 | - // Load the API Data Hooks. |
|
196 | - new Api_Data_Hooks(); |
|
197 | - |
|
198 | - add_action( |
|
199 | - 'plugins_loaded', |
|
200 | - function () { |
|
201 | - // All features from registry should be initialized here. |
|
202 | - $features_registry = Features_Registry::get_instance(); |
|
203 | - $features_registry->initialize_all_features(); |
|
204 | - }, |
|
205 | - 5 |
|
206 | - ); |
|
207 | - |
|
208 | - add_action( |
|
209 | - 'plugins_loaded', |
|
210 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | - function () use ( $plugin ) { |
|
212 | - |
|
213 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
214 | - |
|
215 | - // Register the Dataset module, requires `$api_service`. |
|
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
218 | - |
|
219 | - /* |
|
157 | + /** |
|
158 | + * Filter: wl_feature__enable__widgets. |
|
159 | + * |
|
160 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + * @since 3.27.6 |
|
164 | + */ |
|
165 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
169 | + } |
|
170 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Filter: wl_feature__enable__analysis |
|
174 | + * |
|
175 | + * @param bool Whether to send api request to analysis or not |
|
176 | + * |
|
177 | + * @return bool |
|
178 | + * @since 3.27.6 |
|
179 | + */ |
|
180 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
182 | + } else { |
|
183 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
184 | + } |
|
185 | + |
|
186 | + $plugin = new Wordlift(); |
|
187 | + $plugin->run(); |
|
188 | + |
|
189 | + // Initialize the TTL Cache Cleaner. |
|
190 | + new Ttl_Cache_Cleaner(); |
|
191 | + |
|
192 | + // Load the new Post Adapter. |
|
193 | + new Post_Adapter(); |
|
194 | + |
|
195 | + // Load the API Data Hooks. |
|
196 | + new Api_Data_Hooks(); |
|
197 | + |
|
198 | + add_action( |
|
199 | + 'plugins_loaded', |
|
200 | + function () { |
|
201 | + // All features from registry should be initialized here. |
|
202 | + $features_registry = Features_Registry::get_instance(); |
|
203 | + $features_registry->initialize_all_features(); |
|
204 | + }, |
|
205 | + 5 |
|
206 | + ); |
|
207 | + |
|
208 | + add_action( |
|
209 | + 'plugins_loaded', |
|
210 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | + function () use ( $plugin ) { |
|
212 | + |
|
213 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
214 | + |
|
215 | + // Register the Dataset module, requires `$api_service`. |
|
216 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
218 | + |
|
219 | + /* |
|
220 | 220 | * Require the Entity annotation cleanup module. |
221 | 221 | * |
222 | 222 | * @since 3.34.6 |
223 | 223 | */ |
224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
224 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
225 | 225 | |
226 | - /* |
|
226 | + /* |
|
227 | 227 | * Import LOD entities. |
228 | 228 | * |
229 | 229 | * @since 3.35.0 |
230 | 230 | */ |
231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
231 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
232 | 232 | |
233 | - } |
|
234 | - ); |
|
233 | + } |
|
234 | + ); |
|
235 | 235 | |
236 | 236 | } |
237 | 237 | |
@@ -245,45 +245,45 @@ discard block |
||
245 | 245 | */ |
246 | 246 | function wordlift_plugin_autoload_register() { |
247 | 247 | |
248 | - spl_autoload_register( |
|
249 | - function ( $class_name ) { |
|
248 | + spl_autoload_register( |
|
249 | + function ( $class_name ) { |
|
250 | 250 | |
251 | - // Bail out if these are not our classes. |
|
252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
253 | - return false; |
|
254 | - } |
|
251 | + // Bail out if these are not our classes. |
|
252 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
253 | + return false; |
|
254 | + } |
|
255 | 255 | |
256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
256 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
257 | 257 | |
258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
258 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
259 | 259 | |
260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | - $file = 'class-' . $matches[2] . '.php'; |
|
260 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | + $file = 'class-' . $matches[2] . '.php'; |
|
262 | 262 | |
263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
263 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
264 | 264 | |
265 | - if ( ! file_exists( $full_path ) ) { |
|
266 | - return false; |
|
267 | - } |
|
265 | + if ( ! file_exists( $full_path ) ) { |
|
266 | + return false; |
|
267 | + } |
|
268 | 268 | |
269 | - require_once $full_path; |
|
269 | + require_once $full_path; |
|
270 | 270 | |
271 | - return true; |
|
272 | - } |
|
273 | - ); |
|
271 | + return true; |
|
272 | + } |
|
273 | + ); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | 277 | function wl_block_categories( $categories ) { |
278 | - return array_merge( |
|
279 | - $categories, |
|
280 | - array( |
|
281 | - array( |
|
282 | - 'slug' => 'wordlift', |
|
283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
284 | - ), |
|
285 | - ) |
|
286 | - ); |
|
278 | + return array_merge( |
|
279 | + $categories, |
|
280 | + array( |
|
281 | + array( |
|
282 | + 'slug' => 'wordlift', |
|
283 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
284 | + ), |
|
285 | + ) |
|
286 | + ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
292 | 292 | */ |
293 | 293 | function wl_enqueue_leaflet( $in_footer = false ) { |
294 | - // Leaflet. |
|
295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
294 | + // Leaflet. |
|
295 | + wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | + wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | add_filter( 'block_categories', 'wl_block_categories', 10 ); |
300 | 300 | |
301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
302 | 302 | add_filter( |
303 | - 'wl_feature__enable__dataset', |
|
304 | - function ( $value ) { |
|
305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | - } |
|
303 | + 'wl_feature__enable__dataset', |
|
304 | + function ( $value ) { |
|
305 | + return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | + } |
|
307 | 307 | ); |
308 | 308 | |
309 | 309 | require_once __DIR__ . '/modules/food-kg/load.php'; |
@@ -312,26 +312,26 @@ discard block |
||
312 | 312 | require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
313 | 313 | |
314 | 314 | add_action( |
315 | - 'update_plugins_adthrive.wordlift.io', |
|
316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
317 | - // Bail out if it's not our plugin. |
|
318 | - $update_uri = $plugin_data['UpdateURI']; |
|
319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
320 | - return $update; |
|
321 | - } |
|
322 | - |
|
323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
324 | - |
|
325 | - if ( is_wp_error( $response ) ) { |
|
326 | - return $update; |
|
327 | - } |
|
328 | - |
|
329 | - try { |
|
330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | - } catch ( Exception $e ) { |
|
332 | - return $update; |
|
333 | - } |
|
334 | - }, |
|
335 | - 10, |
|
336 | - 3 |
|
315 | + 'update_plugins_adthrive.wordlift.io', |
|
316 | + function ( $update, $plugin_data, $plugin_file ) { |
|
317 | + // Bail out if it's not our plugin. |
|
318 | + $update_uri = $plugin_data['UpdateURI']; |
|
319 | + if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
320 | + return $update; |
|
321 | + } |
|
322 | + |
|
323 | + $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
324 | + |
|
325 | + if ( is_wp_error( $response ) ) { |
|
326 | + return $update; |
|
327 | + } |
|
328 | + |
|
329 | + try { |
|
330 | + return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | + } catch ( Exception $e ) { |
|
332 | + return $update; |
|
333 | + } |
|
334 | + }, |
|
335 | + 10, |
|
336 | + 3 |
|
337 | 337 | ); |
@@ -31,29 +31,29 @@ discard block |
||
31 | 31 | use Wordlift\Features\Features_Registry; |
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | // If this file is called directly, abort. |
34 | -if ( ! defined( 'WPINC' ) ) { |
|
34 | +if ( ! defined('WPINC')) { |
|
35 | 35 | die; |
36 | 36 | } |
37 | 37 | define( |
38 | 38 | 'WORDLIFT_PLUGIN_FILE', |
39 | 39 | __FILE__ |
40 | 40 | ); |
41 | -define( 'WORDLIFT_VERSION', '3.40.3' ); |
|
41 | +define('WORDLIFT_VERSION', '3.40.3'); |
|
42 | 42 | |
43 | -require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php'; |
|
44 | -require_once __DIR__ . '/modules/common/load.php'; |
|
45 | -require_once __DIR__ . '/modules/include-exclude/load.php'; |
|
43 | +require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php'; |
|
44 | +require_once __DIR__.'/modules/common/load.php'; |
|
45 | +require_once __DIR__.'/modules/include-exclude/load.php'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Filter to disable WLP on any request, defaults to true. |
49 | 49 | * |
50 | 50 | * @since 3.33.6 |
51 | 51 | */ |
52 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
52 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
56 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
57 | 57 | |
58 | 58 | /* |
59 | 59 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | wordlift_plugin_autoload_register(); |
64 | 64 | |
65 | 65 | // Include WordLift constants. |
66 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php'; |
|
66 | +require_once plugin_dir_path(__FILE__).'wordlift-constants.php'; |
|
67 | 67 | |
68 | 68 | // Load modules. |
69 | -require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php'; |
|
69 | +require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php'; |
|
70 | 70 | |
71 | -require_once plugin_dir_path( __FILE__ ) . 'deprecations.php'; |
|
71 | +require_once plugin_dir_path(__FILE__).'deprecations.php'; |
|
72 | 72 | |
73 | 73 | // Load early to enable/disable features. |
74 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
74 | +require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * The code that runs during plugin activation. |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function activate_wordlift() { |
81 | 81 | |
82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
82 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
83 | 83 | |
84 | - $log->info( 'Activating WordLift...' ); |
|
84 | + $log->info('Activating WordLift...'); |
|
85 | 85 | |
86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
86 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
87 | 87 | Wordlift_Activator::activate(); |
88 | 88 | |
89 | 89 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | Top_Entities::activate(); |
105 | 105 | |
106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
106 | + if ( ! wp_next_scheduled('wl_daily_cron')) { |
|
107 | + wp_schedule_event(time(), 'daily', 'wl_daily_cron'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function deactivate_wordlift() { |
117 | 117 | |
118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
118 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
119 | 119 | Wordlift_Deactivator::deactivate(); |
120 | 120 | Wordlift_Http_Api::deactivate(); |
121 | 121 | Ttl_Cache_Cleaner::deactivate(); |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | Key_Validation_Notice::remove_notification_flag(); |
132 | 132 | flush_rewrite_rules(); |
133 | 133 | |
134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
134 | + wp_clear_scheduled_hook('wl_daily_cron'); |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | |
138 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
139 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
138 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
139 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * The core plugin class that is used to define internationalization, |
143 | 143 | * admin-specific hooks, and public-facing site hooks. |
144 | 144 | */ |
145 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
145 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Begins execution of the plugin. |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | * @return bool |
163 | 163 | * @since 3.27.6 |
164 | 164 | */ |
165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
165 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
166 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
167 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
168 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
169 | 169 | } |
170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
170 | + add_filter('widget_text', 'do_shortcode'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Filter: wl_feature__enable__analysis |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | * @return bool |
178 | 178 | * @since 3.27.6 |
179 | 179 | */ |
180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
180 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
181 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
182 | 182 | } else { |
183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
183 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $plugin = new Wordlift(); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | add_action( |
199 | 199 | 'plugins_loaded', |
200 | - function () { |
|
200 | + function() { |
|
201 | 201 | // All features from registry should be initialized here. |
202 | 202 | $features_registry = Features_Registry::get_instance(); |
203 | 203 | $features_registry->initialize_all_features(); |
@@ -208,27 +208,27 @@ discard block |
||
208 | 208 | add_action( |
209 | 209 | 'plugins_loaded', |
210 | 210 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
211 | - function () use ( $plugin ) { |
|
211 | + function() use ($plugin) { |
|
212 | 212 | |
213 | 213 | new Wordlift_Products_Navigator_Shortcode_REST(); |
214 | 214 | |
215 | 215 | // Register the Dataset module, requires `$api_service`. |
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
216 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
217 | + require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php'; |
|
218 | 218 | |
219 | 219 | /* |
220 | 220 | * Require the Entity annotation cleanup module. |
221 | 221 | * |
222 | 222 | * @since 3.34.6 |
223 | 223 | */ |
224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
224 | + require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php'; |
|
225 | 225 | |
226 | 226 | /* |
227 | 227 | * Import LOD entities. |
228 | 228 | * |
229 | 229 | * @since 3.35.0 |
230 | 230 | */ |
231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
231 | + require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php'; |
|
232 | 232 | |
233 | 233 | } |
234 | 234 | ); |
@@ -246,23 +246,23 @@ discard block |
||
246 | 246 | function wordlift_plugin_autoload_register() { |
247 | 247 | |
248 | 248 | spl_autoload_register( |
249 | - function ( $class_name ) { |
|
249 | + function($class_name) { |
|
250 | 250 | |
251 | 251 | // Bail out if these are not our classes. |
252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
252 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
253 | 253 | return false; |
254 | 254 | } |
255 | 255 | |
256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
256 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
257 | 257 | |
258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
258 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
259 | 259 | |
260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | - $file = 'class-' . $matches[2] . '.php'; |
|
260 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
261 | + $file = 'class-'.$matches[2].'.php'; |
|
262 | 262 | |
263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
263 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
264 | 264 | |
265 | - if ( ! file_exists( $full_path ) ) { |
|
265 | + if ( ! file_exists($full_path)) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | -function wl_block_categories( $categories ) { |
|
277 | +function wl_block_categories($categories) { |
|
278 | 278 | return array_merge( |
279 | 279 | $categories, |
280 | 280 | array( |
281 | 281 | array( |
282 | 282 | 'slug' => 'wordlift', |
283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
283 | + 'title' => __('WordLift', 'wordlift'), |
|
284 | 284 | ), |
285 | 285 | ) |
286 | 286 | ); |
@@ -290,45 +290,45 @@ discard block |
||
290 | 290 | * This function is created temporarily to handle the legacy library, |
291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
292 | 292 | */ |
293 | -function wl_enqueue_leaflet( $in_footer = false ) { |
|
293 | +function wl_enqueue_leaflet($in_footer = false) { |
|
294 | 294 | // Leaflet. |
295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
295 | + wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0'); |
|
296 | + wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer); |
|
297 | 297 | } |
298 | 298 | |
299 | -add_filter( 'block_categories', 'wl_block_categories', 10 ); |
|
299 | +add_filter('block_categories', 'wl_block_categories', 10); |
|
300 | 300 | |
301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
302 | 302 | add_filter( |
303 | 303 | 'wl_feature__enable__dataset', |
304 | - function ( $value ) { |
|
305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
304 | + function($value) { |
|
305 | + return apply_filters('wl_features__enable__dataset', $value); |
|
306 | 306 | } |
307 | 307 | ); |
308 | 308 | |
309 | -require_once __DIR__ . '/modules/food-kg/load.php'; |
|
310 | -require_once __DIR__ . '/modules/acf4so/load.php'; |
|
311 | -require_once __DIR__ . '/modules/pods/load.php'; |
|
312 | -require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
|
309 | +require_once __DIR__.'/modules/food-kg/load.php'; |
|
310 | +require_once __DIR__.'/modules/acf4so/load.php'; |
|
311 | +require_once __DIR__.'/modules/pods/load.php'; |
|
312 | +require_once __DIR__.'/modules/include-exclude-push-config/load.php'; |
|
313 | 313 | |
314 | 314 | add_action( |
315 | 315 | 'update_plugins_adthrive.wordlift.io', |
316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
316 | + function($update, $plugin_data, $plugin_file) { |
|
317 | 317 | // Bail out if it's not our plugin. |
318 | 318 | $update_uri = $plugin_data['UpdateURI']; |
319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
319 | + if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) { |
|
320 | 320 | return $update; |
321 | 321 | } |
322 | 322 | |
323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
323 | + $response = wp_remote_get("$update_uri?nocache=".time()); |
|
324 | 324 | |
325 | - if ( is_wp_error( $response ) ) { |
|
325 | + if (is_wp_error($response)) { |
|
326 | 326 | return $update; |
327 | 327 | } |
328 | 328 | |
329 | 329 | try { |
330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | - } catch ( Exception $e ) { |
|
330 | + return json_decode(wp_remote_retrieve_body($response)); |
|
331 | + } catch (Exception $e) { |
|
332 | 332 | return $update; |
333 | 333 | } |
334 | 334 | }, |