1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
<?php // phpcs:ignoreFile
namespace AutomateWoo\Admin\Controllers;
use AutomateWoo\Admin; use AutomateWoo\Clean; use AutomateWoo\Logger; use AutomateWoo\Queue_Manager; use AutomateWoo\Queued_Event_Factory; use AutomateWoo\Report_Queue; use AutomateWoo\Jobs\JobException;
if ( ! defined( 'ABSPATH' ) ) exit;
/** * @class Queue */ class Queue extends Base {
function handle() {
$action = $this->get_current_action();
switch ( $action ) {
case 'run_now': $this->action_run_now(); $this->output_list_table(); break;
case 'bulk_delete': $this->action_bulk_edit( str_replace( 'bulk_', '', $action ) ); $this->output_list_table(); break;
default: $this->output_list_table(); break; } }
private function output_list_table() { $table = new Report_Queue(); $table->prepare_items(); $table->nonce_action = $this->get_nonce_action();
$sidebar_content = '<p>' . sprintf( /* translators: %1$s read more link start, %2$s read more link end. */ __( 'Workflows that are not set to run immediately will be added to this queue. The queue is checked every two minutes so actual run times will vary slightly. %1$sRead more…%2$s', 'automatewoo' ), '<a href="' . Admin::get_docs_link( 'queue', 'queue-list' ) . '" target="_blank">', '</a>' ) . '</p>';
try { $deletion_job = AW()->job_service()->get_job( 'delete_failed_queued_workflows' ); $deletion_period = $deletion_job->get_deletion_period(); $sidebar_content .= '<p>' . sprintf( /* translators: %d Number of days to trigger deletion of failed queue items. */ _n( 'Failed queue items will be deleted after %d day', 'Failed queue items will be deleted after %d days', $deletion_period, 'automatewoo' ), $deletion_period ) . '</p>'; } catch ( JobException $e ) { Logger::error( 'jobs', $e->getMessage() ); }
$this->output_view( 'page-table-with-sidebar', [ 'table' => $table, 'sidebar_content' => $sidebar_content ]); }
/** * Run a single queued event */ private function action_run_now() {
$this->verify_nonce_action();
$queued_event = Queued_Event_Factory::get( absint( aw_request( 'queued_event_id' ) ) );
if ( ! $queued_event ) { return; }
if ( $queued_event->run() ) { $this->add_message( __( 'Queued event run successfully.', 'automatewoo' ) ); } else { $message = $queued_event->get_failure_message(); $this->add_error( __( 'Queued event failed to run.', 'automatewoo'), $message ); } }
/** * @param $action */ private function action_bulk_edit( $action ) {
$this->verify_nonce_action();
$ids = Clean::ids( aw_request( 'queued_event_ids' ) );
if ( empty( $ids ) ) { $this->add_error( __( 'Please select some queued events to bulk edit.', 'automatewoo') ); return; }
foreach ( $ids as $id ) {
$queued_event = Queued_Event_Factory::get( $id );
if ( ! $queued_event ) continue;
switch ( $action ) { case 'delete': $queued_event->delete(); break; } }
$this->add_message( __( 'Bulk edit completed.', 'automatewoo' ) ); } }
return new Queue();
|