15
15
class ActionScheduler_HybridStore extends Store {
16
16
const DEMARKATION_OPTION = 'action_scheduler_hybrid_store_demarkation ' ;
17
17
18
- /** @var ActionScheduler_Store */
18
+ /**
19
+ * Primary store instance.
20
+ *
21
+ * @var ActionScheduler_Store
22
+ */
19
23
private $ primary_store ;
20
- /** @var ActionScheduler_Store */
24
+
25
+ /**
26
+ * Secondary store instance.
27
+ *
28
+ * @var ActionScheduler_Store
29
+ */
21
30
private $ secondary_store ;
22
- /** @var Action_Scheduler\Migration\Runner */
31
+
32
+ /**
33
+ * Runner instance.
34
+ *
35
+ * @var Action_Scheduler\Migration\Runner
36
+ */
23
37
private $ migration_runner ;
24
38
25
39
/**
26
- * @var int The dividing line between IDs of actions created
27
- * by the primary and secondary stores.
40
+ * The dividing line between IDs of actions created
41
+ * by the primary and secondary stores.
42
+ *
43
+ * @var int
28
44
*
29
45
* Methods that accept an action ID will compare the ID against
30
46
* this to determine which store will contain that ID. In almost
@@ -56,10 +72,10 @@ public function __construct( Config $config = null ) {
56
72
* @codeCoverageIgnore
57
73
*/
58
74
public function init () {
59
- add_action ( 'action_scheduler/created_table ' , [ $ this , 'set_autoincrement ' ] , 10 , 2 );
75
+ add_action ( 'action_scheduler/created_table ' , array ( $ this , 'set_autoincrement ' ) , 10 , 2 );
60
76
$ this ->primary_store ->init ();
61
77
$ this ->secondary_store ->init ();
62
- remove_action ( 'action_scheduler/created_table ' , [ $ this , 'set_autoincrement ' ] , 10 );
78
+ remove_action ( 'action_scheduler/created_table ' , array ( $ this , 'set_autoincrement ' ) , 10 );
63
79
}
64
80
65
81
/**
@@ -78,8 +94,14 @@ public function set_autoincrement( $table_name, $table_suffix ) {
78
94
if ( empty ( $ this ->demarkation_id ) ) {
79
95
$ this ->demarkation_id = $ this ->set_demarkation_id ();
80
96
}
81
- /** @var \wpdb $wpdb */
97
+
98
+ /**
99
+ * Global.
100
+ *
101
+ * @var \wpdb $wpdb
102
+ */
82
103
global $ wpdb ;
104
+
83
105
/**
84
106
* A default date of '0000-00-00 00:00:00' is invalid in MySQL 5.7 when configured with
85
107
* sql_mode including both STRICT_TRANS_TABLES and NO_ZERO_DATE.
@@ -91,20 +113,20 @@ public function set_autoincrement( $table_name, $table_suffix ) {
91
113
92
114
$ row_count = $ wpdb ->insert (
93
115
$ wpdb ->{ActionScheduler_StoreSchema::ACTIONS_TABLE },
94
- [
116
+ array (
95
117
'action_id ' => $ this ->demarkation_id ,
96
118
'hook ' => '' ,
97
119
'status ' => '' ,
98
120
'scheduled_date_gmt ' => $ date_gmt ,
99
121
'scheduled_date_local ' => $ date_local ,
100
122
'last_attempt_gmt ' => $ date_gmt ,
101
123
'last_attempt_local ' => $ date_local ,
102
- ]
124
+ )
103
125
);
104
126
if ( $ row_count > 0 ) {
105
127
$ wpdb ->delete (
106
128
$ wpdb ->{ActionScheduler_StoreSchema::ACTIONS_TABLE },
107
- [ 'action_id ' => $ this ->demarkation_id ]
129
+ array ( 'action_id ' => $ this ->demarkation_id )
108
130
);
109
131
}
110
132
}
@@ -122,10 +144,15 @@ public function set_autoincrement( $table_name, $table_suffix ) {
122
144
*/
123
145
private function set_demarkation_id ( $ id = null ) {
124
146
if ( empty ( $ id ) ) {
125
- /** @var \wpdb $wpdb */
147
+ /**
148
+ * Global.
149
+ *
150
+ * @var \wpdb $wpdb
151
+ */
126
152
global $ wpdb ;
153
+
127
154
$ id = (int ) $ wpdb ->get_var ( "SELECT MAX(ID) FROM $ wpdb ->posts " );
128
- $ id ++;
155
+ $ id ++;
129
156
}
130
157
update_option ( self ::DEMARKATION_OPTION , $ id );
131
158
@@ -143,10 +170,10 @@ private function set_demarkation_id( $id = null ) {
143
170
*
144
171
* @return string
145
172
*/
146
- public function find_action ( $ hook , $ params = [] ) {
173
+ public function find_action ( $ hook , $ params = array () ) {
147
174
$ found_unmigrated_action = $ this ->secondary_store ->find_action ( $ hook , $ params );
148
175
if ( ! empty ( $ found_unmigrated_action ) ) {
149
- $ this ->migrate ( [ $ found_unmigrated_action ] );
176
+ $ this ->migrate ( array ( $ found_unmigrated_action ) );
150
177
}
151
178
152
179
return $ this ->primary_store ->find_action ( $ hook , $ params );
@@ -162,7 +189,7 @@ public function find_action( $hook, $params = [] ) {
162
189
*
163
190
* @return int[]
164
191
*/
165
- public function query_actions ( $ query = [] , $ query_type = 'select ' ) {
192
+ public function query_actions ( $ query = array () , $ query_type = 'select ' ) {
166
193
$ found_unmigrated_actions = $ this ->secondary_store ->query_actions ( $ query , 'select ' );
167
194
if ( ! empty ( $ found_unmigrated_actions ) ) {
168
195
$ this ->migrate ( $ found_unmigrated_actions );
@@ -357,19 +384,19 @@ public function get_status( $action_id ) {
357
384
*/
358
385
protected function get_store_from_action_id ( $ action_id , $ primary_first = false ) {
359
386
if ( $ primary_first ) {
360
- $ stores = [
387
+ $ stores = array (
361
388
$ this ->primary_store ,
362
389
$ this ->secondary_store ,
363
- ] ;
390
+ ) ;
364
391
} elseif ( $ action_id < $ this ->demarkation_id ) {
365
- $ stores = [
392
+ $ stores = array (
366
393
$ this ->secondary_store ,
367
394
$ this ->primary_store ,
368
- ] ;
395
+ ) ;
369
396
} else {
370
- $ stores = [
397
+ $ stores = array (
371
398
$ this ->primary_store ,
372
- ] ;
399
+ ) ;
373
400
}
374
401
375
402
foreach ( $ stores as $ store ) {
0 commit comments