Skip to content

Commit 97e045e

Browse files
committed
Merge branch 'trunk' into phpcs/ActionScheduler_wpCommentLogger_Test.php
# Conflicts: # phpcs.xml
2 parents ea715ad + 7181366 commit 97e045e

File tree

4 files changed

+75
-38
lines changed

4 files changed

+75
-38
lines changed

classes/data-stores/ActionScheduler_HybridStore.php

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,32 @@
1515
class ActionScheduler_HybridStore extends Store {
1616
const DEMARKATION_OPTION = 'action_scheduler_hybrid_store_demarkation';
1717

18-
/** @var ActionScheduler_Store */
18+
/**
19+
* Primary store instance.
20+
*
21+
* @var ActionScheduler_Store
22+
*/
1923
private $primary_store;
20-
/** @var ActionScheduler_Store */
24+
25+
/**
26+
* Secondary store instance.
27+
*
28+
* @var ActionScheduler_Store
29+
*/
2130
private $secondary_store;
22-
/** @var Action_Scheduler\Migration\Runner */
31+
32+
/**
33+
* Runner instance.
34+
*
35+
* @var Action_Scheduler\Migration\Runner
36+
*/
2337
private $migration_runner;
2438

2539
/**
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
2844
*
2945
* Methods that accept an action ID will compare the ID against
3046
* this to determine which store will contain that ID. In almost
@@ -56,10 +72,10 @@ public function __construct( Config $config = null ) {
5672
* @codeCoverageIgnore
5773
*/
5874
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 );
6076
$this->primary_store->init();
6177
$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 );
6379
}
6480

