@@ -13,97 +13,97 @@ |
||
| 13 | 13 | * @codeCoverageIgnore |
| 14 | 14 | */ |
| 15 | 15 | class ActionMigrator { |
| 16 | - /** var ActionScheduler_Store */ |
|
| 17 | - private $source; |
|
| 18 | - |
|
| 19 | - /** var ActionScheduler_Store */ |
|
| 20 | - private $destination; |
|
| 21 | - |
|
| 22 | - /** var LogMigrator */ |
|
| 23 | - private $log_migrator; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * ActionMigrator constructor. |
|
| 27 | - * |
|
| 28 | - * @param ActionScheduler_Store $source_store Source store object. |
|
| 29 | - * @param ActionScheduler_Store $destination_store Destination store object. |
|
| 30 | - * @param LogMigrator $log_migrator Log migrator object. |
|
| 31 | - */ |
|
| 32 | - public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
| 33 | - $this->source = $source_store; |
|
| 34 | - $this->destination = $destination_store; |
|
| 35 | - $this->log_migrator = $log_migrator; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Migrate an action. |
|
| 40 | - * |
|
| 41 | - * @param int $source_action_id Action ID. |
|
| 42 | - * |
|
| 43 | - * @return int 0|new action ID |
|
| 44 | - */ |
|
| 45 | - public function migrate( $source_action_id ) { |
|
| 46 | - try { |
|
| 47 | - $action = $this->source->fetch_action( $source_action_id ); |
|
| 48 | - $status = $this->source->get_status( $source_action_id ); |
|
| 49 | - } catch ( \Exception $e ) { |
|
| 50 | - $action = null; |
|
| 51 | - $status = ''; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
| 55 | - // null action or empty status means the fetch operation failed or the action didn't exist |
|
| 56 | - // null schedule means it's missing vital data |
|
| 57 | - // delete it and move on |
|
| 58 | - try { |
|
| 59 | - $this->source->delete_action( $source_action_id ); |
|
| 60 | - } catch ( \Exception $e ) { |
|
| 61 | - // nothing to do, it didn't exist in the first place |
|
| 62 | - } |
|
| 63 | - do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
| 64 | - |
|
| 65 | - return 0; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - try { |
|
| 69 | - |
|
| 70 | - // Make sure the last attempt date is set correctly for completed and failed actions |
|
| 71 | - $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
| 72 | - |
|
| 73 | - $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
| 74 | - } catch ( \Exception $e ) { |
|
| 75 | - do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
| 76 | - |
|
| 77 | - return 0; // could not save the action in the new store |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - try { |
|
| 81 | - switch ( $status ) { |
|
| 82 | - case \ActionScheduler_Store::STATUS_FAILED : |
|
| 83 | - $this->destination->mark_failure( $destination_action_id ); |
|
| 84 | - break; |
|
| 85 | - case \ActionScheduler_Store::STATUS_CANCELED : |
|
| 86 | - $this->destination->cancel_action( $destination_action_id ); |
|
| 87 | - break; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
| 91 | - $this->source->delete_action( $source_action_id ); |
|
| 92 | - |
|
| 93 | - $test_action = $this->source->fetch_action( $source_action_id ); |
|
| 94 | - if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
| 95 | - throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'woocommerce' ), $source_action_id ) ); |
|
| 96 | - } |
|
| 97 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 98 | - |
|
| 99 | - return $destination_action_id; |
|
| 100 | - } catch ( \Exception $e ) { |
|
| 101 | - // could not delete from the old store |
|
| 102 | - $this->source->mark_migrated( $source_action_id ); |
|
| 103 | - do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 104 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 105 | - |
|
| 106 | - return $destination_action_id; |
|
| 107 | - } |
|
| 108 | - } |
|
| 16 | + /** var ActionScheduler_Store */ |
|
| 17 | + private $source; |
|
| 18 | + |
|
| 19 | + /** var ActionScheduler_Store */ |
|
| 20 | + private $destination; |
|
| 21 | + |
|
| 22 | + /** var LogMigrator */ |
|
| 23 | + private $log_migrator; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * ActionMigrator constructor. |
|
| 27 | + * |
|
| 28 | + * @param ActionScheduler_Store $source_store Source store object. |
|
| 29 | + * @param ActionScheduler_Store $destination_store Destination store object. |
|
| 30 | + * @param LogMigrator $log_migrator Log migrator object. |
|
| 31 | + */ |
|
| 32 | + public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
| 33 | + $this->source = $source_store; |
|
| 34 | + $this->destination = $destination_store; |
|
| 35 | + $this->log_migrator = $log_migrator; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Migrate an action. |
|
| 40 | + * |
|
| 41 | + * @param int $source_action_id Action ID. |
|
| 42 | + * |
|
| 43 | + * @return int 0|new action ID |
|
| 44 | + */ |
|
| 45 | + public function migrate( $source_action_id ) { |
|
| 46 | + try { |
|
| 47 | + $action = $this->source->fetch_action( $source_action_id ); |
|
| 48 | + $status = $this->source->get_status( $source_action_id ); |
|
| 49 | + } catch ( \Exception $e ) { |
|
| 50 | + $action = null; |
|
| 51 | + $status = ''; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
| 55 | + // null action or empty status means the fetch operation failed or the action didn't exist |
|
| 56 | + // null schedule means it's missing vital data |
|
| 57 | + // delete it and move on |
|
| 58 | + try { |
|
| 59 | + $this->source->delete_action( $source_action_id ); |
|
| 60 | + } catch ( \Exception $e ) { |
|
| 61 | + // nothing to do, it didn't exist in the first place |
|
| 62 | + } |
|
| 63 | + do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
| 64 | + |
|
| 65 | + return 0; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + try { |
|
| 69 | + |
|
| 70 | + // Make sure the last attempt date is set correctly for completed and failed actions |
|
| 71 | + $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
| 72 | + |
|
| 73 | + $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
| 74 | + } catch ( \Exception $e ) { |
|
| 75 | + do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
| 76 | + |
|
| 77 | + return 0; // could not save the action in the new store |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + try { |
|
| 81 | + switch ( $status ) { |
|
| 82 | + case \ActionScheduler_Store::STATUS_FAILED : |
|
| 83 | + $this->destination->mark_failure( $destination_action_id ); |
|
| 84 | + break; |
|
| 85 | + case \ActionScheduler_Store::STATUS_CANCELED : |
|
| 86 | + $this->destination->cancel_action( $destination_action_id ); |
|
| 87 | + break; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
| 91 | + $this->source->delete_action( $source_action_id ); |
|
| 92 | + |
|
| 93 | + $test_action = $this->source->fetch_action( $source_action_id ); |
|
| 94 | + if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
| 95 | + throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'woocommerce' ), $source_action_id ) ); |
|
| 96 | + } |
|
| 97 | + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 98 | + |
|
| 99 | + return $destination_action_id; |
|
| 100 | + } catch ( \Exception $e ) { |
|
| 101 | + // could not delete from the old store |
|
| 102 | + $this->source->mark_migrated( $source_action_id ); |
|
| 103 | + do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 104 | + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 105 | + |
|
| 106 | + return $destination_action_id; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param ActionScheduler_Store $destination_store Destination store object. |
| 30 | 30 | * @param LogMigrator $log_migrator Log migrator object. |
| 31 | 31 | */ |
| 32 | - public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
| 32 | + public function __construct(\ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator) { |
|
| 33 | 33 | $this->source = $source_store; |
| 34 | 34 | $this->destination = $destination_store; |
| 35 | 35 | $this->log_migrator = $log_migrator; |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return int 0|new action ID |
| 44 | 44 | */ |
| 45 | - public function migrate( $source_action_id ) { |
|
| 45 | + public function migrate($source_action_id) { |
|
| 46 | 46 | try { |
| 47 | - $action = $this->source->fetch_action( $source_action_id ); |
|
| 48 | - $status = $this->source->get_status( $source_action_id ); |
|
| 49 | - } catch ( \Exception $e ) { |
|
| 47 | + $action = $this->source->fetch_action($source_action_id); |
|
| 48 | + $status = $this->source->get_status($source_action_id); |
|
| 49 | + } catch (\Exception $e) { |
|
| 50 | 50 | $action = null; |
| 51 | 51 | $status = ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
| 54 | + if (is_null($action) || empty($status) || !$action->get_schedule()->get_date()) { |
|
| 55 | 55 | // null action or empty status means the fetch operation failed or the action didn't exist |
| 56 | 56 | // null schedule means it's missing vital data |
| 57 | 57 | // delete it and move on |
| 58 | 58 | try { |
| 59 | - $this->source->delete_action( $source_action_id ); |
|
| 60 | - } catch ( \Exception $e ) { |
|
| 59 | + $this->source->delete_action($source_action_id); |
|
| 60 | + } catch (\Exception $e) { |
|
| 61 | 61 | // nothing to do, it didn't exist in the first place |
| 62 | 62 | } |
| 63 | - do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
| 63 | + do_action('action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination); |
|
| 64 | 64 | |
| 65 | 65 | return 0; |
| 66 | 66 | } |
@@ -68,40 +68,40 @@ discard block |
||
| 68 | 68 | try { |
| 69 | 69 | |
| 70 | 70 | // Make sure the last attempt date is set correctly for completed and failed actions |
| 71 | - $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
| 71 | + $last_attempt_date = ($status !== \ActionScheduler_Store::STATUS_PENDING) ? $this->source->get_date($source_action_id) : null; |
|
| 72 | 72 | |
| 73 | - $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
| 74 | - } catch ( \Exception $e ) { |
|
| 75 | - do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
| 73 | + $destination_action_id = $this->destination->save_action($action, null, $last_attempt_date); |
|
| 74 | + } catch (\Exception $e) { |
|
| 75 | + do_action('action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination); |
|
| 76 | 76 | |
| 77 | 77 | return 0; // could not save the action in the new store |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | try { |
| 81 | - switch ( $status ) { |
|
| 81 | + switch ($status) { |
|
| 82 | 82 | case \ActionScheduler_Store::STATUS_FAILED : |
| 83 | - $this->destination->mark_failure( $destination_action_id ); |
|
| 83 | + $this->destination->mark_failure($destination_action_id); |
|
| 84 | 84 | break; |
| 85 | 85 | case \ActionScheduler_Store::STATUS_CANCELED : |
| 86 | - $this->destination->cancel_action( $destination_action_id ); |
|
| 86 | + $this->destination->cancel_action($destination_action_id); |
|
| 87 | 87 | break; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
| 91 | - $this->source->delete_action( $source_action_id ); |
|
| 90 | + $this->log_migrator->migrate($source_action_id, $destination_action_id); |
|
| 91 | + $this->source->delete_action($source_action_id); |
|
| 92 | 92 | |
| 93 | - $test_action = $this->source->fetch_action( $source_action_id ); |
|
| 94 | - if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
| 95 | - throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'woocommerce' ), $source_action_id ) ); |
|
| 93 | + $test_action = $this->source->fetch_action($source_action_id); |
|
| 94 | + if (!is_a($test_action, 'ActionScheduler_NullAction')) { |
|
| 95 | + throw new \RuntimeException(sprintf(__('Unable to remove source migrated action %s', 'woocommerce'), $source_action_id)); |
|
| 96 | 96 | } |
| 97 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 97 | + do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
| 98 | 98 | |
| 99 | 99 | return $destination_action_id; |
| 100 | - } catch ( \Exception $e ) { |
|
| 100 | + } catch (\Exception $e) { |
|
| 101 | 101 | // could not delete from the old store |
| 102 | - $this->source->mark_migrated( $source_action_id ); |
|
| 103 | - do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 104 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 102 | + $this->source->mark_migrated($source_action_id); |
|
| 103 | + do_action('action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
| 104 | + do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
| 105 | 105 | |
| 106 | 106 | return $destination_action_id; |
| 107 | 107 | } |
@@ -13,116 +13,116 @@ |
||
| 13 | 13 | * @codeCoverageIgnore |
| 14 | 14 | */ |
| 15 | 15 | class Scheduler { |
| 16 | - /** Migration action hook. */ |
|
| 17 | - const HOOK = 'action_scheduler/migration_hook'; |
|
| 18 | - |
|
| 19 | - /** Migration action group. */ |
|
| 20 | - const GROUP = 'action-scheduler-migration'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set up the callback for the scheduled job. |
|
| 24 | - */ |
|
| 25 | - public function hook() { |
|
| 26 | - add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Remove the callback for the scheduled job. |
|
| 31 | - */ |
|
| 32 | - public function unhook() { |
|
| 33 | - remove_action( self::HOOK, array( $this, 'run_migration' ), 10 ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The migration callback. |
|
| 38 | - */ |
|
| 39 | - public function run_migration() { |
|
| 40 | - $migration_runner = $this->get_migration_runner(); |
|
| 41 | - $count = $migration_runner->run( $this->get_batch_size() ); |
|
| 42 | - |
|
| 43 | - if ( $count === 0 ) { |
|
| 44 | - $this->mark_complete(); |
|
| 45 | - } else { |
|
| 46 | - $this->schedule_migration( time() + $this->get_schedule_interval() ); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Mark the migration complete. |
|
| 52 | - */ |
|
| 53 | - public function mark_complete() { |
|
| 54 | - $this->unschedule_migration(); |
|
| 55 | - |
|
| 56 | - \ActionScheduler_DataController::mark_migration_complete(); |
|
| 57 | - do_action( 'action_scheduler/migration_complete' ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Get a flag indicating whether the migration is scheduled. |
|
| 62 | - * |
|
| 63 | - * @return bool Whether there is a pending action in the store to handle the migration |
|
| 64 | - */ |
|
| 65 | - public function is_migration_scheduled() { |
|
| 66 | - $next = as_next_scheduled_action( self::HOOK ); |
|
| 67 | - |
|
| 68 | - return ! empty( $next ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Schedule the migration. |
|
| 73 | - * |
|
| 74 | - * @param int $when Optional timestamp to run the next migration batch. Defaults to now. |
|
| 75 | - * |
|
| 76 | - * @return string The action ID |
|
| 77 | - */ |
|
| 78 | - public function schedule_migration( $when = 0 ) { |
|
| 79 | - $next = as_next_scheduled_action( self::HOOK ); |
|
| 80 | - |
|
| 81 | - if ( ! empty( $next ) ) { |
|
| 82 | - return $next; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ( empty( $when ) ) { |
|
| 86 | - $when = time() + MINUTE_IN_SECONDS; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Remove the scheduled migration action. |
|
| 94 | - */ |
|
| 95 | - public function unschedule_migration() { |
|
| 96 | - as_unschedule_action( self::HOOK, null, self::GROUP ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Get migration batch schedule interval. |
|
| 101 | - * |
|
| 102 | - * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners. |
|
| 103 | - */ |
|
| 104 | - private function get_schedule_interval() { |
|
| 105 | - return (int) apply_filters( 'action_scheduler/migration_interval', 0 ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get migration batch size. |
|
| 110 | - * |
|
| 111 | - * @return int Number of actions to migrate in each batch. Defaults to 250. |
|
| 112 | - */ |
|
| 113 | - private function get_batch_size() { |
|
| 114 | - return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Get migration runner object. |
|
| 119 | - * |
|
| 120 | - * @return Runner |
|
| 121 | - */ |
|
| 122 | - private function get_migration_runner() { |
|
| 123 | - $config = Controller::instance()->get_migration_config_object(); |
|
| 124 | - |
|
| 125 | - return new Runner( $config ); |
|
| 126 | - } |
|
| 16 | + /** Migration action hook. */ |
|
| 17 | + const HOOK = 'action_scheduler/migration_hook'; |
|
| 18 | + |
|
| 19 | + /** Migration action group. */ |
|
| 20 | + const GROUP = 'action-scheduler-migration'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set up the callback for the scheduled job. |
|
| 24 | + */ |
|
| 25 | + public function hook() { |
|
| 26 | + add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Remove the callback for the scheduled job. |
|
| 31 | + */ |
|
| 32 | + public function unhook() { |
|
| 33 | + remove_action( self::HOOK, array( $this, 'run_migration' ), 10 ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The migration callback. |
|
| 38 | + */ |
|
| 39 | + public function run_migration() { |
|
| 40 | + $migration_runner = $this->get_migration_runner(); |
|
| 41 | + $count = $migration_runner->run( $this->get_batch_size() ); |
|
| 42 | + |
|
| 43 | + if ( $count === 0 ) { |
|
| 44 | + $this->mark_complete(); |
|
| 45 | + } else { |
|
| 46 | + $this->schedule_migration( time() + $this->get_schedule_interval() ); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Mark the migration complete. |
|
| 52 | + */ |
|
| 53 | + public function mark_complete() { |
|
| 54 | + $this->unschedule_migration(); |
|
| 55 | + |
|
| 56 | + \ActionScheduler_DataController::mark_migration_complete(); |
|
| 57 | + do_action( 'action_scheduler/migration_complete' ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Get a flag indicating whether the migration is scheduled. |
|
| 62 | + * |
|
| 63 | + * @return bool Whether there is a pending action in the store to handle the migration |
|
| 64 | + */ |
|
| 65 | + public function is_migration_scheduled() { |
|
| 66 | + $next = as_next_scheduled_action( self::HOOK ); |
|
| 67 | + |
|
| 68 | + return ! empty( $next ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Schedule the migration. |
|
| 73 | + * |
|
| 74 | + * @param int $when Optional timestamp to run the next migration batch. Defaults to now. |
|
| 75 | + * |
|
| 76 | + * @return string The action ID |
|
| 77 | + */ |
|
| 78 | + public function schedule_migration( $when = 0 ) { |
|
| 79 | + $next = as_next_scheduled_action( self::HOOK ); |
|
| 80 | + |
|
| 81 | + if ( ! empty( $next ) ) { |
|
| 82 | + return $next; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if ( empty( $when ) ) { |
|
| 86 | + $when = time() + MINUTE_IN_SECONDS; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Remove the scheduled migration action. |
|
| 94 | + */ |
|
| 95 | + public function unschedule_migration() { |
|
| 96 | + as_unschedule_action( self::HOOK, null, self::GROUP ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Get migration batch schedule interval. |
|
| 101 | + * |
|
| 102 | + * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners. |
|
| 103 | + */ |
|
| 104 | + private function get_schedule_interval() { |
|
| 105 | + return (int) apply_filters( 'action_scheduler/migration_interval', 0 ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get migration batch size. |
|
| 110 | + * |
|
| 111 | + * @return int Number of actions to migrate in each batch. Defaults to 250. |
|
| 112 | + */ |
|
| 113 | + private function get_batch_size() { |
|
| 114 | + return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Get migration runner object. |
|
| 119 | + * |
|
| 120 | + * @return Runner |
|
| 121 | + */ |
|
| 122 | + private function get_migration_runner() { |
|
| 123 | + $config = Controller::instance()->get_migration_config_object(); |
|
| 124 | + |
|
| 125 | + return new Runner( $config ); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | } |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * Set up the callback for the scheduled job. |
| 24 | 24 | */ |
| 25 | 25 | public function hook() { |
| 26 | - add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 ); |
|
| 26 | + add_action(self::HOOK, array($this, 'run_migration'), 10, 0); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Remove the callback for the scheduled job. |
| 31 | 31 | */ |
| 32 | 32 | public function unhook() { |
| 33 | - remove_action( self::HOOK, array( $this, 'run_migration' ), 10 ); |
|
| 33 | + remove_action(self::HOOK, array($this, 'run_migration'), 10); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function run_migration() { |
| 40 | 40 | $migration_runner = $this->get_migration_runner(); |
| 41 | - $count = $migration_runner->run( $this->get_batch_size() ); |
|
| 41 | + $count = $migration_runner->run($this->get_batch_size()); |
|
| 42 | 42 | |
| 43 | - if ( $count === 0 ) { |
|
| 43 | + if ($count === 0) { |
|
| 44 | 44 | $this->mark_complete(); |
| 45 | 45 | } else { |
| 46 | - $this->schedule_migration( time() + $this->get_schedule_interval() ); |
|
| 46 | + $this->schedule_migration(time() + $this->get_schedule_interval()); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $this->unschedule_migration(); |
| 55 | 55 | |
| 56 | 56 | \ActionScheduler_DataController::mark_migration_complete(); |
| 57 | - do_action( 'action_scheduler/migration_complete' ); |
|
| 57 | + do_action('action_scheduler/migration_complete'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * @return bool Whether there is a pending action in the store to handle the migration |
| 64 | 64 | */ |
| 65 | 65 | public function is_migration_scheduled() { |
| 66 | - $next = as_next_scheduled_action( self::HOOK ); |
|
| 66 | + $next = as_next_scheduled_action(self::HOOK); |
|
| 67 | 67 | |
| 68 | - return ! empty( $next ); |
|
| 68 | + return !empty($next); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -75,25 +75,25 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return string The action ID |
| 77 | 77 | */ |
| 78 | - public function schedule_migration( $when = 0 ) { |
|
| 79 | - $next = as_next_scheduled_action( self::HOOK ); |
|
| 78 | + public function schedule_migration($when = 0) { |
|
| 79 | + $next = as_next_scheduled_action(self::HOOK); |
|
| 80 | 80 | |
| 81 | - if ( ! empty( $next ) ) { |
|
| 81 | + if (!empty($next)) { |
|
| 82 | 82 | return $next; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( empty( $when ) ) { |
|
| 85 | + if (empty($when)) { |
|
| 86 | 86 | $when = time() + MINUTE_IN_SECONDS; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); |
|
| 89 | + return as_schedule_single_action($when, self::HOOK, array(), self::GROUP); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Remove the scheduled migration action. |
| 94 | 94 | */ |
| 95 | 95 | public function unschedule_migration() { |
| 96 | - as_unschedule_action( self::HOOK, null, self::GROUP ); |
|
| 96 | + as_unschedule_action(self::HOOK, null, self::GROUP); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners. |
| 103 | 103 | */ |
| 104 | 104 | private function get_schedule_interval() { |
| 105 | - return (int) apply_filters( 'action_scheduler/migration_interval', 0 ); |
|
| 105 | + return (int) apply_filters('action_scheduler/migration_interval', 0); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return int Number of actions to migrate in each batch. Defaults to 250. |
| 112 | 112 | */ |
| 113 | 113 | private function get_batch_size() { |
| 114 | - return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 ); |
|
| 114 | + return (int) apply_filters('action_scheduler/migration_batch_size', 250); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | private function get_migration_runner() { |
| 123 | 123 | $config = Controller::instance()->get_migration_config_object(); |
| 124 | 124 | |
| 125 | - return new Runner( $config ); |
|
| 125 | + return new Runner($config); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | } |
@@ -17,152 +17,152 @@ |
||
| 17 | 17 | * A config builder for the ActionScheduler\Migration\Runner class |
| 18 | 18 | */ |
| 19 | 19 | class Config { |
| 20 | - /** @var ActionScheduler_Store */ |
|
| 21 | - private $source_store; |
|
| 22 | - |
|
| 23 | - /** @var ActionScheduler_Logger */ |
|
| 24 | - private $source_logger; |
|
| 25 | - |
|
| 26 | - /** @var ActionScheduler_Store */ |
|
| 27 | - private $destination_store; |
|
| 28 | - |
|
| 29 | - /** @var ActionScheduler_Logger */ |
|
| 30 | - private $destination_logger; |
|
| 31 | - |
|
| 32 | - /** @var Progress bar */ |
|
| 33 | - private $progress_bar; |
|
| 34 | - |
|
| 35 | - /** @var bool */ |
|
| 36 | - private $dry_run = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Config constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() { |
|
| 42 | - |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Get the configured source store. |
|
| 47 | - * |
|
| 48 | - * @return ActionScheduler_Store |
|
| 49 | - */ |
|
| 50 | - public function get_source_store() { |
|
| 51 | - if ( empty( $this->source_store ) ) { |
|
| 52 | - throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'woocommerce' ) ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $this->source_store; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Set the configured source store. |
|
| 60 | - * |
|
| 61 | - * @param ActionScheduler_Store $store Source store object. |
|
| 62 | - */ |
|
| 63 | - public function set_source_store( Store $store ) { |
|
| 64 | - $this->source_store = $store; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Get the configured source loger. |
|
| 69 | - * |
|
| 70 | - * @return ActionScheduler_Logger |
|
| 71 | - */ |
|
| 72 | - public function get_source_logger() { |
|
| 73 | - if ( empty( $this->source_logger ) ) { |
|
| 74 | - throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'woocommerce' ) ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $this->source_logger; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Set the configured source logger. |
|
| 82 | - * |
|
| 83 | - * @param ActionScheduler_Logger $logger |
|
| 84 | - */ |
|
| 85 | - public function set_source_logger( Logger $logger ) { |
|
| 86 | - $this->source_logger = $logger; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Get the configured destination store. |
|
| 91 | - * |
|
| 92 | - * @return ActionScheduler_Store |
|
| 93 | - */ |
|
| 94 | - public function get_destination_store() { |
|
| 95 | - if ( empty( $this->destination_store ) ) { |
|
| 96 | - throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'woocommerce' ) ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $this->destination_store; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Set the configured destination store. |
|
| 104 | - * |
|
| 105 | - * @param ActionScheduler_Store $store |
|
| 106 | - */ |
|
| 107 | - public function set_destination_store( Store $store ) { |
|
| 108 | - $this->destination_store = $store; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Get the configured destination logger. |
|
| 113 | - * |
|
| 114 | - * @return ActionScheduler_Logger |
|
| 115 | - */ |
|
| 116 | - public function get_destination_logger() { |
|
| 117 | - if ( empty( $this->destination_logger ) ) { |
|
| 118 | - throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'woocommerce' ) ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $this->destination_logger; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set the configured destination logger. |
|
| 126 | - * |
|
| 127 | - * @param ActionScheduler_Logger $logger |
|
| 128 | - */ |
|
| 129 | - public function set_destination_logger( Logger $logger ) { |
|
| 130 | - $this->destination_logger = $logger; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Get flag indicating whether it's a dry run. |
|
| 135 | - * |
|
| 136 | - * @return bool |
|
| 137 | - */ |
|
| 138 | - public function get_dry_run() { |
|
| 139 | - return $this->dry_run; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Set flag indicating whether it's a dry run. |
|
| 144 | - * |
|
| 145 | - * @param bool $dry_run |
|
| 146 | - */ |
|
| 147 | - public function set_dry_run( $dry_run ) { |
|
| 148 | - $this->dry_run = (bool) $dry_run; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Get progress bar object. |
|
| 153 | - * |
|
| 154 | - * @return ActionScheduler\WPCLI\ProgressBar |
|
| 155 | - */ |
|
| 156 | - public function get_progress_bar() { |
|
| 157 | - return $this->progress_bar; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Set progress bar object. |
|
| 162 | - * |
|
| 163 | - * @param ActionScheduler\WPCLI\ProgressBar $progress_bar |
|
| 164 | - */ |
|
| 165 | - public function set_progress_bar( ProgressBar $progress_bar ) { |
|
| 166 | - $this->progress_bar = $progress_bar; |
|
| 167 | - } |
|
| 20 | + /** @var ActionScheduler_Store */ |
|
| 21 | + private $source_store; |
|
| 22 | + |
|
| 23 | + /** @var ActionScheduler_Logger */ |
|
| 24 | + private $source_logger; |
|
| 25 | + |
|
| 26 | + /** @var ActionScheduler_Store */ |
|
| 27 | + private $destination_store; |
|
| 28 | + |
|
| 29 | + /** @var ActionScheduler_Logger */ |
|
| 30 | + private $destination_logger; |
|
| 31 | + |
|
| 32 | + /** @var Progress bar */ |
|
| 33 | + private $progress_bar; |
|
| 34 | + |
|
| 35 | + /** @var bool */ |
|
| 36 | + private $dry_run = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Config constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() { |
|
| 42 | + |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Get the configured source store. |
|
| 47 | + * |
|
| 48 | + * @return ActionScheduler_Store |
|
| 49 | + */ |
|
| 50 | + public function get_source_store() { |
|
| 51 | + if ( empty( $this->source_store ) ) { |
|
| 52 | + throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'woocommerce' ) ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $this->source_store; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Set the configured source store. |
|
| 60 | + * |
|
| 61 | + * @param ActionScheduler_Store $store Source store object. |
|
| 62 | + */ |
|
| 63 | + public function set_source_store( Store $store ) { |
|
| 64 | + $this->source_store = $store; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Get the configured source loger. |
|
| 69 | + * |
|
| 70 | + * @return ActionScheduler_Logger |
|
| 71 | + */ |
|
| 72 | + public function get_source_logger() { |
|
| 73 | + if ( empty( $this->source_logger ) ) { |
|
| 74 | + throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'woocommerce' ) ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $this->source_logger; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Set the configured source logger. |
|
| 82 | + * |
|
| 83 | + * @param ActionScheduler_Logger $logger |
|
| 84 | + */ |
|
| 85 | + public function set_source_logger( Logger $logger ) { |
|
| 86 | + $this->source_logger = $logger; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Get the configured destination store. |
|
| 91 | + * |
|
| 92 | + * @return ActionScheduler_Store |
|
| 93 | + */ |
|
| 94 | + public function get_destination_store() { |
|
| 95 | + if ( empty( $this->destination_store ) ) { |
|
| 96 | + throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'woocommerce' ) ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $this->destination_store; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Set the configured destination store. |
|
| 104 | + * |
|
| 105 | + * @param ActionScheduler_Store $store |
|
| 106 | + */ |
|
| 107 | + public function set_destination_store( Store $store ) { |
|
| 108 | + $this->destination_store = $store; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Get the configured destination logger. |
|
| 113 | + * |
|
| 114 | + * @return ActionScheduler_Logger |
|
| 115 | + */ |
|
| 116 | + public function get_destination_logger() { |
|
| 117 | + if ( empty( $this->destination_logger ) ) { |
|
| 118 | + throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'woocommerce' ) ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $this->destination_logger; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set the configured destination logger. |
|
| 126 | + * |
|
| 127 | + * @param ActionScheduler_Logger $logger |
|
| 128 | + */ |
|
| 129 | + public function set_destination_logger( Logger $logger ) { |
|
| 130 | + $this->destination_logger = $logger; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Get flag indicating whether it's a dry run. |
|
| 135 | + * |
|
| 136 | + * @return bool |
|
| 137 | + */ |
|
| 138 | + public function get_dry_run() { |
|
| 139 | + return $this->dry_run; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Set flag indicating whether it's a dry run. |
|
| 144 | + * |
|
| 145 | + * @param bool $dry_run |
|
| 146 | + */ |
|
| 147 | + public function set_dry_run( $dry_run ) { |
|
| 148 | + $this->dry_run = (bool) $dry_run; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Get progress bar object. |
|
| 153 | + * |
|
| 154 | + * @return ActionScheduler\WPCLI\ProgressBar |
|
| 155 | + */ |
|
| 156 | + public function get_progress_bar() { |
|
| 157 | + return $this->progress_bar; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Set progress bar object. |
|
| 162 | + * |
|
| 163 | + * @param ActionScheduler\WPCLI\ProgressBar $progress_bar |
|
| 164 | + */ |
|
| 165 | + public function set_progress_bar( ProgressBar $progress_bar ) { |
|
| 166 | + $this->progress_bar = $progress_bar; |
|
| 167 | + } |
|
| 168 | 168 | } |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | * @return ActionScheduler_Store |
| 49 | 49 | */ |
| 50 | 50 | public function get_source_store() { |
| 51 | - if ( empty( $this->source_store ) ) { |
|
| 52 | - throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'woocommerce' ) ); |
|
| 51 | + if (empty($this->source_store)) { |
|
| 52 | + throw new \RuntimeException(__('Source store must be configured before running a migration', 'woocommerce')); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $this->source_store; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param ActionScheduler_Store $store Source store object. |
| 62 | 62 | */ |
| 63 | - public function set_source_store( Store $store ) { |
|
| 63 | + public function set_source_store(Store $store) { |
|
| 64 | 64 | $this->source_store = $store; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * @return ActionScheduler_Logger |
| 71 | 71 | */ |
| 72 | 72 | public function get_source_logger() { |
| 73 | - if ( empty( $this->source_logger ) ) { |
|
| 74 | - throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'woocommerce' ) ); |
|
| 73 | + if (empty($this->source_logger)) { |
|
| 74 | + throw new \RuntimeException(__('Source logger must be configured before running a migration', 'woocommerce')); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | return $this->source_logger; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @param ActionScheduler_Logger $logger |
| 84 | 84 | */ |
| 85 | - public function set_source_logger( Logger $logger ) { |
|
| 85 | + public function set_source_logger(Logger $logger) { |
|
| 86 | 86 | $this->source_logger = $logger; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * @return ActionScheduler_Store |
| 93 | 93 | */ |
| 94 | 94 | public function get_destination_store() { |
| 95 | - if ( empty( $this->destination_store ) ) { |
|
| 96 | - throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'woocommerce' ) ); |
|
| 95 | + if (empty($this->destination_store)) { |
|
| 96 | + throw new \RuntimeException(__('Destination store must be configured before running a migration', 'woocommerce')); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return $this->destination_store; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @param ActionScheduler_Store $store |
| 106 | 106 | */ |
| 107 | - public function set_destination_store( Store $store ) { |
|
| 107 | + public function set_destination_store(Store $store) { |
|
| 108 | 108 | $this->destination_store = $store; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | * @return ActionScheduler_Logger |
| 115 | 115 | */ |
| 116 | 116 | public function get_destination_logger() { |
| 117 | - if ( empty( $this->destination_logger ) ) { |
|
| 118 | - throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'woocommerce' ) ); |
|
| 117 | + if (empty($this->destination_logger)) { |
|
| 118 | + throw new \RuntimeException(__('Destination logger must be configured before running a migration', 'woocommerce')); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | return $this->destination_logger; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @param ActionScheduler_Logger $logger |
| 128 | 128 | */ |
| 129 | - public function set_destination_logger( Logger $logger ) { |
|
| 129 | + public function set_destination_logger(Logger $logger) { |
|
| 130 | 130 | $this->destination_logger = $logger; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @param bool $dry_run |
| 146 | 146 | */ |
| 147 | - public function set_dry_run( $dry_run ) { |
|
| 147 | + public function set_dry_run($dry_run) { |
|
| 148 | 148 | $this->dry_run = (bool) $dry_run; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @param ActionScheduler\WPCLI\ProgressBar $progress_bar |
| 164 | 164 | */ |
| 165 | - public function set_progress_bar( ProgressBar $progress_bar ) { |
|
| 165 | + public function set_progress_bar(ProgressBar $progress_bar) { |
|
| 166 | 166 | $this->progress_bar = $progress_bar; |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -16,71 +16,71 @@ |
||
| 16 | 16 | * @codeCoverageIgnore |
| 17 | 17 | */ |
| 18 | 18 | class BatchFetcher { |
| 19 | - /** var ActionScheduler_Store */ |
|
| 20 | - private $store; |
|
| 19 | + /** var ActionScheduler_Store */ |
|
| 20 | + private $store; |
|
| 21 | 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 | - } |
|
| 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 | 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 | - } |
|
| 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 | 45 | |
| 46 | - return []; |
|
| 47 | - } |
|
| 46 | + return []; |
|
| 47 | + } |
|
| 48 | 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 | - ]; |
|
| 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 | 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 | - ]; |
|
| 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 | 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 | - } |
|
| 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 | 86 | } |
| 87 | 87 | \ No newline at end of file |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param ActionScheduler_Store $source_store Source store object. |
| 26 | 26 | */ |
| 27 | - public function __construct( Store $source_store ) { |
|
| 27 | + public function __construct(Store $source_store) { |
|
| 28 | 28 | $this->store = $source_store; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return int[] A list of action IDs |
| 37 | 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 ) ) { |
|
| 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 | 42 | return $action_ids; |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return array |
| 55 | 55 | */ |
| 56 | - private function get_query_strategies( $count ) { |
|
| 56 | + private function get_query_strategies($count) { |
|
| 57 | 57 | $now = as_get_datetime_object(); |
| 58 | 58 | $args = [ |
| 59 | 59 | 'date' => $now, |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | '', // any other unanticipated status |
| 73 | 73 | ]; |
| 74 | 74 | |
| 75 | - foreach ( $priorities as $status ) { |
|
| 76 | - yield wp_parse_args( [ |
|
| 75 | + foreach ($priorities as $status) { |
|
| 76 | + yield wp_parse_args([ |
|
| 77 | 77 | 'status' => $status, |
| 78 | 78 | 'date_compare' => '<=', |
| 79 | - ], $args ); |
|
| 80 | - yield wp_parse_args( [ |
|
| 79 | + ], $args); |
|
| 80 | + yield wp_parse_args([ |
|
| 81 | 81 | 'status' => $status, |
| 82 | 82 | 'date_compare' => '>=', |
| 83 | - ], $args ); |
|
| 83 | + ], $args); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | \ No newline at end of file |
@@ -19,85 +19,85 @@ discard block |
||
| 19 | 19 | * @codeCoverageIgnore |
| 20 | 20 | */ |
| 21 | 21 | class Controller { |
| 22 | - private static $instance; |
|
| 23 | - |
|
| 24 | - /** @var Action_Scheduler\Migration\Scheduler */ |
|
| 25 | - private $migration_scheduler; |
|
| 26 | - |
|
| 27 | - /** @var string */ |
|
| 28 | - private $store_classname; |
|
| 29 | - |
|
| 30 | - /** @var string */ |
|
| 31 | - private $logger_classname; |
|
| 32 | - |
|
| 33 | - /** @var bool */ |
|
| 34 | - private $migrate_custom_store; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Controller constructor. |
|
| 38 | - * |
|
| 39 | - * @param Scheduler $migration_scheduler Migration scheduler object. |
|
| 40 | - */ |
|
| 41 | - protected function __construct( Scheduler $migration_scheduler ) { |
|
| 42 | - $this->migration_scheduler = $migration_scheduler; |
|
| 43 | - $this->store_classname = ''; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Set the action store class name. |
|
| 48 | - * |
|
| 49 | - * @param string $class Classname of the store class. |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function get_store_class( $class ) { |
|
| 54 | - if ( \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 55 | - return \ActionScheduler_DataController::DATASTORE_CLASS; |
|
| 56 | - } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { |
|
| 57 | - $this->store_classname = $class; |
|
| 58 | - return $class; |
|
| 59 | - } else { |
|
| 60 | - return 'ActionScheduler_HybridStore'; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Set the action logger class name. |
|
| 66 | - * |
|
| 67 | - * @param string $class Classname of the logger class. |
|
| 68 | - * |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public function get_logger_class( $class ) { |
|
| 72 | - \ActionScheduler_Store::instance(); |
|
| 73 | - |
|
| 74 | - if ( $this->has_custom_datastore() ) { |
|
| 75 | - $this->logger_classname = $class; |
|
| 76 | - return $class; |
|
| 77 | - } else { |
|
| 78 | - return \ActionScheduler_DataController::LOGGER_CLASS; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Get flag indicating whether a custom datastore is in use. |
|
| 84 | - * |
|
| 85 | - * @return bool |
|
| 86 | - */ |
|
| 87 | - public function has_custom_datastore() { |
|
| 88 | - return (bool) $this->store_classname; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set up the background migration process. |
|
| 93 | - * |
|
| 94 | - * @return void |
|
| 95 | - */ |
|
| 96 | - public function schedule_migration() { |
|
| 97 | - $logging_tables = new ActionScheduler_LoggerSchema(); |
|
| 98 | - $store_tables = new ActionScheduler_StoreSchema(); |
|
| 99 | - |
|
| 100 | - /* |
|
| 22 | + private static $instance; |
|
| 23 | + |
|
| 24 | + /** @var Action_Scheduler\Migration\Scheduler */ |
|
| 25 | + private $migration_scheduler; |
|
| 26 | + |
|
| 27 | + /** @var string */ |
|
| 28 | + private $store_classname; |
|
| 29 | + |
|
| 30 | + /** @var string */ |
|
| 31 | + private $logger_classname; |
|
| 32 | + |
|
| 33 | + /** @var bool */ |
|
| 34 | + private $migrate_custom_store; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Controller constructor. |
|
| 38 | + * |
|
| 39 | + * @param Scheduler $migration_scheduler Migration scheduler object. |
|
| 40 | + */ |
|
| 41 | + protected function __construct( Scheduler $migration_scheduler ) { |
|
| 42 | + $this->migration_scheduler = $migration_scheduler; |
|
| 43 | + $this->store_classname = ''; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Set the action store class name. |
|
| 48 | + * |
|
| 49 | + * @param string $class Classname of the store class. |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function get_store_class( $class ) { |
|
| 54 | + if ( \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 55 | + return \ActionScheduler_DataController::DATASTORE_CLASS; |
|
| 56 | + } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { |
|
| 57 | + $this->store_classname = $class; |
|
| 58 | + return $class; |
|
| 59 | + } else { |
|
| 60 | + return 'ActionScheduler_HybridStore'; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Set the action logger class name. |
|
| 66 | + * |
|
| 67 | + * @param string $class Classname of the logger class. |
|
| 68 | + * |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public function get_logger_class( $class ) { |
|
| 72 | + \ActionScheduler_Store::instance(); |
|
| 73 | + |
|
| 74 | + if ( $this->has_custom_datastore() ) { |
|
| 75 | + $this->logger_classname = $class; |
|
| 76 | + return $class; |
|
| 77 | + } else { |
|
| 78 | + return \ActionScheduler_DataController::LOGGER_CLASS; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Get flag indicating whether a custom datastore is in use. |
|
| 84 | + * |
|
| 85 | + * @return bool |
|
| 86 | + */ |
|
| 87 | + public function has_custom_datastore() { |
|
| 88 | + return (bool) $this->store_classname; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set up the background migration process. |
|
| 93 | + * |
|
| 94 | + * @return void |
|
| 95 | + */ |
|
| 96 | + public function schedule_migration() { |
|
| 97 | + $logging_tables = new ActionScheduler_LoggerSchema(); |
|
| 98 | + $store_tables = new ActionScheduler_StoreSchema(); |
|
| 99 | + |
|
| 100 | + /* |
|
| 101 | 101 | * In some unusual cases, the expected tables may not have been created. In such cases |
| 102 | 102 | * we do not schedule a migration as doing so will lead to fatal error conditions. |
| 103 | 103 | * |
@@ -107,120 +107,120 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @see https://github.com/woocommerce/action-scheduler/issues/653 |
| 109 | 109 | */ |
| 110 | - if ( |
|
| 111 | - ActionScheduler_DataController::is_migration_complete() |
|
| 112 | - || $this->migration_scheduler->is_migration_scheduled() |
|
| 113 | - || ! $store_tables->tables_exist() |
|
| 114 | - || ! $logging_tables->tables_exist() |
|
| 115 | - ) { |
|
| 116 | - return; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $this->migration_scheduler->schedule_migration(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Get the default migration config object |
|
| 124 | - * |
|
| 125 | - * @return ActionScheduler\Migration\Config |
|
| 126 | - */ |
|
| 127 | - public function get_migration_config_object() { |
|
| 128 | - static $config = null; |
|
| 129 | - |
|
| 130 | - if ( ! $config ) { |
|
| 131 | - $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); |
|
| 132 | - $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); |
|
| 133 | - |
|
| 134 | - $config = new Config(); |
|
| 135 | - $config->set_source_store( $source_store ); |
|
| 136 | - $config->set_source_logger( $source_logger ); |
|
| 137 | - $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); |
|
| 138 | - $config->set_destination_logger( new \ActionScheduler_DBLogger() ); |
|
| 139 | - |
|
| 140 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 141 | - $config->set_progress_bar( new ProgressBar( '', 0 ) ); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return apply_filters( 'action_scheduler/migration_config', $config ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Hook dashboard migration notice. |
|
| 150 | - */ |
|
| 151 | - public function hook_admin_notices() { |
|
| 152 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 153 | - return; |
|
| 154 | - } |
|
| 155 | - add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Show a dashboard notice that migration is in progress. |
|
| 160 | - */ |
|
| 161 | - public function display_migration_notice() { |
|
| 162 | - printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'woocommerce' ) ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Add store classes. Hook migration. |
|
| 167 | - */ |
|
| 168 | - private function hook() { |
|
| 169 | - add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); |
|
| 170 | - add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); |
|
| 171 | - add_action( 'init', array( $this, 'maybe_hook_migration' ) ); |
|
| 172 | - add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); |
|
| 173 | - |
|
| 174 | - // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
|
| 175 | - add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
| 176 | - add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Possibly hook the migration scheduler action. |
|
| 181 | - * |
|
| 182 | - * @author Jeremy Pry |
|
| 183 | - */ |
|
| 184 | - public function maybe_hook_migration() { |
|
| 185 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $this->migration_scheduler->hook(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Allow datastores to enable migration to AS tables. |
|
| 194 | - */ |
|
| 195 | - public function allow_migration() { |
|
| 196 | - if ( ! \ActionScheduler_DataController::dependencies_met() ) { |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ( null === $this->migrate_custom_store ) { |
|
| 201 | - $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Proceed with the migration if the dependencies have been met. |
|
| 209 | - */ |
|
| 210 | - public static function init() { |
|
| 211 | - if ( \ActionScheduler_DataController::dependencies_met() ) { |
|
| 212 | - self::instance()->hook(); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Singleton factory. |
|
| 218 | - */ |
|
| 219 | - public static function instance() { |
|
| 220 | - if ( ! isset( self::$instance ) ) { |
|
| 221 | - self::$instance = new static( new Scheduler() ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - return self::$instance; |
|
| 225 | - } |
|
| 110 | + if ( |
|
| 111 | + ActionScheduler_DataController::is_migration_complete() |
|
| 112 | + || $this->migration_scheduler->is_migration_scheduled() |
|
| 113 | + || ! $store_tables->tables_exist() |
|
| 114 | + || ! $logging_tables->tables_exist() |
|
| 115 | + ) { |
|
| 116 | + return; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $this->migration_scheduler->schedule_migration(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Get the default migration config object |
|
| 124 | + * |
|
| 125 | + * @return ActionScheduler\Migration\Config |
|
| 126 | + */ |
|
| 127 | + public function get_migration_config_object() { |
|
| 128 | + static $config = null; |
|
| 129 | + |
|
| 130 | + if ( ! $config ) { |
|
| 131 | + $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); |
|
| 132 | + $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); |
|
| 133 | + |
|
| 134 | + $config = new Config(); |
|
| 135 | + $config->set_source_store( $source_store ); |
|
| 136 | + $config->set_source_logger( $source_logger ); |
|
| 137 | + $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); |
|
| 138 | + $config->set_destination_logger( new \ActionScheduler_DBLogger() ); |
|
| 139 | + |
|
| 140 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 141 | + $config->set_progress_bar( new ProgressBar( '', 0 ) ); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return apply_filters( 'action_scheduler/migration_config', $config ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Hook dashboard migration notice. |
|
| 150 | + */ |
|
| 151 | + public function hook_admin_notices() { |
|
| 152 | + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 153 | + return; |
|
| 154 | + } |
|
| 155 | + add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Show a dashboard notice that migration is in progress. |
|
| 160 | + */ |
|
| 161 | + public function display_migration_notice() { |
|
| 162 | + printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'woocommerce' ) ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Add store classes. Hook migration. |
|
| 167 | + */ |
|
| 168 | + private function hook() { |
|
| 169 | + add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); |
|
| 170 | + add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); |
|
| 171 | + add_action( 'init', array( $this, 'maybe_hook_migration' ) ); |
|
| 172 | + add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); |
|
| 173 | + |
|
| 174 | + // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
|
| 175 | + add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
| 176 | + add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Possibly hook the migration scheduler action. |
|
| 181 | + * |
|
| 182 | + * @author Jeremy Pry |
|
| 183 | + */ |
|
| 184 | + public function maybe_hook_migration() { |
|
| 185 | + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $this->migration_scheduler->hook(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Allow datastores to enable migration to AS tables. |
|
| 194 | + */ |
|
| 195 | + public function allow_migration() { |
|
| 196 | + if ( ! \ActionScheduler_DataController::dependencies_met() ) { |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ( null === $this->migrate_custom_store ) { |
|
| 201 | + $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Proceed with the migration if the dependencies have been met. |
|
| 209 | + */ |
|
| 210 | + public static function init() { |
|
| 211 | + if ( \ActionScheduler_DataController::dependencies_met() ) { |
|
| 212 | + self::instance()->hook(); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Singleton factory. |
|
| 218 | + */ |
|
| 219 | + public static function instance() { |
|
| 220 | + if ( ! isset( self::$instance ) ) { |
|
| 221 | + self::$instance = new static( new Scheduler() ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + return self::$instance; |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param Scheduler $migration_scheduler Migration scheduler object. |
| 40 | 40 | */ |
| 41 | - protected function __construct( Scheduler $migration_scheduler ) { |
|
| 41 | + protected function __construct(Scheduler $migration_scheduler) { |
|
| 42 | 42 | $this->migration_scheduler = $migration_scheduler; |
| 43 | 43 | $this->store_classname = ''; |
| 44 | 44 | } |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string |
| 52 | 52 | */ |
| 53 | - public function get_store_class( $class ) { |
|
| 54 | - if ( \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 53 | + public function get_store_class($class) { |
|
| 54 | + if (\ActionScheduler_DataController::is_migration_complete()) { |
|
| 55 | 55 | return \ActionScheduler_DataController::DATASTORE_CLASS; |
| 56 | - } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { |
|
| 56 | + } elseif (\ActionScheduler_Store::DEFAULT_CLASS !== $class) { |
|
| 57 | 57 | $this->store_classname = $class; |
| 58 | 58 | return $class; |
| 59 | 59 | } else { |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | - public function get_logger_class( $class ) { |
|
| 71 | + public function get_logger_class($class) { |
|
| 72 | 72 | \ActionScheduler_Store::instance(); |
| 73 | 73 | |
| 74 | - if ( $this->has_custom_datastore() ) { |
|
| 74 | + if ($this->has_custom_datastore()) { |
|
| 75 | 75 | $this->logger_classname = $class; |
| 76 | 76 | return $class; |
| 77 | 77 | } else { |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | if ( |
| 111 | 111 | ActionScheduler_DataController::is_migration_complete() |
| 112 | 112 | || $this->migration_scheduler->is_migration_scheduled() |
| 113 | - || ! $store_tables->tables_exist() |
|
| 114 | - || ! $logging_tables->tables_exist() |
|
| 113 | + || !$store_tables->tables_exist() |
|
| 114 | + || !$logging_tables->tables_exist() |
|
| 115 | 115 | ) { |
| 116 | 116 | return; |
| 117 | 117 | } |
@@ -127,53 +127,53 @@ discard block |
||
| 127 | 127 | public function get_migration_config_object() { |
| 128 | 128 | static $config = null; |
| 129 | 129 | |
| 130 | - if ( ! $config ) { |
|
| 130 | + if (!$config) { |
|
| 131 | 131 | $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); |
| 132 | 132 | $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); |
| 133 | 133 | |
| 134 | 134 | $config = new Config(); |
| 135 | - $config->set_source_store( $source_store ); |
|
| 136 | - $config->set_source_logger( $source_logger ); |
|
| 137 | - $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); |
|
| 138 | - $config->set_destination_logger( new \ActionScheduler_DBLogger() ); |
|
| 135 | + $config->set_source_store($source_store); |
|
| 136 | + $config->set_source_logger($source_logger); |
|
| 137 | + $config->set_destination_store(new \ActionScheduler_DBStoreMigrator()); |
|
| 138 | + $config->set_destination_logger(new \ActionScheduler_DBLogger()); |
|
| 139 | 139 | |
| 140 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 141 | - $config->set_progress_bar( new ProgressBar( '', 0 ) ); |
|
| 140 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 141 | + $config->set_progress_bar(new ProgressBar('', 0)); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - return apply_filters( 'action_scheduler/migration_config', $config ); |
|
| 145 | + return apply_filters('action_scheduler/migration_config', $config); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * Hook dashboard migration notice. |
| 150 | 150 | */ |
| 151 | 151 | public function hook_admin_notices() { |
| 152 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 152 | + if (!$this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) { |
|
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | - add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); |
|
| 155 | + add_action('admin_notices', array($this, 'display_migration_notice'), 10, 0); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | 159 | * Show a dashboard notice that migration is in progress. |
| 160 | 160 | */ |
| 161 | 161 | public function display_migration_notice() { |
| 162 | - printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'woocommerce' ) ); |
|
| 162 | + printf('<div class="notice notice-warning"><p>%s</p></div>', esc_html__('Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'woocommerce')); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | 166 | * Add store classes. Hook migration. |
| 167 | 167 | */ |
| 168 | 168 | private function hook() { |
| 169 | - add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); |
|
| 170 | - add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); |
|
| 171 | - add_action( 'init', array( $this, 'maybe_hook_migration' ) ); |
|
| 172 | - add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); |
|
| 169 | + add_filter('action_scheduler_store_class', array($this, 'get_store_class'), 100, 1); |
|
| 170 | + add_filter('action_scheduler_logger_class', array($this, 'get_logger_class'), 100, 1); |
|
| 171 | + add_action('init', array($this, 'maybe_hook_migration')); |
|
| 172 | + add_action('wp_loaded', array($this, 'schedule_migration')); |
|
| 173 | 173 | |
| 174 | 174 | // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
| 175 | - add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
| 176 | - add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
| 175 | + add_action('load-tools_page_action-scheduler', array($this, 'hook_admin_notices'), 10, 0); |
|
| 176 | + add_action('load-woocommerce_page_wc-status', array($this, 'hook_admin_notices'), 10, 0); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @author Jeremy Pry |
| 183 | 183 | */ |
| 184 | 184 | public function maybe_hook_migration() { |
| 185 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
| 185 | + if (!$this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) { |
|
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -193,22 +193,22 @@ discard block |
||
| 193 | 193 | * Allow datastores to enable migration to AS tables. |
| 194 | 194 | */ |
| 195 | 195 | public function allow_migration() { |
| 196 | - if ( ! \ActionScheduler_DataController::dependencies_met() ) { |
|
| 196 | + if (!\ActionScheduler_DataController::dependencies_met()) { |
|
| 197 | 197 | return false; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - if ( null === $this->migrate_custom_store ) { |
|
| 201 | - $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); |
|
| 200 | + if (null === $this->migrate_custom_store) { |
|
| 201 | + $this->migrate_custom_store = apply_filters('action_scheduler_migrate_data_store', false); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; |
|
| 204 | + return (!$this->has_custom_datastore()) || $this->migrate_custom_store; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Proceed with the migration if the dependencies have been met. |
| 209 | 209 | */ |
| 210 | 210 | public static function init() { |
| 211 | - if ( \ActionScheduler_DataController::dependencies_met() ) { |
|
| 211 | + if (\ActionScheduler_DataController::dependencies_met()) { |
|
| 212 | 212 | self::instance()->hook(); |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | * Singleton factory. |
| 218 | 218 | */ |
| 219 | 219 | public static function instance() { |
| 220 | - if ( ! isset( self::$instance ) ) { |
|
| 221 | - self::$instance = new static( new Scheduler() ); |
|
| 220 | + if (!isset(self::$instance)) { |
|
| 221 | + self::$instance = new static(new Scheduler()); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | return self::$instance; |
@@ -15,35 +15,35 @@ |
||
| 15 | 15 | * @codeCoverageIgnore |
| 16 | 16 | */ |
| 17 | 17 | class LogMigrator { |
| 18 | - /** @var ActionScheduler_Logger */ |
|
| 19 | - private $source; |
|
| 18 | + /** @var ActionScheduler_Logger */ |
|
| 19 | + private $source; |
|
| 20 | 20 | |
| 21 | - /** @var ActionScheduler_Logger */ |
|
| 22 | - private $destination; |
|
| 21 | + /** @var ActionScheduler_Logger */ |
|
| 22 | + private $destination; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * ActionMigrator constructor. |
|
| 26 | - * |
|
| 27 | - * @param ActionScheduler_Logger $source_logger Source logger object. |
|
| 28 | - * @param ActionScheduler_Logger $destination_Logger Destination logger object. |
|
| 29 | - */ |
|
| 30 | - public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) { |
|
| 31 | - $this->source = $source_logger; |
|
| 32 | - $this->destination = $destination_Logger; |
|
| 33 | - } |
|
| 24 | + /** |
|
| 25 | + * ActionMigrator constructor. |
|
| 26 | + * |
|
| 27 | + * @param ActionScheduler_Logger $source_logger Source logger object. |
|
| 28 | + * @param ActionScheduler_Logger $destination_Logger Destination logger object. |
|
| 29 | + */ |
|
| 30 | + public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) { |
|
| 31 | + $this->source = $source_logger; |
|
| 32 | + $this->destination = $destination_Logger; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Migrate an action log. |
|
| 37 | - * |
|
| 38 | - * @param int $source_action_id Source logger object. |
|
| 39 | - * @param int $destination_action_id Destination logger object. |
|
| 40 | - */ |
|
| 41 | - public function migrate( $source_action_id, $destination_action_id ) { |
|
| 42 | - $logs = $this->source->get_logs( $source_action_id ); |
|
| 43 | - foreach ( $logs as $log ) { |
|
| 44 | - if ( $log->get_action_id() == $source_action_id ) { |
|
| 45 | - $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 35 | + /** |
|
| 36 | + * Migrate an action log. |
|
| 37 | + * |
|
| 38 | + * @param int $source_action_id Source logger object. |
|
| 39 | + * @param int $destination_action_id Destination logger object. |
|
| 40 | + */ |
|
| 41 | + public function migrate( $source_action_id, $destination_action_id ) { |
|
| 42 | + $logs = $this->source->get_logs( $source_action_id ); |
|
| 43 | + foreach ( $logs as $log ) { |
|
| 44 | + if ( $log->get_action_id() == $source_action_id ) { |
|
| 45 | + $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @param ActionScheduler_Logger $source_logger Source logger object. |
| 28 | 28 | * @param ActionScheduler_Logger $destination_Logger Destination logger object. |
| 29 | 29 | */ |
| 30 | - public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) { |
|
| 30 | + public function __construct(ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger) { |
|
| 31 | 31 | $this->source = $source_logger; |
| 32 | 32 | $this->destination = $destination_Logger; |
| 33 | 33 | } |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | * @param int $source_action_id Source logger object. |
| 39 | 39 | * @param int $destination_action_id Destination logger object. |
| 40 | 40 | */ |
| 41 | - public function migrate( $source_action_id, $destination_action_id ) { |
|
| 42 | - $logs = $this->source->get_logs( $source_action_id ); |
|
| 43 | - foreach ( $logs as $log ) { |
|
| 44 | - if ( $log->get_action_id() == $source_action_id ) { |
|
| 45 | - $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); |
|
| 41 | + public function migrate($source_action_id, $destination_action_id) { |
|
| 42 | + $logs = $this->source->get_logs($source_action_id); |
|
| 43 | + foreach ($logs as $log) { |
|
| 44 | + if ($log->get_action_id() == $source_action_id) { |
|
| 45 | + $this->destination->log($destination_action_id, $log->get_message(), $log->get_date()); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -9,39 +9,39 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ActionScheduler_DBStoreMigrator extends ActionScheduler_DBStore { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Save an action with optional last attempt date. |
|
| 14 | - * |
|
| 15 | - * Normally, saving an action sets its attempted date to 0000-00-00 00:00:00 because when an action is first saved, |
|
| 16 | - * it can't have been attempted yet, but migrated completed actions will have an attempted date, so we need to save |
|
| 17 | - * that when first saving the action. |
|
| 18 | - * |
|
| 19 | - * @param ActionScheduler_Action $action |
|
| 20 | - * @param \DateTime $scheduled_date Optional date of the first instance to store. |
|
| 21 | - * @param \DateTime $last_attempt_date Optional date the action was last attempted. |
|
| 22 | - * |
|
| 23 | - * @return string The action ID |
|
| 24 | - * @throws \RuntimeException When the action is not saved. |
|
| 25 | - */ |
|
| 26 | - public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){ |
|
| 27 | - try { |
|
| 28 | - /** @var \wpdb $wpdb */ |
|
| 29 | - global $wpdb; |
|
| 12 | + /** |
|
| 13 | + * Save an action with optional last attempt date. |
|
| 14 | + * |
|
| 15 | + * Normally, saving an action sets its attempted date to 0000-00-00 00:00:00 because when an action is first saved, |
|
| 16 | + * it can't have been attempted yet, but migrated completed actions will have an attempted date, so we need to save |
|
| 17 | + * that when first saving the action. |
|
| 18 | + * |
|
| 19 | + * @param ActionScheduler_Action $action |
|
| 20 | + * @param \DateTime $scheduled_date Optional date of the first instance to store. |
|
| 21 | + * @param \DateTime $last_attempt_date Optional date the action was last attempted. |
|
| 22 | + * |
|
| 23 | + * @return string The action ID |
|
| 24 | + * @throws \RuntimeException When the action is not saved. |
|
| 25 | + */ |
|
| 26 | + public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){ |
|
| 27 | + try { |
|
| 28 | + /** @var \wpdb $wpdb */ |
|
| 29 | + global $wpdb; |
|
| 30 | 30 | |
| 31 | - $action_id = parent::save_action( $action, $scheduled_date ); |
|
| 31 | + $action_id = parent::save_action( $action, $scheduled_date ); |
|
| 32 | 32 | |
| 33 | - if ( null !== $last_attempt_date ) { |
|
| 34 | - $data = [ |
|
| 35 | - 'last_attempt_gmt' => $this->get_scheduled_date_string( $action, $last_attempt_date ), |
|
| 36 | - 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ), |
|
| 37 | - ]; |
|
| 33 | + if ( null !== $last_attempt_date ) { |
|
| 34 | + $data = [ |
|
| 35 | + 'last_attempt_gmt' => $this->get_scheduled_date_string( $action, $last_attempt_date ), |
|
| 36 | + 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ), |
|
| 37 | + ]; |
|
| 38 | 38 | |
| 39 | - $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) ); |
|
| 40 | - } |
|
| 39 | + $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) ); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $action_id; |
|
| 43 | - } catch ( \Exception $e ) { |
|
| 44 | - throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 ); |
|
| 45 | - } |
|
| 46 | - } |
|
| 42 | + return $action_id; |
|
| 43 | + } catch ( \Exception $e ) { |
|
| 44 | + throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 ); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -23,25 +23,25 @@ |
||
| 23 | 23 | * @return string The action ID |
| 24 | 24 | * @throws \RuntimeException When the action is not saved. |
| 25 | 25 | */ |
| 26 | - public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){ |
|
| 26 | + public function save_action(ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null) { |
|
| 27 | 27 | try { |
| 28 | 28 | /** @var \wpdb $wpdb */ |
| 29 | 29 | global $wpdb; |
| 30 | 30 | |
| 31 | - $action_id = parent::save_action( $action, $scheduled_date ); |
|
| 31 | + $action_id = parent::save_action($action, $scheduled_date); |
|
| 32 | 32 | |
| 33 | - if ( null !== $last_attempt_date ) { |
|
| 33 | + if (null !== $last_attempt_date) { |
|
| 34 | 34 | $data = [ |
| 35 | - 'last_attempt_gmt' => $this->get_scheduled_date_string( $action, $last_attempt_date ), |
|
| 36 | - 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ), |
|
| 35 | + 'last_attempt_gmt' => $this->get_scheduled_date_string($action, $last_attempt_date), |
|
| 36 | + 'last_attempt_local' => $this->get_scheduled_date_string_local($action, $last_attempt_date), |
|
| 37 | 37 | ]; |
| 38 | 38 | |
| 39 | - $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) ); |
|
| 39 | + $wpdb->update($wpdb->actionscheduler_actions, $data, array('action_id' => $action_id), array('%s', '%s'), array('%d')); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | return $action_id; |
| 43 | - } catch ( \Exception $e ) { |
|
| 44 | - throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 ); |
|
| 43 | + } catch (\Exception $e) { |
|
| 44 | + throw new \RuntimeException(sprintf(__('Error saving action: %s', 'woocommerce'), $e->getMessage()), 0); |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -11,13 +11,13 @@ |
||
| 11 | 11 | * @codeCoverageIgnore |
| 12 | 12 | */ |
| 13 | 13 | class DryRun_LogMigrator extends LogMigrator { |
| 14 | - /** |
|
| 15 | - * Simulate migrating an action log. |
|
| 16 | - * |
|
| 17 | - * @param int $source_action_id Source logger object. |
|
| 18 | - * @param int $destination_action_id Destination logger object. |
|
| 19 | - */ |
|
| 20 | - public function migrate( $source_action_id, $destination_action_id ) { |
|
| 21 | - // no-op |
|
| 22 | - } |
|
| 14 | + /** |
|
| 15 | + * Simulate migrating an action log. |
|
| 16 | + * |
|
| 17 | + * @param int $source_action_id Source logger object. |
|
| 18 | + * @param int $destination_action_id Destination logger object. |
|
| 19 | + */ |
|
| 20 | + public function migrate( $source_action_id, $destination_action_id ) { |
|
| 21 | + // no-op |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | * @param int $source_action_id Source logger object. |
| 18 | 18 | * @param int $destination_action_id Destination logger object. |
| 19 | 19 | */ |
| 20 | - public function migrate( $source_action_id, $destination_action_id ) { |
|
| 20 | + public function migrate($source_action_id, $destination_action_id) { |
|
| 21 | 21 | // no-op |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -6,638 +6,638 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The package name. |
|
| 11 | - * |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - protected $package = 'action-scheduler'; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Columns to show (name => label). |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected $columns = array(); |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Actions (name => label). |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $row_actions = array(); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The active data stores |
|
| 32 | - * |
|
| 33 | - * @var ActionScheduler_Store |
|
| 34 | - */ |
|
| 35 | - protected $store; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * A logger to use for getting action logs to display |
|
| 39 | - * |
|
| 40 | - * @var ActionScheduler_Logger |
|
| 41 | - */ |
|
| 42 | - protected $logger; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * A ActionScheduler_QueueRunner runner instance (or child class) |
|
| 46 | - * |
|
| 47 | - * @var ActionScheduler_QueueRunner |
|
| 48 | - */ |
|
| 49 | - protected $runner; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Bulk actions. The key of the array is the method name of the implementation: |
|
| 53 | - * |
|
| 54 | - * bulk_<key>(array $ids, string $sql_in). |
|
| 55 | - * |
|
| 56 | - * See the comments in the parent class for further details |
|
| 57 | - * |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - protected $bulk_actions = array(); |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Flag variable to render our notifications, if any, once. |
|
| 64 | - * |
|
| 65 | - * @var bool |
|
| 66 | - */ |
|
| 67 | - protected static $did_notification = false; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days" |
|
| 71 | - * |
|
| 72 | - * @var array |
|
| 73 | - */ |
|
| 74 | - private static $time_periods; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Sets the current data store object into `store->action` and initialises the object. |
|
| 78 | - * |
|
| 79 | - * @param ActionScheduler_Store $store |
|
| 80 | - * @param ActionScheduler_Logger $logger |
|
| 81 | - * @param ActionScheduler_QueueRunner $runner |
|
| 82 | - */ |
|
| 83 | - public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { |
|
| 84 | - |
|
| 85 | - $this->store = $store; |
|
| 86 | - $this->logger = $logger; |
|
| 87 | - $this->runner = $runner; |
|
| 88 | - |
|
| 89 | - $this->table_header = __( 'Scheduled Actions', 'woocommerce' ); |
|
| 90 | - |
|
| 91 | - $this->bulk_actions = array( |
|
| 92 | - 'delete' => __( 'Delete', 'woocommerce' ), |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $this->columns = array( |
|
| 96 | - 'hook' => __( 'Hook', 'woocommerce' ), |
|
| 97 | - 'status' => __( 'Status', 'woocommerce' ), |
|
| 98 | - 'args' => __( 'Arguments', 'woocommerce' ), |
|
| 99 | - 'group' => __( 'Group', 'woocommerce' ), |
|
| 100 | - 'recurrence' => __( 'Recurrence', 'woocommerce' ), |
|
| 101 | - 'schedule' => __( 'Scheduled Date', 'woocommerce' ), |
|
| 102 | - 'log_entries' => __( 'Log', 'woocommerce' ), |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $this->sort_by = array( |
|
| 106 | - 'schedule', |
|
| 107 | - 'hook', |
|
| 108 | - 'group', |
|
| 109 | - ); |
|
| 110 | - |
|
| 111 | - $this->search_by = array( |
|
| 112 | - 'hook', |
|
| 113 | - 'args', |
|
| 114 | - 'claim_id', |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - $request_status = $this->get_request_status(); |
|
| 118 | - |
|
| 119 | - if ( empty( $request_status ) ) { |
|
| 120 | - $this->sort_by[] = 'status'; |
|
| 121 | - } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { |
|
| 122 | - $this->columns += array( 'claim_id' => __( 'Claim ID', 'woocommerce' ) ); |
|
| 123 | - $this->sort_by[] = 'claim_id'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $this->row_actions = array( |
|
| 127 | - 'hook' => array( |
|
| 128 | - 'run' => array( |
|
| 129 | - 'name' => __( 'Run', 'woocommerce' ), |
|
| 130 | - 'desc' => __( 'Process the action now as if it were run as part of a queue', 'woocommerce' ), |
|
| 131 | - ), |
|
| 132 | - 'cancel' => array( |
|
| 133 | - 'name' => __( 'Cancel', 'woocommerce' ), |
|
| 134 | - 'desc' => __( 'Cancel the action now to avoid it being run in future', 'woocommerce' ), |
|
| 135 | - 'class' => 'cancel trash', |
|
| 136 | - ), |
|
| 137 | - ), |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - self::$time_periods = array( |
|
| 141 | - array( |
|
| 142 | - 'seconds' => YEAR_IN_SECONDS, |
|
| 143 | - /* translators: %s: amount of time */ |
|
| 144 | - 'names' => _n_noop( '%s year', '%s years', 'woocommerce' ), |
|
| 145 | - ), |
|
| 146 | - array( |
|
| 147 | - 'seconds' => MONTH_IN_SECONDS, |
|
| 148 | - /* translators: %s: amount of time */ |
|
| 149 | - 'names' => _n_noop( '%s month', '%s months', 'woocommerce' ), |
|
| 150 | - ), |
|
| 151 | - array( |
|
| 152 | - 'seconds' => WEEK_IN_SECONDS, |
|
| 153 | - /* translators: %s: amount of time */ |
|
| 154 | - 'names' => _n_noop( '%s week', '%s weeks', 'woocommerce' ), |
|
| 155 | - ), |
|
| 156 | - array( |
|
| 157 | - 'seconds' => DAY_IN_SECONDS, |
|
| 158 | - /* translators: %s: amount of time */ |
|
| 159 | - 'names' => _n_noop( '%s day', '%s days', 'woocommerce' ), |
|
| 160 | - ), |
|
| 161 | - array( |
|
| 162 | - 'seconds' => HOUR_IN_SECONDS, |
|
| 163 | - /* translators: %s: amount of time */ |
|
| 164 | - 'names' => _n_noop( '%s hour', '%s hours', 'woocommerce' ), |
|
| 165 | - ), |
|
| 166 | - array( |
|
| 167 | - 'seconds' => MINUTE_IN_SECONDS, |
|
| 168 | - /* translators: %s: amount of time */ |
|
| 169 | - 'names' => _n_noop( '%s minute', '%s minutes', 'woocommerce' ), |
|
| 170 | - ), |
|
| 171 | - array( |
|
| 172 | - 'seconds' => 1, |
|
| 173 | - /* translators: %s: amount of time */ |
|
| 174 | - 'names' => _n_noop( '%s second', '%s seconds', 'woocommerce' ), |
|
| 175 | - ), |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - parent::__construct( |
|
| 179 | - array( |
|
| 180 | - 'singular' => 'action-scheduler', |
|
| 181 | - 'plural' => 'action-scheduler', |
|
| 182 | - 'ajax' => false, |
|
| 183 | - ) |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - add_screen_option( |
|
| 187 | - 'per_page', |
|
| 188 | - array( |
|
| 189 | - 'default' => $this->items_per_page, |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - add_filter( 'set_screen_option_' . $this->get_per_page_option_name(), array( $this, 'set_items_per_page_option' ), 10, 3 ); |
|
| 194 | - set_screen_options(); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Handles setting the items_per_page option for this screen. |
|
| 199 | - * |
|
| 200 | - * @param mixed $status Default false (to skip saving the current option). |
|
| 201 | - * @param string $option Screen option name. |
|
| 202 | - * @param int $value Screen option value. |
|
| 203 | - * @return int |
|
| 204 | - */ |
|
| 205 | - public function set_items_per_page_option( $status, $option, $value ) { |
|
| 206 | - return $value; |
|
| 207 | - } |
|
| 208 | - /** |
|
| 209 | - * Convert an interval of seconds into a two part human friendly string. |
|
| 210 | - * |
|
| 211 | - * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning |
|
| 212 | - * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step |
|
| 213 | - * further to display two degrees of accuracy. |
|
| 214 | - * |
|
| 215 | - * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ |
|
| 216 | - * |
|
| 217 | - * @param int $interval A interval in seconds. |
|
| 218 | - * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. |
|
| 219 | - * @return string A human friendly string representation of the interval. |
|
| 220 | - */ |
|
| 221 | - private static function human_interval( $interval, $periods_to_include = 2 ) { |
|
| 222 | - |
|
| 223 | - if ( $interval <= 0 ) { |
|
| 224 | - return __( 'Now!', 'woocommerce' ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $output = ''; |
|
| 228 | - |
|
| 229 | - for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { |
|
| 230 | - |
|
| 231 | - $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); |
|
| 232 | - |
|
| 233 | - if ( $periods_in_interval > 0 ) { |
|
| 234 | - if ( ! empty( $output ) ) { |
|
| 235 | - $output .= ' '; |
|
| 236 | - } |
|
| 237 | - $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'woocommerce' ), $periods_in_interval ); |
|
| 238 | - $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
|
| 239 | - $periods_included++; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return $output; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Returns the recurrence of an action or 'Non-repeating'. The output is human readable. |
|
| 248 | - * |
|
| 249 | - * @param ActionScheduler_Action $action |
|
| 250 | - * |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - protected function get_recurrence( $action ) { |
|
| 254 | - $schedule = $action->get_schedule(); |
|
| 255 | - if ( $schedule->is_recurring() ) { |
|
| 256 | - $recurrence = $schedule->get_recurrence(); |
|
| 257 | - |
|
| 258 | - if ( is_numeric( $recurrence ) ) { |
|
| 259 | - /* translators: %s: time interval */ |
|
| 260 | - return sprintf( __( 'Every %s', 'woocommerce' ), self::human_interval( $recurrence ) ); |
|
| 261 | - } else { |
|
| 262 | - return $recurrence; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return __( 'Non-repeating', 'woocommerce' ); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Serializes the argument of an action to render it in a human friendly format. |
|
| 271 | - * |
|
| 272 | - * @param array $row The array representation of the current row of the table |
|
| 273 | - * |
|
| 274 | - * @return string |
|
| 275 | - */ |
|
| 276 | - public function column_args( array $row ) { |
|
| 277 | - if ( empty( $row['args'] ) ) { |
|
| 278 | - return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - $row_html = '<ul>'; |
|
| 282 | - foreach ( $row['args'] as $key => $value ) { |
|
| 283 | - $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); |
|
| 284 | - } |
|
| 285 | - $row_html .= '</ul>'; |
|
| 286 | - |
|
| 287 | - return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
| 292 | - * |
|
| 293 | - * @param array $row Action array. |
|
| 294 | - * @return string |
|
| 295 | - */ |
|
| 296 | - public function column_log_entries( array $row ) { |
|
| 297 | - |
|
| 298 | - $log_entries_html = '<ol>'; |
|
| 299 | - |
|
| 300 | - $timezone = new DateTimezone( 'UTC' ); |
|
| 301 | - |
|
| 302 | - foreach ( $row['log_entries'] as $log_entry ) { |
|
| 303 | - $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $log_entries_html .= '</ol>'; |
|
| 307 | - |
|
| 308 | - return $log_entries_html; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
| 313 | - * |
|
| 314 | - * @param ActionScheduler_LogEntry $log_entry |
|
| 315 | - * @param DateTimezone $timezone |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { |
|
| 319 | - $date = $log_entry->get_date(); |
|
| 320 | - $date->setTimezone( $timezone ); |
|
| 321 | - return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Only display row actions for pending actions. |
|
| 326 | - * |
|
| 327 | - * @param array $row Row to render |
|
| 328 | - * @param string $column_name Current row |
|
| 329 | - * |
|
| 330 | - * @return string |
|
| 331 | - */ |
|
| 332 | - protected function maybe_render_actions( $row, $column_name ) { |
|
| 333 | - if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) { |
|
| 334 | - return parent::maybe_render_actions( $row, $column_name ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return ''; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Renders admin notifications |
|
| 342 | - * |
|
| 343 | - * Notifications: |
|
| 344 | - * 1. When the maximum number of tasks are being executed simultaneously. |
|
| 345 | - * 2. Notifications when a task is manually executed. |
|
| 346 | - * 3. Tables are missing. |
|
| 347 | - */ |
|
| 348 | - public function display_admin_notices() { |
|
| 349 | - global $wpdb; |
|
| 350 | - |
|
| 351 | - if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { |
|
| 352 | - $table_list = array( |
|
| 353 | - 'actionscheduler_actions', |
|
| 354 | - 'actionscheduler_logs', |
|
| 355 | - 'actionscheduler_groups', |
|
| 356 | - 'actionscheduler_claims', |
|
| 357 | - ); |
|
| 358 | - |
|
| 359 | - $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 360 | - foreach ( $table_list as $table_name ) { |
|
| 361 | - if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { |
|
| 362 | - $this->admin_notices[] = array( |
|
| 363 | - 'class' => 'error', |
|
| 364 | - 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'woocommerce' ), |
|
| 365 | - ); |
|
| 366 | - $this->recreate_tables(); |
|
| 367 | - parent::display_admin_notices(); |
|
| 368 | - |
|
| 369 | - return; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ( $this->runner->has_maximum_concurrent_batches() ) { |
|
| 375 | - $claim_count = $this->store->get_claim_count(); |
|
| 376 | - $this->admin_notices[] = array( |
|
| 377 | - 'class' => 'updated', |
|
| 378 | - 'message' => sprintf( |
|
| 379 | - /* translators: %s: amount of claims */ |
|
| 380 | - _n( |
|
| 381 | - 'Maximum simultaneous queues already in progress (%s queue). No additional queues will begin processing until the current queues are complete.', |
|
| 382 | - 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', |
|
| 383 | - $claim_count, |
|
| 384 | - 'woocommerce' |
|
| 385 | - ), |
|
| 386 | - $claim_count |
|
| 387 | - ), |
|
| 388 | - ); |
|
| 389 | - } elseif ( $this->store->has_pending_actions_due() ) { |
|
| 390 | - |
|
| 391 | - $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
|
| 392 | - |
|
| 393 | - // No lock set or lock expired |
|
| 394 | - if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
|
| 395 | - $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); |
|
| 396 | - /* translators: %s: process URL */ |
|
| 397 | - $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'woocommerce' ), esc_url( $in_progress_url ) ); |
|
| 398 | - } else { |
|
| 399 | - /* translators: %d: seconds */ |
|
| 400 | - $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'woocommerce' ), $async_request_lock_expiration - time() ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $this->admin_notices[] = array( |
|
| 404 | - 'class' => 'notice notice-info', |
|
| 405 | - 'message' => $async_request_message, |
|
| 406 | - ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - $notification = get_transient( 'action_scheduler_admin_notice' ); |
|
| 410 | - |
|
| 411 | - if ( is_array( $notification ) ) { |
|
| 412 | - delete_transient( 'action_scheduler_admin_notice' ); |
|
| 413 | - |
|
| 414 | - $action = $this->store->fetch_action( $notification['action_id'] ); |
|
| 415 | - $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
|
| 416 | - if ( 1 == $notification['success'] ) { |
|
| 417 | - $class = 'updated'; |
|
| 418 | - switch ( $notification['row_action_type'] ) { |
|
| 419 | - case 'run' : |
|
| 420 | - /* translators: %s: action HTML */ |
|
| 421 | - $action_message_html = sprintf( __( 'Successfully executed action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 422 | - break; |
|
| 423 | - case 'cancel' : |
|
| 424 | - /* translators: %s: action HTML */ |
|
| 425 | - $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 426 | - break; |
|
| 427 | - default : |
|
| 428 | - /* translators: %s: action HTML */ |
|
| 429 | - $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 430 | - break; |
|
| 431 | - } |
|
| 432 | - } else { |
|
| 433 | - $class = 'error'; |
|
| 434 | - /* translators: 1: action HTML 2: action ID 3: error message */ |
|
| 435 | - $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'woocommerce' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); |
|
| 439 | - |
|
| 440 | - $this->admin_notices[] = array( |
|
| 441 | - 'class' => $class, |
|
| 442 | - 'message' => $action_message_html, |
|
| 443 | - ); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - parent::display_admin_notices(); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Prints the scheduled date in a human friendly format. |
|
| 451 | - * |
|
| 452 | - * @param array $row The array representation of the current row of the table |
|
| 453 | - * |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - public function column_schedule( $row ) { |
|
| 457 | - return $this->get_schedule_display_string( $row['schedule'] ); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Get the scheduled date in a human friendly format. |
|
| 462 | - * |
|
| 463 | - * @param ActionScheduler_Schedule $schedule |
|
| 464 | - * @return string |
|
| 465 | - */ |
|
| 466 | - protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
|
| 467 | - |
|
| 468 | - $schedule_display_string = ''; |
|
| 469 | - |
|
| 470 | - if ( ! $schedule->get_date() ) { |
|
| 471 | - return '0000-00-00 00:00:00'; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $next_timestamp = $schedule->get_date()->getTimestamp(); |
|
| 475 | - |
|
| 476 | - $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); |
|
| 477 | - $schedule_display_string .= '<br/>'; |
|
| 478 | - |
|
| 479 | - if ( gmdate( 'U' ) > $next_timestamp ) { |
|
| 480 | - /* translators: %s: date interval */ |
|
| 481 | - $schedule_display_string .= sprintf( __( ' (%s ago)', 'woocommerce' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); |
|
| 482 | - } else { |
|
| 483 | - /* translators: %s: date interval */ |
|
| 484 | - $schedule_display_string .= sprintf( __( ' (%s)', 'woocommerce' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $schedule_display_string; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Bulk delete |
|
| 492 | - * |
|
| 493 | - * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data |
|
| 494 | - * properly validated by the callee and it will delete the actions without any extra validation. |
|
| 495 | - * |
|
| 496 | - * @param array $ids |
|
| 497 | - * @param string $ids_sql Inherited and unused |
|
| 498 | - */ |
|
| 499 | - protected function bulk_delete( array $ids, $ids_sql ) { |
|
| 500 | - foreach ( $ids as $id ) { |
|
| 501 | - $this->store->delete_action( $id ); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
| 507 | - * parameters are valid. |
|
| 508 | - * |
|
| 509 | - * @param int $action_id |
|
| 510 | - */ |
|
| 511 | - protected function row_action_cancel( $action_id ) { |
|
| 512 | - $this->process_row_action( $action_id, 'cancel' ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
| 517 | - * parameters are valid. |
|
| 518 | - * |
|
| 519 | - * @param int $action_id |
|
| 520 | - */ |
|
| 521 | - protected function row_action_run( $action_id ) { |
|
| 522 | - $this->process_row_action( $action_id, 'run' ); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Force the data store schema updates. |
|
| 527 | - */ |
|
| 528 | - protected function recreate_tables() { |
|
| 529 | - if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { |
|
| 530 | - $store = $this->store; |
|
| 531 | - } else { |
|
| 532 | - $store = new ActionScheduler_HybridStore(); |
|
| 533 | - } |
|
| 534 | - add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); |
|
| 535 | - |
|
| 536 | - $store_schema = new ActionScheduler_StoreSchema(); |
|
| 537 | - $logger_schema = new ActionScheduler_LoggerSchema(); |
|
| 538 | - $store_schema->register_tables( true ); |
|
| 539 | - $logger_schema->register_tables( true ); |
|
| 540 | - |
|
| 541 | - remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); |
|
| 542 | - } |
|
| 543 | - /** |
|
| 544 | - * Implements the logic behind processing an action once an action link is clicked on the list table. |
|
| 545 | - * |
|
| 546 | - * @param int $action_id |
|
| 547 | - * @param string $row_action_type The type of action to perform on the action. |
|
| 548 | - */ |
|
| 549 | - protected function process_row_action( $action_id, $row_action_type ) { |
|
| 550 | - try { |
|
| 551 | - switch ( $row_action_type ) { |
|
| 552 | - case 'run' : |
|
| 553 | - $this->runner->process_action( $action_id, 'Admin List Table' ); |
|
| 554 | - break; |
|
| 555 | - case 'cancel' : |
|
| 556 | - $this->store->cancel_action( $action_id ); |
|
| 557 | - break; |
|
| 558 | - } |
|
| 559 | - $success = 1; |
|
| 560 | - $error_message = ''; |
|
| 561 | - } catch ( Exception $e ) { |
|
| 562 | - $success = 0; |
|
| 563 | - $error_message = $e->getMessage(); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * {@inheritDoc} |
|
| 571 | - */ |
|
| 572 | - public function prepare_items() { |
|
| 573 | - $this->prepare_column_headers(); |
|
| 574 | - |
|
| 575 | - $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); |
|
| 576 | - |
|
| 577 | - $query = array( |
|
| 578 | - 'per_page' => $per_page, |
|
| 579 | - 'offset' => $this->get_items_offset(), |
|
| 580 | - 'status' => $this->get_request_status(), |
|
| 581 | - 'orderby' => $this->get_request_orderby(), |
|
| 582 | - 'order' => $this->get_request_order(), |
|
| 583 | - 'search' => $this->get_request_search_query(), |
|
| 584 | - ); |
|
| 585 | - |
|
| 586 | - $this->items = array(); |
|
| 587 | - |
|
| 588 | - $total_items = $this->store->query_actions( $query, 'count' ); |
|
| 589 | - |
|
| 590 | - $status_labels = $this->store->get_status_labels(); |
|
| 591 | - |
|
| 592 | - foreach ( $this->store->query_actions( $query ) as $action_id ) { |
|
| 593 | - try { |
|
| 594 | - $action = $this->store->fetch_action( $action_id ); |
|
| 595 | - } catch ( Exception $e ) { |
|
| 596 | - continue; |
|
| 597 | - } |
|
| 598 | - if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { |
|
| 599 | - continue; |
|
| 600 | - } |
|
| 601 | - $this->items[ $action_id ] = array( |
|
| 602 | - 'ID' => $action_id, |
|
| 603 | - 'hook' => $action->get_hook(), |
|
| 604 | - 'status_name' => $this->store->get_status( $action_id ), |
|
| 605 | - 'status' => $status_labels[ $this->store->get_status( $action_id ) ], |
|
| 606 | - 'args' => $action->get_args(), |
|
| 607 | - 'group' => $action->get_group(), |
|
| 608 | - 'log_entries' => $this->logger->get_logs( $action_id ), |
|
| 609 | - 'claim_id' => $this->store->get_claim_id( $action_id ), |
|
| 610 | - 'recurrence' => $this->get_recurrence( $action ), |
|
| 611 | - 'schedule' => $action->get_schedule(), |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - $this->set_pagination_args( array( |
|
| 616 | - 'total_items' => $total_items, |
|
| 617 | - 'per_page' => $per_page, |
|
| 618 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
| 619 | - ) ); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * Prints the available statuses so the user can click to filter. |
|
| 624 | - */ |
|
| 625 | - protected function display_filter_by_status() { |
|
| 626 | - $this->status_counts = $this->store->action_counts(); |
|
| 627 | - parent::display_filter_by_status(); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Get the text to display in the search box on the list table. |
|
| 632 | - */ |
|
| 633 | - protected function get_search_box_button_text() { |
|
| 634 | - return __( 'Search hook, args and claim ID', 'woocommerce' ); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * {@inheritDoc} |
|
| 639 | - */ |
|
| 640 | - protected function get_per_page_option_name() { |
|
| 641 | - return str_replace( '-', '_', $this->screen->id ) . '_per_page'; |
|
| 642 | - } |
|
| 9 | + /** |
|
| 10 | + * The package name. |
|
| 11 | + * |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + protected $package = 'action-scheduler'; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Columns to show (name => label). |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected $columns = array(); |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Actions (name => label). |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $row_actions = array(); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The active data stores |
|
| 32 | + * |
|
| 33 | + * @var ActionScheduler_Store |
|
| 34 | + */ |
|
| 35 | + protected $store; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * A logger to use for getting action logs to display |
|
| 39 | + * |
|
| 40 | + * @var ActionScheduler_Logger |
|
| 41 | + */ |
|
| 42 | + protected $logger; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * A ActionScheduler_QueueRunner runner instance (or child class) |
|
| 46 | + * |
|
| 47 | + * @var ActionScheduler_QueueRunner |
|
| 48 | + */ |
|
| 49 | + protected $runner; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Bulk actions. The key of the array is the method name of the implementation: |
|
| 53 | + * |
|
| 54 | + * bulk_<key>(array $ids, string $sql_in). |
|
| 55 | + * |
|
| 56 | + * See the comments in the parent class for further details |
|
| 57 | + * |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + protected $bulk_actions = array(); |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Flag variable to render our notifications, if any, once. |
|
| 64 | + * |
|
| 65 | + * @var bool |
|
| 66 | + */ |
|
| 67 | + protected static $did_notification = false; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days" |
|
| 71 | + * |
|
| 72 | + * @var array |
|
| 73 | + */ |
|
| 74 | + private static $time_periods; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Sets the current data store object into `store->action` and initialises the object. |
|
| 78 | + * |
|
| 79 | + * @param ActionScheduler_Store $store |
|
| 80 | + * @param ActionScheduler_Logger $logger |
|
| 81 | + * @param ActionScheduler_QueueRunner $runner |
|
| 82 | + */ |
|
| 83 | + public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { |
|
| 84 | + |
|
| 85 | + $this->store = $store; |
|
| 86 | + $this->logger = $logger; |
|
| 87 | + $this->runner = $runner; |
|
| 88 | + |
|
| 89 | + $this->table_header = __( 'Scheduled Actions', 'woocommerce' ); |
|
| 90 | + |
|
| 91 | + $this->bulk_actions = array( |
|
| 92 | + 'delete' => __( 'Delete', 'woocommerce' ), |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $this->columns = array( |
|
| 96 | + 'hook' => __( 'Hook', 'woocommerce' ), |
|
| 97 | + 'status' => __( 'Status', 'woocommerce' ), |
|
| 98 | + 'args' => __( 'Arguments', 'woocommerce' ), |
|
| 99 | + 'group' => __( 'Group', 'woocommerce' ), |
|
| 100 | + 'recurrence' => __( 'Recurrence', 'woocommerce' ), |
|
| 101 | + 'schedule' => __( 'Scheduled Date', 'woocommerce' ), |
|
| 102 | + 'log_entries' => __( 'Log', 'woocommerce' ), |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $this->sort_by = array( |
|
| 106 | + 'schedule', |
|
| 107 | + 'hook', |
|
| 108 | + 'group', |
|
| 109 | + ); |
|
| 110 | + |
|
| 111 | + $this->search_by = array( |
|
| 112 | + 'hook', |
|
| 113 | + 'args', |
|
| 114 | + 'claim_id', |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + $request_status = $this->get_request_status(); |
|
| 118 | + |
|
| 119 | + if ( empty( $request_status ) ) { |
|
| 120 | + $this->sort_by[] = 'status'; |
|
| 121 | + } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { |
|
| 122 | + $this->columns += array( 'claim_id' => __( 'Claim ID', 'woocommerce' ) ); |
|
| 123 | + $this->sort_by[] = 'claim_id'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $this->row_actions = array( |
|
| 127 | + 'hook' => array( |
|
| 128 | + 'run' => array( |
|
| 129 | + 'name' => __( 'Run', 'woocommerce' ), |
|
| 130 | + 'desc' => __( 'Process the action now as if it were run as part of a queue', 'woocommerce' ), |
|
| 131 | + ), |
|
| 132 | + 'cancel' => array( |
|
| 133 | + 'name' => __( 'Cancel', 'woocommerce' ), |
|
| 134 | + 'desc' => __( 'Cancel the action now to avoid it being run in future', 'woocommerce' ), |
|
| 135 | + 'class' => 'cancel trash', |
|
| 136 | + ), |
|
| 137 | + ), |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + self::$time_periods = array( |
|
| 141 | + array( |
|
| 142 | + 'seconds' => YEAR_IN_SECONDS, |
|
| 143 | + /* translators: %s: amount of time */ |
|
| 144 | + 'names' => _n_noop( '%s year', '%s years', 'woocommerce' ), |
|
| 145 | + ), |
|
| 146 | + array( |
|
| 147 | + 'seconds' => MONTH_IN_SECONDS, |
|
| 148 | + /* translators: %s: amount of time */ |
|
| 149 | + 'names' => _n_noop( '%s month', '%s months', 'woocommerce' ), |
|
| 150 | + ), |
|
| 151 | + array( |
|
| 152 | + 'seconds' => WEEK_IN_SECONDS, |
|
| 153 | + /* translators: %s: amount of time */ |
|
| 154 | + 'names' => _n_noop( '%s week', '%s weeks', 'woocommerce' ), |
|
| 155 | + ), |
|
| 156 | + array( |
|
| 157 | + 'seconds' => DAY_IN_SECONDS, |
|
| 158 | + /* translators: %s: amount of time */ |
|
| 159 | + 'names' => _n_noop( '%s day', '%s days', 'woocommerce' ), |
|
| 160 | + ), |
|
| 161 | + array( |
|
| 162 | + 'seconds' => HOUR_IN_SECONDS, |
|
| 163 | + /* translators: %s: amount of time */ |
|
| 164 | + 'names' => _n_noop( '%s hour', '%s hours', 'woocommerce' ), |
|
| 165 | + ), |
|
| 166 | + array( |
|
| 167 | + 'seconds' => MINUTE_IN_SECONDS, |
|
| 168 | + /* translators: %s: amount of time */ |
|
| 169 | + 'names' => _n_noop( '%s minute', '%s minutes', 'woocommerce' ), |
|
| 170 | + ), |
|
| 171 | + array( |
|
| 172 | + 'seconds' => 1, |
|
| 173 | + /* translators: %s: amount of time */ |
|
| 174 | + 'names' => _n_noop( '%s second', '%s seconds', 'woocommerce' ), |
|
| 175 | + ), |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + parent::__construct( |
|
| 179 | + array( |
|
| 180 | + 'singular' => 'action-scheduler', |
|
| 181 | + 'plural' => 'action-scheduler', |
|
| 182 | + 'ajax' => false, |
|
| 183 | + ) |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + add_screen_option( |
|
| 187 | + 'per_page', |
|
| 188 | + array( |
|
| 189 | + 'default' => $this->items_per_page, |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + add_filter( 'set_screen_option_' . $this->get_per_page_option_name(), array( $this, 'set_items_per_page_option' ), 10, 3 ); |
|
| 194 | + set_screen_options(); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Handles setting the items_per_page option for this screen. |
|
| 199 | + * |
|
| 200 | + * @param mixed $status Default false (to skip saving the current option). |
|
| 201 | + * @param string $option Screen option name. |
|
| 202 | + * @param int $value Screen option value. |
|
| 203 | + * @return int |
|
| 204 | + */ |
|
| 205 | + public function set_items_per_page_option( $status, $option, $value ) { |
|
| 206 | + return $value; |
|
| 207 | + } |
|
| 208 | + /** |
|
| 209 | + * Convert an interval of seconds into a two part human friendly string. |
|
| 210 | + * |
|
| 211 | + * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning |
|
| 212 | + * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step |
|
| 213 | + * further to display two degrees of accuracy. |
|
| 214 | + * |
|
| 215 | + * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ |
|
| 216 | + * |
|
| 217 | + * @param int $interval A interval in seconds. |
|
| 218 | + * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. |
|
| 219 | + * @return string A human friendly string representation of the interval. |
|
| 220 | + */ |
|
| 221 | + private static function human_interval( $interval, $periods_to_include = 2 ) { |
|
| 222 | + |
|
| 223 | + if ( $interval <= 0 ) { |
|
| 224 | + return __( 'Now!', 'woocommerce' ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $output = ''; |
|
| 228 | + |
|
| 229 | + for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { |
|
| 230 | + |
|
| 231 | + $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); |
|
| 232 | + |
|
| 233 | + if ( $periods_in_interval > 0 ) { |
|
| 234 | + if ( ! empty( $output ) ) { |
|
| 235 | + $output .= ' '; |
|
| 236 | + } |
|
| 237 | + $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'woocommerce' ), $periods_in_interval ); |
|
| 238 | + $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
|
| 239 | + $periods_included++; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return $output; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Returns the recurrence of an action or 'Non-repeating'. The output is human readable. |
|
| 248 | + * |
|
| 249 | + * @param ActionScheduler_Action $action |
|
| 250 | + * |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + protected function get_recurrence( $action ) { |
|
| 254 | + $schedule = $action->get_schedule(); |
|
| 255 | + if ( $schedule->is_recurring() ) { |
|
| 256 | + $recurrence = $schedule->get_recurrence(); |
|
| 257 | + |
|
| 258 | + if ( is_numeric( $recurrence ) ) { |
|
| 259 | + /* translators: %s: time interval */ |
|
| 260 | + return sprintf( __( 'Every %s', 'woocommerce' ), self::human_interval( $recurrence ) ); |
|
| 261 | + } else { |
|
| 262 | + return $recurrence; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return __( 'Non-repeating', 'woocommerce' ); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Serializes the argument of an action to render it in a human friendly format. |
|
| 271 | + * |
|
| 272 | + * @param array $row The array representation of the current row of the table |
|
| 273 | + * |
|
| 274 | + * @return string |
|
| 275 | + */ |
|
| 276 | + public function column_args( array $row ) { |
|
| 277 | + if ( empty( $row['args'] ) ) { |
|
| 278 | + return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + $row_html = '<ul>'; |
|
| 282 | + foreach ( $row['args'] as $key => $value ) { |
|
| 283 | + $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); |
|
| 284 | + } |
|
| 285 | + $row_html .= '</ul>'; |
|
| 286 | + |
|
| 287 | + return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
| 292 | + * |
|
| 293 | + * @param array $row Action array. |
|
| 294 | + * @return string |
|
| 295 | + */ |
|
| 296 | + public function column_log_entries( array $row ) { |
|
| 297 | + |
|
| 298 | + $log_entries_html = '<ol>'; |
|
| 299 | + |
|
| 300 | + $timezone = new DateTimezone( 'UTC' ); |
|
| 301 | + |
|
| 302 | + foreach ( $row['log_entries'] as $log_entry ) { |
|
| 303 | + $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $log_entries_html .= '</ol>'; |
|
| 307 | + |
|
| 308 | + return $log_entries_html; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. |
|
| 313 | + * |
|
| 314 | + * @param ActionScheduler_LogEntry $log_entry |
|
| 315 | + * @param DateTimezone $timezone |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { |
|
| 319 | + $date = $log_entry->get_date(); |
|
| 320 | + $date->setTimezone( $timezone ); |
|
| 321 | + return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Only display row actions for pending actions. |
|
| 326 | + * |
|
| 327 | + * @param array $row Row to render |
|
| 328 | + * @param string $column_name Current row |
|
| 329 | + * |
|
| 330 | + * @return string |
|
| 331 | + */ |
|
| 332 | + protected function maybe_render_actions( $row, $column_name ) { |
|
| 333 | + if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) { |
|
| 334 | + return parent::maybe_render_actions( $row, $column_name ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return ''; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Renders admin notifications |
|
| 342 | + * |
|
| 343 | + * Notifications: |
|
| 344 | + * 1. When the maximum number of tasks are being executed simultaneously. |
|
| 345 | + * 2. Notifications when a task is manually executed. |
|
| 346 | + * 3. Tables are missing. |
|
| 347 | + */ |
|
| 348 | + public function display_admin_notices() { |
|
| 349 | + global $wpdb; |
|
| 350 | + |
|
| 351 | + if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { |
|
| 352 | + $table_list = array( |
|
| 353 | + 'actionscheduler_actions', |
|
| 354 | + 'actionscheduler_logs', |
|
| 355 | + 'actionscheduler_groups', |
|
| 356 | + 'actionscheduler_claims', |
|
| 357 | + ); |
|
| 358 | + |
|
| 359 | + $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 360 | + foreach ( $table_list as $table_name ) { |
|
| 361 | + if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { |
|
| 362 | + $this->admin_notices[] = array( |
|
| 363 | + 'class' => 'error', |
|
| 364 | + 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'woocommerce' ), |
|
| 365 | + ); |
|
| 366 | + $this->recreate_tables(); |
|
| 367 | + parent::display_admin_notices(); |
|
| 368 | + |
|
| 369 | + return; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ( $this->runner->has_maximum_concurrent_batches() ) { |
|
| 375 | + $claim_count = $this->store->get_claim_count(); |
|
| 376 | + $this->admin_notices[] = array( |
|
| 377 | + 'class' => 'updated', |
|
| 378 | + 'message' => sprintf( |
|
| 379 | + /* translators: %s: amount of claims */ |
|
| 380 | + _n( |
|
| 381 | + 'Maximum simultaneous queues already in progress (%s queue). No additional queues will begin processing until the current queues are complete.', |
|
| 382 | + 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', |
|
| 383 | + $claim_count, |
|
| 384 | + 'woocommerce' |
|
| 385 | + ), |
|
| 386 | + $claim_count |
|
| 387 | + ), |
|
| 388 | + ); |
|
| 389 | + } elseif ( $this->store->has_pending_actions_due() ) { |
|
| 390 | + |
|
| 391 | + $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
|
| 392 | + |
|
| 393 | + // No lock set or lock expired |
|
| 394 | + if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
|
| 395 | + $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); |
|
| 396 | + /* translators: %s: process URL */ |
|
| 397 | + $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'woocommerce' ), esc_url( $in_progress_url ) ); |
|
| 398 | + } else { |
|
| 399 | + /* translators: %d: seconds */ |
|
| 400 | + $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'woocommerce' ), $async_request_lock_expiration - time() ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $this->admin_notices[] = array( |
|
| 404 | + 'class' => 'notice notice-info', |
|
| 405 | + 'message' => $async_request_message, |
|
| 406 | + ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + $notification = get_transient( 'action_scheduler_admin_notice' ); |
|
| 410 | + |
|
| 411 | + if ( is_array( $notification ) ) { |
|
| 412 | + delete_transient( 'action_scheduler_admin_notice' ); |
|
| 413 | + |
|
| 414 | + $action = $this->store->fetch_action( $notification['action_id'] ); |
|
| 415 | + $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
|
| 416 | + if ( 1 == $notification['success'] ) { |
|
| 417 | + $class = 'updated'; |
|
| 418 | + switch ( $notification['row_action_type'] ) { |
|
| 419 | + case 'run' : |
|
| 420 | + /* translators: %s: action HTML */ |
|
| 421 | + $action_message_html = sprintf( __( 'Successfully executed action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 422 | + break; |
|
| 423 | + case 'cancel' : |
|
| 424 | + /* translators: %s: action HTML */ |
|
| 425 | + $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 426 | + break; |
|
| 427 | + default : |
|
| 428 | + /* translators: %s: action HTML */ |
|
| 429 | + $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 430 | + break; |
|
| 431 | + } |
|
| 432 | + } else { |
|
| 433 | + $class = 'error'; |
|
| 434 | + /* translators: 1: action HTML 2: action ID 3: error message */ |
|
| 435 | + $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'woocommerce' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); |
|
| 439 | + |
|
| 440 | + $this->admin_notices[] = array( |
|
| 441 | + 'class' => $class, |
|
| 442 | + 'message' => $action_message_html, |
|
| 443 | + ); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + parent::display_admin_notices(); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Prints the scheduled date in a human friendly format. |
|
| 451 | + * |
|
| 452 | + * @param array $row The array representation of the current row of the table |
|
| 453 | + * |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + public function column_schedule( $row ) { |
|
| 457 | + return $this->get_schedule_display_string( $row['schedule'] ); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Get the scheduled date in a human friendly format. |
|
| 462 | + * |
|
| 463 | + * @param ActionScheduler_Schedule $schedule |
|
| 464 | + * @return string |
|
| 465 | + */ |
|
| 466 | + protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
|
| 467 | + |
|
| 468 | + $schedule_display_string = ''; |
|
| 469 | + |
|
| 470 | + if ( ! $schedule->get_date() ) { |
|
| 471 | + return '0000-00-00 00:00:00'; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $next_timestamp = $schedule->get_date()->getTimestamp(); |
|
| 475 | + |
|
| 476 | + $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); |
|
| 477 | + $schedule_display_string .= '<br/>'; |
|
| 478 | + |
|
| 479 | + if ( gmdate( 'U' ) > $next_timestamp ) { |
|
| 480 | + /* translators: %s: date interval */ |
|
| 481 | + $schedule_display_string .= sprintf( __( ' (%s ago)', 'woocommerce' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); |
|
| 482 | + } else { |
|
| 483 | + /* translators: %s: date interval */ |
|
| 484 | + $schedule_display_string .= sprintf( __( ' (%s)', 'woocommerce' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $schedule_display_string; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Bulk delete |
|
| 492 | + * |
|
| 493 | + * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data |
|
| 494 | + * properly validated by the callee and it will delete the actions without any extra validation. |
|
| 495 | + * |
|
| 496 | + * @param array $ids |
|
| 497 | + * @param string $ids_sql Inherited and unused |
|
| 498 | + */ |
|
| 499 | + protected function bulk_delete( array $ids, $ids_sql ) { |
|
| 500 | + foreach ( $ids as $id ) { |
|
| 501 | + $this->store->delete_action( $id ); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
| 507 | + * parameters are valid. |
|
| 508 | + * |
|
| 509 | + * @param int $action_id |
|
| 510 | + */ |
|
| 511 | + protected function row_action_cancel( $action_id ) { |
|
| 512 | + $this->process_row_action( $action_id, 'cancel' ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their |
|
| 517 | + * parameters are valid. |
|
| 518 | + * |
|
| 519 | + * @param int $action_id |
|
| 520 | + */ |
|
| 521 | + protected function row_action_run( $action_id ) { |
|
| 522 | + $this->process_row_action( $action_id, 'run' ); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Force the data store schema updates. |
|
| 527 | + */ |
|
| 528 | + protected function recreate_tables() { |
|
| 529 | + if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { |
|
| 530 | + $store = $this->store; |
|
| 531 | + } else { |
|
| 532 | + $store = new ActionScheduler_HybridStore(); |
|
| 533 | + } |
|
| 534 | + add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); |
|
| 535 | + |
|
| 536 | + $store_schema = new ActionScheduler_StoreSchema(); |
|
| 537 | + $logger_schema = new ActionScheduler_LoggerSchema(); |
|
| 538 | + $store_schema->register_tables( true ); |
|
| 539 | + $logger_schema->register_tables( true ); |
|
| 540 | + |
|
| 541 | + remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); |
|
| 542 | + } |
|
| 543 | + /** |
|
| 544 | + * Implements the logic behind processing an action once an action link is clicked on the list table. |
|
| 545 | + * |
|
| 546 | + * @param int $action_id |
|
| 547 | + * @param string $row_action_type The type of action to perform on the action. |
|
| 548 | + */ |
|
| 549 | + protected function process_row_action( $action_id, $row_action_type ) { |
|
| 550 | + try { |
|
| 551 | + switch ( $row_action_type ) { |
|
| 552 | + case 'run' : |
|
| 553 | + $this->runner->process_action( $action_id, 'Admin List Table' ); |
|
| 554 | + break; |
|
| 555 | + case 'cancel' : |
|
| 556 | + $this->store->cancel_action( $action_id ); |
|
| 557 | + break; |
|
| 558 | + } |
|
| 559 | + $success = 1; |
|
| 560 | + $error_message = ''; |
|
| 561 | + } catch ( Exception $e ) { |
|
| 562 | + $success = 0; |
|
| 563 | + $error_message = $e->getMessage(); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * {@inheritDoc} |
|
| 571 | + */ |
|
| 572 | + public function prepare_items() { |
|
| 573 | + $this->prepare_column_headers(); |
|
| 574 | + |
|
| 575 | + $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); |
|
| 576 | + |
|
| 577 | + $query = array( |
|
| 578 | + 'per_page' => $per_page, |
|
| 579 | + 'offset' => $this->get_items_offset(), |
|
| 580 | + 'status' => $this->get_request_status(), |
|
| 581 | + 'orderby' => $this->get_request_orderby(), |
|
| 582 | + 'order' => $this->get_request_order(), |
|
| 583 | + 'search' => $this->get_request_search_query(), |
|
| 584 | + ); |
|
| 585 | + |
|
| 586 | + $this->items = array(); |
|
| 587 | + |
|
| 588 | + $total_items = $this->store->query_actions( $query, 'count' ); |
|
| 589 | + |
|
| 590 | + $status_labels = $this->store->get_status_labels(); |
|
| 591 | + |
|
| 592 | + foreach ( $this->store->query_actions( $query ) as $action_id ) { |
|
| 593 | + try { |
|
| 594 | + $action = $this->store->fetch_action( $action_id ); |
|
| 595 | + } catch ( Exception $e ) { |
|
| 596 | + continue; |
|
| 597 | + } |
|
| 598 | + if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { |
|
| 599 | + continue; |
|
| 600 | + } |
|
| 601 | + $this->items[ $action_id ] = array( |
|
| 602 | + 'ID' => $action_id, |
|
| 603 | + 'hook' => $action->get_hook(), |
|
| 604 | + 'status_name' => $this->store->get_status( $action_id ), |
|
| 605 | + 'status' => $status_labels[ $this->store->get_status( $action_id ) ], |
|
| 606 | + 'args' => $action->get_args(), |
|
| 607 | + 'group' => $action->get_group(), |
|
| 608 | + 'log_entries' => $this->logger->get_logs( $action_id ), |
|
| 609 | + 'claim_id' => $this->store->get_claim_id( $action_id ), |
|
| 610 | + 'recurrence' => $this->get_recurrence( $action ), |
|
| 611 | + 'schedule' => $action->get_schedule(), |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + $this->set_pagination_args( array( |
|
| 616 | + 'total_items' => $total_items, |
|
| 617 | + 'per_page' => $per_page, |
|
| 618 | + 'total_pages' => ceil( $total_items / $per_page ), |
|
| 619 | + ) ); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * Prints the available statuses so the user can click to filter. |
|
| 624 | + */ |
|
| 625 | + protected function display_filter_by_status() { |
|
| 626 | + $this->status_counts = $this->store->action_counts(); |
|
| 627 | + parent::display_filter_by_status(); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Get the text to display in the search box on the list table. |
|
| 632 | + */ |
|
| 633 | + protected function get_search_box_button_text() { |
|
| 634 | + return __( 'Search hook, args and claim ID', 'woocommerce' ); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * {@inheritDoc} |
|
| 639 | + */ |
|
| 640 | + protected function get_per_page_option_name() { |
|
| 641 | + return str_replace( '-', '_', $this->screen->id ) . '_per_page'; |
|
| 642 | + } |
|
| 643 | 643 | } |
@@ -80,26 +80,26 @@ discard block |
||
| 80 | 80 | * @param ActionScheduler_Logger $logger |
| 81 | 81 | * @param ActionScheduler_QueueRunner $runner |
| 82 | 82 | */ |
| 83 | - public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { |
|
| 83 | + public function __construct(ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner) { |
|
| 84 | 84 | |
| 85 | 85 | $this->store = $store; |
| 86 | 86 | $this->logger = $logger; |
| 87 | 87 | $this->runner = $runner; |
| 88 | 88 | |
| 89 | - $this->table_header = __( 'Scheduled Actions', 'woocommerce' ); |
|
| 89 | + $this->table_header = __('Scheduled Actions', 'woocommerce'); |
|
| 90 | 90 | |
| 91 | 91 | $this->bulk_actions = array( |
| 92 | - 'delete' => __( 'Delete', 'woocommerce' ), |
|
| 92 | + 'delete' => __('Delete', 'woocommerce'), |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | $this->columns = array( |
| 96 | - 'hook' => __( 'Hook', 'woocommerce' ), |
|
| 97 | - 'status' => __( 'Status', 'woocommerce' ), |
|
| 98 | - 'args' => __( 'Arguments', 'woocommerce' ), |
|
| 99 | - 'group' => __( 'Group', 'woocommerce' ), |
|
| 100 | - 'recurrence' => __( 'Recurrence', 'woocommerce' ), |
|
| 101 | - 'schedule' => __( 'Scheduled Date', 'woocommerce' ), |
|
| 102 | - 'log_entries' => __( 'Log', 'woocommerce' ), |
|
| 96 | + 'hook' => __('Hook', 'woocommerce'), |
|
| 97 | + 'status' => __('Status', 'woocommerce'), |
|
| 98 | + 'args' => __('Arguments', 'woocommerce'), |
|
| 99 | + 'group' => __('Group', 'woocommerce'), |
|
| 100 | + 'recurrence' => __('Recurrence', 'woocommerce'), |
|
| 101 | + 'schedule' => __('Scheduled Date', 'woocommerce'), |
|
| 102 | + 'log_entries' => __('Log', 'woocommerce'), |
|
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | 105 | $this->sort_by = array( |
@@ -116,22 +116,22 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $request_status = $this->get_request_status(); |
| 118 | 118 | |
| 119 | - if ( empty( $request_status ) ) { |
|
| 119 | + if (empty($request_status)) { |
|
| 120 | 120 | $this->sort_by[] = 'status'; |
| 121 | - } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { |
|
| 122 | - $this->columns += array( 'claim_id' => __( 'Claim ID', 'woocommerce' ) ); |
|
| 121 | + } elseif (in_array($request_status, array('in-progress', 'failed'))) { |
|
| 122 | + $this->columns += array('claim_id' => __('Claim ID', 'woocommerce')); |
|
| 123 | 123 | $this->sort_by[] = 'claim_id'; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $this->row_actions = array( |
| 127 | 127 | 'hook' => array( |
| 128 | 128 | 'run' => array( |
| 129 | - 'name' => __( 'Run', 'woocommerce' ), |
|
| 130 | - 'desc' => __( 'Process the action now as if it were run as part of a queue', 'woocommerce' ), |
|
| 129 | + 'name' => __('Run', 'woocommerce'), |
|
| 130 | + 'desc' => __('Process the action now as if it were run as part of a queue', 'woocommerce'), |
|
| 131 | 131 | ), |
| 132 | 132 | 'cancel' => array( |
| 133 | - 'name' => __( 'Cancel', 'woocommerce' ), |
|
| 134 | - 'desc' => __( 'Cancel the action now to avoid it being run in future', 'woocommerce' ), |
|
| 133 | + 'name' => __('Cancel', 'woocommerce'), |
|
| 134 | + 'desc' => __('Cancel the action now to avoid it being run in future', 'woocommerce'), |
|
| 135 | 135 | 'class' => 'cancel trash', |
| 136 | 136 | ), |
| 137 | 137 | ), |
@@ -141,37 +141,37 @@ discard block |
||
| 141 | 141 | array( |
| 142 | 142 | 'seconds' => YEAR_IN_SECONDS, |
| 143 | 143 | /* translators: %s: amount of time */ |
| 144 | - 'names' => _n_noop( '%s year', '%s years', 'woocommerce' ), |
|
| 144 | + 'names' => _n_noop('%s year', '%s years', 'woocommerce'), |
|
| 145 | 145 | ), |
| 146 | 146 | array( |
| 147 | 147 | 'seconds' => MONTH_IN_SECONDS, |
| 148 | 148 | /* translators: %s: amount of time */ |
| 149 | - 'names' => _n_noop( '%s month', '%s months', 'woocommerce' ), |
|
| 149 | + 'names' => _n_noop('%s month', '%s months', 'woocommerce'), |
|
| 150 | 150 | ), |
| 151 | 151 | array( |
| 152 | 152 | 'seconds' => WEEK_IN_SECONDS, |
| 153 | 153 | /* translators: %s: amount of time */ |
| 154 | - 'names' => _n_noop( '%s week', '%s weeks', 'woocommerce' ), |
|
| 154 | + 'names' => _n_noop('%s week', '%s weeks', 'woocommerce'), |
|
| 155 | 155 | ), |
| 156 | 156 | array( |
| 157 | 157 | 'seconds' => DAY_IN_SECONDS, |
| 158 | 158 | /* translators: %s: amount of time */ |
| 159 | - 'names' => _n_noop( '%s day', '%s days', 'woocommerce' ), |
|
| 159 | + 'names' => _n_noop('%s day', '%s days', 'woocommerce'), |
|
| 160 | 160 | ), |
| 161 | 161 | array( |
| 162 | 162 | 'seconds' => HOUR_IN_SECONDS, |
| 163 | 163 | /* translators: %s: amount of time */ |
| 164 | - 'names' => _n_noop( '%s hour', '%s hours', 'woocommerce' ), |
|
| 164 | + 'names' => _n_noop('%s hour', '%s hours', 'woocommerce'), |
|
| 165 | 165 | ), |
| 166 | 166 | array( |
| 167 | 167 | 'seconds' => MINUTE_IN_SECONDS, |
| 168 | 168 | /* translators: %s: amount of time */ |
| 169 | - 'names' => _n_noop( '%s minute', '%s minutes', 'woocommerce' ), |
|
| 169 | + 'names' => _n_noop('%s minute', '%s minutes', 'woocommerce'), |
|
| 170 | 170 | ), |
| 171 | 171 | array( |
| 172 | 172 | 'seconds' => 1, |
| 173 | 173 | /* translators: %s: amount of time */ |
| 174 | - 'names' => _n_noop( '%s second', '%s seconds', 'woocommerce' ), |
|
| 174 | + 'names' => _n_noop('%s second', '%s seconds', 'woocommerce'), |
|
| 175 | 175 | ), |
| 176 | 176 | ); |
| 177 | 177 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | ) |
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | - add_filter( 'set_screen_option_' . $this->get_per_page_option_name(), array( $this, 'set_items_per_page_option' ), 10, 3 ); |
|
| 193 | + add_filter('set_screen_option_' . $this->get_per_page_option_name(), array($this, 'set_items_per_page_option'), 10, 3); |
|
| 194 | 194 | set_screen_options(); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @param int $value Screen option value. |
| 203 | 203 | * @return int |
| 204 | 204 | */ |
| 205 | - public function set_items_per_page_option( $status, $option, $value ) { |
|
| 205 | + public function set_items_per_page_option($status, $option, $value) { |
|
| 206 | 206 | return $value; |
| 207 | 207 | } |
| 208 | 208 | /** |
@@ -218,24 +218,24 @@ discard block |
||
| 218 | 218 | * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. |
| 219 | 219 | * @return string A human friendly string representation of the interval. |
| 220 | 220 | */ |
| 221 | - private static function human_interval( $interval, $periods_to_include = 2 ) { |
|
| 221 | + private static function human_interval($interval, $periods_to_include = 2) { |
|
| 222 | 222 | |
| 223 | - if ( $interval <= 0 ) { |
|
| 224 | - return __( 'Now!', 'woocommerce' ); |
|
| 223 | + if ($interval <= 0) { |
|
| 224 | + return __('Now!', 'woocommerce'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $output = ''; |
| 228 | 228 | |
| 229 | - for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { |
|
| 229 | + for ($time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count(self::$time_periods) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++) { |
|
| 230 | 230 | |
| 231 | - $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); |
|
| 231 | + $periods_in_interval = floor($seconds_remaining / self::$time_periods[$time_period_index]['seconds']); |
|
| 232 | 232 | |
| 233 | - if ( $periods_in_interval > 0 ) { |
|
| 234 | - if ( ! empty( $output ) ) { |
|
| 233 | + if ($periods_in_interval > 0) { |
|
| 234 | + if (!empty($output)) { |
|
| 235 | 235 | $output .= ' '; |
| 236 | 236 | } |
| 237 | - $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'woocommerce' ), $periods_in_interval ); |
|
| 238 | - $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
|
| 237 | + $output .= sprintf(_n(self::$time_periods[$time_period_index]['names'][0], self::$time_periods[$time_period_index]['names'][1], $periods_in_interval, 'woocommerce'), $periods_in_interval); |
|
| 238 | + $seconds_remaining -= $periods_in_interval * self::$time_periods[$time_period_index]['seconds']; |
|
| 239 | 239 | $periods_included++; |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -250,20 +250,20 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | - protected function get_recurrence( $action ) { |
|
| 253 | + protected function get_recurrence($action) { |
|
| 254 | 254 | $schedule = $action->get_schedule(); |
| 255 | - if ( $schedule->is_recurring() ) { |
|
| 255 | + if ($schedule->is_recurring()) { |
|
| 256 | 256 | $recurrence = $schedule->get_recurrence(); |
| 257 | 257 | |
| 258 | - if ( is_numeric( $recurrence ) ) { |
|
| 258 | + if (is_numeric($recurrence)) { |
|
| 259 | 259 | /* translators: %s: time interval */ |
| 260 | - return sprintf( __( 'Every %s', 'woocommerce' ), self::human_interval( $recurrence ) ); |
|
| 260 | + return sprintf(__('Every %s', 'woocommerce'), self::human_interval($recurrence)); |
|
| 261 | 261 | } else { |
| 262 | 262 | return $recurrence; |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - return __( 'Non-repeating', 'woocommerce' ); |
|
| 266 | + return __('Non-repeating', 'woocommerce'); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -273,18 +273,18 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | - public function column_args( array $row ) { |
|
| 277 | - if ( empty( $row['args'] ) ) { |
|
| 278 | - return apply_filters( 'action_scheduler_list_table_column_args', '', $row ); |
|
| 276 | + public function column_args(array $row) { |
|
| 277 | + if (empty($row['args'])) { |
|
| 278 | + return apply_filters('action_scheduler_list_table_column_args', '', $row); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | $row_html = '<ul>'; |
| 282 | - foreach ( $row['args'] as $key => $value ) { |
|
| 283 | - $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); |
|
| 282 | + foreach ($row['args'] as $key => $value) { |
|
| 283 | + $row_html .= sprintf('<li><code>%s => %s</code></li>', esc_html(var_export($key, true)), esc_html(var_export($value, true))); |
|
| 284 | 284 | } |
| 285 | 285 | $row_html .= '</ul>'; |
| 286 | 286 | |
| 287 | - return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
|
| 287 | + return apply_filters('action_scheduler_list_table_column_args', $row_html, $row); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * @param array $row Action array. |
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | - public function column_log_entries( array $row ) { |
|
| 296 | + public function column_log_entries(array $row) { |
|
| 297 | 297 | |
| 298 | 298 | $log_entries_html = '<ol>'; |
| 299 | 299 | |
| 300 | - $timezone = new DateTimezone( 'UTC' ); |
|
| 300 | + $timezone = new DateTimezone('UTC'); |
|
| 301 | 301 | |
| 302 | - foreach ( $row['log_entries'] as $log_entry ) { |
|
| 303 | - $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); |
|
| 302 | + foreach ($row['log_entries'] as $log_entry) { |
|
| 303 | + $log_entries_html .= $this->get_log_entry_html($log_entry, $timezone); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $log_entries_html .= '</ol>'; |
@@ -315,10 +315,10 @@ discard block |
||
| 315 | 315 | * @param DateTimezone $timezone |
| 316 | 316 | * @return string |
| 317 | 317 | */ |
| 318 | - protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { |
|
| 318 | + protected function get_log_entry_html(ActionScheduler_LogEntry $log_entry, DateTimezone $timezone) { |
|
| 319 | 319 | $date = $log_entry->get_date(); |
| 320 | - $date->setTimezone( $timezone ); |
|
| 321 | - return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) ); |
|
| 320 | + $date->setTimezone($timezone); |
|
| 321 | + return sprintf('<li><strong>%s</strong><br/>%s</li>', esc_html($date->format('Y-m-d H:i:s O')), esc_html($log_entry->get_message())); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @return string |
| 331 | 331 | */ |
| 332 | - protected function maybe_render_actions( $row, $column_name ) { |
|
| 333 | - if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) { |
|
| 334 | - return parent::maybe_render_actions( $row, $column_name ); |
|
| 332 | + protected function maybe_render_actions($row, $column_name) { |
|
| 333 | + if ('pending' === strtolower($row['status_name'])) { |
|
| 334 | + return parent::maybe_render_actions($row, $column_name); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | return ''; |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | public function display_admin_notices() { |
| 349 | 349 | global $wpdb; |
| 350 | 350 | |
| 351 | - if ( ( is_a( $this->store, 'ActionScheduler_HybridStore' ) || is_a( $this->store, 'ActionScheduler_DBStore' ) ) && apply_filters( 'action_scheduler_enable_recreate_data_store', true ) ) { |
|
| 351 | + if ((is_a($this->store, 'ActionScheduler_HybridStore') || is_a($this->store, 'ActionScheduler_DBStore')) && apply_filters('action_scheduler_enable_recreate_data_store', true)) { |
|
| 352 | 352 | $table_list = array( |
| 353 | 353 | 'actionscheduler_actions', |
| 354 | 354 | 'actionscheduler_logs', |
@@ -356,12 +356,12 @@ discard block |
||
| 356 | 356 | 'actionscheduler_claims', |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | - $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 360 | - foreach ( $table_list as $table_name ) { |
|
| 361 | - if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { |
|
| 359 | + $found_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 360 | + foreach ($table_list as $table_name) { |
|
| 361 | + if (!in_array($wpdb->prefix . $table_name, $found_tables)) { |
|
| 362 | 362 | $this->admin_notices[] = array( |
| 363 | 363 | 'class' => 'error', |
| 364 | - 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'woocommerce' ), |
|
| 364 | + 'message' => __('It appears one or more database tables were missing. Attempting to re-create the missing table(s).', 'woocommerce'), |
|
| 365 | 365 | ); |
| 366 | 366 | $this->recreate_tables(); |
| 367 | 367 | parent::display_admin_notices(); |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if ( $this->runner->has_maximum_concurrent_batches() ) { |
|
| 374 | + if ($this->runner->has_maximum_concurrent_batches()) { |
|
| 375 | 375 | $claim_count = $this->store->get_claim_count(); |
| 376 | 376 | $this->admin_notices[] = array( |
| 377 | 377 | 'class' => 'updated', |
@@ -386,18 +386,18 @@ discard block |
||
| 386 | 386 | $claim_count |
| 387 | 387 | ), |
| 388 | 388 | ); |
| 389 | - } elseif ( $this->store->has_pending_actions_due() ) { |
|
| 389 | + } elseif ($this->store->has_pending_actions_due()) { |
|
| 390 | 390 | |
| 391 | - $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
|
| 391 | + $async_request_lock_expiration = ActionScheduler::lock()->get_expiration('async-request-runner'); |
|
| 392 | 392 | |
| 393 | 393 | // No lock set or lock expired |
| 394 | - if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
|
| 395 | - $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) ); |
|
| 394 | + if (false === $async_request_lock_expiration || $async_request_lock_expiration < time()) { |
|
| 395 | + $in_progress_url = add_query_arg('status', 'in-progress', remove_query_arg('status')); |
|
| 396 | 396 | /* translators: %s: process URL */ |
| 397 | - $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'woocommerce' ), esc_url( $in_progress_url ) ); |
|
| 397 | + $async_request_message = sprintf(__('A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'woocommerce'), esc_url($in_progress_url)); |
|
| 398 | 398 | } else { |
| 399 | 399 | /* translators: %d: seconds */ |
| 400 | - $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'woocommerce' ), $async_request_lock_expiration - time() ); |
|
| 400 | + $async_request_message = sprintf(__('The next queue will begin processing in approximately %d seconds.', 'woocommerce'), $async_request_lock_expiration - time()); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | $this->admin_notices[] = array( |
@@ -406,36 +406,36 @@ discard block |
||
| 406 | 406 | ); |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - $notification = get_transient( 'action_scheduler_admin_notice' ); |
|
| 409 | + $notification = get_transient('action_scheduler_admin_notice'); |
|
| 410 | 410 | |
| 411 | - if ( is_array( $notification ) ) { |
|
| 412 | - delete_transient( 'action_scheduler_admin_notice' ); |
|
| 411 | + if (is_array($notification)) { |
|
| 412 | + delete_transient('action_scheduler_admin_notice'); |
|
| 413 | 413 | |
| 414 | - $action = $this->store->fetch_action( $notification['action_id'] ); |
|
| 414 | + $action = $this->store->fetch_action($notification['action_id']); |
|
| 415 | 415 | $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
| 416 | - if ( 1 == $notification['success'] ) { |
|
| 416 | + if (1 == $notification['success']) { |
|
| 417 | 417 | $class = 'updated'; |
| 418 | - switch ( $notification['row_action_type'] ) { |
|
| 418 | + switch ($notification['row_action_type']) { |
|
| 419 | 419 | case 'run' : |
| 420 | 420 | /* translators: %s: action HTML */ |
| 421 | - $action_message_html = sprintf( __( 'Successfully executed action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 421 | + $action_message_html = sprintf(__('Successfully executed action: %s', 'woocommerce'), $action_hook_html); |
|
| 422 | 422 | break; |
| 423 | 423 | case 'cancel' : |
| 424 | 424 | /* translators: %s: action HTML */ |
| 425 | - $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 425 | + $action_message_html = sprintf(__('Successfully canceled action: %s', 'woocommerce'), $action_hook_html); |
|
| 426 | 426 | break; |
| 427 | 427 | default : |
| 428 | 428 | /* translators: %s: action HTML */ |
| 429 | - $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'woocommerce' ), $action_hook_html ); |
|
| 429 | + $action_message_html = sprintf(__('Successfully processed change for action: %s', 'woocommerce'), $action_hook_html); |
|
| 430 | 430 | break; |
| 431 | 431 | } |
| 432 | 432 | } else { |
| 433 | 433 | $class = 'error'; |
| 434 | 434 | /* translators: 1: action HTML 2: action ID 3: error message */ |
| 435 | - $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'woocommerce' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); |
|
| 435 | + $action_message_html = sprintf(__('Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'woocommerce'), $action_hook_html, esc_html($notification['action_id']), esc_html($notification['error_message'])); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); |
|
| 438 | + $action_message_html = apply_filters('action_scheduler_admin_notice_html', $action_message_html, $action, $notification); |
|
| 439 | 439 | |
| 440 | 440 | $this->admin_notices[] = array( |
| 441 | 441 | 'class' => $class, |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | * |
| 454 | 454 | * @return string |
| 455 | 455 | */ |
| 456 | - public function column_schedule( $row ) { |
|
| 457 | - return $this->get_schedule_display_string( $row['schedule'] ); |
|
| 456 | + public function column_schedule($row) { |
|
| 457 | + return $this->get_schedule_display_string($row['schedule']); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | * @param ActionScheduler_Schedule $schedule |
| 464 | 464 | * @return string |
| 465 | 465 | */ |
| 466 | - protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { |
|
| 466 | + protected function get_schedule_display_string(ActionScheduler_Schedule $schedule) { |
|
| 467 | 467 | |
| 468 | 468 | $schedule_display_string = ''; |
| 469 | 469 | |
| 470 | - if ( ! $schedule->get_date() ) { |
|
| 470 | + if (!$schedule->get_date()) { |
|
| 471 | 471 | return '0000-00-00 00:00:00'; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $next_timestamp = $schedule->get_date()->getTimestamp(); |
| 475 | 475 | |
| 476 | - $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' ); |
|
| 476 | + $schedule_display_string .= $schedule->get_date()->format('Y-m-d H:i:s O'); |
|
| 477 | 477 | $schedule_display_string .= '<br/>'; |
| 478 | 478 | |
| 479 | - if ( gmdate( 'U' ) > $next_timestamp ) { |
|
| 479 | + if (gmdate('U') > $next_timestamp) { |
|
| 480 | 480 | /* translators: %s: date interval */ |
| 481 | - $schedule_display_string .= sprintf( __( ' (%s ago)', 'woocommerce' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); |
|
| 481 | + $schedule_display_string .= sprintf(__(' (%s ago)', 'woocommerce'), self::human_interval(gmdate('U') - $next_timestamp)); |
|
| 482 | 482 | } else { |
| 483 | 483 | /* translators: %s: date interval */ |
| 484 | - $schedule_display_string .= sprintf( __( ' (%s)', 'woocommerce' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); |
|
| 484 | + $schedule_display_string .= sprintf(__(' (%s)', 'woocommerce'), self::human_interval($next_timestamp - gmdate('U'))); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | return $schedule_display_string; |
@@ -496,9 +496,9 @@ discard block |
||
| 496 | 496 | * @param array $ids |
| 497 | 497 | * @param string $ids_sql Inherited and unused |
| 498 | 498 | */ |
| 499 | - protected function bulk_delete( array $ids, $ids_sql ) { |
|
| 500 | - foreach ( $ids as $id ) { |
|
| 501 | - $this->store->delete_action( $id ); |
|
| 499 | + protected function bulk_delete(array $ids, $ids_sql) { |
|
| 500 | + foreach ($ids as $id) { |
|
| 501 | + $this->store->delete_action($id); |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | |
@@ -508,8 +508,8 @@ discard block |
||
| 508 | 508 | * |
| 509 | 509 | * @param int $action_id |
| 510 | 510 | */ |
| 511 | - protected function row_action_cancel( $action_id ) { |
|
| 512 | - $this->process_row_action( $action_id, 'cancel' ); |
|
| 511 | + protected function row_action_cancel($action_id) { |
|
| 512 | + $this->process_row_action($action_id, 'cancel'); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,27 +518,27 @@ discard block |
||
| 518 | 518 | * |
| 519 | 519 | * @param int $action_id |
| 520 | 520 | */ |
| 521 | - protected function row_action_run( $action_id ) { |
|
| 522 | - $this->process_row_action( $action_id, 'run' ); |
|
| 521 | + protected function row_action_run($action_id) { |
|
| 522 | + $this->process_row_action($action_id, 'run'); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
| 526 | 526 | * Force the data store schema updates. |
| 527 | 527 | */ |
| 528 | 528 | protected function recreate_tables() { |
| 529 | - if ( is_a( $this->store, 'ActionScheduler_HybridStore' ) ) { |
|
| 529 | + if (is_a($this->store, 'ActionScheduler_HybridStore')) { |
|
| 530 | 530 | $store = $this->store; |
| 531 | 531 | } else { |
| 532 | 532 | $store = new ActionScheduler_HybridStore(); |
| 533 | 533 | } |
| 534 | - add_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10, 2 ); |
|
| 534 | + add_action('action_scheduler/created_table', array($store, 'set_autoincrement'), 10, 2); |
|
| 535 | 535 | |
| 536 | 536 | $store_schema = new ActionScheduler_StoreSchema(); |
| 537 | 537 | $logger_schema = new ActionScheduler_LoggerSchema(); |
| 538 | - $store_schema->register_tables( true ); |
|
| 539 | - $logger_schema->register_tables( true ); |
|
| 538 | + $store_schema->register_tables(true); |
|
| 539 | + $logger_schema->register_tables(true); |
|
| 540 | 540 | |
| 541 | - remove_action( 'action_scheduler/created_table', array( $store, 'set_autoincrement' ), 10 ); |
|
| 541 | + remove_action('action_scheduler/created_table', array($store, 'set_autoincrement'), 10); |
|
| 542 | 542 | } |
| 543 | 543 | /** |
| 544 | 544 | * Implements the logic behind processing an action once an action link is clicked on the list table. |
@@ -546,24 +546,24 @@ discard block |
||
| 546 | 546 | * @param int $action_id |
| 547 | 547 | * @param string $row_action_type The type of action to perform on the action. |
| 548 | 548 | */ |
| 549 | - protected function process_row_action( $action_id, $row_action_type ) { |
|
| 549 | + protected function process_row_action($action_id, $row_action_type) { |
|
| 550 | 550 | try { |
| 551 | - switch ( $row_action_type ) { |
|
| 551 | + switch ($row_action_type) { |
|
| 552 | 552 | case 'run' : |
| 553 | - $this->runner->process_action( $action_id, 'Admin List Table' ); |
|
| 553 | + $this->runner->process_action($action_id, 'Admin List Table'); |
|
| 554 | 554 | break; |
| 555 | 555 | case 'cancel' : |
| 556 | - $this->store->cancel_action( $action_id ); |
|
| 556 | + $this->store->cancel_action($action_id); |
|
| 557 | 557 | break; |
| 558 | 558 | } |
| 559 | 559 | $success = 1; |
| 560 | 560 | $error_message = ''; |
| 561 | - } catch ( Exception $e ) { |
|
| 561 | + } catch (Exception $e) { |
|
| 562 | 562 | $success = 0; |
| 563 | 563 | $error_message = $e->getMessage(); |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
|
| 566 | + set_transient('action_scheduler_admin_notice', compact('action_id', 'success', 'error_message', 'row_action_type'), 30); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | public function prepare_items() { |
| 573 | 573 | $this->prepare_column_headers(); |
| 574 | 574 | |
| 575 | - $per_page = $this->get_items_per_page( $this->get_per_page_option_name(), $this->items_per_page ); |
|
| 575 | + $per_page = $this->get_items_per_page($this->get_per_page_option_name(), $this->items_per_page); |
|
| 576 | 576 | |
| 577 | 577 | $query = array( |
| 578 | 578 | 'per_page' => $per_page, |
@@ -585,38 +585,38 @@ discard block |
||
| 585 | 585 | |
| 586 | 586 | $this->items = array(); |
| 587 | 587 | |
| 588 | - $total_items = $this->store->query_actions( $query, 'count' ); |
|
| 588 | + $total_items = $this->store->query_actions($query, 'count'); |
|
| 589 | 589 | |
| 590 | 590 | $status_labels = $this->store->get_status_labels(); |
| 591 | 591 | |
| 592 | - foreach ( $this->store->query_actions( $query ) as $action_id ) { |
|
| 592 | + foreach ($this->store->query_actions($query) as $action_id) { |
|
| 593 | 593 | try { |
| 594 | - $action = $this->store->fetch_action( $action_id ); |
|
| 595 | - } catch ( Exception $e ) { |
|
| 594 | + $action = $this->store->fetch_action($action_id); |
|
| 595 | + } catch (Exception $e) { |
|
| 596 | 596 | continue; |
| 597 | 597 | } |
| 598 | - if ( is_a( $action, 'ActionScheduler_NullAction' ) ) { |
|
| 598 | + if (is_a($action, 'ActionScheduler_NullAction')) { |
|
| 599 | 599 | continue; |
| 600 | 600 | } |
| 601 | - $this->items[ $action_id ] = array( |
|
| 601 | + $this->items[$action_id] = array( |
|
| 602 | 602 | 'ID' => $action_id, |
| 603 | 603 | 'hook' => $action->get_hook(), |
| 604 | - 'status_name' => $this->store->get_status( $action_id ), |
|
| 605 | - 'status' => $status_labels[ $this->store->get_status( $action_id ) ], |
|
| 604 | + 'status_name' => $this->store->get_status($action_id), |
|
| 605 | + 'status' => $status_labels[$this->store->get_status($action_id)], |
|
| 606 | 606 | 'args' => $action->get_args(), |
| 607 | 607 | 'group' => $action->get_group(), |
| 608 | - 'log_entries' => $this->logger->get_logs( $action_id ), |
|
| 609 | - 'claim_id' => $this->store->get_claim_id( $action_id ), |
|
| 610 | - 'recurrence' => $this->get_recurrence( $action ), |
|
| 608 | + 'log_entries' => $this->logger->get_logs($action_id), |
|
| 609 | + 'claim_id' => $this->store->get_claim_id($action_id), |
|
| 610 | + 'recurrence' => $this->get_recurrence($action), |
|
| 611 | 611 | 'schedule' => $action->get_schedule(), |
| 612 | 612 | ); |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - $this->set_pagination_args( array( |
|
| 615 | + $this->set_pagination_args(array( |
|
| 616 | 616 | 'total_items' => $total_items, |
| 617 | 617 | 'per_page' => $per_page, |
| 618 | - 'total_pages' => ceil( $total_items / $per_page ), |
|
| 619 | - ) ); |
|
| 618 | + 'total_pages' => ceil($total_items / $per_page), |
|
| 619 | + )); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -631,13 +631,13 @@ discard block |
||
| 631 | 631 | * Get the text to display in the search box on the list table. |
| 632 | 632 | */ |
| 633 | 633 | protected function get_search_box_button_text() { |
| 634 | - return __( 'Search hook, args and claim ID', 'woocommerce' ); |
|
| 634 | + return __('Search hook, args and claim ID', 'woocommerce'); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
| 638 | 638 | * {@inheritDoc} |
| 639 | 639 | */ |
| 640 | 640 | protected function get_per_page_option_name() { |
| 641 | - return str_replace( '-', '_', $this->screen->id ) . '_per_page'; |
|
| 641 | + return str_replace('-', '_', $this->screen->id) . '_per_page'; |
|
| 642 | 642 | } |
| 643 | 643 | } |