PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / trunk
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler vtrunk
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / vendor / woocommerce / action-scheduler / classes / migration / BatchFetcher.php

BatchFetcher.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler trunk, at vendor/woocommerce/action-scheduler/classes/migration/BatchFetcher.php

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