ActionScheduler_QueueCleaner::clean_actionspublicWC 1.0

Delete selected actions limited by status and date.

Метод класса: ActionScheduler_QueueCleaner{}

Хуков нет.

Возвращает

Массив. Actions deleted.

Использование

$ActionScheduler_QueueCleaner = new ActionScheduler_QueueCleaner();
$ActionScheduler_QueueCleaner->clean_actions( $statuses_to_purge, $cutoff_date, $batch_size, $context );
$statuses_to_purge(string[]) (обязательный)
List of action statuses to purge.
По умолчанию: canceled, complete
$cutoff_date(DateTime) (обязательный)
Date limit for selecting actions.
По умолчанию: 31 days ago
$batch_size(int|null)
Maximum number of actions per status to delete.
По умолчанию: 20
$context(строка)
Calling process context.
По умолчанию: old

Код ActionScheduler_QueueCleaner::clean_actions() WC 9.9.5

public function clean_actions( array $statuses_to_purge, DateTime $cutoff_date, $batch_size = null, $context = 'old' ) {
	$batch_size = ! is_null( $batch_size ) ? $batch_size : $this->batch_size;
	$cutoff     = ! is_null( $cutoff_date ) ? $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 = array();

	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;
}