WordPress at a glance
class is not described

Action_Scheduler\Migration

Controller{} WC 3.0.0

Class Controller

The main plugin/initialization class for migration to custom tables.

Return

null. Nothing.

Usage

$Controller = new Controller();
// use class methods

Methods

  1. __construct( Scheduler $migration_scheduler )
  2. ERROR: no method name found on line ` * @param string $class Classname of the store class.`
  3. ERROR: no method name found on line ` *`
  4. ERROR: no method name found on line ` * @return string`
  5. ERROR: no method name found on line ` /**`
  6. ERROR: no method name found on line ``
  7. ERROR: no method name found on line ``
  8. ERROR: no method name found on line ``
  9. ERROR: no method name found on line ``
  10. ERROR: no method name found on line ``
  11. ERROR: no method name found on line ` }`
  12. ERROR: no method name found on line ``
  13. static( new Scheduler() )
  14. ERROR: no method name found on line ``
  15. allow_migration()
  16. ERROR: no method name found on line ``
  17. ERROR: no method name found on line ``
  18. ERROR: no method name found on line ``
  19. display_migration_notice()
  20. ERROR: no method name found on line ``
  21. ERROR: no method name found on line ` }`
  22. ERROR: no method name found on line ``
  23. ERROR: no method name found on line ` * Proceed with the migration if the dependencies have been met.`
  24. ERROR: no method name found on line ``
  25. ERROR: no method name found on line ` }`
  26. ERROR: no method name found on line ``
  27. ERROR: no method name found on line ``
  28. ERROR: no method name found on line ``
  29. ERROR: no method name found on line ``
  30. ERROR: no method name found on line ``
  31. ERROR: no method name found on line ``
  32. ERROR: no method name found on line ``
  33. ERROR: no method name found on line ``
  34. ERROR: no method name found on line ``
  35. ERROR: no method name found on line ``
  36. ERROR: no method name found on line ``
  37. ERROR: no method name found on line ``
  38. if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() )
  39. ERROR: no method name found on line ``
  40. apply_filters( 'action_scheduler_migrate_data_store', false )
  41. ERROR: no method name found on line ``
  42. ERROR: no method name found on line ``
  43. ERROR: no method name found on line ``
  44. ERROR: no method name found on line ``
  45. ERROR: no method name found on line ``
  46. ERROR: no method name found on line ``
  47. ERROR: no method name found on line ` $this->logger_classname = $class;`
  48. ERROR: no method name found on line ``
  49. ERROR: no method name found on line ``
  50. ERROR: no method name found on line ``
  51. ERROR: no method name found on line ``
  52. ERROR: no method name found on line ``
  53. ERROR: no method name found on line ``
  54. ERROR: no method name found on line ``
  55. ERROR: no method name found on line ``
  56. ERROR: no method name found on line ``
  57. ERROR: no method name found on line ``
  58. ERROR: no method name found on line ` */`
  59. ERROR: no method name found on line ` /**`
  60. return ( ! $this->has_custom_datastore() )
  61. ERROR: no method name found on line ``
  62. ERROR: no method name found on line ``
  63. ERROR: no method name found on line ``
  64. ERROR: no method name found on line ``
  65. ERROR: no method name found on line ` /**`
  66. ERROR: no method name found on line ``
  67. ERROR: no method name found on line ` * Possibly hook the migration scheduler action.`
  68. ERROR: no method name found on line ` return;`
  69. ERROR: no method name found on line ` */`
  70. add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 )
  71. ERROR: no method name found on line ` // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen`
  72. maybe_hook_migration()
  73. ERROR: no method name found on line ``
  74. ERROR: no method name found on line ``
  75. ERROR: no method name found on line ` /**`
  76. add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 )
  77. ERROR: no method name found on line ``
  78. ERROR: no method name found on line ``
  79. ERROR: no method name found on line ` * Possibly hook the migration scheduler action.`
  80. ERROR: no method name found on line ``
  81. ERROR: no method name found on line ``
  82. ERROR: no method name found on line ` *`
  83. ERROR: no method name found on line ``
  84. ERROR: no method name found on line ` * @return bool`
  85. ERROR: no method name found on line ` }`
  86. ERROR: no method name found on line ` *`
  87. ERROR: no method name found on line ` }`
  88. ERROR: no method name found on line ` }`
  89. ERROR: no method name found on line ` return \ActionScheduler_DataController::DATASTORE_CLASS;`
  90. ERROR: no method name found on line ` $this->logger_classname = $class;`
  91. get_logger_class( $class )
  92. ERROR: no method name found on line ` * @param string $class Classname of the logger class.`
  93. ERROR: no method name found on line ` *`
  94. ERROR: no method name found on line ` */`
  95. ERROR: no method name found on line ` *`
  96. ERROR: no method name found on line ` */`
  97. ERROR: no method name found on line ` $this->store_classname = '';`
  98. ERROR: no method name found on line ` } else {`
  99. ERROR: no method name found on line ` } else {`
  100. ERROR: no method name found on line ` * @param string $class Classname of the logger class.`
  101. ERROR: no method name found on line ` return 'ActionScheduler_HybridStore';`
  102. ERROR: no method name found on line ``
  103. get_migration_config_object()
  104. init()
  105. ERROR: no method name found on line ``
  106. ERROR: no method name found on line ``
  107. ERROR: no method name found on line ` /**`
  108. ERROR: no method name found on line ``
  109. ERROR: no method name found on line ``
  110. ERROR: no method name found on line ``
  111. get_store_class( $class )
  112. has_custom_datastore()
  113. hook()
  114. hook_admin_notices()
  115. set_progress_bar( new ProgressBar( '', 0 ) )
  116. ERROR: no method name found on line ` static $config = null;`
  117. instance()
  118. ERROR: no method name found on line ``
  119. ERROR: no method name found on line ``
  120. ERROR: no method name found on line ``
  121. ERROR: no method name found on line ``
  122. ERROR: no method name found on line ``
  123. ERROR: no method name found on line ``
  124. ERROR: no method name found on line ``
  125. ERROR: no method name found on line ``
  126. ERROR: no method name found on line ``
  127. ERROR: no method name found on line ``
  128. ERROR: no method name found on line ``
  129. ERROR: no method name found on line ` return;`
  130. ERROR: no method name found on line ` }`
  131. Config()
  132. ERROR: no method name found on line ` * Get the default migration config object`
  133. ERROR: no method name found on line ` * Hook dashboard migration notice.`
  134. ERROR: no method name found on line ``
  135. ERROR: no method name found on line ``
  136. ERROR: no method name found on line ``
  137. ERROR: no method name found on line ` }`
  138. ERROR: no method name found on line ` static $config = null;`
  139. ERROR: no method name found on line ``
  140. ERROR: no method name found on line ` * @return void`
  141. ERROR: no method name found on line ` }`
  142. store_classname() : new \ActionScheduler_wpPostStore()
  143. set_source_logger( $source_logger )
  144. ERROR: no method name found on line ` $this->store_classname = $class;`
  145. ERROR: no method name found on line ` * Show a dashboard notice that migration is in progress.`
  146. ERROR: no method name found on line ``
  147. ERROR: no method name found on line ` * Singleton factory.`
  148. ERROR: no method name found on line ``
  149. ERROR: no method name found on line ` }`
  150. ERROR: no method name found on line ` */`
  151. ERROR: no method name found on line ` /**`
  152. ERROR: no method name found on line ` *`
  153. ERROR: no method name found on line ` }`
  154. ERROR: no method name found on line ` $this->store_classname = '';`
  155. ERROR: no method name found on line ` }`
  156. ERROR: no method name found on line ` }`
  157. ERROR: no method name found on line ` $this->store_classname = '';`
  158. ERROR: no method name found on line ` *`
  159. ERROR: no method name found on line ` $this->store_classname = '';`
  160. ERROR: no method name found on line ` $this->migration_scheduler = $migration_scheduler;`
  161. ERROR: no method name found on line ` * @param string $class Classname of the store class.`
  162. ERROR: no method name found on line ` }`
  163. ERROR: no method name found on line ` * @param Scheduler $migration_scheduler Migration scheduler object.`
  164. ERROR: no method name found on line ` *`
  165. ERROR: no method name found on line ` }`
  166. schedule_migration()
  167. ERROR: no method name found on line `}`
  168. ERROR: no method name found on line ``
  169. ERROR: no method name found on line ` *`
  170. ERROR: no method name found on line ``
  171. ERROR: no method name found on line ``

