Skip to content

Commit 3222b69

Browse files
committed
Merge branch 'trunk' into fix-forum-17945942
2 parents 716cf60 + ef1021e commit 3222b69

17 files changed

+325
-164
lines changed

.github/workflows/pr-unit-tests.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ jobs:
1111
matrix:
1212
# We test against the earliest and latest PHP versions for each major supported version.
1313
php: [ '7.0', '7.4', '8.0', '8.3' ]
14-
wp: [ '6.4', '6.5', 'latest', 'nightly' ]
14+
wp: [ '6.4', '6.5', '6.6', 'latest', 'nightly' ]
1515
multisite: [ '0', '1' ]
1616
exclude:
1717
# WordPress 6.6+ requires PHP 7.2+
18+
- php: 7.0
19+
wp: 6.6
1820
- php: 7.0
1921
wp: latest
2022
- php: 7.0
@@ -44,14 +46,19 @@ jobs:
4446
php --version
4547
composer --version
4648
47-
- name: Get cached composer directories
48-
uses: actions/cache@v2
49+
- name: Get composer cache directory
50+
id: composer-cache
51+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
52+
53+
- name: Cache dependencies
54+
uses: actions/cache@v4
4955
with:
50-
path: ./vendor
51-
key: ${{ runner.os }}-${{ hashFiles('./composer.lock') }}
56+
path: ${{ steps.composer-cache.outputs.dir }}
57+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
58+
restore-keys: ${{ runner.os }}-composer-
5259

53-
- name: Setup and install composer
54-
run: composer install
60+
- name: Install dependencies
61+
run: composer install --prefer-dist
5562

5663
- name: Setup PHPUnit
5764
run: |

