ActionScheduler_QueueCleaner::clean_actions()
Delete selected actions limited by status and date.
Method of the class: ActionScheduler_QueueCleaner{}
No Hooks.
Return
Array
. Actions deleted.
Usage
$ActionScheduler_QueueCleaner = new ActionScheduler_QueueCleaner(); $ActionScheduler_QueueCleaner->clean_actions( $statuses_to_purge, $cutoff_date, $batch_size, $context );
- $statuses_to_purge(string[]) (required)
- List of action statuses to purge.
Default: canceled, complete - $cutoff_date(DateTime) (required)
- Date limit for selecting actions.
Default: 31 days ago - $batch_size(int|null)
- Maximum number of actions per status to delete.
Default: 20 - $context(string)
- Calling process context.
Default: old
ActionScheduler_QueueCleaner::clean_actions() ActionScheduler QueueCleaner::clean actions code WC 9.3.1
public function clean_actions( array $statuses_to_purge, DateTime $cutoff_date, $batch_size = null, $context = 'old' ) { $batch_size = $batch_size !== null ? $batch_size : $this->batch_size; $cutoff = $cutoff_date !== null ? $cutoff_date : as_get_datetime_object( $this->month_in_seconds . ' seconds ago' ); $lifespan = time() - $cutoff->getTimestamp(); if ( empty( $statuses_to_purge ) ) { $statuses_to_purge = $this->default_statuses_to_purge; } $deleted_actions = []; foreach ( $statuses_to_purge as $status ) { $actions_to_delete = $this->store->query_actions( array( 'status' => $status, 'modified' => $cutoff, 'modified_compare' => '<=', 'per_page' => $batch_size, 'orderby' => 'none', ) ); $deleted_actions = array_merge( $deleted_actions, $this->delete_actions( $actions_to_delete, $lifespan, $context ) ); } return $deleted_actions; }