Skip to content

Commit 27ac0f5

Browse files
Merge pull request #1073 from cloudinary/fix/cron-run-txt-warning
Fix cron-run.txt PHP warning
2 parents 5bde74c + a1ba163 commit 27ac0f5

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

php/class-cron.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,20 @@ public function run_queue( WP_REST_Request $request ) {
391391
$this->init_time = (int) $request->get_param( 'time' );
392392
$queue = $this->locker->get_lock_file( $this->init_time );
393393
register_shutdown_function( array( $this, 'cleanup_failed_cron' ) );
394-
foreach ( $queue as $name ) {
395-
if ( ! isset( $this->processes[ $name ] ) ) {
396-
continue;
397-
}
398-
$process = $this->processes[ $name ];
399-
$data = $process['callback']( $name );
400-
// @todo: Log data result.
401394

402-
$this->unlock_schedule_process( $name );
395+
if ( ! empty( $queue ) ) {
396+
foreach ( $queue as $name ) {
397+
if ( ! isset( $this->processes[ $name ] ) ) {
398+
continue;
399+
}
400+
$process = $this->processes[ $name ];
401+
$data = $process['callback']( $name );
402+
// @todo: Log data result.
403+
404+
$this->unlock_schedule_process( $name );
405+
}
403406
}
407+
404408
$this->locker->delete_lock_file( $this->init_time );
405409
}
406410

php/cron/class-lock-file.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ class Lock_File {
3333
*/
3434
public function get_lock_file( $file = null ) {
3535
$lock_file = $this->get_lock_file_name( $file );
36-
$data = file_get_contents( $lock_file ); // phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
36+
37+
if ( ! file_exists( $lock_file ) ) {
38+
return '';
39+
}
40+
41+
$data = file_get_contents( $lock_file ); // phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
42+
3743
if ( false !== strpos( $data, '[' ) ) {
3844
$data = json_decode( $data, true );
3945
}
@@ -106,5 +112,4 @@ public function delete_lock_file( $file = null ) {
106112
$file = $this->get_lock_file_name( $file );
107113
wp_delete_file( $file );
108114
}
109-
110115
}

0 commit comments

Comments
 (0)