PluginProbe
WANotifier for Forms and Actions / 2.7.5
WANotifier for Forms and Actions v2.7.5
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / libraries / action-scheduler / classes / migration / BatchFetcher.php

BatchFetcher.php in WANotifier for Forms and Actions 2.7.5, at libraries/action-scheduler/classes/migration/BatchFetcher.php

86 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Action_Scheduler\Migration;
5
6
7 use ActionScheduler_Store as Store;
8
9 /**
10 * Class BatchFetcher
11 *
12 * @package Action_Scheduler\Migration
13 *
14 * @since 3.0.0
15 *
16 * @codeCoverageIgnore
17 */
18 class BatchFetcher {
19 /** var ActionScheduler_Store */
20 private $store;
21
22 /**
23 * BatchFetcher constructor.
24 *
25 * @param ActionScheduler_Store $source_store Source store object.
26 */
27 public function __construct( Store $source_store ) {
28 $this->store = $source_store;
29 }
30
31 /**
32 * Retrieve a list of actions.
33 *
34 * @param int $count The number of actions to retrieve
35 *
36 * @return int[] A list of action IDs
37 */
38 public function fetch( $count = 10 ) {
39 foreach ( $this->get_query_strategies( $count ) as $query ) {
40 $action_ids = $this->store->query_actions( $query );
41 if ( ! empty( $action_ids ) ) {
42 return $action_ids;
43 }
44 }
45
46 return [];
47 }
48
49 /**
50 * Generate a list of prioritized of action search parameters.
51 *
52 * @param int $count Number of actions to find.
53 *
54 * @return array
55 */
56 private function get_query_strategies( $count ) {
57 $now = as_get_datetime_object();
58 $args = [
59 'date' => $now,
60 'per_page' => $count,
61 'offset' => 0,
62 'orderby' => 'date',
63 'order' => 'ASC',
64 ];
65
66 $priorities = [
67 Store::STATUS_PENDING,
68 Store::STATUS_FAILED,
69 Store::STATUS_CANCELED,
70 Store::STATUS_COMPLETE,
71 Store::STATUS_RUNNING,
72 '', // any other unanticipated status
73 ];
74
75 foreach ( $priorities as $status ) {
76 yield wp_parse_args( [
77 'status' => $status,
78 'date_compare' => '<=',
79 ], $args );
80 yield wp_parse_args( [
81 'status' => $status,
82 'date_compare' => '>=',
83 ], $args );
84 }
85 }
86 }