6581
/**
@@ -78,8 +94,14 @@ public function set_autoincrement( $table_name, $table_suffix ) {
7894
if ( empty( $this->demarkation_id ) ) {
7995
$this->demarkation_id = $this->set_demarkation_id();
8096
}
81-
/** @var \wpdb $wpdb */
97+
98+
/**
99+
* Global.
100+
*
101+
* @var \wpdb $wpdb
102+
*/
82103
global $wpdb;
104+
83105
/**
84106
* A default date of '0000-00-00 00:00:00' is invalid in MySQL 5.7 when configured with
85107
* sql_mode including both STRICT_TRANS_TABLES and NO_ZERO_DATE.
@@ -91,20 +113,20 @@ public function set_autoincrement( $table_name, $table_suffix ) {
91113

92114
$row_count = $wpdb->insert(
93115
$wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
94-
[
116+
array(
95117
'action_id' => $this->demarkation_id,
96118
'hook' => '',
97119
'status' => '',
98120
'scheduled_date_gmt' => $date_gmt,
99121
'scheduled_date_local' => $date_local,
100122
'last_attempt_gmt' => $date_gmt,
101123
'last_attempt_local' => $date_local,
102-
]
124+
)
103125
);
104126
if ( $row_count > 0 ) {
105127
$wpdb->delete(
106128
$wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
107-
[ 'action_id' => $this->demarkation_id ]
129+
array( 'action_id' => $this->demarkation_id )
108130
);
109131
}
110132
}
@@ -122,10 +144,15 @@ public function set_autoincrement( $table_name, $table_suffix ) {
122144
*/
123145
private function set_demarkation_id( $id = null ) {
124146
if ( empty( $id ) ) {
125-
/** @var \wpdb $wpdb */
147+
/**
148+
* Global.
149+
*
150+
* @var \wpdb $wpdb
151+
*/
126152
global $wpdb;
153+
127154
$id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" );
128-
$id ++;
155+
$id++;
129156
}
130157
update_option( self::DEMARKATION_OPTION, $id );
131158

@@ -143,10 +170,10 @@ private function set_demarkation_id( $id = null ) {
143170
*
144171
* @return string
145172
*/
146-
public function find_action( $hook, $params = [] ) {
173+
public function find_action( $hook, $params = array() ) {
147174
$found_unmigrated_action = $this->secondary_store->find_action( $hook, $params );
148175
if ( ! empty( $found_unmigrated_action ) ) {
149-
$this->migrate( [ $found_unmigrated_action ] );
176+
$this->migrate( array( $found_unmigrated_action ) );
150177
}
151178

152179
return $this->primary_store->find_action( $hook, $params );
@@ -162,7 +189,7 @@ public function find_action( $hook, $params = [] ) {
162189
*
163190
* @return int[]
164191
*/
165-
public function query_actions( $query = [], $query_type = 'select' ) {
192+
public function query_actions( $query = array(), $query_type = 'select' ) {
166193
$found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' );
167194
if ( ! empty( $found_unmigrated_actions ) ) {
168195
$this->migrate( $found_unmigrated_actions );
@@ -357,19 +384,19 @@ public function get_status( $action_id ) {
357384
*/
358385
protected function get_store_from_action_id( $action_id, $primary_first = false ) {
359386
if ( $primary_first ) {
360-
$stores = [
387+
$stores = array(
361388
$this->primary_store,
362389
$this->secondary_store,
363-
];
390+
);
364391
} elseif ( $action_id < $this->demarkation_id ) {
365-
$stores = [
392+
$stores = array(
366393
$this->secondary_store,
367394
$this->primary_store,
368-
];
395+
);
369396
} else {
370-
$stores = [
397+
$stores = array(
371398
$this->primary_store,
372-
];
399+
);
373400
}
374401

375402
foreach ( $stores as $store ) {

classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* Class ActionScheduler_wpPostStore_PostStatusRegistrar
5+
*
56
* @codeCoverageIgnore
67
*/
78
class ActionScheduler_wpPostStore_PostStatusRegistrar {

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
<rule ref="PEAR.NamingConventions.ValidClassName">
5252
<exclude-pattern>tests/phpunit/logging/ActionScheduler_wpCommentLogger_Test.php</exclude-pattern>
53+
<exclude-pattern>classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php</exclude-pattern>
5354
<exclude-pattern>classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php</exclude-pattern>
5455
<exclude-pattern>tests/phpunit/jobstore/ActionScheduler_wpPostStore_Test.php</exclude-pattern>
5556
<exclude-pattern>classes/data-stores/ActionScheduler_wpCommentLogger.php</exclude-pattern>

tests/phpunit/migration/LogMigrator_Test.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
* @group migration
88
*/
99
class LogMigrator_Test extends ActionScheduler_UnitTestCase {
10-
function setUp() {
10+
public function setUp() {
1111
parent::setUp();
12-
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
13-
// register the post type and taxonomy necessary for the store to work
12+
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
13+
// register the post type and taxonomy necessary for the store to work.
1414
$store = new ActionScheduler_wpPostStore();
1515
$store->init();
1616
}
1717
}
1818

1919
public function test_migrate_from_wpComment_to_db() {
20-
$source = new ActionScheduler_wpCommentLogger();
21-
$destination = new ActionScheduler_DBLogger();
22-
$migrator = new LogMigrator( $source, $destination );
23-
$source_action_id = rand( 10, 10000 );
24-
$destination_action_id = rand( 10, 10000 );
20+
$source = new ActionScheduler_wpCommentLogger();
21+
$destination = new ActionScheduler_DBLogger();
22+
$migrator = new LogMigrator( $source, $destination );
23+
$source_action_id = wp_rand( 10, 10000 );
24+
$destination_action_id = wp_rand( 10, 10000 );
2525

26-
$logs = [];
27-
for ( $i = 0 ; $i < 3 ; $i++ ) {
28-
for ( $j = 0 ; $j < 5 ; $j++ ) {
29-
$logs[ $i ][ $j ] = md5(rand());
30-
if ( $i == 1 ) {
26+
$logs = array();
27+
for ( $i = 0; $i < 3; $i++ ) {
28+
for ( $j = 0; $j < 5; $j++ ) {
29+
$logs[ $i ][ $j ] = md5( wp_rand() );
30+
if ( 1 === $i ) {
3131
$source->log( $source_action_id, $logs[ $i ][ $j ] );
3232
}
3333
}
@@ -36,9 +36,17 @@ public function test_migrate_from_wpComment_to_db() {
3636
$migrator->migrate( $source_action_id, $destination_action_id );
3737

3838
$migrated = $destination->get_logs( $destination_action_id );
39-
$this->assertEqualSets( $logs[ 1 ], array_map( function( $log ) { return $log->get_message(); }, $migrated ) );
39+
$this->assertEqualSets(
40+
$logs[1],
41+
array_map(
42+
function( $log ) {
43+
return $log->get_message();
44+
},
45+
$migrated
46+
)
47+
);
4048

41-
// no API for deleting logs, so we leave them for manual cleanup later
49+
// no API for deleting logs, so we leave them for manual cleanup later.
4250
$this->assertCount( 5, $source->get_logs( $source_action_id ) );
4351
}
44-
}
52+
}

0 commit comments

Comments
 (0)