ActionMigrator.php
1 year ago
ActionScheduler_DBStoreMigrator.php
1 year ago
BatchFetcher.php
1 year ago
Config.php
1 year ago
Controller.php
1 year ago
DryRun_ActionMigrator.php
1 year ago
DryRun_LogMigrator.php
1 year ago
LogMigrator.php
1 year ago
Runner.php
1 year ago
Scheduler.php
1 year ago
BatchFetcher.php
96 lines
| 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 |