Notes

  • Package: Action_Scheduler\Migration

Changelog

Since 3.0.0 Introduced.

Code of Controller{} WC 5.3.0

<?php
class Controller {
	private static $instance;

	/** @var Action_Scheduler\Migration\Scheduler */
	private $migration_scheduler;

	/** @var string */
	private $store_classname;

	/** @var string */
	private $logger_classname;

	/** @var bool */
	private $migrate_custom_store;

	/**
	 * Controller constructor.
	 *
	 * @param Scheduler $migration_scheduler Migration scheduler object.
	 */
	protected function __construct( Scheduler $migration_scheduler ) {
		$this->migration_scheduler = $migration_scheduler;
		$this->store_classname     = '';
	}

	/**
	 * Set the action store class name.
	 *
	 * @param string $class Classname of the store class.
	 *
	 * @return string
	 */
	public function get_store_class( $class ) {
		if ( \ActionScheduler_DataController::is_migration_complete() ) {
			return \ActionScheduler_DataController::DATASTORE_CLASS;
		} elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
			$this->store_classname = $class;
			return $class;
		} else {
			return 'ActionScheduler_HybridStore';
		}
	}

	/**
	 * Set the action logger class name.
	 *
	 * @param string $class Classname of the logger class.
	 *
	 * @return string
	 */
	public function get_logger_class( $class ) {
		\ActionScheduler_Store::instance();

		if ( $this->has_custom_datastore() ) {
			$this->logger_classname = $class;
			return $class;
		} else {
			return \ActionScheduler_DataController::LOGGER_CLASS;
		}
	}

	/**
	 * Get flag indicating whether a custom datastore is in use.
	 *
	 * @return bool
	 */
	public function has_custom_datastore() {
		return (bool) $this->store_classname;
	}

	/**
	 * Set up the background migration process
	 *
	 * @return void
	 */
	public function schedule_migration() {
		if ( \ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled() ) {
			return;
		}

		$this->migration_scheduler->schedule_migration();
	}

	/**
	 * Get the default migration config object
	 *
	 * @return ActionScheduler\Migration\Config
	 */
	public function get_migration_config_object() {
		static $config = null;

		if ( ! $config ) {
			$source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
			$source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();

			$config = new Config();
			$config->set_source_store( $source_store );
			$config->set_source_logger( $source_logger );
			$config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
			$config->set_destination_logger( new \ActionScheduler_DBLogger() );

			if ( defined( 'WP_CLI' ) && WP_CLI ) {
				$config->set_progress_bar( new ProgressBar( '', 0 ) );
			}
		}

		return apply_filters( 'action_scheduler/migration_config', $config );
	}

	/**
	 * Hook dashboard migration notice.
	 */
	public function hook_admin_notices() {
		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
			return;
		}
		add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
	}

	/**
	 * Show a dashboard notice that migration is in progress.
	 */
	public function display_migration_notice() {
		printf( '<div class="notice notice-warning"><p>%s</p></div>', __( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'woocommerce' ) );
	}

	/**
	 * Add store classes. Hook migration.
	 */
	private function hook() {
		add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
		add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
		add_action( 'init', array( $this, 'maybe_hook_migration' ) );
		add_action( 'wp_loaded', array( $this, 'schedule_migration' ) );

		// Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
		add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
		add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
	}

	/**
	 * Possibly hook the migration scheduler action.
	 *
	 * @author Jeremy Pry
	 */
	public function maybe_hook_migration() {
		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
			return;
		}

		$this->migration_scheduler->hook();
	}

	/**
	 * Allow datastores to enable migration to AS tables.
	 */
	public function allow_migration() {
		if ( ! \ActionScheduler_DataController::dependencies_met() ) {
			return false;
		}

		if ( null === $this->migrate_custom_store ) {
			$this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
		}

		return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
	}

	/**
	 * Proceed with the migration if the dependencies have been met.
	 */
	public static function init() {
		if ( \ActionScheduler_DataController::dependencies_met() ) {
			self::instance()->hook();
		}
	}

	/**
	 * Singleton factory.
	 */
	public static function instance() {
		if ( ! isset( self::$instance ) ) {
			self::$instance = new static( new Scheduler() );
		}

		return self::$instance;
	}
}