ActionMigrator.php
1 year ago
ActionScheduler_DBStoreMigrator.php
1 year ago
BatchFetcher.php
1 year ago
Config.php
4 years 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
index.php
3 years ago
BatchFetcher.php
54 lines
| 1 | <?php |
| 2 | namespace Action_Scheduler\Migration; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use ActionScheduler_Store as Store; |
| 5 | class BatchFetcher { |
| 6 | private $store; |
| 7 | public function __construct( Store $source_store ) { |
| 8 | $this->store = $source_store; |
| 9 | } |
| 10 | public function fetch( $count = 10 ) { |
| 11 | foreach ( $this->get_query_strategies( $count ) as $query ) { |
| 12 | $action_ids = $this->store->query_actions( $query ); |
| 13 | if ( ! empty( $action_ids ) ) { |
| 14 | return $action_ids; |
| 15 | } |
| 16 | } |
| 17 | return array(); |
| 18 | } |
| 19 | private function get_query_strategies( $count ) { |
| 20 | $now = as_get_datetime_object(); |
| 21 | $args = array( |
| 22 | 'date' => $now, |
| 23 | 'per_page' => $count, |
| 24 | 'offset' => 0, |
| 25 | 'orderby' => 'date', |
| 26 | 'order' => 'ASC', |
| 27 | ); |
| 28 | $priorities = array( |
| 29 | Store::STATUS_PENDING, |
| 30 | Store::STATUS_FAILED, |
| 31 | Store::STATUS_CANCELED, |
| 32 | Store::STATUS_COMPLETE, |
| 33 | Store::STATUS_RUNNING, |
| 34 | '', // any other unanticipated status. |
| 35 | ); |
| 36 | foreach ( $priorities as $status ) { |
| 37 | yield wp_parse_args( |
| 38 | array( |
| 39 | 'status' => $status, |
| 40 | 'date_compare' => '<=', |
| 41 | ), |
| 42 | $args |
| 43 | ); |
| 44 | yield wp_parse_args( |
| 45 | array( |
| 46 | 'status' => $status, |
| 47 | 'date_compare' => '>=', |
| 48 | ), |
| 49 | $args |
| 50 | ); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 |