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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / packages / action-scheduler / classes / ActionScheduler_DataController.php
woocommerce / packages / action-scheduler / classes Last commit date
WP_CLI 11 months ago abstracts 11 months ago actions 1 year ago data-stores 11 months ago migration 1 year ago schedules 1 year ago schema 11 months ago ActionScheduler_ActionClaim.php 1 year ago ActionScheduler_ActionFactory.php 1 year ago ActionScheduler_AdminView.php 1 year ago ActionScheduler_AsyncRequest_QueueRunner.php 1 year ago ActionScheduler_Compatibility.php 1 year ago ActionScheduler_DataController.php 11 months ago ActionScheduler_DateTime.php 1 year ago ActionScheduler_Exception.php 3 years ago ActionScheduler_FatalErrorMonitor.php 1 year ago ActionScheduler_InvalidActionException.php 1 year ago ActionScheduler_ListTable.php 1 year ago ActionScheduler_LogEntry.php 1 year ago ActionScheduler_NullLogEntry.php 1 year ago ActionScheduler_OptionLock.php 1 year ago ActionScheduler_QueueCleaner.php 1 year ago ActionScheduler_QueueRunner.php 1 year ago ActionScheduler_RecurringActionScheduler.php 11 months ago ActionScheduler_SystemInformation.php 1 year ago ActionScheduler_Versions.php 1 year ago ActionScheduler_WPCommentCleaner.php 1 year ago ActionScheduler_wcSystemStatus.php 11 months ago
ActionScheduler_DataController.php
211 lines
1 <?php
2
3 use Action_Scheduler\Migration\Controller;
4
5 /**
6 * Class ActionScheduler_DataController
7 *
8 * The main plugin/initialization class for the data stores.
9 *
10 * Responsible for hooking everything up with WordPress.
11 *
12 * @package Action_Scheduler
13 *
14 * @since 3.0.0
15 */
16 class ActionScheduler_DataController {
17 /** Action data store class name. */
18 const DATASTORE_CLASS = 'ActionScheduler_DBStore';
19
20 /** Logger data store class name. */
21 const LOGGER_CLASS = 'ActionScheduler_DBLogger';
22
23 /** Migration status option name. */
24 const STATUS_FLAG = 'action_scheduler_migration_status';
25
26 /** Migration status option value. */
27 const STATUS_COMPLETE = 'complete';
28
29 /** Migration minimum required PHP version. */
30 const MIN_PHP_VERSION = '5.5';
31
32 /**
33 * Instance.
34 *
35 * @var ActionScheduler_DataController
36 */
37 private static $instance;
38
39 /**
40 * Sleep time in seconds.
41 *
42 * @var int
43 */
44 private static $sleep_time = 0;
45
46 /**
47 * Tick count required for freeing memory.
48 *
49 * @var int
50 */
51 private static $free_ticks = 50;
52
53 /**
54 * Get a flag indicating whether the migration environment dependencies are met.
55 *
56 * @return bool
57 */
58 public static function dependencies_met() {
59 $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
60 return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
61 }
62
63 /**
64 * Get a flag indicating whether the migration is complete.
65 *
66 * @return bool Whether the flag has been set marking the migration as complete
67 */
68 public static function is_migration_complete() {
69 return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE;
70 }
71
72 /**
73 * Mark the migration as complete.
74 */
75 public static function mark_migration_complete() {
76 update_option( self::STATUS_FLAG, self::STATUS_COMPLETE );
77 }
78
79 /**
80 * Unmark migration when a plugin is de-activated. Will not work in case of silent activation, for example in an update.
81 * We do this to mitigate the bug of lost actions which happens if there was an AS 2.x to AS 3.x migration in the past, but that plugin is now
82 * deactivated and the site was running on AS 2.x again.
83 */
84 public static function mark_migration_incomplete() {
85 delete_option( self::STATUS_FLAG );
86 }
87
88 /**
89 * Set the action store class name.
90 *
91 * @param string $class Classname of the store class.
92 *
93 * @return string
94 */
95 public static function set_store_class( $class ) {
96 return self::DATASTORE_CLASS;
97 }
98
99 /**
100 * Set the action logger class name.
101 *
102 * @param string $class Classname of the logger class.
103 *
104 * @return string
105 */
106 public static function set_logger_class( $class ) {
107 return self::LOGGER_CLASS;
108 }
109
110 /**
111 * Set the sleep time in seconds.
112 *
113 * @param integer $sleep_time The number of seconds to pause before resuming operation.
114 */
115 public static function set_sleep_time( $sleep_time ) {
116 self::$sleep_time = (int) $sleep_time;
117 }
118
119 /**
120 * Set the tick count required for freeing memory.
121 *
122 * @param integer $free_ticks The number of ticks to free memory on.
123 */
124 public static function set_free_ticks( $free_ticks ) {
125 self::$free_ticks = (int) $free_ticks;
126 }
127
128 /**
129 * Free memory if conditions are met.
130 *
131 * @param int $ticks Current tick count.
132 */
133 public static function maybe_free_memory( $ticks ) {
134 if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) {
135 self::free_memory();
136 }
137 }
138
139 /**
140 * Reduce memory footprint by clearing the database query and object caches.
141 */
142 public static function free_memory() {
143 if ( 0 < self::$sleep_time ) {
144 /* translators: %d: amount of time */
145 \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'woocommerce' ), self::$sleep_time ) );
146 sleep( self::$sleep_time );
147 }
148
149 \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'woocommerce' ) );
150
151 /**
152 * Globals.
153 *
154 * @var $wpdb \wpdb
155 * @var $wp_object_cache \WP_Object_Cache
156 */
157 global $wpdb, $wp_object_cache;
158
159 $wpdb->queries = array();
160
161 if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) {
162 return;
163 }
164
165 // Not all drop-ins support these props, however, there may be existing installations that rely on these being cleared.
166 if ( property_exists( $wp_object_cache, 'group_ops' ) ) {
167 $wp_object_cache->group_ops = array();
168 }
169 if ( property_exists( $wp_object_cache, 'stats' ) ) {
170 $wp_object_cache->stats = array();
171 }
172 if ( property_exists( $wp_object_cache, 'memcache_debug' ) ) {
173 $wp_object_cache->memcache_debug = array();
174 }
175 if ( property_exists( $wp_object_cache, 'cache' ) ) {
176 $wp_object_cache->cache = array();
177 }
178
179 if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
180 call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important!
181 }
182 }
183
184 /**
185 * Connect to table datastores if migration is complete.
186 * Otherwise, proceed with the migration if the dependencies have been met.
187 */
188 public static function init() {
189 if ( self::is_migration_complete() ) {
190 add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 );
191 add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 );
192 add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) );
193 } elseif ( self::dependencies_met() ) {
194 Controller::init();
195 }
196
197 add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) );
198 }
199
200 /**
201 * Singleton factory.
202 */
203 public static function instance() {
204 if ( ! isset( self::$instance ) ) {
205 self::$instance = new static();
206 }
207
208 return self::$instance;
209 }
210 }
211