action-scheduler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Version: 3.8.2
99
* License: GPLv3
1010
* Requires at least: 6.4
11-
* Tested up to: 6.6
11+
* Tested up to: 6.7
1212
* Requires PHP: 7.0
1313
*
1414
* Copyright 2019 Automattic, Inc. (https://automattic.com/contact/)

classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public function run( $args, $assoc_args ) {
9191

9292
$batches_completed = 0;
9393
$actions_completed = 0;
94-
$unlimited = $batches === 0;
95-
if ( is_callable( [ ActionScheduler::store(), 'set_claim_filter' ] ) ) {
94+
$unlimited = 0 === $batches;
95+
if ( is_callable( array( ActionScheduler::store(), 'set_claim_filter' ) ) ) {
9696
$exclude_groups = $this->parse_comma_separated_string( $exclude_groups );
9797

9898
if ( ! empty( $exclude_groups ) ) {
99-
ActionScheduler::store()->set_claim_filter('exclude-groups', $exclude_groups );
99+
ActionScheduler::store()->set_claim_filter( 'exclude-groups', $exclude_groups );
100100
}
101101
}
102102

@@ -141,8 +141,6 @@ private function parse_comma_separated_string( $string ): array {
141141
/**
142142
* Print WP CLI message about how many actions are about to be processed.
143143
*
144-
* @author Jeremy Pry
145-
*
146144
* @param int $total Number of actions found.
147145
*/
148146
protected function print_total_actions( $total ) {
@@ -158,8 +156,6 @@ protected function print_total_actions( $total ) {
158156
/**
159157
* Print WP CLI message about how many batches of actions were processed.
160158
*
161-
* @author Jeremy Pry
162-
*
163159
* @param int $batches_completed Number of completed batches.
164160
*/
165161
protected function print_total_batches( $batches_completed ) {
@@ -175,11 +171,9 @@ protected function print_total_batches( $batches_completed ) {
175171
/**
176172
* Convert an exception into a WP CLI error.
177173
*
178-
* @author Jeremy Pry
179-
*
180174
* @param Exception $e The error object.
181175
*
182-
* @throws \WP_CLI\ExitException
176+
* @throws \WP_CLI\ExitException Under some conditions WP CLI may throw an exception.
183177
*/
184178
protected function print_error( Exception $e ) {
185179
WP_CLI::error(
@@ -194,8 +188,6 @@ protected function print_error( Exception $e ) {
194188
/**
195189
* Print a success message with the number of completed actions.
196190
*
197-
* @author Jeremy Pry
198-
*
199191
* @param int $actions_completed Number of completed actions.
200192
*/
201193
protected function print_success( $actions_completed ) {

classes/WP_CLI/ProgressBar.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,39 @@
1717
*/
1818
class ProgressBar {
1919

20-
/** @var integer */
20+
/**
21+
* Current number of ticks.
22+
*
23+
* @var integer
24+
*/
2125
protected $total_ticks;
2226

23-
/** @var integer */
27+
/**
28+
* Total number of ticks.
29+
*
30+
* @var integer
31+
*/
2432
protected $count;
2533

26-
/** @var integer */
34+
/**
35+
* Progress bar update interval.
36+
*
37+
* @var integer
38+
*/
2739
protected $interval;
2840

29-
/** @var string */
41+
/**
42+
* Progress bar message.
43+
*
44+
* @var string
45+
*/
3046
protected $message;
3147

32-
/** @var \cli\progress\Bar */
48+
/**
49+
* Instance.
50+
*
51+
* @var \cli\progress\Bar
52+
*/
3353
protected $progress_bar;
3454

3555
/**
@@ -38,7 +58,7 @@ class ProgressBar {
3858
* @param string $message Text to display before the progress bar.
3959
* @param integer $count Total number of ticks to be performed.
4060
* @param integer $interval Optional. The interval in milliseconds between updates. Default 100.
41-
*
61+
*
4262
* @throws \Exception When this is not run within WP CLI.
4363
*/
4464
public function __construct( $message, $count, $interval = 100 ) {
@@ -64,7 +84,7 @@ public function tick() {
6484
$this->progress_bar->tick();
6585
$this->total_ticks++;
6686

67-
do_action( 'action_scheduler/progress_tick', $this->total_ticks );
87+
do_action( 'action_scheduler/progress_tick', $this->total_ticks ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
6888
}
6989

7090
/**

classes/data-stores/ActionScheduler_wpCommentLogger.php

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
77
const AGENT = 'ActionScheduler';
8-
const TYPE = 'action_log';
8+
const TYPE = 'action_log';
99

1010
/**
1111
* Create log entry.
@@ -16,8 +16,8 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
1616
*
1717
* @return string The log entry ID
1818
*/
19-
public function log( $action_id, $message, DateTime $date = NULL ) {
20-
if ( empty($date) ) {
19+
public function log( $action_id, $message, DateTime $date = null ) {
20+
if ( empty( $date ) ) {
2121
$date = as_get_datetime_object();
2222
} else {
2323
$date = as_get_datetime_object( clone $date );
@@ -35,18 +35,19 @@ public function log( $action_id, $message, DateTime $date = NULL ) {
3535
*/
3636
protected function create_wp_comment( $action_id, $message, DateTime $date ) {
3737

38-
$comment_date_gmt = $date->format('Y-m-d H:i:s');
38+
$comment_date_gmt = $date->format( 'Y-m-d H:i:s' );
3939
ActionScheduler_TimezoneHelper::set_local_timezone( $date );
4040
$comment_data = array(
41-
'comment_post_ID' => $action_id,
42-
'comment_date' => $date->format('Y-m-d H:i:s'),
41+
'comment_post_ID' => $action_id,
42+
'comment_date' => $date->format( 'Y-m-d H:i:s' ),
4343
'comment_date_gmt' => $comment_date_gmt,
44-
'comment_author' => self::AGENT,
45-
'comment_content' => $message,
46-
'comment_agent' => self::AGENT,
47-
'comment_type' => self::TYPE,
44+
'comment_author' => self::AGENT,
45+
'comment_content' => $message,
46+
'comment_agent' => self::AGENT,
47+
'comment_type' => self::TYPE,
4848
);
49-
return wp_insert_comment($comment_data);
49+
50+
return wp_insert_comment( $comment_data );
5051
}
5152

5253
/**
@@ -58,7 +59,8 @@ protected function create_wp_comment( $action_id, $message, DateTime $date ) {
5859
*/
5960
public function get_entry( $entry_id ) {
6061
$comment = $this->get_comment( $entry_id );
61-
if ( empty($comment) || $comment->comment_type != self::TYPE ) {
62+
63+
if ( empty( $comment ) || self::TYPE !== $comment->comment_type ) {
6264
return new ActionScheduler_NullLogEntry();
6365
}
6466

@@ -76,23 +78,30 @@ public function get_entry( $entry_id ) {
7678
*/
7779
public function get_logs( $action_id ) {
7880
$status = 'all';
79-
if ( get_post_status($action_id) == 'trash' ) {
81+
$logs = array();
82+
83+
if ( get_post_status( $action_id ) === 'trash' ) {
8084
$status = 'post-trashed';
8185
}
82-
$comments = get_comments(array(
83-
'post_id' => $action_id,
84-
'orderby' => 'comment_date_gmt',
85-
'order' => 'ASC',
86-
'type' => self::TYPE,
87-
'status' => $status,
88-
));
89-
$logs = array();
86+
87+
$comments = get_comments(
88+
array(
89+
'post_id' => $action_id,
90+
'orderby' => 'comment_date_gmt',
91+
'order' => 'ASC',
92+
'type' => self::TYPE,
93+
'status' => $status,
94+
)
95+
);
96+
9097
foreach ( $comments as $c ) {
9198
$entry = $this->get_entry( $c );
92-
if ( !empty($entry) ) {
99+
100+
if ( ! empty( $entry ) ) {
93101
$logs[] = $entry;
94102
}
95103
}
104+
96105
return $logs;
97106
}
98107

@@ -105,20 +114,18 @@ protected function get_comment( $comment_id ) {
105114
return get_comment( $comment_id );
106115
}
107116

108-
109-
110117
/**
111118
* Filter comment queries.
112119
*
113120
* @param WP_Comment_Query $query Comment query object.
114121
*/
115122
public function filter_comment_queries( $query ) {
116-
foreach ( array('ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID') as $key ) {
117-
if ( !empty($query->query_vars[$key]) ) {
123+
foreach ( array( 'ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID' ) as $key ) {
124+
if ( ! empty( $query->query_vars[ $key ] ) ) {
118125
return; // don't slow down queries that wouldn't include action_log comments anyway.
119126
}
120127
}
121-
$query->query_vars['action_log_filter'] = TRUE;
128+
$query->query_vars['action_log_filter'] = true;
122129
add_filter( 'comments_clauses', array( $this, 'filter_comment_query_clauses' ), 10, 2 );
123130
}
124131

@@ -131,7 +138,7 @@ public function filter_comment_queries( $query ) {
131138
* @return array
132139
*/
133140
public function filter_comment_query_clauses( $clauses, $query ) {
134-
if ( !empty($query->query_vars['action_log_filter']) ) {
141+
if ( ! empty( $query->query_vars['action_log_filter'] ) ) {
135142
$clauses['where'] .= $this->get_where_clause();
136143
}
137144
return $clauses;
@@ -192,17 +199,21 @@ protected function get_comment_count() {
192199
$stats = get_transient( 'as_comment_count' );
193200

194201
if ( ! $stats ) {
195-
$stats = array();
196-
197-
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );
198-
199-
$total = 0;
200-
$stats = array();
201-
$approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
202+
$stats = array();
203+
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );
204+
$total = 0;
205+
$stats = array();
206+
$approved = array(
207+
'0' => 'moderated',
208+
'1' => 'approved',
209+
'spam' => 'spam',
210+
'trash' => 'trash',
211+
'post-trashed' => 'post-trashed',
212+
);
202213

203214
foreach ( (array) $count as $row ) {
204215
// Don't count post-trashed toward totals.
205-
if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
216+
if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
206217
$total += $row['num_comments'];
207218
}
208219
if ( isset( $approved[ $row['comment_approved'] ] ) ) {
@@ -258,14 +269,14 @@ public function init() {
258269
* Defer comment counting.
259270
*/
260271
public function disable_comment_counting() {
261-
wp_defer_comment_counting(true);
272+
wp_defer_comment_counting( true );
262273
}
263274

264275
/**
265276
* Enable comment counting.
266277
*/
267278
public function enable_comment_counting() {
268-
wp_defer_comment_counting(false);
279+
wp_defer_comment_counting( false );
269280
}
270281

271282
}

0 commit comments

Comments
 (0)