@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @throws Exception When this is not run within WP CLI |
29 | 29 | */ |
30 | - public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) { |
|
31 | - if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
30 | + public function __construct(ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null) { |
|
31 | + if (!(defined('WP_CLI') && WP_CLI)) { |
|
32 | 32 | /* translators: %s php class name */ |
33 | - throw new Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) ); |
|
33 | + throw new Exception(sprintf(__('The %s class can only be run within WP CLI.', 'action-scheduler'), __CLASS__)); |
|
34 | 34 | } |
35 | 35 | |
36 | - parent::__construct( $store, $monitor, $cleaner ); |
|
36 | + parent::__construct($store, $monitor, $cleaner); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -49,25 +49,25 @@ discard block |
||
49 | 49 | * @return int The number of actions that will be run. |
50 | 50 | * @throws \WP_CLI\ExitException When there are too many concurrent batches. |
51 | 51 | */ |
52 | - public function setup( $batch_size, $hooks = array(), $group = '', $force = false ) { |
|
52 | + public function setup($batch_size, $hooks = array(), $group = '', $force = false) { |
|
53 | 53 | $this->run_cleanup(); |
54 | 54 | $this->add_hooks(); |
55 | 55 | |
56 | 56 | // Check to make sure there aren't too many concurrent processes running. |
57 | - if ( $this->has_maximum_concurrent_batches() ) { |
|
58 | - if ( $force ) { |
|
59 | - WP_CLI::warning( __( 'There are too many concurrent batches, but the run is forced to continue.', 'action-scheduler' ) ); |
|
57 | + if ($this->has_maximum_concurrent_batches()) { |
|
58 | + if ($force) { |
|
59 | + WP_CLI::warning(__('There are too many concurrent batches, but the run is forced to continue.', 'action-scheduler')); |
|
60 | 60 | } else { |
61 | - WP_CLI::error( __( 'There are too many concurrent batches.', 'action-scheduler' ) ); |
|
61 | + WP_CLI::error(__('There are too many concurrent batches.', 'action-scheduler')); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | 65 | // Stake a claim and store it. |
66 | - $this->claim = $this->store->stake_claim( $batch_size, null, $hooks, $group ); |
|
67 | - $this->monitor->attach( $this->claim ); |
|
66 | + $this->claim = $this->store->stake_claim($batch_size, null, $hooks, $group); |
|
67 | + $this->monitor->attach($this->claim); |
|
68 | 68 | $this->actions = $this->claim->get_actions(); |
69 | 69 | |
70 | - return count( $this->actions ); |
|
70 | + return count($this->actions); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @author Jeremy Pry |
77 | 77 | */ |
78 | 78 | protected function add_hooks() { |
79 | - add_action( 'action_scheduler_before_execute', array( $this, 'before_execute' ) ); |
|
80 | - add_action( 'action_scheduler_after_execute', array( $this, 'after_execute' ), 10, 2 ); |
|
81 | - add_action( 'action_scheduler_failed_execution', array( $this, 'action_failed' ), 10, 2 ); |
|
79 | + add_action('action_scheduler_before_execute', array($this, 'before_execute')); |
|
80 | + add_action('action_scheduler_after_execute', array($this, 'after_execute'), 10, 2); |
|
81 | + add_action('action_scheduler_failed_execution', array($this, 'action_failed'), 10, 2); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | * @author Jeremy Pry |
88 | 88 | */ |
89 | 89 | protected function setup_progress_bar() { |
90 | - $count = count( $this->actions ); |
|
90 | + $count = count($this->actions); |
|
91 | 91 | $this->progress_bar = new ProgressBar( |
92 | 92 | /* translators: %d: amount of actions */ |
93 | - sprintf( _n( 'Running %d action', 'Running %d actions', $count, 'action-scheduler' ), number_format_i18n( $count ) ), |
|
93 | + sprintf(_n('Running %d action', 'Running %d actions', $count, 'action-scheduler'), number_format_i18n($count)), |
|
94 | 94 | $count |
95 | 95 | ); |
96 | 96 | } |
@@ -104,24 +104,24 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return int The number of actions processed. |
106 | 106 | */ |
107 | - public function run( $context = 'WP CLI' ) { |
|
108 | - do_action( 'action_scheduler_before_process_queue' ); |
|
107 | + public function run($context = 'WP CLI') { |
|
108 | + do_action('action_scheduler_before_process_queue'); |
|
109 | 109 | $this->setup_progress_bar(); |
110 | - foreach ( $this->actions as $action_id ) { |
|
110 | + foreach ($this->actions as $action_id) { |
|
111 | 111 | // Error if we lost the claim. |
112 | - if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $this->claim->get_id() ) ) ) { |
|
113 | - WP_CLI::warning( __( 'The claim has been lost. Aborting current batch.', 'action-scheduler' ) ); |
|
112 | + if (!in_array($action_id, $this->store->find_actions_by_claim_id($this->claim->get_id()))) { |
|
113 | + WP_CLI::warning(__('The claim has been lost. Aborting current batch.', 'action-scheduler')); |
|
114 | 114 | break; |
115 | 115 | } |
116 | 116 | |
117 | - $this->process_action( $action_id, $context ); |
|
117 | + $this->process_action($action_id, $context); |
|
118 | 118 | $this->progress_bar->tick(); |
119 | 119 | } |
120 | 120 | |
121 | 121 | $completed = $this->progress_bar->current(); |
122 | 122 | $this->progress_bar->finish(); |
123 | - $this->store->release_claim( $this->claim ); |
|
124 | - do_action( 'action_scheduler_after_process_queue' ); |
|
123 | + $this->store->release_claim($this->claim); |
|
124 | + do_action('action_scheduler_after_process_queue'); |
|
125 | 125 | |
126 | 126 | return $completed; |
127 | 127 | } |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @param $action_id |
135 | 135 | */ |
136 | - public function before_execute( $action_id ) { |
|
136 | + public function before_execute($action_id) { |
|
137 | 137 | /* translators: %s refers to the action ID */ |
138 | - WP_CLI::log( sprintf( __( 'Started processing action %s', 'action-scheduler' ), $action_id ) ); |
|
138 | + WP_CLI::log(sprintf(__('Started processing action %s', 'action-scheduler'), $action_id)); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | * @param int $action_id |
147 | 147 | * @param null|ActionScheduler_Action $action The instance of the action. Default to null for backward compatibility. |
148 | 148 | */ |
149 | - public function after_execute( $action_id, $action = null ) { |
|
149 | + public function after_execute($action_id, $action = null) { |
|
150 | 150 | // backward compatibility |
151 | - if ( null === $action ) { |
|
152 | - $action = $this->store->fetch_action( $action_id ); |
|
151 | + if (null === $action) { |
|
152 | + $action = $this->store->fetch_action($action_id); |
|
153 | 153 | } |
154 | 154 | /* translators: 1: action ID 2: hook name */ |
155 | - WP_CLI::log( sprintf( __( 'Completed processing action %1$s with hook: %2$s', 'action-scheduler' ), $action_id, $action->get_hook() ) ); |
|
155 | + WP_CLI::log(sprintf(__('Completed processing action %1$s with hook: %2$s', 'action-scheduler'), $action_id, $action->get_hook())); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | * @param Exception $exception |
165 | 165 | * @throws \WP_CLI\ExitException With failure message. |
166 | 166 | */ |
167 | - public function action_failed( $action_id, $exception ) { |
|
167 | + public function action_failed($action_id, $exception) { |
|
168 | 168 | WP_CLI::error( |
169 | 169 | /* translators: 1: action ID 2: exception message */ |
170 | - sprintf( __( 'Error processing action %1$s: %2$s', 'action-scheduler' ), $action_id, $exception->getMessage() ), |
|
170 | + sprintf(__('Error processing action %1$s: %2$s', 'action-scheduler'), $action_id, $exception->getMessage()), |
|
171 | 171 | false |
172 | 172 | ); |
173 | 173 | } |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | * @param int $sleep_time Amount of seconds to sleep |
179 | 179 | * @deprecated 3.0.0 |
180 | 180 | */ |
181 | - protected function stop_the_insanity( $sleep_time = 0 ) { |
|
182 | - _deprecated_function( 'ActionScheduler_WPCLI_QueueRunner::stop_the_insanity', '3.0.0', 'ActionScheduler_DataController::free_memory' ); |
|
181 | + protected function stop_the_insanity($sleep_time = 0) { |
|
182 | + _deprecated_function('ActionScheduler_WPCLI_QueueRunner::stop_the_insanity', '3.0.0', 'ActionScheduler_DataController::free_memory'); |
|
183 | 183 | |
184 | 184 | ActionScheduler_DataController::free_memory(); |
185 | 185 | } |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | */ |
190 | 190 | protected function maybe_stop_the_insanity() { |
191 | 191 | // The value returned by progress_bar->current() might be padded. Remove padding, and convert to int. |
192 | - $current_iteration = intval( trim( $this->progress_bar->current() ) ); |
|
193 | - if ( 0 === $current_iteration % 50 ) { |
|
192 | + $current_iteration = intval(trim($this->progress_bar->current())); |
|
193 | + if (0 === $current_iteration % 50) { |
|
194 | 194 | $this->stop_the_insanity(); |
195 | 195 | } |
196 | 196 | } |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | * Register the command with WP-CLI |
29 | 29 | */ |
30 | 30 | public function register() { |
31 | - if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { |
|
31 | + if (!defined('WP_CLI') || !WP_CLI) { |
|
32 | 32 | return; |
33 | 33 | } |
34 | 34 | |
35 | - WP_CLI::add_command( 'action-scheduler migrate', [ $this, 'migrate' ], [ |
|
35 | + WP_CLI::add_command('action-scheduler migrate', [$this, 'migrate'], [ |
|
36 | 36 | 'shortdesc' => 'Migrates actions to the DB tables store', |
37 | 37 | 'synopsis' => [ |
38 | 38 | [ |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | 'description' => 'Reports on the actions that would have been migrated, but does not change any data', |
64 | 64 | ], |
65 | 65 | ], |
66 | - ] ); |
|
66 | + ]); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -74,31 +74,31 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return void |
76 | 76 | */ |
77 | - public function migrate( $positional_args, $assoc_args ) { |
|
77 | + public function migrate($positional_args, $assoc_args) { |
|
78 | 78 | $this->init_logging(); |
79 | 79 | |
80 | - $config = $this->get_migration_config( $assoc_args ); |
|
81 | - $runner = new Runner( $config ); |
|
80 | + $config = $this->get_migration_config($assoc_args); |
|
81 | + $runner = new Runner($config); |
|
82 | 82 | $runner->init_destination(); |
83 | 83 | |
84 | - $batch_size = isset( $assoc_args[ 'batch-size' ] ) ? (int) $assoc_args[ 'batch-size' ] : 100; |
|
85 | - $free_on = isset( $assoc_args[ 'free-memory-on' ] ) ? (int) $assoc_args[ 'free-memory-on' ] : 50; |
|
86 | - $sleep = isset( $assoc_args[ 'pause' ] ) ? (int) $assoc_args[ 'pause' ] : 0; |
|
87 | - \ActionScheduler_DataController::set_free_ticks( $free_on ); |
|
88 | - \ActionScheduler_DataController::set_sleep_time( $sleep ); |
|
84 | + $batch_size = isset($assoc_args['batch-size']) ? (int) $assoc_args['batch-size'] : 100; |
|
85 | + $free_on = isset($assoc_args['free-memory-on']) ? (int) $assoc_args['free-memory-on'] : 50; |
|
86 | + $sleep = isset($assoc_args['pause']) ? (int) $assoc_args['pause'] : 0; |
|
87 | + \ActionScheduler_DataController::set_free_ticks($free_on); |
|
88 | + \ActionScheduler_DataController::set_sleep_time($sleep); |
|
89 | 89 | |
90 | 90 | do { |
91 | - $actions_processed = $runner->run( $batch_size ); |
|
91 | + $actions_processed = $runner->run($batch_size); |
|
92 | 92 | $this->total_processed += $actions_processed; |
93 | - } while ( $actions_processed > 0 ); |
|
93 | + } while ($actions_processed > 0); |
|
94 | 94 | |
95 | - if ( ! $config->get_dry_run() ) { |
|
95 | + if (!$config->get_dry_run()) { |
|
96 | 96 | // let the scheduler know that there's nothing left to do |
97 | 97 | $scheduler = new Scheduler(); |
98 | 98 | $scheduler->mark_complete(); |
99 | 99 | } |
100 | 100 | |
101 | - WP_CLI::success( sprintf( '%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed ) ); |
|
101 | + WP_CLI::success(sprintf('%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed)); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return ActionScheduler\Migration\Config |
110 | 110 | */ |
111 | - private function get_migration_config( $args ) { |
|
112 | - $args = wp_parse_args( $args, [ |
|
111 | + private function get_migration_config($args) { |
|
112 | + $args = wp_parse_args($args, [ |
|
113 | 113 | 'dry-run' => false, |
114 | - ] ); |
|
114 | + ]); |
|
115 | 115 | |
116 | 116 | $config = Controller::instance()->get_migration_config_object(); |
117 | - $config->set_dry_run( ! empty( $args[ 'dry-run' ] ) ); |
|
117 | + $config->set_dry_run(!empty($args['dry-run'])); |
|
118 | 118 | |
119 | 119 | return $config; |
120 | 120 | } |
@@ -123,26 +123,26 @@ discard block |
||
123 | 123 | * Hook command line logging into migration actions. |
124 | 124 | */ |
125 | 125 | private function init_logging() { |
126 | - add_action( 'action_scheduler/migrate_action_dry_run', function ( $action_id ) { |
|
127 | - WP_CLI::debug( sprintf( 'Dry-run: migrated action %d', $action_id ) ); |
|
128 | - }, 10, 1 ); |
|
129 | - add_action( 'action_scheduler/no_action_to_migrate', function ( $action_id ) { |
|
130 | - WP_CLI::debug( sprintf( 'No action found to migrate for ID %d', $action_id ) ); |
|
131 | - }, 10, 1 ); |
|
132 | - add_action( 'action_scheduler/migrate_action_failed', function ( $action_id ) { |
|
133 | - WP_CLI::warning( sprintf( 'Failed migrating action with ID %d', $action_id ) ); |
|
134 | - }, 10, 1 ); |
|
135 | - add_action( 'action_scheduler/migrate_action_incomplete', function ( $source_id, $destination_id ) { |
|
136 | - WP_CLI::warning( sprintf( 'Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id ) ); |
|
137 | - }, 10, 2 ); |
|
138 | - add_action( 'action_scheduler/migrated_action', function ( $source_id, $destination_id ) { |
|
139 | - WP_CLI::debug( sprintf( 'Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id ) ); |
|
140 | - }, 10, 2 ); |
|
141 | - add_action( 'action_scheduler/migration_batch_starting', function ( $batch ) { |
|
142 | - WP_CLI::debug( 'Beginning migration of batch: ' . print_r( $batch, true ) ); |
|
143 | - }, 10, 1 ); |
|
144 | - add_action( 'action_scheduler/migration_batch_complete', function ( $batch ) { |
|
145 | - WP_CLI::log( sprintf( 'Completed migration of %d actions', count( $batch ) ) ); |
|
146 | - }, 10, 1 ); |
|
126 | + add_action('action_scheduler/migrate_action_dry_run', function($action_id) { |
|
127 | + WP_CLI::debug(sprintf('Dry-run: migrated action %d', $action_id)); |
|
128 | + }, 10, 1); |
|
129 | + add_action('action_scheduler/no_action_to_migrate', function($action_id) { |
|
130 | + WP_CLI::debug(sprintf('No action found to migrate for ID %d', $action_id)); |
|
131 | + }, 10, 1); |
|
132 | + add_action('action_scheduler/migrate_action_failed', function($action_id) { |
|
133 | + WP_CLI::warning(sprintf('Failed migrating action with ID %d', $action_id)); |
|
134 | + }, 10, 1); |
|
135 | + add_action('action_scheduler/migrate_action_incomplete', function($source_id, $destination_id) { |
|
136 | + WP_CLI::warning(sprintf('Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id)); |
|
137 | + }, 10, 2); |
|
138 | + add_action('action_scheduler/migrated_action', function($source_id, $destination_id) { |
|
139 | + WP_CLI::debug(sprintf('Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id)); |
|
140 | + }, 10, 2); |
|
141 | + add_action('action_scheduler/migration_batch_starting', function($batch) { |
|
142 | + WP_CLI::debug('Beginning migration of batch: ' . print_r($batch, true)); |
|
143 | + }, 10, 1); |
|
144 | + add_action('action_scheduler/migration_batch_complete', function($batch) { |
|
145 | + WP_CLI::log(sprintf('Completed migration of %d actions', count($batch))); |
|
146 | + }, 10, 1); |
|
147 | 147 | } |
148 | 148 | } |
@@ -40,20 +40,20 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @subcommand run |
42 | 42 | */ |
43 | - public function run( $args, $assoc_args ) { |
|
43 | + public function run($args, $assoc_args) { |
|
44 | 44 | // Handle passed arguments. |
45 | - $batch = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) ); |
|
46 | - $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) ); |
|
47 | - $clean = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) ); |
|
48 | - $hooks = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) ); |
|
49 | - $hooks = array_filter( array_map( 'trim', $hooks ) ); |
|
50 | - $group = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' ); |
|
51 | - $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', '' ); |
|
52 | - $sleep = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', '' ); |
|
53 | - $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false ); |
|
45 | + $batch = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'batch-size', 100)); |
|
46 | + $batches = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'batches', 0)); |
|
47 | + $clean = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'cleanup-batch-size', $batch)); |
|
48 | + $hooks = explode(',', WP_CLI\Utils\get_flag_value($assoc_args, 'hooks', '')); |
|
49 | + $hooks = array_filter(array_map('trim', $hooks)); |
|
50 | + $group = \WP_CLI\Utils\get_flag_value($assoc_args, 'group', ''); |
|
51 | + $free_on = \WP_CLI\Utils\get_flag_value($assoc_args, 'free-memory-on', ''); |
|
52 | + $sleep = \WP_CLI\Utils\get_flag_value($assoc_args, 'pause', ''); |
|
53 | + $force = \WP_CLI\Utils\get_flag_value($assoc_args, 'force', false); |
|
54 | 54 | |
55 | - ActionScheduler_DataController::set_free_ticks( $free_on ); |
|
56 | - ActionScheduler_DataController::set_sleep_time( $sleep ); |
|
55 | + ActionScheduler_DataController::set_free_ticks($free_on); |
|
56 | + ActionScheduler_DataController::set_sleep_time($sleep); |
|
57 | 57 | |
58 | 58 | $batches_completed = 0; |
59 | 59 | $actions_completed = 0; |
@@ -61,29 +61,29 @@ discard block |
||
61 | 61 | |
62 | 62 | try { |
63 | 63 | // Custom queue cleaner instance. |
64 | - $cleaner = new ActionScheduler_QueueCleaner( null, $clean ); |
|
64 | + $cleaner = new ActionScheduler_QueueCleaner(null, $clean); |
|
65 | 65 | |
66 | 66 | // Get the queue runner instance |
67 | - $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner ); |
|
67 | + $runner = new ActionScheduler_WPCLI_QueueRunner(null, null, $cleaner); |
|
68 | 68 | |
69 | 69 | // Determine how many tasks will be run in the first batch. |
70 | - $total = $runner->setup( $batch, $hooks, $group, $force ); |
|
70 | + $total = $runner->setup($batch, $hooks, $group, $force); |
|
71 | 71 | |
72 | 72 | // Run actions for as long as possible. |
73 | - while ( $total > 0 ) { |
|
74 | - $this->print_total_actions( $total ); |
|
73 | + while ($total > 0) { |
|
74 | + $this->print_total_actions($total); |
|
75 | 75 | $actions_completed += $runner->run(); |
76 | 76 | $batches_completed++; |
77 | 77 | |
78 | 78 | // Maybe set up tasks for the next batch. |
79 | - $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0; |
|
79 | + $total = ($unlimited || $batches_completed < $batches) ? $runner->setup($batch, $hooks, $group, $force) : 0; |
|
80 | 80 | } |
81 | - } catch ( Exception $e ) { |
|
82 | - $this->print_error( $e ); |
|
81 | + } catch (Exception $e) { |
|
82 | + $this->print_error($e); |
|
83 | 83 | } |
84 | 84 | |
85 | - $this->print_total_batches( $batches_completed ); |
|
86 | - $this->print_success( $actions_completed ); |
|
85 | + $this->print_total_batches($batches_completed); |
|
86 | + $this->print_success($actions_completed); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @param int $total |
95 | 95 | */ |
96 | - protected function print_total_actions( $total ) { |
|
96 | + protected function print_total_actions($total) { |
|
97 | 97 | WP_CLI::log( |
98 | 98 | sprintf( |
99 | 99 | /* translators: %d refers to how many scheduled taks were found to run */ |
100 | - _n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler' ), |
|
101 | - number_format_i18n( $total ) |
|
100 | + _n('Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler'), |
|
101 | + number_format_i18n($total) |
|
102 | 102 | ) |
103 | 103 | ); |
104 | 104 | } |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @param int $batches_completed |
112 | 112 | */ |
113 | - protected function print_total_batches( $batches_completed ) { |
|
113 | + protected function print_total_batches($batches_completed) { |
|
114 | 114 | WP_CLI::log( |
115 | 115 | sprintf( |
116 | 116 | /* translators: %d refers to the total number of batches executed */ |
117 | - _n( '%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler' ), |
|
118 | - number_format_i18n( $batches_completed ) |
|
117 | + _n('%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler'), |
|
118 | + number_format_i18n($batches_completed) |
|
119 | 119 | ) |
120 | 120 | ); |
121 | 121 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @throws \WP_CLI\ExitException |
131 | 131 | */ |
132 | - protected function print_error( Exception $e ) { |
|
132 | + protected function print_error(Exception $e) { |
|
133 | 133 | WP_CLI::error( |
134 | 134 | sprintf( |
135 | 135 | /* translators: %s refers to the exception error message */ |
136 | - __( 'There was an error running the action scheduler: %s', 'action-scheduler' ), |
|
136 | + __('There was an error running the action scheduler: %s', 'action-scheduler'), |
|
137 | 137 | $e->getMessage() |
138 | 138 | ) |
139 | 139 | ); |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @param int $actions_completed |
148 | 148 | */ |
149 | - protected function print_success( $actions_completed ) { |
|
149 | + protected function print_success($actions_completed) { |
|
150 | 150 | WP_CLI::success( |
151 | 151 | sprintf( |
152 | 152 | /* translators: %d refers to the total number of taskes completed */ |
153 | - _n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler' ), |
|
154 | - number_format_i18n( $actions_completed ) |
|
153 | + _n('%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler'), |
|
154 | + number_format_i18n($actions_completed) |
|
155 | 155 | ) |
156 | 156 | ); |
157 | 157 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @return int |
26 | 26 | */ |
27 | 27 | public function getTimestamp() { |
28 | - return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' ); |
|
28 | + return method_exists('DateTime', 'getTimestamp') ? parent::getTimestamp() : $this->format('U'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param $offset |
37 | 37 | */ |
38 | - public function setUtcOffset( $offset ) { |
|
39 | - $this->utcOffset = intval( $offset ); |
|
38 | + public function setUtcOffset($offset) { |
|
39 | + $this->utcOffset = intval($offset); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @return static |
58 | 58 | * @link http://php.net/manual/en/datetime.settimezone.php |
59 | 59 | */ |
60 | - public function setTimezone( $timezone ) { |
|
60 | + public function setTimezone($timezone) { |
|
61 | 61 | $this->utcOffset = 0; |
62 | - parent::setTimezone( $timezone ); |
|
62 | + parent::setTimezone($timezone); |
|
63 | 63 | |
64 | 64 | return $this; |
65 | 65 | } |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | /** |
9 | 9 | * @var int $action_id |
10 | 10 | */ |
11 | - protected $action_id = ''; |
|
11 | + protected $action_id = ''; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @var string $message |
15 | 15 | */ |
16 | - protected $message = ''; |
|
16 | + protected $message = ''; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @var Datetime $date |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param Datetime $date Datetime object with the time when this log entry was created. If this parameter is |
29 | 29 | * not provided a new Datetime object (with current time) will be created. |
30 | 30 | */ |
31 | - public function __construct( $action_id, $message, $date = null ) { |
|
31 | + public function __construct($action_id, $message, $date = null) { |
|
32 | 32 | |
33 | 33 | /* |
34 | 34 | * ActionScheduler_wpCommentLogger::get_entry() previously passed a 3rd param of $comment->comment_type |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * goodness knows why, so we need to guard against that here instead of using a DateTime type declaration |
38 | 38 | * for the constructor's 3rd param of $date and causing a fatal error with older versions of FUE. |
39 | 39 | */ |
40 | - if ( null !== $date && ! is_a( $date, 'DateTime' ) ) { |
|
41 | - _doing_it_wrong( __METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0' ); |
|
40 | + if (null !== $date && !is_a($date, 'DateTime')) { |
|
41 | + _doing_it_wrong(__METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0'); |
|
42 | 42 | $date = null; |
43 | 43 | } |
44 | 44 |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * @return bool |
45 | 45 | */ |
46 | 46 | public static function dependencies_met() { |
47 | - $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' ); |
|
48 | - return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true ); |
|
47 | + $php_support = version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '>='); |
|
48 | + return $php_support && apply_filters('action_scheduler_migration_dependencies_met', true); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * @return bool Whether the flag has been set marking the migration as complete |
55 | 55 | */ |
56 | 56 | public static function is_migration_complete() { |
57 | - return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE; |
|
57 | + return get_option(self::STATUS_FLAG) === self::STATUS_COMPLETE; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Mark the migration as complete. |
62 | 62 | */ |
63 | 63 | public static function mark_migration_complete() { |
64 | - update_option( self::STATUS_FLAG, self::STATUS_COMPLETE ); |
|
64 | + update_option(self::STATUS_FLAG, self::STATUS_COMPLETE); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * deactivated and the site was running on AS 2.x again. |
71 | 71 | */ |
72 | 72 | public static function mark_migration_incomplete() { |
73 | - delete_option( self::STATUS_FLAG ); |
|
73 | + delete_option(self::STATUS_FLAG); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public static function set_store_class( $class ) { |
|
83 | + public static function set_store_class($class) { |
|
84 | 84 | return self::DATASTORE_CLASS; |
85 | 85 | } |
86 | 86 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - public static function set_logger_class( $class ) { |
|
94 | + public static function set_logger_class($class) { |
|
95 | 95 | return self::LOGGER_CLASS; |
96 | 96 | } |
97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @param integer $sleep_time The number of seconds to pause before resuming operation. |
102 | 102 | */ |
103 | - public static function set_sleep_time( $sleep_time ) { |
|
103 | + public static function set_sleep_time($sleep_time) { |
|
104 | 104 | self::$sleep_time = $sleep_time; |
105 | 105 | } |
106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @param integer $free_ticks The number of ticks to free memory on. |
111 | 111 | */ |
112 | - public static function set_free_ticks( $free_ticks ) { |
|
112 | + public static function set_free_ticks($free_ticks) { |
|
113 | 113 | self::$free_ticks = $free_ticks; |
114 | 114 | } |
115 | 115 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param int $ticks Current tick count. |
120 | 120 | */ |
121 | - public static function maybe_free_memory( $ticks ) { |
|
122 | - if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) { |
|
121 | + public static function maybe_free_memory($ticks) { |
|
122 | + if (self::$free_ticks && 0 === $ticks % self::$free_ticks) { |
|
123 | 123 | self::free_memory(); |
124 | 124 | } |
125 | 125 | } |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | * Reduce memory footprint by clearing the database query and object caches. |
129 | 129 | */ |
130 | 130 | public static function free_memory() { |
131 | - if ( 0 < self::$sleep_time ) { |
|
131 | + if (0 < self::$sleep_time) { |
|
132 | 132 | /* translators: %d: amount of time */ |
133 | - \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) ); |
|
134 | - sleep( self::$sleep_time ); |
|
133 | + \WP_CLI::warning(sprintf(_n('Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler'), self::$sleep_time)); |
|
134 | + sleep(self::$sleep_time); |
|
135 | 135 | } |
136 | 136 | |
137 | - \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) ); |
|
137 | + \WP_CLI::warning(__('Attempting to reduce used memory...', 'action-scheduler')); |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @var $wpdb \wpdb |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | $wpdb->queries = array(); |
146 | 146 | |
147 | - if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) { |
|
147 | + if (!is_a($wp_object_cache, 'WP_Object_Cache')) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | $wp_object_cache->memcache_debug = array(); |
154 | 154 | $wp_object_cache->cache = array(); |
155 | 155 | |
156 | - if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) { |
|
157 | - call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important |
|
156 | + if (is_callable(array($wp_object_cache, '__remoteset'))) { |
|
157 | + call_user_func(array($wp_object_cache, '__remoteset')); // important |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -163,22 +163,22 @@ discard block |
||
163 | 163 | * Otherwise, proceed with the migration if the dependencies have been met. |
164 | 164 | */ |
165 | 165 | public static function init() { |
166 | - if ( self::is_migration_complete() ) { |
|
167 | - add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 ); |
|
168 | - add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 ); |
|
169 | - add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) ); |
|
170 | - } elseif ( self::dependencies_met() ) { |
|
166 | + if (self::is_migration_complete()) { |
|
167 | + add_filter('action_scheduler_store_class', array('ActionScheduler_DataController', 'set_store_class'), 100); |
|
168 | + add_filter('action_scheduler_logger_class', array('ActionScheduler_DataController', 'set_logger_class'), 100); |
|
169 | + add_action('deactivate_plugin', array('ActionScheduler_DataController', 'mark_migration_incomplete')); |
|
170 | + } elseif (self::dependencies_met()) { |
|
171 | 171 | Controller::init(); |
172 | 172 | } |
173 | 173 | |
174 | - add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) ); |
|
174 | + add_action('action_scheduler/progress_tick', array('ActionScheduler_DataController', 'maybe_free_memory')); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | 178 | * Singleton factory. |
179 | 179 | */ |
180 | 180 | public static function instance() { |
181 | - if ( ! isset( self::$instance ) ) { |
|
181 | + if (!isset(self::$instance)) { |
|
182 | 182 | self::$instance = new static(); |
183 | 183 | } |
184 | 184 |
@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | * @param string $action_id The action ID with bad args. |
16 | 16 | * @return static |
17 | 17 | */ |
18 | - public static function from_schedule( $action_id, $schedule ) { |
|
18 | + public static function from_schedule($action_id, $schedule) { |
|
19 | 19 | $message = sprintf( |
20 | 20 | /* translators: 1: action ID 2: schedule */ |
21 | - __( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ), |
|
21 | + __('Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler'), |
|
22 | 22 | $action_id, |
23 | - var_export( $schedule, true ) |
|
23 | + var_export($schedule, true) |
|
24 | 24 | ); |
25 | 25 | |
26 | - return new static( $message ); |
|
26 | + return new static($message); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * @param string $action_id The action ID with bad args. |
35 | 35 | * @return static |
36 | 36 | */ |
37 | - public static function from_decoding_args( $action_id, $args = array() ) { |
|
37 | + public static function from_decoding_args($action_id, $args = array()) { |
|
38 | 38 | $message = sprintf( |
39 | 39 | /* translators: 1: action ID 2: arguments */ |
40 | - __( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ), |
|
40 | + __('Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler'), |
|
41 | 41 | $action_id, |
42 | - var_export( $args, true ) |
|
42 | + var_export($args, true) |
|
43 | 43 | ); |
44 | 44 | |
45 | - return new static( $message ); |
|
45 | + return new static($message); |
|
46 | 46 | } |
47 | 47 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | |
12 | 12 | private $versions = array(); |
13 | 13 | |
14 | - public function register( $version_string, $initialization_callback ) { |
|
15 | - if ( isset($this->versions[$version_string]) ) { |
|
14 | + public function register($version_string, $initialization_callback) { |
|
15 | + if (isset($this->versions[$version_string])) { |
|
16 | 16 | return FALSE; |
17 | 17 | } |
18 | 18 | $this->versions[$version_string] = $initialization_callback; |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | |
26 | 26 | public function latest_version() { |
27 | 27 | $keys = array_keys($this->versions); |
28 | - if ( empty($keys) ) { |
|
28 | + if (empty($keys)) { |
|
29 | 29 | return false; |
30 | 30 | } |
31 | - uasort( $keys, 'version_compare' ); |
|
31 | + uasort($keys, 'version_compare'); |
|
32 | 32 | return end($keys); |
33 | 33 | } |
34 | 34 | |
35 | 35 | public function latest_version_callback() { |
36 | 36 | $latest = $this->latest_version(); |
37 | - if ( empty($latest) || !isset($this->versions[$latest]) ) { |
|
37 | + if (empty($latest) || !isset($this->versions[$latest])) { |
|
38 | 38 | return '__return_null'; |
39 | 39 | } |
40 | 40 | return $this->versions[$latest]; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @codeCoverageIgnore |
46 | 46 | */ |
47 | 47 | public static function instance() { |
48 | - if ( empty(self::$instance) ) { |
|
48 | + if (empty(self::$instance)) { |
|
49 | 49 | self::$instance = new self(); |
50 | 50 | } |
51 | 51 | return self::$instance; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * @param ActionScheduler_FatalErrorMonitor $monitor |
32 | 32 | * @param ActionScheduler_QueueCleaner $cleaner |
33 | 33 | */ |
34 | - public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) { |
|
34 | + public function __construct(ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null) { |
|
35 | 35 | |
36 | - $this->created_time = microtime( true ); |
|
36 | + $this->created_time = microtime(true); |
|
37 | 37 | |
38 | 38 | $this->store = $store ? $store : ActionScheduler_Store::instance(); |
39 | - $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor( $this->store ); |
|
40 | - $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner( $this->store ); |
|
39 | + $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor($this->store); |
|
40 | + $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner($this->store); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -47,35 +47,35 @@ discard block |
||
47 | 47 | * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron' |
48 | 48 | * Generally, this should be capitalised and not localised as it's a proper noun. |
49 | 49 | */ |
50 | - public function process_action( $action_id, $context = '' ) { |
|
50 | + public function process_action($action_id, $context = '') { |
|
51 | 51 | try { |
52 | 52 | $valid_action = false; |
53 | - do_action( 'action_scheduler_before_execute', $action_id, $context ); |
|
53 | + do_action('action_scheduler_before_execute', $action_id, $context); |
|
54 | 54 | |
55 | - if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) { |
|
56 | - do_action( 'action_scheduler_execution_ignored', $action_id, $context ); |
|
55 | + if (ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status($action_id)) { |
|
56 | + do_action('action_scheduler_execution_ignored', $action_id, $context); |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $valid_action = true; |
61 | - do_action( 'action_scheduler_begin_execute', $action_id, $context ); |
|
61 | + do_action('action_scheduler_begin_execute', $action_id, $context); |
|
62 | 62 | |
63 | - $action = $this->store->fetch_action( $action_id ); |
|
64 | - $this->store->log_execution( $action_id ); |
|
63 | + $action = $this->store->fetch_action($action_id); |
|
64 | + $this->store->log_execution($action_id); |
|
65 | 65 | $action->execute(); |
66 | - do_action( 'action_scheduler_after_execute', $action_id, $action, $context ); |
|
67 | - $this->store->mark_complete( $action_id ); |
|
68 | - } catch ( Exception $e ) { |
|
69 | - if ( $valid_action ) { |
|
70 | - $this->store->mark_failure( $action_id ); |
|
71 | - do_action( 'action_scheduler_failed_execution', $action_id, $e, $context ); |
|
66 | + do_action('action_scheduler_after_execute', $action_id, $action, $context); |
|
67 | + $this->store->mark_complete($action_id); |
|
68 | + } catch (Exception $e) { |
|
69 | + if ($valid_action) { |
|
70 | + $this->store->mark_failure($action_id); |
|
71 | + do_action('action_scheduler_failed_execution', $action_id, $e, $context); |
|
72 | 72 | } else { |
73 | - do_action( 'action_scheduler_failed_validation', $action_id, $e, $context ); |
|
73 | + do_action('action_scheduler_failed_validation', $action_id, $e, $context); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) { |
|
78 | - $this->schedule_next_instance( $action, $action_id ); |
|
77 | + if (isset($action) && is_a($action, 'ActionScheduler_Action') && $action->get_schedule()->is_recurring()) { |
|
78 | + $this->schedule_next_instance($action, $action_id); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | * @param ActionScheduler_Action $action |
86 | 86 | * @param int $action_id |
87 | 87 | */ |
88 | - protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) { |
|
88 | + protected function schedule_next_instance(ActionScheduler_Action $action, $action_id) { |
|
89 | 89 | try { |
90 | - ActionScheduler::factory()->repeat( $action ); |
|
91 | - } catch ( Exception $e ) { |
|
92 | - do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action ); |
|
90 | + ActionScheduler::factory()->repeat($action); |
|
91 | + } catch (Exception $e) { |
|
92 | + do_action('action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @author Jeremy Pry |
100 | 100 | */ |
101 | 101 | protected function run_cleanup() { |
102 | - $this->cleaner->clean( 10 * $this->get_time_limit() ); |
|
102 | + $this->cleaner->clean(10 * $this->get_time_limit()); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return int |
109 | 109 | */ |
110 | 110 | public function get_allowed_concurrent_batches() { |
111 | - return apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 1 ); |
|
111 | + return apply_filters('action_scheduler_queue_runner_concurrent_batches', 1); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -130,12 +130,12 @@ discard block |
||
130 | 130 | $time_limit = 30; |
131 | 131 | |
132 | 132 | // Apply deprecated filter from deprecated get_maximum_execution_time() method |
133 | - if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) { |
|
134 | - _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' ); |
|
135 | - $time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit ); |
|
133 | + if (has_filter('action_scheduler_maximum_execution_time')) { |
|
134 | + _deprecated_function('action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit'); |
|
135 | + $time_limit = apply_filters('action_scheduler_maximum_execution_time', $time_limit); |
|
136 | 136 | } |
137 | 137 | |
138 | - return absint( apply_filters( 'action_scheduler_queue_runner_time_limit', $time_limit ) ); |
|
138 | + return absint(apply_filters('action_scheduler_queue_runner_time_limit', $time_limit)); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | * @return int The number of seconds. |
145 | 145 | */ |
146 | 146 | protected function get_execution_time() { |
147 | - $execution_time = microtime( true ) - $this->created_time; |
|
147 | + $execution_time = microtime(true) - $this->created_time; |
|
148 | 148 | |
149 | 149 | // Get the CPU time if the hosting environment uses it rather than wall-clock time to calculate a process's execution time. |
150 | - if ( function_exists( 'getrusage' ) && apply_filters( 'action_scheduler_use_cpu_execution_time', defined( 'PANTHEON_ENVIRONMENT' ) ) ) { |
|
150 | + if (function_exists('getrusage') && apply_filters('action_scheduler_use_cpu_execution_time', defined('PANTHEON_ENVIRONMENT'))) { |
|
151 | 151 | $resource_usages = getrusage(); |
152 | 152 | |
153 | - if ( isset( $resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'] ) ) { |
|
154 | - $execution_time = $resource_usages['ru_stime.tv_sec'] + ( $resource_usages['ru_stime.tv_usec'] / 1000000 ); |
|
153 | + if (isset($resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'])) { |
|
154 | + $execution_time = $resource_usages['ru_stime.tv_sec'] + ($resource_usages['ru_stime.tv_usec'] / 1000000); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action |
165 | 165 | * @return bool |
166 | 166 | */ |
167 | - protected function time_likely_to_be_exceeded( $processed_actions ) { |
|
167 | + protected function time_likely_to_be_exceeded($processed_actions) { |
|
168 | 168 | |
169 | 169 | $execution_time = $this->get_execution_time(); |
170 | 170 | $max_execution_time = $this->get_time_limit(); |
171 | 171 | $time_per_action = $execution_time / $processed_actions; |
172 | - $estimated_time = $execution_time + ( $time_per_action * 3 ); |
|
172 | + $estimated_time = $execution_time + ($time_per_action * 3); |
|
173 | 173 | $likely_to_be_exceeded = $estimated_time > $max_execution_time; |
174 | 174 | |
175 | - return apply_filters( 'action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time ); |
|
175 | + return apply_filters('action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | * @return int |
184 | 184 | */ |
185 | 185 | protected function get_memory_limit() { |
186 | - if ( function_exists( 'ini_get' ) ) { |
|
187 | - $memory_limit = ini_get( 'memory_limit' ); |
|
186 | + if (function_exists('ini_get')) { |
|
187 | + $memory_limit = ini_get('memory_limit'); |
|
188 | 188 | } else { |
189 | 189 | $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce |
190 | 190 | } |
191 | 191 | |
192 | - if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) { |
|
192 | + if (!$memory_limit || -1 === $memory_limit || '-1' === $memory_limit) { |
|
193 | 193 | // Unlimited, set to 32GB. |
194 | 194 | $memory_limit = '32G'; |
195 | 195 | } |
196 | 196 | |
197 | - return ActionScheduler_Compatibility::convert_hr_to_bytes( $memory_limit ); |
|
197 | + return ActionScheduler_Compatibility::convert_hr_to_bytes($memory_limit); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | protected function memory_exceeded() { |
210 | 210 | |
211 | 211 | $memory_limit = $this->get_memory_limit() * 0.90; |
212 | - $current_memory = memory_get_usage( true ); |
|
212 | + $current_memory = memory_get_usage(true); |
|
213 | 213 | $memory_exceeded = $current_memory >= $memory_limit; |
214 | 214 | |
215 | - return apply_filters( 'action_scheduler_memory_exceeded', $memory_exceeded, $this ); |
|
215 | + return apply_filters('action_scheduler_memory_exceeded', $memory_exceeded, $this); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action |
225 | 225 | * @return bool |
226 | 226 | */ |
227 | - protected function batch_limits_exceeded( $processed_actions ) { |
|
228 | - return $this->memory_exceeded() || $this->time_likely_to_be_exceeded( $processed_actions ); |
|
227 | + protected function batch_limits_exceeded($processed_actions) { |
|
228 | + return $this->memory_exceeded() || $this->time_likely_to_be_exceeded($processed_actions); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -236,5 +236,5 @@ discard block |
||
236 | 236 | * Generally, this should be capitalised and not localised as it's a proper noun. |
237 | 237 | * @return int The number of actions processed. |
238 | 238 | */ |
239 | - abstract public function run( $context = '' ); |
|
239 | + abstract public function run($context = ''); |
|
240 | 240 | } |