-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Continued work on queue UI= * Wrapping up the core of the queue UI * Working table for queue UI * Adding counts to the queue * Switch to use wp_count_posts for performance * Style the row table * Adding single view for queue job * Adding queue UI with fixes for retrying
- Loading branch information
Showing
13 changed files
with
761 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/mantle/queue/providers/wordpress/admin/class-queue-job-admin-page.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Queue_Job_Admin_Page class file. | ||
* | ||
* @package Mantle | ||
*/ | ||
|
||
namespace Mantle\Queue\Providers\WordPress\Admin; | ||
|
||
use Mantle\Queue\Providers\WordPress\Post_Status; | ||
use Mantle\Queue\Providers\WordPress\Queue_Job; | ||
use Mantle\Queue\Providers\WordPress\Queue_Worker_Job; | ||
|
||
/** | ||
* Renders the queue admin page screen. | ||
* | ||
* @todo Refactor to use Blade and Mantle templating. | ||
*/ | ||
class Queue_Job_Admin_Page { | ||
|
||
/** | ||
* Render the admin page. | ||
*/ | ||
public function render(): void { | ||
$job_id = ! empty( $_GET['job'] ) ? absint( $_GET['job'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
|
||
match ( true ) { | ||
! empty( $_GET['action'] ) && $job_id => $this->render_action( $job_id ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
! empty( $job_id ) => $this->render_single_job( $job_id ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
default => $this->render_table(), | ||
}; | ||
} | ||
|
||
/** | ||
* Render a single job view. | ||
* | ||
* @param int $job_id The job ID. | ||
*/ | ||
protected function render_single_job( int $job_id ): void { | ||
$job = Queue_Job::find( $job_id ); | ||
|
||
if ( empty( $job ) ) { | ||
wp_die( esc_html__( 'Invalid job ID.', 'mantle' ) ); | ||
} | ||
|
||
include __DIR__ . '/template/single.php'; | ||
} | ||
|
||
/** | ||
* Handle an action (retry/delete). | ||
* | ||
* @param int $job_id The job ID. | ||
*/ | ||
protected function render_action( int $job_id ): void { | ||
if ( | ||
empty( $_GET['_wpnonce'] ) | ||
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'queue-job-action-' . $job_id ) | ||
) { | ||
wp_die( 'Invalid nonce.' ); | ||
} | ||
|
||
$action = sanitize_text_field( wp_unslash( $_GET['action'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
$job = Queue_Job::find( $job_id ); | ||
$message = ''; | ||
|
||
if ( empty( $job ) ) { | ||
wp_die( esc_html__( 'Invalid job ID.', 'mantle' ) ); | ||
} | ||
|
||
if ( 'retry' === $action ) { | ||
if ( Post_Status::FAILED->value !== $job->status ) { | ||
wp_die( esc_html__( 'Job is not in a failed state.', 'mantle' ) ); | ||
} | ||
|
||
( new Queue_Worker_Job( $job ) )->retry(); | ||
|
||
$message = esc_html__( 'Job has been scheduled to be retried.', 'mantle' ); | ||
} elseif ( 'delete' === $action ) { | ||
$job->delete( true ); | ||
|
||
$message = esc_html__( 'Job has been deleted.', 'mantle' ); | ||
} | ||
|
||
if ( ! empty( $message ) ) { | ||
printf( | ||
'<div class="notice notice-success is-dismissible"><p>%s</p></div>', | ||
esc_html( $message ) | ||
); | ||
} | ||
|
||
$this->render_table(); | ||
} | ||
|
||
/** | ||
* Render the queue table. | ||
*/ | ||
protected function render_table(): void { | ||
$table = new Queue_Jobs_Table(); | ||
|
||
$table->prepare_items(); | ||
|
||
include __DIR__ . '/template/table.php'; | ||
} | ||
} |
Oops, something went wrong.