@@ -32,1320 +32,1320 @@ |
||
32 | 32 | class EE_Data_Migration_Manager implements ResettableInterface |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * @var EE_Registry |
|
38 | - */ |
|
39 | - // protected $EE; |
|
40 | - /** |
|
41 | - * name of the WordPress option which stores an array of data about |
|
42 | - */ |
|
43 | - const data_migrations_option_name = 'ee_data_migration'; |
|
44 | - |
|
45 | - |
|
46 | - const data_migration_script_option_prefix = 'ee_data_migration_script_'; |
|
47 | - |
|
48 | - const data_migration_script_mapping_option_prefix = 'ee_dms_map_'; |
|
49 | - |
|
50 | - /** |
|
51 | - * name of the WordPress option which stores the database' current version. IE, the code may be at version 4.2.0, |
|
52 | - * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc. |
|
53 | - */ |
|
54 | - const current_database_state = 'ee_data_migration_current_db_state'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Special status string returned when we're positive there are no more data migration |
|
58 | - * scripts that can be run. |
|
59 | - */ |
|
60 | - const status_no_more_migration_scripts = 'no_more_migration_scripts'; |
|
61 | - |
|
62 | - /** |
|
63 | - * string indicating the migration should continue |
|
64 | - */ |
|
65 | - const status_continue = 'status_continue'; |
|
66 | - |
|
67 | - /** |
|
68 | - * string indicating the migration has completed and should be ended |
|
69 | - */ |
|
70 | - const status_completed = 'status_completed'; |
|
71 | - |
|
72 | - /** |
|
73 | - * string indicating a fatal error occurred and the data migration should be completely aborted |
|
74 | - */ |
|
75 | - const status_fatal_error = 'status_fatal_error'; |
|
76 | - |
|
77 | - /** |
|
78 | - * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent |
|
79 | - * during migration) |
|
80 | - */ |
|
81 | - const step_size = 50; |
|
82 | - |
|
83 | - /** |
|
84 | - * option name that stores the queue of ee plugins needing to have |
|
85 | - * their data initialized (or re-initialized) once we are done migrations |
|
86 | - */ |
|
87 | - const db_init_queue_option_name = 'ee_db_init_queue'; |
|
88 | - |
|
89 | - /** |
|
90 | - * Array of information concerning data migrations that have run in the history |
|
91 | - * of this EE installation. Keys should be the name of the version the script upgraded to |
|
92 | - * |
|
93 | - * @var EE_Data_Migration_Script_Base[] |
|
94 | - */ |
|
95 | - private $_data_migrations_ran = null; |
|
96 | - |
|
97 | - /** |
|
98 | - * The last run script. It's nice to store this somewhere accessible, as its easiest |
|
99 | - * to know which was the last run by which is the newest wp option; but in most of the code |
|
100 | - * we just use the local $_data_migration_ran array, which organized the scripts differently |
|
101 | - * |
|
102 | - * @var EE_Data_Migration_Script_Base |
|
103 | - */ |
|
104 | - private $_last_ran_script = null; |
|
105 | - |
|
106 | - /** |
|
107 | - * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script. |
|
108 | - * |
|
109 | - * @var EE_Data_Migration_Script_Base |
|
110 | - */ |
|
111 | - private $_last_ran_incomplete_script = null; |
|
112 | - |
|
113 | - /** |
|
114 | - * array where keys are classnames, and values are filepaths of all the known migration scripts |
|
115 | - * |
|
116 | - * @var array |
|
117 | - */ |
|
118 | - private $_data_migration_class_to_filepath_map; |
|
119 | - |
|
120 | - /** |
|
121 | - * the following 4 properties are fully set on construction. |
|
122 | - * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished |
|
123 | - * one, we may want to start the next one); whereas the last two indicate whether to continue running a single |
|
124 | - * data migration script |
|
125 | - * |
|
126 | - * @var array |
|
127 | - */ |
|
128 | - public $stati_that_indicate_to_continue_migrations = []; |
|
129 | - |
|
130 | - public $stati_that_indicate_to_stop_migrations = []; |
|
131 | - |
|
132 | - public $stati_that_indicate_to_continue_single_migration_script = []; |
|
133 | - |
|
134 | - public $stati_that_indicate_to_stop_single_migration_script = []; |
|
135 | - |
|
136 | - /** |
|
137 | - * @var TableManager $table_manager |
|
138 | - */ |
|
139 | - protected $_table_manager; |
|
140 | - |
|
141 | - /** |
|
142 | - * @var TableAnalysis $table_analysis |
|
143 | - */ |
|
144 | - protected $_table_analysis; |
|
145 | - |
|
146 | - /** |
|
147 | - * @var array $script_migration_versions |
|
148 | - */ |
|
149 | - protected $script_migration_versions; |
|
150 | - |
|
151 | - /** |
|
152 | - * @var EE_Data_Migration_Manager $_instance |
|
153 | - * @access private |
|
154 | - */ |
|
155 | - private static $_instance = null; |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @singleton method used to instantiate class object |
|
160 | - * @access public |
|
161 | - * @return EE_Data_Migration_Manager instance |
|
162 | - */ |
|
163 | - public static function instance() |
|
164 | - { |
|
165 | - // check if class object is instantiated |
|
166 | - if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
167 | - self::$_instance = new self(); |
|
168 | - } |
|
169 | - return self::$_instance; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, |
|
175 | - * all new usages of the singleton should be made with Classname::instance()) and returns it |
|
176 | - * |
|
177 | - * @return EE_Data_Migration_Manager |
|
178 | - */ |
|
179 | - public static function reset() |
|
180 | - { |
|
181 | - self::$_instance = null; |
|
182 | - return self::instance(); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @throws EE_Error |
|
188 | - * @throws ReflectionException |
|
189 | - */ |
|
190 | - private function __construct() |
|
191 | - { |
|
192 | - $this->stati_that_indicate_to_continue_migrations = [ |
|
193 | - self::status_continue, |
|
194 | - self::status_completed, |
|
195 | - ]; |
|
196 | - $this->stati_that_indicate_to_stop_migrations = [ |
|
197 | - self::status_fatal_error, |
|
198 | - self::status_no_more_migration_scripts, |
|
199 | - ]; |
|
200 | - $this->stati_that_indicate_to_continue_single_migration_script = [ |
|
201 | - self::status_continue, |
|
202 | - ]; |
|
203 | - $this->stati_that_indicate_to_stop_single_migration_script = [ |
|
204 | - self::status_completed, |
|
205 | - self::status_fatal_error |
|
206 | - // note: status_no_more_migration_scripts doesn't apply |
|
207 | - ]; |
|
208 | - // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
|
209 | - // to be defined, because right now it doesn't get autoloaded on its own |
|
210 | - EE_Registry::instance()->load_core('Data_Migration_Class_Base', [], true); |
|
211 | - EE_Registry::instance()->load_core('Data_Migration_Script_Base', [], true); |
|
212 | - EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', [], true); |
|
213 | - EE_Registry::instance()->load_core('Data_Migration_Script_Stage', [], true); |
|
214 | - EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', [], true); |
|
215 | - $this->_table_manager = EE_Registry::instance()->create('TableManager', [], true); |
|
216 | - $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what |
|
222 | - * the option names are like, but generally they're like |
|
223 | - * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that). |
|
224 | - * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived, |
|
225 | - * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php |
|
226 | - * (ex: EE_DMS_Core_4_1_0.dms.php) |
|
227 | - * |
|
228 | - * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
|
229 | - * @return array where the first item is the plugin slug (eg 'Core','Calendar', etc.) and the 2nd is the version of |
|
230 | - * that plugin (eg '4.1.0') |
|
231 | - */ |
|
232 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) |
|
233 | - { |
|
234 | - $plugin_slug_and_version_string = str_replace( |
|
235 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
236 | - "", |
|
237 | - $option_name |
|
238 | - ); |
|
239 | - // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
|
240 | - $parts = explode(".", $plugin_slug_and_version_string); |
|
241 | - |
|
242 | - if (count($parts) == 4) { |
|
243 | - // it's 4.2-style.eg Core.4.1.0 |
|
244 | - $plugin_slug = $parts[0]; // eg Core |
|
245 | - $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
246 | - } else { |
|
247 | - // it's 4.1-style: eg 4.1.0 |
|
248 | - $plugin_slug = 'Core'; |
|
249 | - $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
250 | - } |
|
251 | - return [$plugin_slug, $version_string]; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Gets the DMS class from the WordPress option, otherwise throws an EE_Error if it's not |
|
257 | - * for a known DMS class. |
|
258 | - * |
|
259 | - * @param string $dms_option_name |
|
260 | - * @param string $dms_option_value (serialized) |
|
261 | - * @return EE_Data_Migration_Script_Base |
|
262 | - * @throws EE_Error |
|
263 | - */ |
|
264 | - private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) |
|
265 | - { |
|
266 | - $data_migration_data = maybe_unserialize($dms_option_value); |
|
267 | - if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
268 | - // During multisite migrations, it's possible we already grabbed another instance of this class |
|
269 | - // but for a different blog. Make sure we don't reuse them (as they store info specific |
|
270 | - // to their respective blog, like which database table to migrate). |
|
271 | - $class = LoaderFactory::getLoader()->getNew($data_migration_data['class']); |
|
272 | - if ($class instanceof EE_Data_Migration_Script_Base) { |
|
273 | - $class->instantiate_from_array_of_properties($data_migration_data); |
|
274 | - return $class; |
|
275 | - } else { |
|
276 | - // huh, so it's an object but not a data migration script?? that shouldn't happen |
|
277 | - // just leave it as an array (which will probably just get ignored) |
|
278 | - throw new EE_Error( |
|
279 | - sprintf( |
|
280 | - esc_html__( |
|
281 | - "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", |
|
282 | - 'event_espresso' |
|
283 | - ), |
|
284 | - $data_migration_data['class'] |
|
285 | - ) |
|
286 | - ); |
|
287 | - } |
|
288 | - } else { |
|
289 | - // so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
|
290 | - throw new EE_Error( |
|
291 | - sprintf( |
|
292 | - esc_html__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), |
|
293 | - $dms_option_name |
|
294 | - ) |
|
295 | - ); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Gets the array describing what data migrations have run. |
|
302 | - * Also has a side effect of recording which was the last run, |
|
303 | - * and which was the last run which hasn't finished yet |
|
304 | - * |
|
305 | - * @return array where each element should be an array of EE_Data_Migration_Script_Base |
|
306 | - * (but also has a few legacy arrays in there - which should probably be ignored) |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - public function get_data_migrations_ran() |
|
310 | - { |
|
311 | - if (! $this->_data_migrations_ran) { |
|
312 | - // setup autoloaders for each of the scripts in there |
|
313 | - $this->get_all_data_migration_scripts_available(); |
|
314 | - $data_migrations_options = |
|
315 | - $this->get_all_migration_script_options();// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
316 | - |
|
317 | - $data_migrations_ran = []; |
|
318 | - // convert into data migration script classes where possible |
|
319 | - foreach ($data_migrations_options as $data_migration_option) { |
|
320 | - list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name( |
|
321 | - $data_migration_option['option_name'] |
|
322 | - ); |
|
323 | - |
|
324 | - try { |
|
325 | - $class = $this->_get_dms_class_from_wp_option( |
|
326 | - $data_migration_option['option_name'], |
|
327 | - $data_migration_option['option_value'] |
|
328 | - ); |
|
329 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
330 | - // ok so far THIS is the 'last-run-script'... unless we find another on next iteration |
|
331 | - $this->_last_ran_script = $class; |
|
332 | - if (! $class->is_completed()) { |
|
333 | - // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
|
334 | - $this->_last_ran_incomplete_script = $class; |
|
335 | - } |
|
336 | - } catch (EE_Error $e) { |
|
337 | - // ok so it's not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
|
338 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
339 | - $data_migration_option['option_value'] |
|
340 | - ); |
|
341 | - } |
|
342 | - } |
|
343 | - // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
|
344 | - $this->_data_migrations_ran = $data_migrations_ran; |
|
345 | - if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
346 | - $this->_data_migrations_ran = []; |
|
347 | - } |
|
348 | - } |
|
349 | - return $this->_data_migrations_ran; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * |
|
355 | - * @param string $script_name eg 'DMS_Core_4_1_0' |
|
356 | - * @param string $old_table eg 'wp_events_detail' |
|
357 | - * @param string $old_pk eg 'wp_esp_posts' |
|
358 | - * @param $new_table |
|
359 | - * @return mixed string or int |
|
360 | - * @throws EE_Error |
|
361 | - * @throws ReflectionException |
|
362 | - */ |
|
363 | - public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
|
364 | - { |
|
365 | - $script = EE_Registry::instance()->load_dms($script_name); |
|
366 | - return $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that |
|
372 | - * the last option returned in this array is the most-recently run DMS option |
|
373 | - * |
|
374 | - * @return array |
|
375 | - */ |
|
376 | - public function get_all_migration_script_options() |
|
377 | - { |
|
378 | - global $wpdb; |
|
379 | - return $wpdb->get_results( |
|
380 | - "SELECT * FROM {$wpdb->options} WHERE option_name like '" |
|
381 | - . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
382 | - . "%' ORDER BY option_id ASC", |
|
383 | - ARRAY_A |
|
384 | - ); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded |
|
390 | - * |
|
391 | - * @return array where each value is the full folder path of a folder containing data migration scripts, WITH |
|
392 | - * slashes at the end of the folder name. |
|
393 | - */ |
|
394 | - public function get_data_migration_script_folders() |
|
395 | - { |
|
396 | - return apply_filters( |
|
397 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
398 | - ['Core' => EE_CORE . 'data_migration_scripts'] |
|
399 | - ); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Gets the version the migration script upgrades to |
|
405 | - * |
|
406 | - * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0' |
|
407 | - * @return array { |
|
408 | - * @type string $slug like 'Core','Calendar',etc |
|
409 | - * @type string $version like 4.3.0 |
|
410 | - * } |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
|
414 | - { |
|
415 | - if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
416 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
417 | - } |
|
418 | - $dms_info = $this->parse_dms_classname($migration_script_name); |
|
419 | - $this->script_migration_versions[ $migration_script_name ] = [ |
|
420 | - 'slug' => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
421 | - 'version' => $dms_info['major_version'] |
|
422 | - . "." |
|
423 | - . $dms_info['minor_version'] |
|
424 | - . "." |
|
425 | - . $dms_info['micro_version'], |
|
426 | - ]; |
|
427 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0' |
|
433 | - * |
|
434 | - * @param string $classname |
|
435 | - * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are integers) |
|
436 | - * @throws EE_Error |
|
437 | - */ |
|
438 | - public function parse_dms_classname($classname) |
|
439 | - { |
|
440 | - $matches = []; |
|
441 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
442 | - if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
443 | - throw new EE_Error( |
|
444 | - sprintf( |
|
445 | - esc_html__( |
|
446 | - "%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", |
|
447 | - "event_espresso" |
|
448 | - ), |
|
449 | - $classname |
|
450 | - ) |
|
451 | - ); |
|
452 | - } |
|
453 | - return [ |
|
454 | - 'slug' => $matches[1], |
|
455 | - 'major_version' => intval($matches[2]), |
|
456 | - 'minor_version' => intval($matches[3]), |
|
457 | - 'micro_version' => intval($matches[4]), |
|
458 | - ]; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * Ensures that the option indicating the current DB version is set. This should only be |
|
464 | - * a concern when activating EE for the first time, THEORETICALLY. |
|
465 | - * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise |
|
466 | - * to 4.1.x. |
|
467 | - * |
|
468 | - * @return string of current db state |
|
469 | - */ |
|
470 | - public function ensure_current_database_state_is_set() |
|
471 | - { |
|
472 | - $espresso_db_core_updates = get_option('espresso_db_update', []); |
|
473 | - $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
|
474 | - if (! $db_state) { |
|
475 | - // mark the DB as being in the state as the last version in there. |
|
476 | - // this is done to trigger maintenance mode and do data migration scripts |
|
477 | - // if the admin installed this version of EE over 3.1.x or 4.0.x |
|
478 | - // otherwise, the normal maintenance mode code is fine |
|
479 | - $previous_versions_installed = array_keys($espresso_db_core_updates); |
|
480 | - $previous_version_installed = end($previous_versions_installed); |
|
481 | - if (version_compare('4.1.0', $previous_version_installed)) { |
|
482 | - // last installed version was less than 4.1, so we want the data migrations to happen. |
|
483 | - // SO, we're going to say the DB is at that state |
|
484 | - $db_state = ['Core' => $previous_version_installed]; |
|
485 | - } else { |
|
486 | - $db_state = ['Core' => EVENT_ESPRESSO_VERSION]; |
|
487 | - } |
|
488 | - update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
489 | - } |
|
490 | - // in 4.1, $db_state would have only been a simple string like '4.1.0', |
|
491 | - // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
|
492 | - // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
|
493 | - if (! is_array($db_state)) { |
|
494 | - $db_state = ['Core' => $db_state]; |
|
495 | - update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
496 | - } |
|
497 | - return $db_state; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * Checks if there are any data migration scripts that ought to be run. |
|
503 | - * If found, returns the instantiated classes. |
|
504 | - * If none are found (ie, they've all already been run, or they don't apply), returns an empty array |
|
505 | - * |
|
506 | - * @return EE_Data_Migration_Script_Base[] |
|
507 | - * @throws EE_Error |
|
508 | - * @throws EE_Error |
|
509 | - */ |
|
510 | - public function check_for_applicable_data_migration_scripts() |
|
511 | - { |
|
512 | - // get the option describing what options have already run |
|
513 | - $scripts_ran = $this->get_data_migrations_ran(); |
|
514 | - // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
|
515 | - $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available(); |
|
516 | - |
|
517 | - |
|
518 | - $current_database_state = $this->ensure_current_database_state_is_set(); |
|
519 | - // determine which have already been run |
|
520 | - $script_classes_that_should_run_per_iteration = []; |
|
521 | - $iteration = 0; |
|
522 | - $next_database_state_to_consider = $current_database_state; |
|
523 | - $theoretical_database_state = null; |
|
524 | - do { |
|
525 | - // the next state after the currently-considered one |
|
526 | - // will start off looking the same as the current, but we may make additions... |
|
527 | - $theoretical_database_state = $next_database_state_to_consider; |
|
528 | - // the next db state to consider is |
|
529 | - // "what would the DB be like had we run all the scripts we found that applied last time?" |
|
530 | - foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
531 | - $migrates_to_version = $this->script_migrates_to_version($classname); |
|
532 | - $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
533 | - $script_converts_to_version = $migrates_to_version['version']; |
|
534 | - // check if this version script is DONE or not; or if it's never been run |
|
535 | - if ( |
|
536 | - ! $scripts_ran |
|
537 | - || ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]) |
|
538 | - ) { |
|
539 | - // we haven't run this conversion script before |
|
540 | - // now check if it applies... |
|
541 | - // note that we've added an autoloader for it on get_all_data_migration_scripts_available |
|
542 | - // Also, make sure we get a new one. It's possible this is being ran during a multisite migration, |
|
543 | - // in which case we don't want to reuse a DMS script from a different blog! |
|
544 | - $script = LoaderFactory::getLoader()->getNew($classname); |
|
545 | - /* @var $script EE_Data_Migration_Script_Base */ |
|
546 | - $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
|
547 | - if ($can_migrate) { |
|
548 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
549 | - $migrates_to_version = |
|
550 | - $script->migrates_to_version(); |
|
551 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
552 | - $migrates_to_version['version']; |
|
553 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
554 | - } |
|
555 | - } elseif ( |
|
556 | - $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] |
|
557 | - instanceof |
|
558 | - EE_Data_Migration_Script_Base |
|
559 | - ) { |
|
560 | - // this script has been run, or at least started |
|
561 | - $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
562 | - if ($script->get_status() !== self::status_completed) { |
|
563 | - // this script is already underway... keep going with it |
|
564 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
565 | - $migrates_to_version = |
|
566 | - $script->migrates_to_version(); |
|
567 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
568 | - $migrates_to_version['version']; |
|
569 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
570 | - } |
|
571 | - // else it must have a status that indicates it has finished, |
|
572 | - // so we don't want to try and run it again |
|
573 | - } |
|
574 | - // else it exists, but it's not a proper data migration script maybe the script got renamed? |
|
575 | - // or was simply removed from EE? either way, it's certainly not runnable! |
|
576 | - } |
|
577 | - $iteration++; |
|
578 | - } while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
579 | - // ok we have all the scripts that should run, now let's make them into flat array |
|
580 | - $scripts_that_should_run = []; |
|
581 | - foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
582 | - ksort($scripts_at_priority); |
|
583 | - foreach ($scripts_at_priority as $scripts) { |
|
584 | - foreach ($scripts as $script) { |
|
585 | - $scripts_that_should_run[ get_class($script) ] = $script; |
|
586 | - } |
|
587 | - } |
|
588 | - } |
|
589 | - |
|
590 | - do_action( |
|
591 | - 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', |
|
592 | - $scripts_that_should_run |
|
593 | - ); |
|
594 | - return $scripts_that_should_run; |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * Gets the script which is currently being run, if there is one. If $include_completed_scripts is set to TRUE |
|
600 | - * it will return the last run script even if it's complete. |
|
601 | - * This means: if you want to find the currently-executing script, leave it as FALSE. |
|
602 | - * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE. |
|
603 | - * |
|
604 | - * @param bool $include_completed_scripts |
|
605 | - * @return EE_Data_Migration_Script_Base |
|
606 | - * @throws EE_Error |
|
607 | - */ |
|
608 | - public function get_last_ran_script($include_completed_scripts = false) |
|
609 | - { |
|
610 | - // make sure we've set up the class properties _last_ran_script and _last_ran_incomplete_script |
|
611 | - if (! $this->_data_migrations_ran) { |
|
612 | - $this->get_data_migrations_ran(); |
|
613 | - } |
|
614 | - if ($include_completed_scripts) { |
|
615 | - return $this->_last_ran_script; |
|
616 | - } else { |
|
617 | - return $this->_last_ran_incomplete_script; |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * Runs the data migration scripts (well, each request to this method calls one of the |
|
624 | - * data migration scripts' migration_step() functions). |
|
625 | - * |
|
626 | - * @param int $step_size |
|
627 | - * @return array { |
|
628 | - * // where the first item is one EE_Data_Migration_Script_Base's stati, |
|
629 | - * //and the second item is a string describing what was done |
|
630 | - * @type int $records_to_migrate from the current migration script |
|
631 | - * @type int $records_migrated |
|
632 | - * @type string $status one of EE_Data_Migration_Manager::status_* |
|
633 | - * @type string $script verbose name of the current DMS |
|
634 | - * @type string $message string describing what was done during this step |
|
635 | - * } |
|
636 | - * @throws EE_Error |
|
637 | - */ |
|
638 | - public function migration_step($step_size = 0) |
|
639 | - { |
|
640 | - |
|
641 | - // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
|
642 | - if (class_exists('EE_CPT_Strategy')) { |
|
643 | - remove_action('pre_get_posts', [EE_CPT_Strategy::instance(), 'pre_get_posts'], 5); |
|
644 | - } |
|
645 | - |
|
646 | - try { |
|
647 | - $currently_executing_script = $this->get_last_ran_script(); |
|
648 | - if (! $currently_executing_script) { |
|
649 | - // Find the next script that needs to execute |
|
650 | - $scripts = $this->check_for_applicable_data_migration_scripts(); |
|
651 | - if (! $scripts) { |
|
652 | - // huh, no more scripts to run... apparently we're done! |
|
653 | - // but don't forget to make sure initial data is there |
|
654 | - // we should be good to allow them to exit maintenance mode now |
|
655 | - EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
656 | - EE_Maintenance_Mode::level_0_not_in_maintenance |
|
657 | - ); |
|
658 | - // saving migrations run should actually be unnecessary, |
|
659 | - // but leaving in place just in case... remember this migration was finished |
|
660 | - // (even if we time out while initializing db for core and plugins) |
|
661 | - $this->_save_migrations_ran(); |
|
662 | - // make sure DB was updated AFTER we've recorded the migration was done |
|
663 | - $this->initialize_db_for_enqueued_ee_plugins(); |
|
664 | - return [ |
|
665 | - 'records_to_migrate' => 1, |
|
666 | - 'records_migrated' => 1, |
|
667 | - 'status' => self::status_no_more_migration_scripts, |
|
668 | - 'script' => esc_html__("Data Migration Completed Successfully", "event_espresso"), |
|
669 | - 'message' => esc_html__("All done!", "event_espresso"), |
|
670 | - ]; |
|
671 | - } |
|
672 | - $currently_executing_script = array_shift($scripts); |
|
673 | - // and add to the array/wp option showing the scripts run |
|
674 | - |
|
675 | - $migrates_to = |
|
676 | - $this->script_migrates_to_version(get_class($currently_executing_script)); |
|
677 | - $plugin_slug = $migrates_to['slug']; |
|
678 | - $version = $migrates_to['version']; |
|
679 | - $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
680 | - } |
|
681 | - $current_script_name = get_class($currently_executing_script); |
|
682 | - } catch (Exception $e) { |
|
683 | - // an exception occurred while trying to get migration scripts |
|
684 | - |
|
685 | - $message = sprintf( |
|
686 | - esc_html__("Error Message: %sStack Trace:%s", "event_espresso"), |
|
687 | - $e->getMessage() . '<br>', |
|
688 | - $e->getTraceAsString() |
|
689 | - ); |
|
690 | - // record it on the array of data migration scripts run. This will be overwritten next time we try and try to run data migrations |
|
691 | - // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
|
692 | - $this->add_error_to_migrations_ran( |
|
693 | - sprintf(esc_html__("Could not run data migrations because: %s", "event_espresso"), $message) |
|
694 | - ); |
|
695 | - return [ |
|
696 | - 'records_to_migrate' => 1, |
|
697 | - 'records_migrated' => 0, |
|
698 | - 'status' => self::status_fatal_error, |
|
699 | - 'script' => esc_html__("Error loading data migration scripts", "event_espresso"), |
|
700 | - 'message' => $message, |
|
701 | - ]; |
|
702 | - } |
|
703 | - // can we wrap it up and verify default data? |
|
704 | - $init_dbs = false; |
|
705 | - // ok so we definitely have a data migration script |
|
706 | - try { |
|
707 | - // how big of a bite do we want to take? Allow users to easily override via their wp-config |
|
708 | - if (absint($step_size) < 1) { |
|
709 | - $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) |
|
710 | - ? EE_MIGRATION_STEP_SIZE |
|
711 | - : EE_Data_Migration_Manager::step_size; |
|
712 | - } |
|
713 | - // do what we came to do! |
|
714 | - $currently_executing_script->migration_step($step_size); |
|
715 | - switch ($currently_executing_script->get_status()) { |
|
716 | - case EE_Data_Migration_Manager::status_continue: |
|
717 | - $response_array = [ |
|
718 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
719 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
720 | - 'status' => EE_Data_Migration_Manager::status_continue, |
|
721 | - 'message' => $currently_executing_script->get_feedback_message(), |
|
722 | - 'script' => $currently_executing_script->pretty_name(), |
|
723 | - ]; |
|
724 | - break; |
|
725 | - case EE_Data_Migration_Manager::status_completed: |
|
726 | - // ok so THAT script has completed |
|
727 | - $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
|
728 | - $response_array = [ |
|
729 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
730 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
731 | - 'status' => EE_Data_Migration_Manager::status_completed, |
|
732 | - 'message' => $currently_executing_script->get_feedback_message(), |
|
733 | - 'script' => sprintf( |
|
734 | - esc_html__("%s Completed", 'event_espresso'), |
|
735 | - $currently_executing_script->pretty_name() |
|
736 | - ), |
|
737 | - ]; |
|
738 | - // check if there are any more after this one. |
|
739 | - $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
|
740 | - if (! $scripts_remaining) { |
|
741 | - // we should be good to allow them to exit maintenance mode now |
|
742 | - EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
743 | - EE_Maintenance_Mode::level_0_not_in_maintenance |
|
744 | - ); |
|
745 | - // huh, no more scripts to run... apparently we're done! |
|
746 | - // but don't forget to make sure initial data is there |
|
747 | - $init_dbs = true; |
|
748 | - $response_array['status'] = self::status_no_more_migration_scripts; |
|
749 | - } |
|
750 | - break; |
|
751 | - default: |
|
752 | - $response_array = [ |
|
753 | - 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
754 | - 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
755 | - 'status' => $currently_executing_script->get_status(), |
|
756 | - 'message' => sprintf( |
|
757 | - esc_html__("Minor errors occurred during %s: %s", "event_espresso"), |
|
758 | - $currently_executing_script->pretty_name(), |
|
759 | - implode(", ", $currently_executing_script->get_errors()) |
|
760 | - ), |
|
761 | - 'script' => $currently_executing_script->pretty_name(), |
|
762 | - ]; |
|
763 | - break; |
|
764 | - } |
|
765 | - } catch (Exception $e) { |
|
766 | - // ok so some exception was thrown which killed the data migration script |
|
767 | - // double-check we have a real script |
|
768 | - if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
769 | - $script_name = $currently_executing_script->pretty_name(); |
|
770 | - $currently_executing_script->set_broken(); |
|
771 | - $currently_executing_script->add_error($e->getMessage()); |
|
772 | - } else { |
|
773 | - $script_name = esc_html__("Error getting Migration Script", "event_espresso"); |
|
774 | - } |
|
775 | - $response_array = [ |
|
776 | - 'records_to_migrate' => 1, |
|
777 | - 'records_migrated' => 0, |
|
778 | - 'status' => self::status_fatal_error, |
|
779 | - 'message' => sprintf( |
|
780 | - esc_html__("A fatal error occurred during the migration: %s", "event_espresso"), |
|
781 | - $e->getMessage() |
|
782 | - ), |
|
783 | - 'script' => $script_name, |
|
784 | - ]; |
|
785 | - } |
|
786 | - $successful_save = $this->_save_migrations_ran(); |
|
787 | - if ($successful_save !== true) { |
|
788 | - // ok so the current wp option didn't save. that's tricky, because we'd like to update it |
|
789 | - // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
|
790 | - // however, if we throw an exception, and return that, then the next request |
|
791 | - // won't have as much info in it, and it may be able to save |
|
792 | - throw new EE_Error( |
|
793 | - sprintf( |
|
794 | - esc_html__( |
|
795 | - "The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", |
|
796 | - "event_espresso" |
|
797 | - ), |
|
798 | - $successful_save |
|
799 | - ) |
|
800 | - ); |
|
801 | - } |
|
802 | - // if we're all done, initialize EE plugins' default data etc. |
|
803 | - if ($init_dbs) { |
|
804 | - $this->initialize_db_for_enqueued_ee_plugins(); |
|
805 | - } |
|
806 | - return $response_array; |
|
807 | - } |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * Echo out JSON response to migration script AJAX requests. Takes precautions |
|
812 | - * to buffer output so that we don't throw junk into our json. |
|
813 | - * |
|
814 | - * @return array with keys: |
|
815 | - * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie, |
|
816 | - * it's NOT the count of hwo many remain) |
|
817 | - * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete = |
|
818 | - * records_migrated/records_to_migrate) |
|
819 | - * 'status'=>a string, one of EE_Data_migration_Manager::status_* |
|
820 | - * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into |
|
821 | - * errors, notifications, and successes |
|
822 | - * 'script'=>a pretty name of the script currently running |
|
823 | - */ |
|
824 | - public function response_to_migration_ajax_request() |
|
825 | - { |
|
826 | - ob_start(); |
|
827 | - try { |
|
828 | - $response = $this->migration_step(); |
|
829 | - } catch (Exception $e) { |
|
830 | - $response = [ |
|
831 | - 'records_to_migrate' => 0, |
|
832 | - 'records_migrated' => 0, |
|
833 | - 'status' => EE_Data_Migration_Manager::status_fatal_error, |
|
834 | - 'message' => sprintf( |
|
835 | - esc_html__("Unknown fatal error occurred: %s", "event_espresso"), |
|
836 | - $e->getMessage() |
|
837 | - ), |
|
838 | - 'script' => 'Unknown', |
|
839 | - ]; |
|
840 | - $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
841 | - } |
|
842 | - $warnings_etc = @ob_get_contents(); |
|
843 | - ob_end_clean(); |
|
844 | - $response['message'] .= $warnings_etc; |
|
845 | - return $response; |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * Updates the WordPress option that keeps track of which EE version the database |
|
851 | - * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35) |
|
852 | - * |
|
853 | - * @param array $slug_and_version { |
|
854 | - * @type string $slug like 'Core' or 'Calendar', |
|
855 | - * @type string $version like '4.1.0' |
|
856 | - * } |
|
857 | - * @return void |
|
858 | - */ |
|
859 | - public function update_current_database_state_to($slug_and_version = null) |
|
860 | - { |
|
861 | - if (! $slug_and_version) { |
|
862 | - // no version was provided, assume it should be at the current code version |
|
863 | - $slug_and_version = ['slug' => 'Core', 'version' => espresso_version()]; |
|
864 | - } |
|
865 | - $current_database_state = get_option(self::current_database_state); |
|
866 | - $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
867 | - update_option(self::current_database_state, $current_database_state); |
|
868 | - } |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * Determines if the database is currently at a state matching what's indicated in $slug and $version. |
|
873 | - * |
|
874 | - * @param array $slug_and_version { |
|
875 | - * @type string $slug like 'Core' or 'Calendar', |
|
876 | - * @type string $version like '4.1.0' |
|
877 | - * } |
|
878 | - * @return boolean |
|
879 | - */ |
|
880 | - public function database_needs_updating_to($slug_and_version) |
|
881 | - { |
|
882 | - |
|
883 | - $slug = $slug_and_version['slug']; |
|
884 | - $version = $slug_and_version['version']; |
|
885 | - $current_database_state = get_option(self::current_database_state); |
|
886 | - if (! isset($current_database_state[ $slug ])) { |
|
887 | - return true; |
|
888 | - } else { |
|
889 | - // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
|
890 | - $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
891 | - $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
892 | - $needs_updating = false; |
|
893 | - foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
894 | - if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
895 | - $needs_updating = true; |
|
896 | - break; |
|
897 | - } |
|
898 | - } |
|
899 | - return $needs_updating; |
|
900 | - } |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * Gets all the data migration scripts available in the core folder and folders |
|
906 | - * in addons. Has the side effect of adding them for autoloading |
|
907 | - * |
|
908 | - * @return array keys are expected classnames, values are their filepaths |
|
909 | - * @throws InvalidInterfaceException |
|
910 | - * @throws InvalidDataTypeException |
|
911 | - * @throws EE_Error |
|
912 | - * @throws InvalidArgumentException |
|
913 | - */ |
|
914 | - public function get_all_data_migration_scripts_available() |
|
915 | - { |
|
916 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
917 | - $this->_data_migration_class_to_filepath_map = []; |
|
918 | - foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
919 | - // strip any placeholders added to classname to make it a unique array key |
|
920 | - $eeAddonClass = trim($eeAddonClass, '*'); |
|
921 | - $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
922 | - ? $eeAddonClass |
|
923 | - : ''; |
|
924 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
925 | - $files = glob($folder_path . '*.dms.php'); |
|
926 | - if (empty($files)) { |
|
927 | - continue; |
|
928 | - } |
|
929 | - foreach ($files as $file) { |
|
930 | - $pos_of_last_slash = strrpos($file, '/'); |
|
931 | - $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
932 | - $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
933 | - $slug = $migrates_to['slug']; |
|
934 | - // check that the slug as contained in the DMS is associated with |
|
935 | - // the slug of an addon or core |
|
936 | - if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
937 | - EE_Error::doing_it_wrong( |
|
938 | - __FUNCTION__, |
|
939 | - sprintf( |
|
940 | - esc_html__( |
|
941 | - 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
942 | - 'event_espresso' |
|
943 | - ), |
|
944 | - $classname, |
|
945 | - $slug, |
|
946 | - implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
947 | - ), |
|
948 | - '4.3.0.alpha.019' |
|
949 | - ); |
|
950 | - } |
|
951 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
952 | - } |
|
953 | - } |
|
954 | - EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
955 | - } |
|
956 | - return $this->_data_migration_class_to_filepath_map; |
|
957 | - } |
|
958 | - |
|
959 | - |
|
960 | - /** |
|
961 | - * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs |
|
962 | - * from each addon, and check if they need updating, |
|
963 | - * |
|
964 | - * @return boolean |
|
965 | - */ |
|
966 | - public function addons_need_updating() |
|
967 | - { |
|
968 | - return false; |
|
969 | - } |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * Adds this error string to the data_migrations_ran array, but we don't necessarily know |
|
974 | - * where to put it, so we just throw it in there... better than nothing... |
|
975 | - * |
|
976 | - * @param string $error_message |
|
977 | - */ |
|
978 | - public function add_error_to_migrations_ran($error_message) |
|
979 | - { |
|
980 | - // get last-run migration script |
|
981 | - global $wpdb; |
|
982 | - $last_migration_script_option = $wpdb->get_row( |
|
983 | - "SELECT * FROM $wpdb->options WHERE option_name like '" |
|
984 | - . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
985 | - . "%' ORDER BY option_id DESC LIMIT 1", |
|
986 | - ARRAY_A |
|
987 | - ); |
|
988 | - |
|
989 | - $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) |
|
990 | - ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
|
991 | - // now, tread lightly because we're here because a FATAL non-catchable error |
|
992 | - // was thrown last time when we were trying to run a data migration script |
|
993 | - // so the fatal error could have happened while getting the migration script |
|
994 | - // or doing running it... |
|
995 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace( |
|
996 | - EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
997 | - "", |
|
998 | - $last_migration_script_option['option_name'] |
|
999 | - ) : null; |
|
1000 | - |
|
1001 | - // check if it THINKS it's a data migration script and especially if it's one that HASN'T finished yet |
|
1002 | - // because if it has finished, then it obviously couldn't be the cause of this error, right? (because it's all done) |
|
1003 | - if ( |
|
1004 | - isset($last_ran_migration_script_properties['class']) |
|
1005 | - && isset($last_ran_migration_script_properties['_status']) |
|
1006 | - && $last_ran_migration_script_properties['_status'] != self::status_completed |
|
1007 | - ) { |
|
1008 | - // ok then just add this error to its list of errors |
|
1009 | - $last_ran_migration_script_properties['_errors'][] = $error_message; |
|
1010 | - $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
|
1011 | - } else { |
|
1012 | - // so we don't even know which script was last running |
|
1013 | - // use the data migration error stub, which is designed specifically for this type of thing |
|
1014 | - $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
|
1015 | - $general_migration_error->add_error($error_message); |
|
1016 | - $general_migration_error->set_broken(); |
|
1017 | - $last_ran_migration_script_properties = $general_migration_error->properties_as_array(); |
|
1018 | - $versions_migrated_to = 'Unknown.1.0.0'; |
|
1019 | - // now just to make sure appears as last (in case the were previously a fatal error like this) |
|
1020 | - // delete the old one |
|
1021 | - delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
1022 | - } |
|
1023 | - update_option( |
|
1024 | - self::data_migration_script_option_prefix . $versions_migrated_to, |
|
1025 | - $last_ran_migration_script_properties |
|
1026 | - ); |
|
1027 | - } |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * saves what data migrations have run to the database |
|
1032 | - * |
|
1033 | - * @return bool|string TRUE if successfully saved migrations ran, string if an error occurred |
|
1034 | - * @throws EE_Error |
|
1035 | - */ |
|
1036 | - protected function _save_migrations_ran() |
|
1037 | - { |
|
1038 | - if ($this->_data_migrations_ran == null) { |
|
1039 | - $this->get_data_migrations_ran(); |
|
1040 | - } |
|
1041 | - // now, we don't want to save actual classes to the DB because that's messy |
|
1042 | - $successful_updates = true; |
|
1043 | - foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
1044 | - foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
1045 | - $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
1046 | - $option_name = |
|
1047 | - self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
1048 | - $old_option_value = get_option($option_name); |
|
1049 | - if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
1050 | - $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
|
1051 | - if ($old_option_value != $script_array_for_saving) { |
|
1052 | - $successful_updates = update_option($option_name, $script_array_for_saving); |
|
1053 | - } |
|
1054 | - } else {// we don't know what this array-thing is. So just save it as-is |
|
1055 | - if ($old_option_value != $array_or_migration_obj) { |
|
1056 | - $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - if (! $successful_updates) { |
|
1060 | - global $wpdb; |
|
1061 | - return $wpdb->last_error; |
|
1062 | - } |
|
1063 | - } |
|
1064 | - } |
|
1065 | - return true; |
|
1066 | - // $updated = update_option(self::data_migrations_option_name, $array_of_migrations); |
|
1067 | - // if ($updated !== true) { |
|
1068 | - // global $wpdb; |
|
1069 | - // return $wpdb->last_error; |
|
1070 | - // } else { |
|
1071 | - // return true; |
|
1072 | - // } |
|
1073 | - // wp_mail( |
|
1074 | - // "[email protected]", |
|
1075 | - // time() . " price debug info", |
|
1076 | - // "updated: $updated, last error: $last_error, byte length of option: " . strlen( |
|
1077 | - // serialize($array_of_migrations) |
|
1078 | - // ) |
|
1079 | - // ); |
|
1080 | - } |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Takes an array of data migration script properties and re-creates the class from |
|
1085 | - * them. The argument $properties_array is assumed to have been made by |
|
1086 | - * EE_Data_Migration_Script_Base::properties_as_array() |
|
1087 | - * |
|
1088 | - * @param array $properties_array |
|
1089 | - * @return EE_Data_Migration_Script_Base |
|
1090 | - * @throws EE_Error |
|
1091 | - */ |
|
1092 | - public function _instantiate_script_from_properties_array($properties_array) |
|
1093 | - { |
|
1094 | - if (! isset($properties_array['class'])) { |
|
1095 | - throw new EE_Error( |
|
1096 | - sprintf( |
|
1097 | - esc_html__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
|
1098 | - implode(",", $properties_array) |
|
1099 | - ) |
|
1100 | - ); |
|
1101 | - } |
|
1102 | - $class_name = $properties_array['class']; |
|
1103 | - if (! class_exists($class_name)) { |
|
1104 | - throw new EE_Error(sprintf( |
|
1105 | - esc_html__("There is no migration script named %s", "event_espresso"), |
|
1106 | - $class_name |
|
1107 | - )); |
|
1108 | - } |
|
1109 | - $class = new $class_name(); |
|
1110 | - if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
1111 | - throw new EE_Error( |
|
1112 | - sprintf( |
|
1113 | - esc_html__( |
|
1114 | - "Class '%s' is supposed to be a migration script. Its not, its a '%s'", |
|
1115 | - "event_espresso" |
|
1116 | - ), |
|
1117 | - $class_name, |
|
1118 | - get_class($class) |
|
1119 | - ) |
|
1120 | - ); |
|
1121 | - } |
|
1122 | - $class->instantiate_from_array_of_properties($properties_array); |
|
1123 | - return $class; |
|
1124 | - } |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * Gets the classname for the most up-to-date DMS (ie, the one that will finally |
|
1129 | - * leave the DB in a state usable by the current plugin code). |
|
1130 | - * |
|
1131 | - * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
|
1132 | - * @return string |
|
1133 | - * @throws EE_Error |
|
1134 | - * @throws EE_Error |
|
1135 | - */ |
|
1136 | - public function get_most_up_to_date_dms($plugin_slug = 'Core') |
|
1137 | - { |
|
1138 | - $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
|
1139 | - $most_up_to_date_dms_classname = null; |
|
1140 | - foreach ($class_to_filepath_map as $classname => $filepath) { |
|
1141 | - if ($most_up_to_date_dms_classname === null) { |
|
1142 | - $migrates_to = $this->script_migrates_to_version($classname); |
|
1143 | - $this_plugin_slug = $migrates_to['slug']; |
|
1144 | - if ($this_plugin_slug == $plugin_slug) { |
|
1145 | - // if it's for core, it wins |
|
1146 | - $most_up_to_date_dms_classname = $classname; |
|
1147 | - } |
|
1148 | - // if it wasn't for core, we must keep searching for one that is! |
|
1149 | - continue; |
|
1150 | - } |
|
1151 | - $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
1152 | - $contender_migrates_to = $this->script_migrates_to_version($classname); |
|
1153 | - if ( |
|
1154 | - $contender_migrates_to['slug'] == $plugin_slug |
|
1155 | - && version_compare( |
|
1156 | - $champion_migrates_to['version'], |
|
1157 | - $contender_migrates_to['version'], |
|
1158 | - '<' |
|
1159 | - ) |
|
1160 | - ) { |
|
1161 | - // so the contenders version is higher, and it's for Core |
|
1162 | - $most_up_to_date_dms_classname = $classname; |
|
1163 | - } |
|
1164 | - } |
|
1165 | - return $most_up_to_date_dms_classname; |
|
1166 | - } |
|
1167 | - |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * Gets the migration script specified but ONLY if it has already run. |
|
1171 | - * |
|
1172 | - * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has run, you would run the following code: |
|
1173 | - * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !== |
|
1174 | - * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or |
|
1175 | - * other addon) DMS has run, in case the current DMS depends on it. |
|
1176 | - * |
|
1177 | - * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1178 | - * period. Eg '4.1.0' |
|
1179 | - * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1180 | - * @return EE_Data_Migration_Script_Base |
|
1181 | - * @throws EE_Error |
|
1182 | - */ |
|
1183 | - public function get_migration_ran($version, $plugin_slug = 'Core') |
|
1184 | - { |
|
1185 | - $migrations_ran = $this->get_data_migrations_ran(); |
|
1186 | - if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
1187 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
1188 | - } else { |
|
1189 | - return null; |
|
1190 | - } |
|
1191 | - } |
|
1192 | - |
|
1193 | - |
|
1194 | - /** |
|
1195 | - * Resets the borked data migration scripts, so they're no longer borked, and we can again attempt to migrate |
|
1196 | - * |
|
1197 | - * @return bool |
|
1198 | - * @throws EE_Error |
|
1199 | - */ |
|
1200 | - public function reattempt() |
|
1201 | - { |
|
1202 | - // find if the last-run script was borked |
|
1203 | - // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
|
1204 | - // add an 'error' saying that we attempted to reset |
|
1205 | - // does it have a stage that was borked too? if so make it no longer borked |
|
1206 | - // add an 'error' saying we attempted to reset |
|
1207 | - $last_ran_script = $this->get_last_ran_script(); |
|
1208 | - if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
1209 | - // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
|
1210 | - $last_ran_script->set_completed(); |
|
1211 | - } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
1212 | - $last_ran_script->reattempt(); |
|
1213 | - } else { |
|
1214 | - throw new EE_Error( |
|
1215 | - sprintf( |
|
1216 | - esc_html__( |
|
1217 | - 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', |
|
1218 | - 'event_espresso' |
|
1219 | - ), |
|
1220 | - print_r($last_ran_script, true) |
|
1221 | - ) |
|
1222 | - ); |
|
1223 | - } |
|
1224 | - return $this->_save_migrations_ran(); |
|
1225 | - } |
|
1226 | - |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * Gets whether this particular migration has run or not |
|
1230 | - * |
|
1231 | - * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1232 | - * period. Eg '4.1.0' |
|
1233 | - * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1234 | - * @return boolean |
|
1235 | - * @throws EE_Error |
|
1236 | - */ |
|
1237 | - public function migration_has_ran($version, $plugin_slug = 'Core') |
|
1238 | - { |
|
1239 | - return $this->get_migration_ran($version, $plugin_slug) !== null; |
|
1240 | - } |
|
1241 | - |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Enqueues this ee plugin to have its data initialized |
|
1245 | - * |
|
1246 | - * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
|
1247 | - */ |
|
1248 | - public function enqueue_db_initialization_for($plugin_slug) |
|
1249 | - { |
|
1250 | - $queue = $this->get_db_initialization_queue(); |
|
1251 | - if (! in_array($plugin_slug, $queue)) { |
|
1252 | - $queue[] = $plugin_slug; |
|
1253 | - } |
|
1254 | - update_option(self::db_init_queue_option_name, $queue); |
|
1255 | - } |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
|
1260 | - * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is |
|
1261 | - * in the queue, calls EE_System::initialize_db_if_no_migrations_required(). |
|
1262 | - * |
|
1263 | - * @throws EE_Error |
|
1264 | - */ |
|
1265 | - public function initialize_db_for_enqueued_ee_plugins() |
|
1266 | - { |
|
1267 | - $queue = $this->get_db_initialization_queue(); |
|
1268 | - foreach ($queue as $plugin_slug) { |
|
1269 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
1270 | - if (! $most_up_to_date_dms) { |
|
1271 | - // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
|
1272 | - $verify_db = false; |
|
1273 | - } else { |
|
1274 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1275 | - $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1276 | - } |
|
1277 | - if ($plugin_slug == 'Core') { |
|
1278 | - EE_System::instance()->initialize_db_if_no_migrations_required( |
|
1279 | - false, |
|
1280 | - $verify_db |
|
1281 | - ); |
|
1282 | - } else { |
|
1283 | - // just loop through the addons to make sure their database is set up |
|
1284 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
1285 | - if ($addon->name() == $plugin_slug) { |
|
1286 | - $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1287 | - break; |
|
1288 | - } |
|
1289 | - } |
|
1290 | - } |
|
1291 | - } |
|
1292 | - // because we just initialized the DBs for the enqueued ee plugins |
|
1293 | - // we don't need to keep remembering which ones needed to be initialized |
|
1294 | - delete_option(self::db_init_queue_option_name); |
|
1295 | - } |
|
1296 | - |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Gets a numerically-indexed array of plugin slugs that need to have their databases |
|
1300 | - * (re-)initialized after migrations are complete. ie, each element should be either |
|
1301 | - * 'Core', or the return value of EE_Addon::name() for an addon |
|
1302 | - * |
|
1303 | - * @return array |
|
1304 | - */ |
|
1305 | - public function get_db_initialization_queue() |
|
1306 | - { |
|
1307 | - return get_option(self::db_init_queue_option_name, []); |
|
1308 | - } |
|
1309 | - |
|
1310 | - |
|
1311 | - /** |
|
1312 | - * Gets the injected table analyzer, or throws an exception |
|
1313 | - * |
|
1314 | - * @return TableAnalysis |
|
1315 | - * @throws EE_Error |
|
1316 | - */ |
|
1317 | - protected function _get_table_analysis() |
|
1318 | - { |
|
1319 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
1320 | - return $this->_table_analysis; |
|
1321 | - } else { |
|
1322 | - throw new EE_Error( |
|
1323 | - sprintf( |
|
1324 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1325 | - get_class($this) |
|
1326 | - ) |
|
1327 | - ); |
|
1328 | - } |
|
1329 | - } |
|
1330 | - |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Gets the injected table manager, or throws an exception |
|
1334 | - * |
|
1335 | - * @return TableManager |
|
1336 | - * @throws EE_Error |
|
1337 | - */ |
|
1338 | - protected function _get_table_manager() |
|
1339 | - { |
|
1340 | - if ($this->_table_manager instanceof TableManager) { |
|
1341 | - return $this->_table_manager; |
|
1342 | - } else { |
|
1343 | - throw new EE_Error( |
|
1344 | - sprintf( |
|
1345 | - esc_html__('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1346 | - get_class($this) |
|
1347 | - ) |
|
1348 | - ); |
|
1349 | - } |
|
1350 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * @var EE_Registry |
|
38 | + */ |
|
39 | + // protected $EE; |
|
40 | + /** |
|
41 | + * name of the WordPress option which stores an array of data about |
|
42 | + */ |
|
43 | + const data_migrations_option_name = 'ee_data_migration'; |
|
44 | + |
|
45 | + |
|
46 | + const data_migration_script_option_prefix = 'ee_data_migration_script_'; |
|
47 | + |
|
48 | + const data_migration_script_mapping_option_prefix = 'ee_dms_map_'; |
|
49 | + |
|
50 | + /** |
|
51 | + * name of the WordPress option which stores the database' current version. IE, the code may be at version 4.2.0, |
|
52 | + * but as migrations are performed the database will progress from 3.1.35 to 4.1.0 etc. |
|
53 | + */ |
|
54 | + const current_database_state = 'ee_data_migration_current_db_state'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Special status string returned when we're positive there are no more data migration |
|
58 | + * scripts that can be run. |
|
59 | + */ |
|
60 | + const status_no_more_migration_scripts = 'no_more_migration_scripts'; |
|
61 | + |
|
62 | + /** |
|
63 | + * string indicating the migration should continue |
|
64 | + */ |
|
65 | + const status_continue = 'status_continue'; |
|
66 | + |
|
67 | + /** |
|
68 | + * string indicating the migration has completed and should be ended |
|
69 | + */ |
|
70 | + const status_completed = 'status_completed'; |
|
71 | + |
|
72 | + /** |
|
73 | + * string indicating a fatal error occurred and the data migration should be completely aborted |
|
74 | + */ |
|
75 | + const status_fatal_error = 'status_fatal_error'; |
|
76 | + |
|
77 | + /** |
|
78 | + * the number of 'items' (usually DB rows) to migrate on each 'step' (ajax request sent |
|
79 | + * during migration) |
|
80 | + */ |
|
81 | + const step_size = 50; |
|
82 | + |
|
83 | + /** |
|
84 | + * option name that stores the queue of ee plugins needing to have |
|
85 | + * their data initialized (or re-initialized) once we are done migrations |
|
86 | + */ |
|
87 | + const db_init_queue_option_name = 'ee_db_init_queue'; |
|
88 | + |
|
89 | + /** |
|
90 | + * Array of information concerning data migrations that have run in the history |
|
91 | + * of this EE installation. Keys should be the name of the version the script upgraded to |
|
92 | + * |
|
93 | + * @var EE_Data_Migration_Script_Base[] |
|
94 | + */ |
|
95 | + private $_data_migrations_ran = null; |
|
96 | + |
|
97 | + /** |
|
98 | + * The last run script. It's nice to store this somewhere accessible, as its easiest |
|
99 | + * to know which was the last run by which is the newest wp option; but in most of the code |
|
100 | + * we just use the local $_data_migration_ran array, which organized the scripts differently |
|
101 | + * |
|
102 | + * @var EE_Data_Migration_Script_Base |
|
103 | + */ |
|
104 | + private $_last_ran_script = null; |
|
105 | + |
|
106 | + /** |
|
107 | + * Similarly to _last_ran_script, but this is the last INCOMPLETE migration script. |
|
108 | + * |
|
109 | + * @var EE_Data_Migration_Script_Base |
|
110 | + */ |
|
111 | + private $_last_ran_incomplete_script = null; |
|
112 | + |
|
113 | + /** |
|
114 | + * array where keys are classnames, and values are filepaths of all the known migration scripts |
|
115 | + * |
|
116 | + * @var array |
|
117 | + */ |
|
118 | + private $_data_migration_class_to_filepath_map; |
|
119 | + |
|
120 | + /** |
|
121 | + * the following 4 properties are fully set on construction. |
|
122 | + * Note: the first two apply to whether to continue running ALL migration scripts (ie, even though we're finished |
|
123 | + * one, we may want to start the next one); whereas the last two indicate whether to continue running a single |
|
124 | + * data migration script |
|
125 | + * |
|
126 | + * @var array |
|
127 | + */ |
|
128 | + public $stati_that_indicate_to_continue_migrations = []; |
|
129 | + |
|
130 | + public $stati_that_indicate_to_stop_migrations = []; |
|
131 | + |
|
132 | + public $stati_that_indicate_to_continue_single_migration_script = []; |
|
133 | + |
|
134 | + public $stati_that_indicate_to_stop_single_migration_script = []; |
|
135 | + |
|
136 | + /** |
|
137 | + * @var TableManager $table_manager |
|
138 | + */ |
|
139 | + protected $_table_manager; |
|
140 | + |
|
141 | + /** |
|
142 | + * @var TableAnalysis $table_analysis |
|
143 | + */ |
|
144 | + protected $_table_analysis; |
|
145 | + |
|
146 | + /** |
|
147 | + * @var array $script_migration_versions |
|
148 | + */ |
|
149 | + protected $script_migration_versions; |
|
150 | + |
|
151 | + /** |
|
152 | + * @var EE_Data_Migration_Manager $_instance |
|
153 | + * @access private |
|
154 | + */ |
|
155 | + private static $_instance = null; |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @singleton method used to instantiate class object |
|
160 | + * @access public |
|
161 | + * @return EE_Data_Migration_Manager instance |
|
162 | + */ |
|
163 | + public static function instance() |
|
164 | + { |
|
165 | + // check if class object is instantiated |
|
166 | + if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
167 | + self::$_instance = new self(); |
|
168 | + } |
|
169 | + return self::$_instance; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, |
|
175 | + * all new usages of the singleton should be made with Classname::instance()) and returns it |
|
176 | + * |
|
177 | + * @return EE_Data_Migration_Manager |
|
178 | + */ |
|
179 | + public static function reset() |
|
180 | + { |
|
181 | + self::$_instance = null; |
|
182 | + return self::instance(); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @throws EE_Error |
|
188 | + * @throws ReflectionException |
|
189 | + */ |
|
190 | + private function __construct() |
|
191 | + { |
|
192 | + $this->stati_that_indicate_to_continue_migrations = [ |
|
193 | + self::status_continue, |
|
194 | + self::status_completed, |
|
195 | + ]; |
|
196 | + $this->stati_that_indicate_to_stop_migrations = [ |
|
197 | + self::status_fatal_error, |
|
198 | + self::status_no_more_migration_scripts, |
|
199 | + ]; |
|
200 | + $this->stati_that_indicate_to_continue_single_migration_script = [ |
|
201 | + self::status_continue, |
|
202 | + ]; |
|
203 | + $this->stati_that_indicate_to_stop_single_migration_script = [ |
|
204 | + self::status_completed, |
|
205 | + self::status_fatal_error |
|
206 | + // note: status_no_more_migration_scripts doesn't apply |
|
207 | + ]; |
|
208 | + // make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
|
209 | + // to be defined, because right now it doesn't get autoloaded on its own |
|
210 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', [], true); |
|
211 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', [], true); |
|
212 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', [], true); |
|
213 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', [], true); |
|
214 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', [], true); |
|
215 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', [], true); |
|
216 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * Deciphers, from an option's name, what plugin and version it relates to (see _save_migrations_ran to see what |
|
222 | + * the option names are like, but generally they're like |
|
223 | + * 'ee_data_migration_script_Core.4.1.0' in 4.2 or 'ee_data_migration_script_4.1.0' before that). |
|
224 | + * The option name shouldn't ever be like 'ee_data_migration_script_Core.4.1.0.reg' because it's derived, |
|
225 | + * indirectly, from the data migration's classname, which should always be like EE_DMS_%s_%d_%d_%d.dms.php |
|
226 | + * (ex: EE_DMS_Core_4_1_0.dms.php) |
|
227 | + * |
|
228 | + * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
|
229 | + * @return array where the first item is the plugin slug (eg 'Core','Calendar', etc.) and the 2nd is the version of |
|
230 | + * that plugin (eg '4.1.0') |
|
231 | + */ |
|
232 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) |
|
233 | + { |
|
234 | + $plugin_slug_and_version_string = str_replace( |
|
235 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
236 | + "", |
|
237 | + $option_name |
|
238 | + ); |
|
239 | + // check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
|
240 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
241 | + |
|
242 | + if (count($parts) == 4) { |
|
243 | + // it's 4.2-style.eg Core.4.1.0 |
|
244 | + $plugin_slug = $parts[0]; // eg Core |
|
245 | + $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
246 | + } else { |
|
247 | + // it's 4.1-style: eg 4.1.0 |
|
248 | + $plugin_slug = 'Core'; |
|
249 | + $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
250 | + } |
|
251 | + return [$plugin_slug, $version_string]; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Gets the DMS class from the WordPress option, otherwise throws an EE_Error if it's not |
|
257 | + * for a known DMS class. |
|
258 | + * |
|
259 | + * @param string $dms_option_name |
|
260 | + * @param string $dms_option_value (serialized) |
|
261 | + * @return EE_Data_Migration_Script_Base |
|
262 | + * @throws EE_Error |
|
263 | + */ |
|
264 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) |
|
265 | + { |
|
266 | + $data_migration_data = maybe_unserialize($dms_option_value); |
|
267 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
268 | + // During multisite migrations, it's possible we already grabbed another instance of this class |
|
269 | + // but for a different blog. Make sure we don't reuse them (as they store info specific |
|
270 | + // to their respective blog, like which database table to migrate). |
|
271 | + $class = LoaderFactory::getLoader()->getNew($data_migration_data['class']); |
|
272 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
273 | + $class->instantiate_from_array_of_properties($data_migration_data); |
|
274 | + return $class; |
|
275 | + } else { |
|
276 | + // huh, so it's an object but not a data migration script?? that shouldn't happen |
|
277 | + // just leave it as an array (which will probably just get ignored) |
|
278 | + throw new EE_Error( |
|
279 | + sprintf( |
|
280 | + esc_html__( |
|
281 | + "Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", |
|
282 | + 'event_espresso' |
|
283 | + ), |
|
284 | + $data_migration_data['class'] |
|
285 | + ) |
|
286 | + ); |
|
287 | + } |
|
288 | + } else { |
|
289 | + // so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
|
290 | + throw new EE_Error( |
|
291 | + sprintf( |
|
292 | + esc_html__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), |
|
293 | + $dms_option_name |
|
294 | + ) |
|
295 | + ); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Gets the array describing what data migrations have run. |
|
302 | + * Also has a side effect of recording which was the last run, |
|
303 | + * and which was the last run which hasn't finished yet |
|
304 | + * |
|
305 | + * @return array where each element should be an array of EE_Data_Migration_Script_Base |
|
306 | + * (but also has a few legacy arrays in there - which should probably be ignored) |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + public function get_data_migrations_ran() |
|
310 | + { |
|
311 | + if (! $this->_data_migrations_ran) { |
|
312 | + // setup autoloaders for each of the scripts in there |
|
313 | + $this->get_all_data_migration_scripts_available(); |
|
314 | + $data_migrations_options = |
|
315 | + $this->get_all_migration_script_options();// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
316 | + |
|
317 | + $data_migrations_ran = []; |
|
318 | + // convert into data migration script classes where possible |
|
319 | + foreach ($data_migrations_options as $data_migration_option) { |
|
320 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name( |
|
321 | + $data_migration_option['option_name'] |
|
322 | + ); |
|
323 | + |
|
324 | + try { |
|
325 | + $class = $this->_get_dms_class_from_wp_option( |
|
326 | + $data_migration_option['option_name'], |
|
327 | + $data_migration_option['option_value'] |
|
328 | + ); |
|
329 | + $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
330 | + // ok so far THIS is the 'last-run-script'... unless we find another on next iteration |
|
331 | + $this->_last_ran_script = $class; |
|
332 | + if (! $class->is_completed()) { |
|
333 | + // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
|
334 | + $this->_last_ran_incomplete_script = $class; |
|
335 | + } |
|
336 | + } catch (EE_Error $e) { |
|
337 | + // ok so it's not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
|
338 | + $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
339 | + $data_migration_option['option_value'] |
|
340 | + ); |
|
341 | + } |
|
342 | + } |
|
343 | + // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
|
344 | + $this->_data_migrations_ran = $data_migrations_ran; |
|
345 | + if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
346 | + $this->_data_migrations_ran = []; |
|
347 | + } |
|
348 | + } |
|
349 | + return $this->_data_migrations_ran; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * |
|
355 | + * @param string $script_name eg 'DMS_Core_4_1_0' |
|
356 | + * @param string $old_table eg 'wp_events_detail' |
|
357 | + * @param string $old_pk eg 'wp_esp_posts' |
|
358 | + * @param $new_table |
|
359 | + * @return mixed string or int |
|
360 | + * @throws EE_Error |
|
361 | + * @throws ReflectionException |
|
362 | + */ |
|
363 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
|
364 | + { |
|
365 | + $script = EE_Registry::instance()->load_dms($script_name); |
|
366 | + return $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * Gets all the options containing migration scripts that have been run. Ordering is important: it's assumed that |
|
372 | + * the last option returned in this array is the most-recently run DMS option |
|
373 | + * |
|
374 | + * @return array |
|
375 | + */ |
|
376 | + public function get_all_migration_script_options() |
|
377 | + { |
|
378 | + global $wpdb; |
|
379 | + return $wpdb->get_results( |
|
380 | + "SELECT * FROM {$wpdb->options} WHERE option_name like '" |
|
381 | + . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
382 | + . "%' ORDER BY option_id ASC", |
|
383 | + ARRAY_A |
|
384 | + ); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets the array of folders which contain data migration scripts. Also adds them to be auto-loaded |
|
390 | + * |
|
391 | + * @return array where each value is the full folder path of a folder containing data migration scripts, WITH |
|
392 | + * slashes at the end of the folder name. |
|
393 | + */ |
|
394 | + public function get_data_migration_script_folders() |
|
395 | + { |
|
396 | + return apply_filters( |
|
397 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
398 | + ['Core' => EE_CORE . 'data_migration_scripts'] |
|
399 | + ); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Gets the version the migration script upgrades to |
|
405 | + * |
|
406 | + * @param string $migration_script_name eg 'EE_DMS_Core_4_1_0' |
|
407 | + * @return array { |
|
408 | + * @type string $slug like 'Core','Calendar',etc |
|
409 | + * @type string $version like 4.3.0 |
|
410 | + * } |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
|
414 | + { |
|
415 | + if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
416 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
417 | + } |
|
418 | + $dms_info = $this->parse_dms_classname($migration_script_name); |
|
419 | + $this->script_migration_versions[ $migration_script_name ] = [ |
|
420 | + 'slug' => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
421 | + 'version' => $dms_info['major_version'] |
|
422 | + . "." |
|
423 | + . $dms_info['minor_version'] |
|
424 | + . "." |
|
425 | + . $dms_info['micro_version'], |
|
426 | + ]; |
|
427 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Gets the juicy details out of a dms filename like 'EE_DMS_Core_4_1_0' |
|
433 | + * |
|
434 | + * @param string $classname |
|
435 | + * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are integers) |
|
436 | + * @throws EE_Error |
|
437 | + */ |
|
438 | + public function parse_dms_classname($classname) |
|
439 | + { |
|
440 | + $matches = []; |
|
441 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
442 | + if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
443 | + throw new EE_Error( |
|
444 | + sprintf( |
|
445 | + esc_html__( |
|
446 | + "%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", |
|
447 | + "event_espresso" |
|
448 | + ), |
|
449 | + $classname |
|
450 | + ) |
|
451 | + ); |
|
452 | + } |
|
453 | + return [ |
|
454 | + 'slug' => $matches[1], |
|
455 | + 'major_version' => intval($matches[2]), |
|
456 | + 'minor_version' => intval($matches[3]), |
|
457 | + 'micro_version' => intval($matches[4]), |
|
458 | + ]; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * Ensures that the option indicating the current DB version is set. This should only be |
|
464 | + * a concern when activating EE for the first time, THEORETICALLY. |
|
465 | + * If we detect that we're activating EE4 over top of EE3.1, then we set the current db state to 3.1.x, otherwise |
|
466 | + * to 4.1.x. |
|
467 | + * |
|
468 | + * @return string of current db state |
|
469 | + */ |
|
470 | + public function ensure_current_database_state_is_set() |
|
471 | + { |
|
472 | + $espresso_db_core_updates = get_option('espresso_db_update', []); |
|
473 | + $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
|
474 | + if (! $db_state) { |
|
475 | + // mark the DB as being in the state as the last version in there. |
|
476 | + // this is done to trigger maintenance mode and do data migration scripts |
|
477 | + // if the admin installed this version of EE over 3.1.x or 4.0.x |
|
478 | + // otherwise, the normal maintenance mode code is fine |
|
479 | + $previous_versions_installed = array_keys($espresso_db_core_updates); |
|
480 | + $previous_version_installed = end($previous_versions_installed); |
|
481 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
482 | + // last installed version was less than 4.1, so we want the data migrations to happen. |
|
483 | + // SO, we're going to say the DB is at that state |
|
484 | + $db_state = ['Core' => $previous_version_installed]; |
|
485 | + } else { |
|
486 | + $db_state = ['Core' => EVENT_ESPRESSO_VERSION]; |
|
487 | + } |
|
488 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
489 | + } |
|
490 | + // in 4.1, $db_state would have only been a simple string like '4.1.0', |
|
491 | + // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
|
492 | + // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
|
493 | + if (! is_array($db_state)) { |
|
494 | + $db_state = ['Core' => $db_state]; |
|
495 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
496 | + } |
|
497 | + return $db_state; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * Checks if there are any data migration scripts that ought to be run. |
|
503 | + * If found, returns the instantiated classes. |
|
504 | + * If none are found (ie, they've all already been run, or they don't apply), returns an empty array |
|
505 | + * |
|
506 | + * @return EE_Data_Migration_Script_Base[] |
|
507 | + * @throws EE_Error |
|
508 | + * @throws EE_Error |
|
509 | + */ |
|
510 | + public function check_for_applicable_data_migration_scripts() |
|
511 | + { |
|
512 | + // get the option describing what options have already run |
|
513 | + $scripts_ran = $this->get_data_migrations_ran(); |
|
514 | + // $scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
|
515 | + $script_class_and_filepaths_available = $this->get_all_data_migration_scripts_available(); |
|
516 | + |
|
517 | + |
|
518 | + $current_database_state = $this->ensure_current_database_state_is_set(); |
|
519 | + // determine which have already been run |
|
520 | + $script_classes_that_should_run_per_iteration = []; |
|
521 | + $iteration = 0; |
|
522 | + $next_database_state_to_consider = $current_database_state; |
|
523 | + $theoretical_database_state = null; |
|
524 | + do { |
|
525 | + // the next state after the currently-considered one |
|
526 | + // will start off looking the same as the current, but we may make additions... |
|
527 | + $theoretical_database_state = $next_database_state_to_consider; |
|
528 | + // the next db state to consider is |
|
529 | + // "what would the DB be like had we run all the scripts we found that applied last time?" |
|
530 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
531 | + $migrates_to_version = $this->script_migrates_to_version($classname); |
|
532 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
533 | + $script_converts_to_version = $migrates_to_version['version']; |
|
534 | + // check if this version script is DONE or not; or if it's never been run |
|
535 | + if ( |
|
536 | + ! $scripts_ran |
|
537 | + || ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]) |
|
538 | + ) { |
|
539 | + // we haven't run this conversion script before |
|
540 | + // now check if it applies... |
|
541 | + // note that we've added an autoloader for it on get_all_data_migration_scripts_available |
|
542 | + // Also, make sure we get a new one. It's possible this is being ran during a multisite migration, |
|
543 | + // in which case we don't want to reuse a DMS script from a different blog! |
|
544 | + $script = LoaderFactory::getLoader()->getNew($classname); |
|
545 | + /* @var $script EE_Data_Migration_Script_Base */ |
|
546 | + $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
|
547 | + if ($can_migrate) { |
|
548 | + $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
549 | + $migrates_to_version = |
|
550 | + $script->migrates_to_version(); |
|
551 | + $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
552 | + $migrates_to_version['version']; |
|
553 | + unset($script_class_and_filepaths_available[ $classname ]); |
|
554 | + } |
|
555 | + } elseif ( |
|
556 | + $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] |
|
557 | + instanceof |
|
558 | + EE_Data_Migration_Script_Base |
|
559 | + ) { |
|
560 | + // this script has been run, or at least started |
|
561 | + $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
562 | + if ($script->get_status() !== self::status_completed) { |
|
563 | + // this script is already underway... keep going with it |
|
564 | + $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
565 | + $migrates_to_version = |
|
566 | + $script->migrates_to_version(); |
|
567 | + $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
568 | + $migrates_to_version['version']; |
|
569 | + unset($script_class_and_filepaths_available[ $classname ]); |
|
570 | + } |
|
571 | + // else it must have a status that indicates it has finished, |
|
572 | + // so we don't want to try and run it again |
|
573 | + } |
|
574 | + // else it exists, but it's not a proper data migration script maybe the script got renamed? |
|
575 | + // or was simply removed from EE? either way, it's certainly not runnable! |
|
576 | + } |
|
577 | + $iteration++; |
|
578 | + } while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
579 | + // ok we have all the scripts that should run, now let's make them into flat array |
|
580 | + $scripts_that_should_run = []; |
|
581 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
582 | + ksort($scripts_at_priority); |
|
583 | + foreach ($scripts_at_priority as $scripts) { |
|
584 | + foreach ($scripts as $script) { |
|
585 | + $scripts_that_should_run[ get_class($script) ] = $script; |
|
586 | + } |
|
587 | + } |
|
588 | + } |
|
589 | + |
|
590 | + do_action( |
|
591 | + 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', |
|
592 | + $scripts_that_should_run |
|
593 | + ); |
|
594 | + return $scripts_that_should_run; |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * Gets the script which is currently being run, if there is one. If $include_completed_scripts is set to TRUE |
|
600 | + * it will return the last run script even if it's complete. |
|
601 | + * This means: if you want to find the currently-executing script, leave it as FALSE. |
|
602 | + * If you really just want to find the script which ran most recently, regardless of status, leave it as TRUE. |
|
603 | + * |
|
604 | + * @param bool $include_completed_scripts |
|
605 | + * @return EE_Data_Migration_Script_Base |
|
606 | + * @throws EE_Error |
|
607 | + */ |
|
608 | + public function get_last_ran_script($include_completed_scripts = false) |
|
609 | + { |
|
610 | + // make sure we've set up the class properties _last_ran_script and _last_ran_incomplete_script |
|
611 | + if (! $this->_data_migrations_ran) { |
|
612 | + $this->get_data_migrations_ran(); |
|
613 | + } |
|
614 | + if ($include_completed_scripts) { |
|
615 | + return $this->_last_ran_script; |
|
616 | + } else { |
|
617 | + return $this->_last_ran_incomplete_script; |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * Runs the data migration scripts (well, each request to this method calls one of the |
|
624 | + * data migration scripts' migration_step() functions). |
|
625 | + * |
|
626 | + * @param int $step_size |
|
627 | + * @return array { |
|
628 | + * // where the first item is one EE_Data_Migration_Script_Base's stati, |
|
629 | + * //and the second item is a string describing what was done |
|
630 | + * @type int $records_to_migrate from the current migration script |
|
631 | + * @type int $records_migrated |
|
632 | + * @type string $status one of EE_Data_Migration_Manager::status_* |
|
633 | + * @type string $script verbose name of the current DMS |
|
634 | + * @type string $message string describing what was done during this step |
|
635 | + * } |
|
636 | + * @throws EE_Error |
|
637 | + */ |
|
638 | + public function migration_step($step_size = 0) |
|
639 | + { |
|
640 | + |
|
641 | + // bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
|
642 | + if (class_exists('EE_CPT_Strategy')) { |
|
643 | + remove_action('pre_get_posts', [EE_CPT_Strategy::instance(), 'pre_get_posts'], 5); |
|
644 | + } |
|
645 | + |
|
646 | + try { |
|
647 | + $currently_executing_script = $this->get_last_ran_script(); |
|
648 | + if (! $currently_executing_script) { |
|
649 | + // Find the next script that needs to execute |
|
650 | + $scripts = $this->check_for_applicable_data_migration_scripts(); |
|
651 | + if (! $scripts) { |
|
652 | + // huh, no more scripts to run... apparently we're done! |
|
653 | + // but don't forget to make sure initial data is there |
|
654 | + // we should be good to allow them to exit maintenance mode now |
|
655 | + EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
656 | + EE_Maintenance_Mode::level_0_not_in_maintenance |
|
657 | + ); |
|
658 | + // saving migrations run should actually be unnecessary, |
|
659 | + // but leaving in place just in case... remember this migration was finished |
|
660 | + // (even if we time out while initializing db for core and plugins) |
|
661 | + $this->_save_migrations_ran(); |
|
662 | + // make sure DB was updated AFTER we've recorded the migration was done |
|
663 | + $this->initialize_db_for_enqueued_ee_plugins(); |
|
664 | + return [ |
|
665 | + 'records_to_migrate' => 1, |
|
666 | + 'records_migrated' => 1, |
|
667 | + 'status' => self::status_no_more_migration_scripts, |
|
668 | + 'script' => esc_html__("Data Migration Completed Successfully", "event_espresso"), |
|
669 | + 'message' => esc_html__("All done!", "event_espresso"), |
|
670 | + ]; |
|
671 | + } |
|
672 | + $currently_executing_script = array_shift($scripts); |
|
673 | + // and add to the array/wp option showing the scripts run |
|
674 | + |
|
675 | + $migrates_to = |
|
676 | + $this->script_migrates_to_version(get_class($currently_executing_script)); |
|
677 | + $plugin_slug = $migrates_to['slug']; |
|
678 | + $version = $migrates_to['version']; |
|
679 | + $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
680 | + } |
|
681 | + $current_script_name = get_class($currently_executing_script); |
|
682 | + } catch (Exception $e) { |
|
683 | + // an exception occurred while trying to get migration scripts |
|
684 | + |
|
685 | + $message = sprintf( |
|
686 | + esc_html__("Error Message: %sStack Trace:%s", "event_espresso"), |
|
687 | + $e->getMessage() . '<br>', |
|
688 | + $e->getTraceAsString() |
|
689 | + ); |
|
690 | + // record it on the array of data migration scripts run. This will be overwritten next time we try and try to run data migrations |
|
691 | + // but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
|
692 | + $this->add_error_to_migrations_ran( |
|
693 | + sprintf(esc_html__("Could not run data migrations because: %s", "event_espresso"), $message) |
|
694 | + ); |
|
695 | + return [ |
|
696 | + 'records_to_migrate' => 1, |
|
697 | + 'records_migrated' => 0, |
|
698 | + 'status' => self::status_fatal_error, |
|
699 | + 'script' => esc_html__("Error loading data migration scripts", "event_espresso"), |
|
700 | + 'message' => $message, |
|
701 | + ]; |
|
702 | + } |
|
703 | + // can we wrap it up and verify default data? |
|
704 | + $init_dbs = false; |
|
705 | + // ok so we definitely have a data migration script |
|
706 | + try { |
|
707 | + // how big of a bite do we want to take? Allow users to easily override via their wp-config |
|
708 | + if (absint($step_size) < 1) { |
|
709 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) |
|
710 | + ? EE_MIGRATION_STEP_SIZE |
|
711 | + : EE_Data_Migration_Manager::step_size; |
|
712 | + } |
|
713 | + // do what we came to do! |
|
714 | + $currently_executing_script->migration_step($step_size); |
|
715 | + switch ($currently_executing_script->get_status()) { |
|
716 | + case EE_Data_Migration_Manager::status_continue: |
|
717 | + $response_array = [ |
|
718 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
719 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
720 | + 'status' => EE_Data_Migration_Manager::status_continue, |
|
721 | + 'message' => $currently_executing_script->get_feedback_message(), |
|
722 | + 'script' => $currently_executing_script->pretty_name(), |
|
723 | + ]; |
|
724 | + break; |
|
725 | + case EE_Data_Migration_Manager::status_completed: |
|
726 | + // ok so THAT script has completed |
|
727 | + $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
|
728 | + $response_array = [ |
|
729 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
730 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
731 | + 'status' => EE_Data_Migration_Manager::status_completed, |
|
732 | + 'message' => $currently_executing_script->get_feedback_message(), |
|
733 | + 'script' => sprintf( |
|
734 | + esc_html__("%s Completed", 'event_espresso'), |
|
735 | + $currently_executing_script->pretty_name() |
|
736 | + ), |
|
737 | + ]; |
|
738 | + // check if there are any more after this one. |
|
739 | + $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
|
740 | + if (! $scripts_remaining) { |
|
741 | + // we should be good to allow them to exit maintenance mode now |
|
742 | + EE_Maintenance_Mode::instance()->set_maintenance_level( |
|
743 | + EE_Maintenance_Mode::level_0_not_in_maintenance |
|
744 | + ); |
|
745 | + // huh, no more scripts to run... apparently we're done! |
|
746 | + // but don't forget to make sure initial data is there |
|
747 | + $init_dbs = true; |
|
748 | + $response_array['status'] = self::status_no_more_migration_scripts; |
|
749 | + } |
|
750 | + break; |
|
751 | + default: |
|
752 | + $response_array = [ |
|
753 | + 'records_to_migrate' => $currently_executing_script->count_records_to_migrate(), |
|
754 | + 'records_migrated' => $currently_executing_script->count_records_migrated(), |
|
755 | + 'status' => $currently_executing_script->get_status(), |
|
756 | + 'message' => sprintf( |
|
757 | + esc_html__("Minor errors occurred during %s: %s", "event_espresso"), |
|
758 | + $currently_executing_script->pretty_name(), |
|
759 | + implode(", ", $currently_executing_script->get_errors()) |
|
760 | + ), |
|
761 | + 'script' => $currently_executing_script->pretty_name(), |
|
762 | + ]; |
|
763 | + break; |
|
764 | + } |
|
765 | + } catch (Exception $e) { |
|
766 | + // ok so some exception was thrown which killed the data migration script |
|
767 | + // double-check we have a real script |
|
768 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
769 | + $script_name = $currently_executing_script->pretty_name(); |
|
770 | + $currently_executing_script->set_broken(); |
|
771 | + $currently_executing_script->add_error($e->getMessage()); |
|
772 | + } else { |
|
773 | + $script_name = esc_html__("Error getting Migration Script", "event_espresso"); |
|
774 | + } |
|
775 | + $response_array = [ |
|
776 | + 'records_to_migrate' => 1, |
|
777 | + 'records_migrated' => 0, |
|
778 | + 'status' => self::status_fatal_error, |
|
779 | + 'message' => sprintf( |
|
780 | + esc_html__("A fatal error occurred during the migration: %s", "event_espresso"), |
|
781 | + $e->getMessage() |
|
782 | + ), |
|
783 | + 'script' => $script_name, |
|
784 | + ]; |
|
785 | + } |
|
786 | + $successful_save = $this->_save_migrations_ran(); |
|
787 | + if ($successful_save !== true) { |
|
788 | + // ok so the current wp option didn't save. that's tricky, because we'd like to update it |
|
789 | + // and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
|
790 | + // however, if we throw an exception, and return that, then the next request |
|
791 | + // won't have as much info in it, and it may be able to save |
|
792 | + throw new EE_Error( |
|
793 | + sprintf( |
|
794 | + esc_html__( |
|
795 | + "The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", |
|
796 | + "event_espresso" |
|
797 | + ), |
|
798 | + $successful_save |
|
799 | + ) |
|
800 | + ); |
|
801 | + } |
|
802 | + // if we're all done, initialize EE plugins' default data etc. |
|
803 | + if ($init_dbs) { |
|
804 | + $this->initialize_db_for_enqueued_ee_plugins(); |
|
805 | + } |
|
806 | + return $response_array; |
|
807 | + } |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * Echo out JSON response to migration script AJAX requests. Takes precautions |
|
812 | + * to buffer output so that we don't throw junk into our json. |
|
813 | + * |
|
814 | + * @return array with keys: |
|
815 | + * 'records_to_migrate' which counts ALL the records for the current migration, and should remain constant. (ie, |
|
816 | + * it's NOT the count of hwo many remain) |
|
817 | + * 'records_migrated' which also counts ALL the records which have been migrated (ie, percent_complete = |
|
818 | + * records_migrated/records_to_migrate) |
|
819 | + * 'status'=>a string, one of EE_Data_migration_Manager::status_* |
|
820 | + * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into |
|
821 | + * errors, notifications, and successes |
|
822 | + * 'script'=>a pretty name of the script currently running |
|
823 | + */ |
|
824 | + public function response_to_migration_ajax_request() |
|
825 | + { |
|
826 | + ob_start(); |
|
827 | + try { |
|
828 | + $response = $this->migration_step(); |
|
829 | + } catch (Exception $e) { |
|
830 | + $response = [ |
|
831 | + 'records_to_migrate' => 0, |
|
832 | + 'records_migrated' => 0, |
|
833 | + 'status' => EE_Data_Migration_Manager::status_fatal_error, |
|
834 | + 'message' => sprintf( |
|
835 | + esc_html__("Unknown fatal error occurred: %s", "event_espresso"), |
|
836 | + $e->getMessage() |
|
837 | + ), |
|
838 | + 'script' => 'Unknown', |
|
839 | + ]; |
|
840 | + $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
841 | + } |
|
842 | + $warnings_etc = @ob_get_contents(); |
|
843 | + ob_end_clean(); |
|
844 | + $response['message'] .= $warnings_etc; |
|
845 | + return $response; |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * Updates the WordPress option that keeps track of which EE version the database |
|
851 | + * is at (ie, the code may be at 4.1.0, but the database is still at 3.1.35) |
|
852 | + * |
|
853 | + * @param array $slug_and_version { |
|
854 | + * @type string $slug like 'Core' or 'Calendar', |
|
855 | + * @type string $version like '4.1.0' |
|
856 | + * } |
|
857 | + * @return void |
|
858 | + */ |
|
859 | + public function update_current_database_state_to($slug_and_version = null) |
|
860 | + { |
|
861 | + if (! $slug_and_version) { |
|
862 | + // no version was provided, assume it should be at the current code version |
|
863 | + $slug_and_version = ['slug' => 'Core', 'version' => espresso_version()]; |
|
864 | + } |
|
865 | + $current_database_state = get_option(self::current_database_state); |
|
866 | + $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
867 | + update_option(self::current_database_state, $current_database_state); |
|
868 | + } |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * Determines if the database is currently at a state matching what's indicated in $slug and $version. |
|
873 | + * |
|
874 | + * @param array $slug_and_version { |
|
875 | + * @type string $slug like 'Core' or 'Calendar', |
|
876 | + * @type string $version like '4.1.0' |
|
877 | + * } |
|
878 | + * @return boolean |
|
879 | + */ |
|
880 | + public function database_needs_updating_to($slug_and_version) |
|
881 | + { |
|
882 | + |
|
883 | + $slug = $slug_and_version['slug']; |
|
884 | + $version = $slug_and_version['version']; |
|
885 | + $current_database_state = get_option(self::current_database_state); |
|
886 | + if (! isset($current_database_state[ $slug ])) { |
|
887 | + return true; |
|
888 | + } else { |
|
889 | + // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
|
890 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
891 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
892 | + $needs_updating = false; |
|
893 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
894 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
895 | + $needs_updating = true; |
|
896 | + break; |
|
897 | + } |
|
898 | + } |
|
899 | + return $needs_updating; |
|
900 | + } |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * Gets all the data migration scripts available in the core folder and folders |
|
906 | + * in addons. Has the side effect of adding them for autoloading |
|
907 | + * |
|
908 | + * @return array keys are expected classnames, values are their filepaths |
|
909 | + * @throws InvalidInterfaceException |
|
910 | + * @throws InvalidDataTypeException |
|
911 | + * @throws EE_Error |
|
912 | + * @throws InvalidArgumentException |
|
913 | + */ |
|
914 | + public function get_all_data_migration_scripts_available() |
|
915 | + { |
|
916 | + if (! $this->_data_migration_class_to_filepath_map) { |
|
917 | + $this->_data_migration_class_to_filepath_map = []; |
|
918 | + foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
919 | + // strip any placeholders added to classname to make it a unique array key |
|
920 | + $eeAddonClass = trim($eeAddonClass, '*'); |
|
921 | + $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
922 | + ? $eeAddonClass |
|
923 | + : ''; |
|
924 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
925 | + $files = glob($folder_path . '*.dms.php'); |
|
926 | + if (empty($files)) { |
|
927 | + continue; |
|
928 | + } |
|
929 | + foreach ($files as $file) { |
|
930 | + $pos_of_last_slash = strrpos($file, '/'); |
|
931 | + $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
932 | + $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
933 | + $slug = $migrates_to['slug']; |
|
934 | + // check that the slug as contained in the DMS is associated with |
|
935 | + // the slug of an addon or core |
|
936 | + if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
937 | + EE_Error::doing_it_wrong( |
|
938 | + __FUNCTION__, |
|
939 | + sprintf( |
|
940 | + esc_html__( |
|
941 | + 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
942 | + 'event_espresso' |
|
943 | + ), |
|
944 | + $classname, |
|
945 | + $slug, |
|
946 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
947 | + ), |
|
948 | + '4.3.0.alpha.019' |
|
949 | + ); |
|
950 | + } |
|
951 | + $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
952 | + } |
|
953 | + } |
|
954 | + EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
955 | + } |
|
956 | + return $this->_data_migration_class_to_filepath_map; |
|
957 | + } |
|
958 | + |
|
959 | + |
|
960 | + /** |
|
961 | + * Once we have an addon that works with EE4.1, we will actually want to fetch the PUE slugs |
|
962 | + * from each addon, and check if they need updating, |
|
963 | + * |
|
964 | + * @return boolean |
|
965 | + */ |
|
966 | + public function addons_need_updating() |
|
967 | + { |
|
968 | + return false; |
|
969 | + } |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * Adds this error string to the data_migrations_ran array, but we don't necessarily know |
|
974 | + * where to put it, so we just throw it in there... better than nothing... |
|
975 | + * |
|
976 | + * @param string $error_message |
|
977 | + */ |
|
978 | + public function add_error_to_migrations_ran($error_message) |
|
979 | + { |
|
980 | + // get last-run migration script |
|
981 | + global $wpdb; |
|
982 | + $last_migration_script_option = $wpdb->get_row( |
|
983 | + "SELECT * FROM $wpdb->options WHERE option_name like '" |
|
984 | + . EE_Data_Migration_Manager::data_migration_script_option_prefix |
|
985 | + . "%' ORDER BY option_id DESC LIMIT 1", |
|
986 | + ARRAY_A |
|
987 | + ); |
|
988 | + |
|
989 | + $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) |
|
990 | + ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
|
991 | + // now, tread lightly because we're here because a FATAL non-catchable error |
|
992 | + // was thrown last time when we were trying to run a data migration script |
|
993 | + // so the fatal error could have happened while getting the migration script |
|
994 | + // or doing running it... |
|
995 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace( |
|
996 | + EE_Data_Migration_Manager::data_migration_script_option_prefix, |
|
997 | + "", |
|
998 | + $last_migration_script_option['option_name'] |
|
999 | + ) : null; |
|
1000 | + |
|
1001 | + // check if it THINKS it's a data migration script and especially if it's one that HASN'T finished yet |
|
1002 | + // because if it has finished, then it obviously couldn't be the cause of this error, right? (because it's all done) |
|
1003 | + if ( |
|
1004 | + isset($last_ran_migration_script_properties['class']) |
|
1005 | + && isset($last_ran_migration_script_properties['_status']) |
|
1006 | + && $last_ran_migration_script_properties['_status'] != self::status_completed |
|
1007 | + ) { |
|
1008 | + // ok then just add this error to its list of errors |
|
1009 | + $last_ran_migration_script_properties['_errors'][] = $error_message; |
|
1010 | + $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
|
1011 | + } else { |
|
1012 | + // so we don't even know which script was last running |
|
1013 | + // use the data migration error stub, which is designed specifically for this type of thing |
|
1014 | + $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
|
1015 | + $general_migration_error->add_error($error_message); |
|
1016 | + $general_migration_error->set_broken(); |
|
1017 | + $last_ran_migration_script_properties = $general_migration_error->properties_as_array(); |
|
1018 | + $versions_migrated_to = 'Unknown.1.0.0'; |
|
1019 | + // now just to make sure appears as last (in case the were previously a fatal error like this) |
|
1020 | + // delete the old one |
|
1021 | + delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
1022 | + } |
|
1023 | + update_option( |
|
1024 | + self::data_migration_script_option_prefix . $versions_migrated_to, |
|
1025 | + $last_ran_migration_script_properties |
|
1026 | + ); |
|
1027 | + } |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * saves what data migrations have run to the database |
|
1032 | + * |
|
1033 | + * @return bool|string TRUE if successfully saved migrations ran, string if an error occurred |
|
1034 | + * @throws EE_Error |
|
1035 | + */ |
|
1036 | + protected function _save_migrations_ran() |
|
1037 | + { |
|
1038 | + if ($this->_data_migrations_ran == null) { |
|
1039 | + $this->get_data_migrations_ran(); |
|
1040 | + } |
|
1041 | + // now, we don't want to save actual classes to the DB because that's messy |
|
1042 | + $successful_updates = true; |
|
1043 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
1044 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
1045 | + $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
1046 | + $option_name = |
|
1047 | + self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
1048 | + $old_option_value = get_option($option_name); |
|
1049 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
1050 | + $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
|
1051 | + if ($old_option_value != $script_array_for_saving) { |
|
1052 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
1053 | + } |
|
1054 | + } else {// we don't know what this array-thing is. So just save it as-is |
|
1055 | + if ($old_option_value != $array_or_migration_obj) { |
|
1056 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + if (! $successful_updates) { |
|
1060 | + global $wpdb; |
|
1061 | + return $wpdb->last_error; |
|
1062 | + } |
|
1063 | + } |
|
1064 | + } |
|
1065 | + return true; |
|
1066 | + // $updated = update_option(self::data_migrations_option_name, $array_of_migrations); |
|
1067 | + // if ($updated !== true) { |
|
1068 | + // global $wpdb; |
|
1069 | + // return $wpdb->last_error; |
|
1070 | + // } else { |
|
1071 | + // return true; |
|
1072 | + // } |
|
1073 | + // wp_mail( |
|
1074 | + // "[email protected]", |
|
1075 | + // time() . " price debug info", |
|
1076 | + // "updated: $updated, last error: $last_error, byte length of option: " . strlen( |
|
1077 | + // serialize($array_of_migrations) |
|
1078 | + // ) |
|
1079 | + // ); |
|
1080 | + } |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Takes an array of data migration script properties and re-creates the class from |
|
1085 | + * them. The argument $properties_array is assumed to have been made by |
|
1086 | + * EE_Data_Migration_Script_Base::properties_as_array() |
|
1087 | + * |
|
1088 | + * @param array $properties_array |
|
1089 | + * @return EE_Data_Migration_Script_Base |
|
1090 | + * @throws EE_Error |
|
1091 | + */ |
|
1092 | + public function _instantiate_script_from_properties_array($properties_array) |
|
1093 | + { |
|
1094 | + if (! isset($properties_array['class'])) { |
|
1095 | + throw new EE_Error( |
|
1096 | + sprintf( |
|
1097 | + esc_html__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
|
1098 | + implode(",", $properties_array) |
|
1099 | + ) |
|
1100 | + ); |
|
1101 | + } |
|
1102 | + $class_name = $properties_array['class']; |
|
1103 | + if (! class_exists($class_name)) { |
|
1104 | + throw new EE_Error(sprintf( |
|
1105 | + esc_html__("There is no migration script named %s", "event_espresso"), |
|
1106 | + $class_name |
|
1107 | + )); |
|
1108 | + } |
|
1109 | + $class = new $class_name(); |
|
1110 | + if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
1111 | + throw new EE_Error( |
|
1112 | + sprintf( |
|
1113 | + esc_html__( |
|
1114 | + "Class '%s' is supposed to be a migration script. Its not, its a '%s'", |
|
1115 | + "event_espresso" |
|
1116 | + ), |
|
1117 | + $class_name, |
|
1118 | + get_class($class) |
|
1119 | + ) |
|
1120 | + ); |
|
1121 | + } |
|
1122 | + $class->instantiate_from_array_of_properties($properties_array); |
|
1123 | + return $class; |
|
1124 | + } |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * Gets the classname for the most up-to-date DMS (ie, the one that will finally |
|
1129 | + * leave the DB in a state usable by the current plugin code). |
|
1130 | + * |
|
1131 | + * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
|
1132 | + * @return string |
|
1133 | + * @throws EE_Error |
|
1134 | + * @throws EE_Error |
|
1135 | + */ |
|
1136 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') |
|
1137 | + { |
|
1138 | + $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
|
1139 | + $most_up_to_date_dms_classname = null; |
|
1140 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
1141 | + if ($most_up_to_date_dms_classname === null) { |
|
1142 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
1143 | + $this_plugin_slug = $migrates_to['slug']; |
|
1144 | + if ($this_plugin_slug == $plugin_slug) { |
|
1145 | + // if it's for core, it wins |
|
1146 | + $most_up_to_date_dms_classname = $classname; |
|
1147 | + } |
|
1148 | + // if it wasn't for core, we must keep searching for one that is! |
|
1149 | + continue; |
|
1150 | + } |
|
1151 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
1152 | + $contender_migrates_to = $this->script_migrates_to_version($classname); |
|
1153 | + if ( |
|
1154 | + $contender_migrates_to['slug'] == $plugin_slug |
|
1155 | + && version_compare( |
|
1156 | + $champion_migrates_to['version'], |
|
1157 | + $contender_migrates_to['version'], |
|
1158 | + '<' |
|
1159 | + ) |
|
1160 | + ) { |
|
1161 | + // so the contenders version is higher, and it's for Core |
|
1162 | + $most_up_to_date_dms_classname = $classname; |
|
1163 | + } |
|
1164 | + } |
|
1165 | + return $most_up_to_date_dms_classname; |
|
1166 | + } |
|
1167 | + |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * Gets the migration script specified but ONLY if it has already run. |
|
1171 | + * |
|
1172 | + * Eg, if you wanted to see if 'EE_DMS_Core_4_1_0' has run, you would run the following code: |
|
1173 | + * <code> $core_4_1_0_dms_ran = EE_Data_Migration_Manager::instance()->get_migration_ran( '4.1.0', 'Core' ) !== |
|
1174 | + * NULL;</code> This is especially useful in addons' data migration scripts, this way they can tell if a core (or |
|
1175 | + * other addon) DMS has run, in case the current DMS depends on it. |
|
1176 | + * |
|
1177 | + * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1178 | + * period. Eg '4.1.0' |
|
1179 | + * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1180 | + * @return EE_Data_Migration_Script_Base |
|
1181 | + * @throws EE_Error |
|
1182 | + */ |
|
1183 | + public function get_migration_ran($version, $plugin_slug = 'Core') |
|
1184 | + { |
|
1185 | + $migrations_ran = $this->get_data_migrations_ran(); |
|
1186 | + if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
1187 | + return $migrations_ran[ $plugin_slug ][ $version ]; |
|
1188 | + } else { |
|
1189 | + return null; |
|
1190 | + } |
|
1191 | + } |
|
1192 | + |
|
1193 | + |
|
1194 | + /** |
|
1195 | + * Resets the borked data migration scripts, so they're no longer borked, and we can again attempt to migrate |
|
1196 | + * |
|
1197 | + * @return bool |
|
1198 | + * @throws EE_Error |
|
1199 | + */ |
|
1200 | + public function reattempt() |
|
1201 | + { |
|
1202 | + // find if the last-run script was borked |
|
1203 | + // set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
|
1204 | + // add an 'error' saying that we attempted to reset |
|
1205 | + // does it have a stage that was borked too? if so make it no longer borked |
|
1206 | + // add an 'error' saying we attempted to reset |
|
1207 | + $last_ran_script = $this->get_last_ran_script(); |
|
1208 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
1209 | + // if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
|
1210 | + $last_ran_script->set_completed(); |
|
1211 | + } elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
1212 | + $last_ran_script->reattempt(); |
|
1213 | + } else { |
|
1214 | + throw new EE_Error( |
|
1215 | + sprintf( |
|
1216 | + esc_html__( |
|
1217 | + 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', |
|
1218 | + 'event_espresso' |
|
1219 | + ), |
|
1220 | + print_r($last_ran_script, true) |
|
1221 | + ) |
|
1222 | + ); |
|
1223 | + } |
|
1224 | + return $this->_save_migrations_ran(); |
|
1225 | + } |
|
1226 | + |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * Gets whether this particular migration has run or not |
|
1230 | + * |
|
1231 | + * @param string $version the version the DMS searched for migrates to. Usually just the content before the 3rd |
|
1232 | + * period. Eg '4.1.0' |
|
1233 | + * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
|
1234 | + * @return boolean |
|
1235 | + * @throws EE_Error |
|
1236 | + */ |
|
1237 | + public function migration_has_ran($version, $plugin_slug = 'Core') |
|
1238 | + { |
|
1239 | + return $this->get_migration_ran($version, $plugin_slug) !== null; |
|
1240 | + } |
|
1241 | + |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * Enqueues this ee plugin to have its data initialized |
|
1245 | + * |
|
1246 | + * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
|
1247 | + */ |
|
1248 | + public function enqueue_db_initialization_for($plugin_slug) |
|
1249 | + { |
|
1250 | + $queue = $this->get_db_initialization_queue(); |
|
1251 | + if (! in_array($plugin_slug, $queue)) { |
|
1252 | + $queue[] = $plugin_slug; |
|
1253 | + } |
|
1254 | + update_option(self::db_init_queue_option_name, $queue); |
|
1255 | + } |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
|
1260 | + * specified in EE_Data_Migration_Manager::get_db_init_queue(), and if 'Core' is |
|
1261 | + * in the queue, calls EE_System::initialize_db_if_no_migrations_required(). |
|
1262 | + * |
|
1263 | + * @throws EE_Error |
|
1264 | + */ |
|
1265 | + public function initialize_db_for_enqueued_ee_plugins() |
|
1266 | + { |
|
1267 | + $queue = $this->get_db_initialization_queue(); |
|
1268 | + foreach ($queue as $plugin_slug) { |
|
1269 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
1270 | + if (! $most_up_to_date_dms) { |
|
1271 | + // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
|
1272 | + $verify_db = false; |
|
1273 | + } else { |
|
1274 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1275 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1276 | + } |
|
1277 | + if ($plugin_slug == 'Core') { |
|
1278 | + EE_System::instance()->initialize_db_if_no_migrations_required( |
|
1279 | + false, |
|
1280 | + $verify_db |
|
1281 | + ); |
|
1282 | + } else { |
|
1283 | + // just loop through the addons to make sure their database is set up |
|
1284 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
1285 | + if ($addon->name() == $plugin_slug) { |
|
1286 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1287 | + break; |
|
1288 | + } |
|
1289 | + } |
|
1290 | + } |
|
1291 | + } |
|
1292 | + // because we just initialized the DBs for the enqueued ee plugins |
|
1293 | + // we don't need to keep remembering which ones needed to be initialized |
|
1294 | + delete_option(self::db_init_queue_option_name); |
|
1295 | + } |
|
1296 | + |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Gets a numerically-indexed array of plugin slugs that need to have their databases |
|
1300 | + * (re-)initialized after migrations are complete. ie, each element should be either |
|
1301 | + * 'Core', or the return value of EE_Addon::name() for an addon |
|
1302 | + * |
|
1303 | + * @return array |
|
1304 | + */ |
|
1305 | + public function get_db_initialization_queue() |
|
1306 | + { |
|
1307 | + return get_option(self::db_init_queue_option_name, []); |
|
1308 | + } |
|
1309 | + |
|
1310 | + |
|
1311 | + /** |
|
1312 | + * Gets the injected table analyzer, or throws an exception |
|
1313 | + * |
|
1314 | + * @return TableAnalysis |
|
1315 | + * @throws EE_Error |
|
1316 | + */ |
|
1317 | + protected function _get_table_analysis() |
|
1318 | + { |
|
1319 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
1320 | + return $this->_table_analysis; |
|
1321 | + } else { |
|
1322 | + throw new EE_Error( |
|
1323 | + sprintf( |
|
1324 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1325 | + get_class($this) |
|
1326 | + ) |
|
1327 | + ); |
|
1328 | + } |
|
1329 | + } |
|
1330 | + |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Gets the injected table manager, or throws an exception |
|
1334 | + * |
|
1335 | + * @return TableManager |
|
1336 | + * @throws EE_Error |
|
1337 | + */ |
|
1338 | + protected function _get_table_manager() |
|
1339 | + { |
|
1340 | + if ($this->_table_manager instanceof TableManager) { |
|
1341 | + return $this->_table_manager; |
|
1342 | + } else { |
|
1343 | + throw new EE_Error( |
|
1344 | + sprintf( |
|
1345 | + esc_html__('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1346 | + get_class($this) |
|
1347 | + ) |
|
1348 | + ); |
|
1349 | + } |
|
1350 | + } |
|
1351 | 1351 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | public static function instance() |
164 | 164 | { |
165 | 165 | // check if class object is instantiated |
166 | - if (! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
166 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
167 | 167 | self::$_instance = new self(); |
168 | 168 | } |
169 | 169 | return self::$_instance; |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | */ |
190 | 190 | private function __construct() |
191 | 191 | { |
192 | - $this->stati_that_indicate_to_continue_migrations = [ |
|
192 | + $this->stati_that_indicate_to_continue_migrations = [ |
|
193 | 193 | self::status_continue, |
194 | 194 | self::status_completed, |
195 | 195 | ]; |
196 | - $this->stati_that_indicate_to_stop_migrations = [ |
|
196 | + $this->stati_that_indicate_to_stop_migrations = [ |
|
197 | 197 | self::status_fatal_error, |
198 | 198 | self::status_no_more_migration_scripts, |
199 | 199 | ]; |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | |
242 | 242 | if (count($parts) == 4) { |
243 | 243 | // it's 4.2-style.eg Core.4.1.0 |
244 | - $plugin_slug = $parts[0]; // eg Core |
|
245 | - $version_string = $parts[1] . "." . $parts[2] . "." . $parts[3]; // eg 4.1.0 |
|
244 | + $plugin_slug = $parts[0]; // eg Core |
|
245 | + $version_string = $parts[1].".".$parts[2].".".$parts[3]; // eg 4.1.0 |
|
246 | 246 | } else { |
247 | 247 | // it's 4.1-style: eg 4.1.0 |
248 | 248 | $plugin_slug = 'Core'; |
249 | - $version_string = $plugin_slug_and_version_string;// eg 4.1.0 |
|
249 | + $version_string = $plugin_slug_and_version_string; // eg 4.1.0 |
|
250 | 250 | } |
251 | 251 | return [$plugin_slug, $version_string]; |
252 | 252 | } |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function get_data_migrations_ran() |
310 | 310 | { |
311 | - if (! $this->_data_migrations_ran) { |
|
311 | + if ( ! $this->_data_migrations_ran) { |
|
312 | 312 | // setup autoloaders for each of the scripts in there |
313 | 313 | $this->get_all_data_migration_scripts_available(); |
314 | 314 | $data_migrations_options = |
315 | - $this->get_all_migration_script_options();// get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
315 | + $this->get_all_migration_script_options(); // get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
316 | 316 | |
317 | 317 | $data_migrations_ran = []; |
318 | 318 | // convert into data migration script classes where possible |
@@ -322,27 +322,27 @@ discard block |
||
322 | 322 | ); |
323 | 323 | |
324 | 324 | try { |
325 | - $class = $this->_get_dms_class_from_wp_option( |
|
325 | + $class = $this->_get_dms_class_from_wp_option( |
|
326 | 326 | $data_migration_option['option_name'], |
327 | 327 | $data_migration_option['option_value'] |
328 | 328 | ); |
329 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = $class; |
|
329 | + $data_migrations_ran[$plugin_slug][$version_string] = $class; |
|
330 | 330 | // ok so far THIS is the 'last-run-script'... unless we find another on next iteration |
331 | 331 | $this->_last_ran_script = $class; |
332 | - if (! $class->is_completed()) { |
|
332 | + if ( ! $class->is_completed()) { |
|
333 | 333 | // sometimes we also like to know which was the last incomplete script (or if there are any at all) |
334 | 334 | $this->_last_ran_incomplete_script = $class; |
335 | 335 | } |
336 | 336 | } catch (EE_Error $e) { |
337 | 337 | // ok so it's not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
338 | - $data_migrations_ran[ $plugin_slug ][ $version_string ] = maybe_unserialize( |
|
338 | + $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize( |
|
339 | 339 | $data_migration_option['option_value'] |
340 | 340 | ); |
341 | 341 | } |
342 | 342 | } |
343 | 343 | // so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
344 | 344 | $this->_data_migrations_ran = $data_migrations_ran; |
345 | - if (! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
345 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
346 | 346 | $this->_data_migrations_ran = []; |
347 | 347 | } |
348 | 348 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) |
364 | 364 | { |
365 | - $script = EE_Registry::instance()->load_dms($script_name); |
|
365 | + $script = EE_Registry::instance()->load_dms($script_name); |
|
366 | 366 | return $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
367 | 367 | } |
368 | 368 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | { |
396 | 396 | return apply_filters( |
397 | 397 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
398 | - ['Core' => EE_CORE . 'data_migration_scripts'] |
|
398 | + ['Core' => EE_CORE.'data_migration_scripts'] |
|
399 | 399 | ); |
400 | 400 | } |
401 | 401 | |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | */ |
413 | 413 | public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') |
414 | 414 | { |
415 | - if (isset($this->script_migration_versions[ $migration_script_name ])) { |
|
416 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
415 | + if (isset($this->script_migration_versions[$migration_script_name])) { |
|
416 | + return $this->script_migration_versions[$migration_script_name]; |
|
417 | 417 | } |
418 | 418 | $dms_info = $this->parse_dms_classname($migration_script_name); |
419 | - $this->script_migration_versions[ $migration_script_name ] = [ |
|
419 | + $this->script_migration_versions[$migration_script_name] = [ |
|
420 | 420 | 'slug' => $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
421 | 421 | 'version' => $dms_info['major_version'] |
422 | 422 | . "." |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | . "." |
425 | 425 | . $dms_info['micro_version'], |
426 | 426 | ]; |
427 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
427 | + return $this->script_migration_versions[$migration_script_name]; |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | { |
440 | 440 | $matches = []; |
441 | 441 | preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
442 | - if (! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
442 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
443 | 443 | throw new EE_Error( |
444 | 444 | sprintf( |
445 | 445 | esc_html__( |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | { |
472 | 472 | $espresso_db_core_updates = get_option('espresso_db_update', []); |
473 | 473 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
474 | - if (! $db_state) { |
|
474 | + if ( ! $db_state) { |
|
475 | 475 | // mark the DB as being in the state as the last version in there. |
476 | 476 | // this is done to trigger maintenance mode and do data migration scripts |
477 | 477 | // if the admin installed this version of EE over 3.1.x or 4.0.x |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | // in 4.1, $db_state would have only been a simple string like '4.1.0', |
491 | 491 | // but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
492 | 492 | // db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
493 | - if (! is_array($db_state)) { |
|
493 | + if ( ! is_array($db_state)) { |
|
494 | 494 | $db_state = ['Core' => $db_state]; |
495 | 495 | update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
496 | 496 | } |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | // check if this version script is DONE or not; or if it's never been run |
535 | 535 | if ( |
536 | 536 | ! $scripts_ran |
537 | - || ! isset($scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]) |
|
537 | + || ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]) |
|
538 | 538 | ) { |
539 | 539 | // we haven't run this conversion script before |
540 | 540 | // now check if it applies... |
@@ -545,28 +545,28 @@ discard block |
||
545 | 545 | /* @var $script EE_Data_Migration_Script_Base */ |
546 | 546 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
547 | 547 | if ($can_migrate) { |
548 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
548 | + $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
|
549 | 549 | $migrates_to_version = |
550 | 550 | $script->migrates_to_version(); |
551 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
551 | + $next_database_state_to_consider[$migrates_to_version['slug']] = |
|
552 | 552 | $migrates_to_version['version']; |
553 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
553 | + unset($script_class_and_filepaths_available[$classname]); |
|
554 | 554 | } |
555 | 555 | } elseif ( |
556 | - $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ] |
|
556 | + $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] |
|
557 | 557 | instanceof |
558 | 558 | EE_Data_Migration_Script_Base |
559 | 559 | ) { |
560 | 560 | // this script has been run, or at least started |
561 | - $script = $scripts_ran[ $script_converts_plugin_slug ][ $script_converts_to_version ]; |
|
561 | + $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
|
562 | 562 | if ($script->get_status() !== self::status_completed) { |
563 | 563 | // this script is already underway... keep going with it |
564 | - $script_classes_that_should_run_per_iteration[ $iteration ][ $script->priority() ][] = $script; |
|
564 | + $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
|
565 | 565 | $migrates_to_version = |
566 | 566 | $script->migrates_to_version(); |
567 | - $next_database_state_to_consider[ $migrates_to_version['slug'] ] = |
|
567 | + $next_database_state_to_consider[$migrates_to_version['slug']] = |
|
568 | 568 | $migrates_to_version['version']; |
569 | - unset($script_class_and_filepaths_available[ $classname ]); |
|
569 | + unset($script_class_and_filepaths_available[$classname]); |
|
570 | 570 | } |
571 | 571 | // else it must have a status that indicates it has finished, |
572 | 572 | // so we don't want to try and run it again |
@@ -575,14 +575,14 @@ discard block |
||
575 | 575 | // or was simply removed from EE? either way, it's certainly not runnable! |
576 | 576 | } |
577 | 577 | $iteration++; |
578 | - } while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
578 | + }while ($next_database_state_to_consider !== $theoretical_database_state && $iteration < 6); |
|
579 | 579 | // ok we have all the scripts that should run, now let's make them into flat array |
580 | 580 | $scripts_that_should_run = []; |
581 | 581 | foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
582 | 582 | ksort($scripts_at_priority); |
583 | 583 | foreach ($scripts_at_priority as $scripts) { |
584 | 584 | foreach ($scripts as $script) { |
585 | - $scripts_that_should_run[ get_class($script) ] = $script; |
|
585 | + $scripts_that_should_run[get_class($script)] = $script; |
|
586 | 586 | } |
587 | 587 | } |
588 | 588 | } |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | public function get_last_ran_script($include_completed_scripts = false) |
609 | 609 | { |
610 | 610 | // make sure we've set up the class properties _last_ran_script and _last_ran_incomplete_script |
611 | - if (! $this->_data_migrations_ran) { |
|
611 | + if ( ! $this->_data_migrations_ran) { |
|
612 | 612 | $this->get_data_migrations_ran(); |
613 | 613 | } |
614 | 614 | if ($include_completed_scripts) { |
@@ -645,10 +645,10 @@ discard block |
||
645 | 645 | |
646 | 646 | try { |
647 | 647 | $currently_executing_script = $this->get_last_ran_script(); |
648 | - if (! $currently_executing_script) { |
|
648 | + if ( ! $currently_executing_script) { |
|
649 | 649 | // Find the next script that needs to execute |
650 | 650 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
651 | - if (! $scripts) { |
|
651 | + if ( ! $scripts) { |
|
652 | 652 | // huh, no more scripts to run... apparently we're done! |
653 | 653 | // but don't forget to make sure initial data is there |
654 | 654 | // we should be good to allow them to exit maintenance mode now |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | $this->script_migrates_to_version(get_class($currently_executing_script)); |
677 | 677 | $plugin_slug = $migrates_to['slug']; |
678 | 678 | $version = $migrates_to['version']; |
679 | - $this->_data_migrations_ran[ $plugin_slug ][ $version ] = $currently_executing_script; |
|
679 | + $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
|
680 | 680 | } |
681 | 681 | $current_script_name = get_class($currently_executing_script); |
682 | 682 | } catch (Exception $e) { |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | |
685 | 685 | $message = sprintf( |
686 | 686 | esc_html__("Error Message: %sStack Trace:%s", "event_espresso"), |
687 | - $e->getMessage() . '<br>', |
|
687 | + $e->getMessage().'<br>', |
|
688 | 688 | $e->getTraceAsString() |
689 | 689 | ); |
690 | 690 | // record it on the array of data migration scripts run. This will be overwritten next time we try and try to run data migrations |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | ]; |
738 | 738 | // check if there are any more after this one. |
739 | 739 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
740 | - if (! $scripts_remaining) { |
|
740 | + if ( ! $scripts_remaining) { |
|
741 | 741 | // we should be good to allow them to exit maintenance mode now |
742 | 742 | EE_Maintenance_Mode::instance()->set_maintenance_level( |
743 | 743 | EE_Maintenance_Mode::level_0_not_in_maintenance |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | ), |
838 | 838 | 'script' => 'Unknown', |
839 | 839 | ]; |
840 | - $this->add_error_to_migrations_ran($e->getMessage() . "; Stack trace:" . $e->getTraceAsString()); |
|
840 | + $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
|
841 | 841 | } |
842 | 842 | $warnings_etc = @ob_get_contents(); |
843 | 843 | ob_end_clean(); |
@@ -858,12 +858,12 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function update_current_database_state_to($slug_and_version = null) |
860 | 860 | { |
861 | - if (! $slug_and_version) { |
|
861 | + if ( ! $slug_and_version) { |
|
862 | 862 | // no version was provided, assume it should be at the current code version |
863 | 863 | $slug_and_version = ['slug' => 'Core', 'version' => espresso_version()]; |
864 | 864 | } |
865 | 865 | $current_database_state = get_option(self::current_database_state); |
866 | - $current_database_state[ $slug_and_version['slug'] ] = $slug_and_version['version']; |
|
866 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
867 | 867 | update_option(self::current_database_state, $current_database_state); |
868 | 868 | } |
869 | 869 | |
@@ -883,15 +883,15 @@ discard block |
||
883 | 883 | $slug = $slug_and_version['slug']; |
884 | 884 | $version = $slug_and_version['version']; |
885 | 885 | $current_database_state = get_option(self::current_database_state); |
886 | - if (! isset($current_database_state[ $slug ])) { |
|
886 | + if ( ! isset($current_database_state[$slug])) { |
|
887 | 887 | return true; |
888 | 888 | } else { |
889 | 889 | // just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
890 | - $version_parts_current_db_state = array_slice(explode('.', $current_database_state[ $slug ]), 0, 3); |
|
890 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
891 | 891 | $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
892 | 892 | $needs_updating = false; |
893 | 893 | foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
894 | - if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ]) { |
|
894 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
895 | 895 | $needs_updating = true; |
896 | 896 | break; |
897 | 897 | } |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | */ |
914 | 914 | public function get_all_data_migration_scripts_available() |
915 | 915 | { |
916 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
916 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
917 | 917 | $this->_data_migration_class_to_filepath_map = []; |
918 | 918 | foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
919 | 919 | // strip any placeholders added to classname to make it a unique array key |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | ? $eeAddonClass |
923 | 923 | : ''; |
924 | 924 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
925 | - $files = glob($folder_path . '*.dms.php'); |
|
925 | + $files = glob($folder_path.'*.dms.php'); |
|
926 | 926 | if (empty($files)) { |
927 | 927 | continue; |
928 | 928 | } |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | '4.3.0.alpha.019' |
949 | 949 | ); |
950 | 950 | } |
951 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
951 | + $this->_data_migration_class_to_filepath_map[$classname] = $file; |
|
952 | 952 | } |
953 | 953 | } |
954 | 954 | EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
@@ -1018,10 +1018,10 @@ discard block |
||
1018 | 1018 | $versions_migrated_to = 'Unknown.1.0.0'; |
1019 | 1019 | // now just to make sure appears as last (in case the were previously a fatal error like this) |
1020 | 1020 | // delete the old one |
1021 | - delete_option(self::data_migration_script_option_prefix . $versions_migrated_to); |
|
1021 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
1022 | 1022 | } |
1023 | 1023 | update_option( |
1024 | - self::data_migration_script_option_prefix . $versions_migrated_to, |
|
1024 | + self::data_migration_script_option_prefix.$versions_migrated_to, |
|
1025 | 1025 | $last_ran_migration_script_properties |
1026 | 1026 | ); |
1027 | 1027 | } |
@@ -1042,9 +1042,9 @@ discard block |
||
1042 | 1042 | $successful_updates = true; |
1043 | 1043 | foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
1044 | 1044 | foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
1045 | - $plugin_slug_for_use_in_option_name = $plugin_slug . "."; |
|
1045 | + $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
|
1046 | 1046 | $option_name = |
1047 | - self::data_migration_script_option_prefix . $plugin_slug_for_use_in_option_name . $version_string; |
|
1047 | + self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
|
1048 | 1048 | $old_option_value = get_option($option_name); |
1049 | 1049 | if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
1050 | 1050 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | $successful_updates = update_option($option_name, $array_or_migration_obj); |
1057 | 1057 | } |
1058 | 1058 | } |
1059 | - if (! $successful_updates) { |
|
1059 | + if ( ! $successful_updates) { |
|
1060 | 1060 | global $wpdb; |
1061 | 1061 | return $wpdb->last_error; |
1062 | 1062 | } |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | */ |
1092 | 1092 | public function _instantiate_script_from_properties_array($properties_array) |
1093 | 1093 | { |
1094 | - if (! isset($properties_array['class'])) { |
|
1094 | + if ( ! isset($properties_array['class'])) { |
|
1095 | 1095 | throw new EE_Error( |
1096 | 1096 | sprintf( |
1097 | 1097 | esc_html__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), |
@@ -1100,14 +1100,14 @@ discard block |
||
1100 | 1100 | ); |
1101 | 1101 | } |
1102 | 1102 | $class_name = $properties_array['class']; |
1103 | - if (! class_exists($class_name)) { |
|
1103 | + if ( ! class_exists($class_name)) { |
|
1104 | 1104 | throw new EE_Error(sprintf( |
1105 | 1105 | esc_html__("There is no migration script named %s", "event_espresso"), |
1106 | 1106 | $class_name |
1107 | 1107 | )); |
1108 | 1108 | } |
1109 | 1109 | $class = new $class_name(); |
1110 | - if (! $class instanceof EE_Data_Migration_Script_Base) { |
|
1110 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
1111 | 1111 | throw new EE_Error( |
1112 | 1112 | sprintf( |
1113 | 1113 | esc_html__( |
@@ -1183,8 +1183,8 @@ discard block |
||
1183 | 1183 | public function get_migration_ran($version, $plugin_slug = 'Core') |
1184 | 1184 | { |
1185 | 1185 | $migrations_ran = $this->get_data_migrations_ran(); |
1186 | - if (isset($migrations_ran[ $plugin_slug ]) && isset($migrations_ran[ $plugin_slug ][ $version ])) { |
|
1187 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
1186 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
1187 | + return $migrations_ran[$plugin_slug][$version]; |
|
1188 | 1188 | } else { |
1189 | 1189 | return null; |
1190 | 1190 | } |
@@ -1248,7 +1248,7 @@ discard block |
||
1248 | 1248 | public function enqueue_db_initialization_for($plugin_slug) |
1249 | 1249 | { |
1250 | 1250 | $queue = $this->get_db_initialization_queue(); |
1251 | - if (! in_array($plugin_slug, $queue)) { |
|
1251 | + if ( ! in_array($plugin_slug, $queue)) { |
|
1252 | 1252 | $queue[] = $plugin_slug; |
1253 | 1253 | } |
1254 | 1254 | update_option(self::db_init_queue_option_name, $queue); |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | $queue = $this->get_db_initialization_queue(); |
1268 | 1268 | foreach ($queue as $plugin_slug) { |
1269 | 1269 | $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
1270 | - if (! $most_up_to_date_dms) { |
|
1270 | + if ( ! $most_up_to_date_dms) { |
|
1271 | 1271 | // if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
1272 | 1272 | $verify_db = false; |
1273 | 1273 | } else { |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function is_espresso_event($event = null) |
21 | 21 | { |
22 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
23 | - // extract EE_Event object from passed param regardless of what it is (within reason of course) |
|
24 | - $event = EEH_Event_View::get_event($event); |
|
25 | - // do we have a valid event ? |
|
26 | - return $event instanceof EE_Event; |
|
27 | - } |
|
28 | - return false; |
|
22 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
23 | + // extract EE_Event object from passed param regardless of what it is (within reason of course) |
|
24 | + $event = EEH_Event_View::get_event($event); |
|
25 | + // do we have a valid event ? |
|
26 | + return $event instanceof EE_Event; |
|
27 | + } |
|
28 | + return false; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function is_espresso_event_single() |
38 | 38 | { |
39 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
40 | - global $wp_query; |
|
41 | - // return conditionals set by CPTs |
|
42 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : false; |
|
43 | - } |
|
44 | - return false; |
|
39 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
40 | + global $wp_query; |
|
41 | + // return conditionals set by CPTs |
|
42 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : false; |
|
43 | + } |
|
44 | + return false; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function is_espresso_event_archive() |
54 | 54 | { |
55 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
56 | - global $wp_query; |
|
57 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : false; |
|
58 | - } |
|
59 | - return false; |
|
55 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
56 | + global $wp_query; |
|
57 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : false; |
|
58 | + } |
|
59 | + return false; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function is_espresso_event_taxonomy() |
69 | 69 | { |
70 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
71 | - global $wp_query; |
|
72 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : false; |
|
73 | - } |
|
74 | - return false; |
|
70 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
71 | + global $wp_query; |
|
72 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : false; |
|
73 | + } |
|
74 | + return false; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | */ |
86 | 86 | function is_espresso_venue($venue = null) |
87 | 87 | { |
88 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
89 | - // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
|
90 | - $venue = EEH_Venue_View::get_venue($venue, false); |
|
91 | - // do we have a valid event ? |
|
92 | - return $venue instanceof EE_Venue; |
|
93 | - } |
|
94 | - return false; |
|
88 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
89 | + // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
|
90 | + $venue = EEH_Venue_View::get_venue($venue, false); |
|
91 | + // do we have a valid event ? |
|
92 | + return $venue instanceof EE_Venue; |
|
93 | + } |
|
94 | + return false; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function is_espresso_venue_single() |
104 | 104 | { |
105 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
106 | - global $wp_query; |
|
107 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : false; |
|
108 | - } |
|
109 | - return false; |
|
105 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
106 | + global $wp_query; |
|
107 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : false; |
|
108 | + } |
|
109 | + return false; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function is_espresso_venue_archive() |
119 | 119 | { |
120 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
121 | - global $wp_query; |
|
122 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : false; |
|
123 | - } |
|
124 | - return false; |
|
120 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
121 | + global $wp_query; |
|
122 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : false; |
|
123 | + } |
|
124 | + return false; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | */ |
133 | 133 | function is_espresso_venue_taxonomy() |
134 | 134 | { |
135 | - if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
136 | - global $wp_query; |
|
137 | - return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : false; |
|
138 | - } |
|
139 | - return false; |
|
135 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
136 | + global $wp_query; |
|
137 | + return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : false; |
|
138 | + } |
|
139 | + return false; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -148,62 +148,62 @@ discard block |
||
148 | 148 | */ |
149 | 149 | function can_use_espresso_conditionals($conditional_tag) |
150 | 150 | { |
151 | - if (! did_action('AHEE__EE_System__initialize')) { |
|
152 | - EE_Error::doing_it_wrong( |
|
153 | - __FUNCTION__, |
|
154 | - sprintf( |
|
155 | - esc_html__( |
|
156 | - 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', |
|
157 | - 'event_espresso' |
|
158 | - ), |
|
159 | - $conditional_tag |
|
160 | - ), |
|
161 | - '4.4.0' |
|
162 | - ); |
|
163 | - return false; |
|
164 | - } |
|
165 | - return true; |
|
151 | + if (! did_action('AHEE__EE_System__initialize')) { |
|
152 | + EE_Error::doing_it_wrong( |
|
153 | + __FUNCTION__, |
|
154 | + sprintf( |
|
155 | + esc_html__( |
|
156 | + 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', |
|
157 | + 'event_espresso' |
|
158 | + ), |
|
159 | + $conditional_tag |
|
160 | + ), |
|
161 | + '4.4.0' |
|
162 | + ); |
|
163 | + return false; |
|
164 | + } |
|
165 | + return true; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
169 | 169 | /*************************** Event Queries ***************************/ |
170 | 170 | |
171 | 171 | if (! function_exists('espresso_get_events')) { |
172 | - /** |
|
173 | - * espresso_get_events |
|
174 | - * |
|
175 | - * @param array $params |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - function espresso_get_events($params = []) |
|
179 | - { |
|
180 | - //set default params |
|
181 | - $default_espresso_events_params = [ |
|
182 | - 'limit' => 10, |
|
183 | - 'show_expired' => false, |
|
184 | - 'month' => null, |
|
185 | - 'category_slug' => null, |
|
186 | - 'order_by' => 'start_date', |
|
187 | - 'sort' => 'ASC', |
|
188 | - ]; |
|
189 | - // allow the defaults to be filtered |
|
190 | - $default_espresso_events_params = apply_filters( |
|
191 | - 'espresso_get_events__default_espresso_events_params', |
|
192 | - $default_espresso_events_params |
|
193 | - ); |
|
194 | - // grab params and merge with defaults, then extract |
|
195 | - $params = array_merge($default_espresso_events_params, $params); |
|
196 | - // run the query |
|
197 | - $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
198 | - // assign results to a variable so we can return it |
|
199 | - $events = $events_query->have_posts() ? $events_query->posts : []; |
|
200 | - // but first reset the query and postdata |
|
201 | - wp_reset_query(); |
|
202 | - wp_reset_postdata(); |
|
203 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
204 | - unset($events_query); |
|
205 | - return $events; |
|
206 | - } |
|
172 | + /** |
|
173 | + * espresso_get_events |
|
174 | + * |
|
175 | + * @param array $params |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + function espresso_get_events($params = []) |
|
179 | + { |
|
180 | + //set default params |
|
181 | + $default_espresso_events_params = [ |
|
182 | + 'limit' => 10, |
|
183 | + 'show_expired' => false, |
|
184 | + 'month' => null, |
|
185 | + 'category_slug' => null, |
|
186 | + 'order_by' => 'start_date', |
|
187 | + 'sort' => 'ASC', |
|
188 | + ]; |
|
189 | + // allow the defaults to be filtered |
|
190 | + $default_espresso_events_params = apply_filters( |
|
191 | + 'espresso_get_events__default_espresso_events_params', |
|
192 | + $default_espresso_events_params |
|
193 | + ); |
|
194 | + // grab params and merge with defaults, then extract |
|
195 | + $params = array_merge($default_espresso_events_params, $params); |
|
196 | + // run the query |
|
197 | + $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
198 | + // assign results to a variable so we can return it |
|
199 | + $events = $events_query->have_posts() ? $events_query->posts : []; |
|
200 | + // but first reset the query and postdata |
|
201 | + wp_reset_query(); |
|
202 | + wp_reset_postdata(); |
|
203 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
204 | + unset($events_query); |
|
205 | + return $events; |
|
206 | + } |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -218,357 +218,357 @@ discard block |
||
218 | 218 | */ |
219 | 219 | function espresso_load_ticket_selector() |
220 | 220 | { |
221 | - EE_Registry::instance()->load_file(EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
221 | + EE_Registry::instance()->load_file(EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | if (! function_exists('espresso_ticket_selector')) { |
225 | - /** |
|
226 | - * espresso_ticket_selector |
|
227 | - * |
|
228 | - * @param null $event |
|
229 | - * @throws EE_Error |
|
230 | - * @throws ReflectionException |
|
231 | - */ |
|
232 | - function espresso_ticket_selector($event = null) |
|
233 | - { |
|
234 | - if (! apply_filters('FHEE_disable_espresso_ticket_selector', false)) { |
|
235 | - espresso_load_ticket_selector(); |
|
236 | - EED_Ticket_Selector::set_definitions(); |
|
237 | - echo EED_Ticket_Selector::display_ticket_selector($event); // already escaped |
|
238 | - } |
|
239 | - } |
|
225 | + /** |
|
226 | + * espresso_ticket_selector |
|
227 | + * |
|
228 | + * @param null $event |
|
229 | + * @throws EE_Error |
|
230 | + * @throws ReflectionException |
|
231 | + */ |
|
232 | + function espresso_ticket_selector($event = null) |
|
233 | + { |
|
234 | + if (! apply_filters('FHEE_disable_espresso_ticket_selector', false)) { |
|
235 | + espresso_load_ticket_selector(); |
|
236 | + EED_Ticket_Selector::set_definitions(); |
|
237 | + echo EED_Ticket_Selector::display_ticket_selector($event); // already escaped |
|
238 | + } |
|
239 | + } |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | |
243 | 243 | if (! function_exists('espresso_view_details_btn')) { |
244 | - /** |
|
245 | - * espresso_view_details_btn |
|
246 | - * |
|
247 | - * @param null $event |
|
248 | - * @throws EE_Error |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - function espresso_view_details_btn($event = null) |
|
252 | - { |
|
253 | - if (! apply_filters('FHEE_disable_espresso_view_details_btn', false)) { |
|
254 | - espresso_load_ticket_selector(); |
|
255 | - echo EED_Ticket_Selector::display_ticket_selector($event, true); // already escaped |
|
256 | - } |
|
257 | - } |
|
244 | + /** |
|
245 | + * espresso_view_details_btn |
|
246 | + * |
|
247 | + * @param null $event |
|
248 | + * @throws EE_Error |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + function espresso_view_details_btn($event = null) |
|
252 | + { |
|
253 | + if (! apply_filters('FHEE_disable_espresso_view_details_btn', false)) { |
|
254 | + espresso_load_ticket_selector(); |
|
255 | + echo EED_Ticket_Selector::display_ticket_selector($event, true); // already escaped |
|
256 | + } |
|
257 | + } |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
261 | 261 | /*************************** EEH_Event_View ***************************/ |
262 | 262 | |
263 | 263 | if (! function_exists('espresso_load_event_list_assets')) { |
264 | - /** |
|
265 | - * espresso_load_event_list_assets |
|
266 | - * ensures that event list styles and scripts are loaded |
|
267 | - * |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - function espresso_load_event_list_assets() |
|
271 | - { |
|
272 | - $event_list = EED_Events_Archive::instance(); |
|
273 | - add_action('AHEE__EE_System__initialize_last', [$event_list, 'load_event_list_assets'], 10); |
|
274 | - add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
275 | - } |
|
264 | + /** |
|
265 | + * espresso_load_event_list_assets |
|
266 | + * ensures that event list styles and scripts are loaded |
|
267 | + * |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + function espresso_load_event_list_assets() |
|
271 | + { |
|
272 | + $event_list = EED_Events_Archive::instance(); |
|
273 | + add_action('AHEE__EE_System__initialize_last', [$event_list, 'load_event_list_assets'], 10); |
|
274 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
275 | + } |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | |
279 | 279 | if (! function_exists('espresso_event_reg_button')) { |
280 | - /** |
|
281 | - * espresso_event_reg_button |
|
282 | - * returns the "Register Now" button if event is active, |
|
283 | - * an inactive button like status banner if the event is not active |
|
284 | - * or a "Read More" button if so desired |
|
285 | - * |
|
286 | - * @param null $btn_text_if_active |
|
287 | - * @param bool $btn_text_if_inactive |
|
288 | - * @param bool $EVT_ID |
|
289 | - * @return void |
|
290 | - * @throws EE_Error |
|
291 | - * @throws ReflectionException |
|
292 | - */ |
|
293 | - function espresso_event_reg_button($btn_text_if_active = null, $btn_text_if_inactive = false, $EVT_ID = false) |
|
294 | - { |
|
295 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
296 | - if (! $event instanceof EE_Event) { |
|
297 | - return; |
|
298 | - } |
|
299 | - $event_status = $event->get_active_status(); |
|
300 | - switch ($event_status) { |
|
301 | - case EE_Datetime::sold_out : |
|
302 | - $btn_text = __('Sold Out', 'event_espresso'); |
|
303 | - $class = 'ee-pink'; |
|
304 | - break; |
|
305 | - case EE_Datetime::expired : |
|
306 | - $btn_text = __('Event is Over', 'event_espresso'); |
|
307 | - $class = 'ee-grey'; |
|
308 | - break; |
|
309 | - case EE_Datetime::inactive : |
|
310 | - $btn_text = __('Event Not Active', 'event_espresso'); |
|
311 | - $class = 'ee-grey'; |
|
312 | - break; |
|
313 | - case EE_Datetime::cancelled : |
|
314 | - $btn_text = __('Event was Cancelled', 'event_espresso'); |
|
315 | - $class = 'ee-red'; |
|
316 | - break; |
|
317 | - case EE_Datetime::upcoming : |
|
318 | - case EE_Datetime::active : |
|
319 | - default : |
|
320 | - $btn_text = ! empty($btn_text_if_active) |
|
321 | - ? $btn_text_if_active |
|
322 | - : __('Register Now', 'event_espresso'); |
|
323 | - $class = 'ee-green'; |
|
324 | - } |
|
325 | - if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
326 | - $btn_text = $btn_text_if_inactive; |
|
327 | - $class = 'ee-grey'; |
|
328 | - } |
|
329 | - ?> |
|
280 | + /** |
|
281 | + * espresso_event_reg_button |
|
282 | + * returns the "Register Now" button if event is active, |
|
283 | + * an inactive button like status banner if the event is not active |
|
284 | + * or a "Read More" button if so desired |
|
285 | + * |
|
286 | + * @param null $btn_text_if_active |
|
287 | + * @param bool $btn_text_if_inactive |
|
288 | + * @param bool $EVT_ID |
|
289 | + * @return void |
|
290 | + * @throws EE_Error |
|
291 | + * @throws ReflectionException |
|
292 | + */ |
|
293 | + function espresso_event_reg_button($btn_text_if_active = null, $btn_text_if_inactive = false, $EVT_ID = false) |
|
294 | + { |
|
295 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
296 | + if (! $event instanceof EE_Event) { |
|
297 | + return; |
|
298 | + } |
|
299 | + $event_status = $event->get_active_status(); |
|
300 | + switch ($event_status) { |
|
301 | + case EE_Datetime::sold_out : |
|
302 | + $btn_text = __('Sold Out', 'event_espresso'); |
|
303 | + $class = 'ee-pink'; |
|
304 | + break; |
|
305 | + case EE_Datetime::expired : |
|
306 | + $btn_text = __('Event is Over', 'event_espresso'); |
|
307 | + $class = 'ee-grey'; |
|
308 | + break; |
|
309 | + case EE_Datetime::inactive : |
|
310 | + $btn_text = __('Event Not Active', 'event_espresso'); |
|
311 | + $class = 'ee-grey'; |
|
312 | + break; |
|
313 | + case EE_Datetime::cancelled : |
|
314 | + $btn_text = __('Event was Cancelled', 'event_espresso'); |
|
315 | + $class = 'ee-red'; |
|
316 | + break; |
|
317 | + case EE_Datetime::upcoming : |
|
318 | + case EE_Datetime::active : |
|
319 | + default : |
|
320 | + $btn_text = ! empty($btn_text_if_active) |
|
321 | + ? $btn_text_if_active |
|
322 | + : __('Register Now', 'event_espresso'); |
|
323 | + $class = 'ee-green'; |
|
324 | + } |
|
325 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
326 | + $btn_text = $btn_text_if_inactive; |
|
327 | + $class = 'ee-grey'; |
|
328 | + } |
|
329 | + ?> |
|
330 | 330 | <a class="ee-button ee-register-button <?php echo esc_attr($class); ?>" |
331 | 331 | href="<?php espresso_event_link_url($EVT_ID); ?>" |
332 | 332 | <?php echo EED_Events_Archive::link_target(); // already escaped |
333 | - ?> |
|
333 | + ?> |
|
334 | 334 | > |
335 | 335 | <?php echo esc_html($btn_text); ?> |
336 | 336 | </a> |
337 | 337 | <?php |
338 | - } |
|
338 | + } |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | |
342 | 342 | if (! function_exists('espresso_display_ticket_selector')) { |
343 | - /** |
|
344 | - * espresso_display_ticket_selector |
|
345 | - * whether or not to display the Ticket Selector for an event |
|
346 | - * |
|
347 | - * @param bool $EVT_ID |
|
348 | - * @return boolean |
|
349 | - * @throws EE_Error |
|
350 | - * @throws ReflectionException |
|
351 | - */ |
|
352 | - function espresso_display_ticket_selector($EVT_ID = false) |
|
353 | - { |
|
354 | - return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
355 | - } |
|
343 | + /** |
|
344 | + * espresso_display_ticket_selector |
|
345 | + * whether or not to display the Ticket Selector for an event |
|
346 | + * |
|
347 | + * @param bool $EVT_ID |
|
348 | + * @return boolean |
|
349 | + * @throws EE_Error |
|
350 | + * @throws ReflectionException |
|
351 | + */ |
|
352 | + function espresso_display_ticket_selector($EVT_ID = false) |
|
353 | + { |
|
354 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
355 | + } |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | |
359 | 359 | if (! function_exists('espresso_event_status_banner')) { |
360 | - /** |
|
361 | - * espresso_event_status |
|
362 | - * returns a banner showing the event status if it is sold out, expired, or inactive |
|
363 | - * |
|
364 | - * @param bool $EVT_ID |
|
365 | - * @return string |
|
366 | - * @throws EE_Error |
|
367 | - * @throws ReflectionException |
|
368 | - */ |
|
369 | - function espresso_event_status_banner($EVT_ID = false) |
|
370 | - { |
|
371 | - return EEH_Event_View::event_status($EVT_ID); |
|
372 | - } |
|
360 | + /** |
|
361 | + * espresso_event_status |
|
362 | + * returns a banner showing the event status if it is sold out, expired, or inactive |
|
363 | + * |
|
364 | + * @param bool $EVT_ID |
|
365 | + * @return string |
|
366 | + * @throws EE_Error |
|
367 | + * @throws ReflectionException |
|
368 | + */ |
|
369 | + function espresso_event_status_banner($EVT_ID = false) |
|
370 | + { |
|
371 | + return EEH_Event_View::event_status($EVT_ID); |
|
372 | + } |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
376 | 376 | if (! function_exists('espresso_event_status')) { |
377 | - /** |
|
378 | - * espresso_event_status |
|
379 | - * returns the event status if it is sold out, expired, or inactive |
|
380 | - * |
|
381 | - * @param int $EVT_ID |
|
382 | - * @param bool $echo |
|
383 | - * @return string |
|
384 | - * @throws EE_Error |
|
385 | - * @throws ReflectionException |
|
386 | - */ |
|
387 | - function espresso_event_status($EVT_ID = 0, $echo = true) |
|
388 | - { |
|
389 | - return EEH_Event_View::event_active_status($EVT_ID, $echo); |
|
390 | - } |
|
377 | + /** |
|
378 | + * espresso_event_status |
|
379 | + * returns the event status if it is sold out, expired, or inactive |
|
380 | + * |
|
381 | + * @param int $EVT_ID |
|
382 | + * @param bool $echo |
|
383 | + * @return string |
|
384 | + * @throws EE_Error |
|
385 | + * @throws ReflectionException |
|
386 | + */ |
|
387 | + function espresso_event_status($EVT_ID = 0, $echo = true) |
|
388 | + { |
|
389 | + return EEH_Event_View::event_active_status($EVT_ID, $echo); |
|
390 | + } |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | |
394 | 394 | if (! function_exists('espresso_event_categories')) { |
395 | - /** |
|
396 | - * espresso_event_categories |
|
397 | - * returns the terms associated with an event |
|
398 | - * |
|
399 | - * @param int $EVT_ID |
|
400 | - * @param bool $hide_uncategorized |
|
401 | - * @param bool $echo |
|
402 | - * @return string |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - */ |
|
406 | - function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = true, $echo = true) |
|
407 | - { |
|
408 | - if ($echo) { |
|
409 | - echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); // already escaped |
|
410 | - return ''; |
|
411 | - } |
|
412 | - return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
413 | - } |
|
395 | + /** |
|
396 | + * espresso_event_categories |
|
397 | + * returns the terms associated with an event |
|
398 | + * |
|
399 | + * @param int $EVT_ID |
|
400 | + * @param bool $hide_uncategorized |
|
401 | + * @param bool $echo |
|
402 | + * @return string |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + */ |
|
406 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = true, $echo = true) |
|
407 | + { |
|
408 | + if ($echo) { |
|
409 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); // already escaped |
|
410 | + return ''; |
|
411 | + } |
|
412 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
413 | + } |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | |
417 | 417 | if (! function_exists('espresso_event_tickets_available')) { |
418 | - /** |
|
419 | - * espresso_event_tickets_available |
|
420 | - * returns the ticket types available for purchase for an event |
|
421 | - * |
|
422 | - * @param int $EVT_ID |
|
423 | - * @param bool $echo |
|
424 | - * @param bool $format |
|
425 | - * @return string |
|
426 | - * @throws EE_Error |
|
427 | - * @throws ReflectionException |
|
428 | - */ |
|
429 | - function espresso_event_tickets_available($EVT_ID = 0, $echo = true, $format = true) |
|
430 | - { |
|
431 | - $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
432 | - if (is_array($tickets) && ! empty($tickets)) { |
|
433 | - // if formatting then $html will be a string, else it will be an array of ticket objects |
|
434 | - $html = |
|
435 | - $format ? '<ul id="ee-event-tickets-ul-' . esc_attr($EVT_ID) . '" class="ee-event-tickets-ul">' : []; |
|
436 | - foreach ($tickets as $ticket) { |
|
437 | - if ($ticket instanceof EE_Ticket) { |
|
438 | - if ($format) { |
|
439 | - $html .= '<li id="ee-event-tickets-li-' |
|
440 | - . esc_attr($ticket->ID()) |
|
441 | - . '" class="ee-event-tickets-li">'; |
|
442 | - $html .= esc_html($ticket->name()) . ' '; |
|
443 | - $html .= EEH_Template::format_currency( |
|
444 | - $ticket->get_ticket_total_with_taxes() |
|
445 | - ); // already escaped |
|
446 | - $html .= '</li>'; |
|
447 | - } else { |
|
448 | - $html[] = $ticket; |
|
449 | - } |
|
450 | - } |
|
451 | - } |
|
452 | - if ($format) { |
|
453 | - $html .= '</ul>'; |
|
454 | - } |
|
455 | - if ($echo && $format) { |
|
456 | - echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
457 | - return ''; |
|
458 | - } |
|
459 | - return $html; |
|
460 | - } |
|
461 | - return ''; |
|
462 | - } |
|
418 | + /** |
|
419 | + * espresso_event_tickets_available |
|
420 | + * returns the ticket types available for purchase for an event |
|
421 | + * |
|
422 | + * @param int $EVT_ID |
|
423 | + * @param bool $echo |
|
424 | + * @param bool $format |
|
425 | + * @return string |
|
426 | + * @throws EE_Error |
|
427 | + * @throws ReflectionException |
|
428 | + */ |
|
429 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = true, $format = true) |
|
430 | + { |
|
431 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
432 | + if (is_array($tickets) && ! empty($tickets)) { |
|
433 | + // if formatting then $html will be a string, else it will be an array of ticket objects |
|
434 | + $html = |
|
435 | + $format ? '<ul id="ee-event-tickets-ul-' . esc_attr($EVT_ID) . '" class="ee-event-tickets-ul">' : []; |
|
436 | + foreach ($tickets as $ticket) { |
|
437 | + if ($ticket instanceof EE_Ticket) { |
|
438 | + if ($format) { |
|
439 | + $html .= '<li id="ee-event-tickets-li-' |
|
440 | + . esc_attr($ticket->ID()) |
|
441 | + . '" class="ee-event-tickets-li">'; |
|
442 | + $html .= esc_html($ticket->name()) . ' '; |
|
443 | + $html .= EEH_Template::format_currency( |
|
444 | + $ticket->get_ticket_total_with_taxes() |
|
445 | + ); // already escaped |
|
446 | + $html .= '</li>'; |
|
447 | + } else { |
|
448 | + $html[] = $ticket; |
|
449 | + } |
|
450 | + } |
|
451 | + } |
|
452 | + if ($format) { |
|
453 | + $html .= '</ul>'; |
|
454 | + } |
|
455 | + if ($echo && $format) { |
|
456 | + echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
457 | + return ''; |
|
458 | + } |
|
459 | + return $html; |
|
460 | + } |
|
461 | + return ''; |
|
462 | + } |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | if (! function_exists('espresso_event_date_obj')) { |
466 | - /** |
|
467 | - * espresso_event_date_obj |
|
468 | - * returns the primary date object for an event |
|
469 | - * |
|
470 | - * @param bool $EVT_ID |
|
471 | - * @return EE_Datetime|null |
|
472 | - * @throws EE_Error |
|
473 | - * @throws ReflectionException |
|
474 | - */ |
|
475 | - function espresso_event_date_obj($EVT_ID = false) |
|
476 | - { |
|
477 | - return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
478 | - } |
|
466 | + /** |
|
467 | + * espresso_event_date_obj |
|
468 | + * returns the primary date object for an event |
|
469 | + * |
|
470 | + * @param bool $EVT_ID |
|
471 | + * @return EE_Datetime|null |
|
472 | + * @throws EE_Error |
|
473 | + * @throws ReflectionException |
|
474 | + */ |
|
475 | + function espresso_event_date_obj($EVT_ID = false) |
|
476 | + { |
|
477 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
478 | + } |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | |
482 | 482 | if (! function_exists('espresso_event_date')) { |
483 | - /** |
|
484 | - * espresso_event_date |
|
485 | - * returns the primary date for an event |
|
486 | - * |
|
487 | - * @param string $date_format |
|
488 | - * @param string $time_format |
|
489 | - * @param bool $EVT_ID |
|
490 | - * @param bool $echo |
|
491 | - * @return string |
|
492 | - * @throws EE_Error |
|
493 | - * @throws ReflectionException |
|
494 | - */ |
|
495 | - function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
496 | - { |
|
497 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
498 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
499 | - $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
500 | - $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
501 | - if ($echo) { |
|
502 | - echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); // already escaped |
|
503 | - return ''; |
|
504 | - } |
|
505 | - return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
506 | - |
|
507 | - } |
|
483 | + /** |
|
484 | + * espresso_event_date |
|
485 | + * returns the primary date for an event |
|
486 | + * |
|
487 | + * @param string $date_format |
|
488 | + * @param string $time_format |
|
489 | + * @param bool $EVT_ID |
|
490 | + * @param bool $echo |
|
491 | + * @return string |
|
492 | + * @throws EE_Error |
|
493 | + * @throws ReflectionException |
|
494 | + */ |
|
495 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
496 | + { |
|
497 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
498 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
499 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
500 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
501 | + if ($echo) { |
|
502 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); // already escaped |
|
503 | + return ''; |
|
504 | + } |
|
505 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
506 | + |
|
507 | + } |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
511 | 511 | if (! function_exists('espresso_list_of_event_dates')) { |
512 | - /** |
|
513 | - * espresso_list_of_event_dates |
|
514 | - * returns a unordered list of dates for an event |
|
515 | - * |
|
516 | - * @param int $EVT_ID |
|
517 | - * @param string $date_format |
|
518 | - * @param string $time_format |
|
519 | - * @param bool $echo |
|
520 | - * @param null $show_expired |
|
521 | - * @param bool $format |
|
522 | - * @param bool $add_breaks |
|
523 | - * @param null $limit |
|
524 | - * @return string |
|
525 | - * @throws EE_Error |
|
526 | - * @throws ReflectionException |
|
527 | - */ |
|
528 | - function espresso_list_of_event_dates( |
|
529 | - $EVT_ID = 0, |
|
530 | - $date_format = '', |
|
531 | - $time_format = '', |
|
532 | - $echo = true, |
|
533 | - $show_expired = null, |
|
534 | - $format = true, |
|
535 | - $add_breaks = true, |
|
536 | - $limit = null |
|
537 | - ) { |
|
538 | - $allowedtags = AllowedTags::getAllowedTags(); |
|
539 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
541 | - $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
542 | - $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
543 | - $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, false, $limit); |
|
544 | - if (! $format) { |
|
545 | - return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
546 | - } |
|
547 | - $newline = $add_breaks ? '<br />' : ''; |
|
548 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
549 | - global $post; |
|
550 | - $html = |
|
551 | - '<ul id="ee-event-datetimes-ul-' . esc_attr($post->ID) . '" class="ee-event-datetimes-ul ee-clearfix">'; |
|
552 | - foreach ($datetimes as $datetime) { |
|
553 | - if ($datetime instanceof EE_Datetime) { |
|
554 | - |
|
555 | - $datetime_name = $datetime->name(); |
|
556 | - $datetime_html = ! empty($datetime_name) |
|
557 | - ? ' |
|
512 | + /** |
|
513 | + * espresso_list_of_event_dates |
|
514 | + * returns a unordered list of dates for an event |
|
515 | + * |
|
516 | + * @param int $EVT_ID |
|
517 | + * @param string $date_format |
|
518 | + * @param string $time_format |
|
519 | + * @param bool $echo |
|
520 | + * @param null $show_expired |
|
521 | + * @param bool $format |
|
522 | + * @param bool $add_breaks |
|
523 | + * @param null $limit |
|
524 | + * @return string |
|
525 | + * @throws EE_Error |
|
526 | + * @throws ReflectionException |
|
527 | + */ |
|
528 | + function espresso_list_of_event_dates( |
|
529 | + $EVT_ID = 0, |
|
530 | + $date_format = '', |
|
531 | + $time_format = '', |
|
532 | + $echo = true, |
|
533 | + $show_expired = null, |
|
534 | + $format = true, |
|
535 | + $add_breaks = true, |
|
536 | + $limit = null |
|
537 | + ) { |
|
538 | + $allowedtags = AllowedTags::getAllowedTags(); |
|
539 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
541 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
542 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
543 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, false, $limit); |
|
544 | + if (! $format) { |
|
545 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
546 | + } |
|
547 | + $newline = $add_breaks ? '<br />' : ''; |
|
548 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
549 | + global $post; |
|
550 | + $html = |
|
551 | + '<ul id="ee-event-datetimes-ul-' . esc_attr($post->ID) . '" class="ee-event-datetimes-ul ee-clearfix">'; |
|
552 | + foreach ($datetimes as $datetime) { |
|
553 | + if ($datetime instanceof EE_Datetime) { |
|
554 | + |
|
555 | + $datetime_name = $datetime->name(); |
|
556 | + $datetime_html = ! empty($datetime_name) |
|
557 | + ? ' |
|
558 | 558 | <strong class="ee-event-datetimes-li-date-name"> |
559 | 559 | ' . esc_html($datetime_name) . ' |
560 | 560 | </strong>' . $newline |
561 | - : ''; |
|
561 | + : ''; |
|
562 | 562 | |
563 | - $datetime_description = $datetime->description(); |
|
564 | - $datetime_html .= ! empty($datetime_description) |
|
565 | - ? ' |
|
563 | + $datetime_description = $datetime->description(); |
|
564 | + $datetime_html .= ! empty($datetime_description) |
|
565 | + ? ' |
|
566 | 566 | <span class="ee-event-datetimes-li-date-desc"> |
567 | 567 | ' . wp_kses($datetime_description, $allowedtags) . ' |
568 | 568 | </span>' . $newline |
569 | - : ''; |
|
569 | + : ''; |
|
570 | 570 | |
571 | - $datetime_html .= ' |
|
571 | + $datetime_html .= ' |
|
572 | 572 | <span class="dashicons dashicons-calendar"></span> |
573 | 573 | <span class="ee-event-datetimes-li-daterange">' . $datetime->date_range($date_format) . '</span> |
574 | 574 | <br/> |
@@ -576,482 +576,482 @@ discard block |
||
576 | 576 | <span class="ee-event-datetimes-li-timerange">' . $datetime->time_range($time_format) . '</span> |
577 | 577 | '; |
578 | 578 | |
579 | - $datetime_html = apply_filters( |
|
580 | - 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
581 | - $datetime_html, |
|
582 | - $datetime |
|
583 | - ); |
|
579 | + $datetime_html = apply_filters( |
|
580 | + 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
581 | + $datetime_html, |
|
582 | + $datetime |
|
583 | + ); |
|
584 | 584 | |
585 | - $DTD_ID = esc_attr($datetime->ID()); |
|
586 | - $active_status = esc_attr(' ee-event-datetimes-li-' . $datetime->get_active_status()); |
|
585 | + $DTD_ID = esc_attr($datetime->ID()); |
|
586 | + $active_status = esc_attr(' ee-event-datetimes-li-' . $datetime->get_active_status()); |
|
587 | 587 | |
588 | - $html .= ' |
|
588 | + $html .= ' |
|
589 | 589 | <li id="ee-event-datetimes-li-' . $DTD_ID . '" class="ee-event-datetimes-li' . $active_status . '"> |
590 | 590 | ' . $datetime_html . ' |
591 | 591 | </li>'; |
592 | - } |
|
593 | - } |
|
594 | - $html .= '</ul>'; |
|
595 | - } else { |
|
596 | - $html = |
|
597 | - ' |
|
592 | + } |
|
593 | + } |
|
594 | + $html .= '</ul>'; |
|
595 | + } else { |
|
596 | + $html = |
|
597 | + ' |
|
598 | 598 | <p> |
599 | 599 | <span class="dashicons dashicons-marker pink-text"></span> |
600 | 600 | ' . esc_html__( |
601 | - 'There are no upcoming dates for this event.', |
|
602 | - 'event_espresso' |
|
603 | - ) . ' |
|
601 | + 'There are no upcoming dates for this event.', |
|
602 | + 'event_espresso' |
|
603 | + ) . ' |
|
604 | 604 | </p> |
605 | 605 | <br/>'; |
606 | - } |
|
607 | - if ($echo) { |
|
608 | - echo wp_kses($html, AllowedTags::getWithFormTags()); |
|
609 | - return ''; |
|
610 | - } |
|
611 | - return $html; |
|
612 | - } |
|
606 | + } |
|
607 | + if ($echo) { |
|
608 | + echo wp_kses($html, AllowedTags::getWithFormTags()); |
|
609 | + return ''; |
|
610 | + } |
|
611 | + return $html; |
|
612 | + } |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | |
616 | 616 | if (! function_exists('espresso_event_end_date')) { |
617 | - /** |
|
618 | - * espresso_event_end_date |
|
619 | - * returns the last date for an event |
|
620 | - * |
|
621 | - * @param string $date_format |
|
622 | - * @param string $time_format |
|
623 | - * @param bool $EVT_ID |
|
624 | - * @param bool $echo |
|
625 | - * @return string |
|
626 | - * @throws EE_Error |
|
627 | - * @throws ReflectionException |
|
628 | - */ |
|
629 | - function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
630 | - { |
|
631 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
632 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
633 | - $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
634 | - $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
635 | - if ($echo) { |
|
636 | - echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); // already escaped |
|
637 | - return ''; |
|
638 | - } |
|
639 | - return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
640 | - } |
|
617 | + /** |
|
618 | + * espresso_event_end_date |
|
619 | + * returns the last date for an event |
|
620 | + * |
|
621 | + * @param string $date_format |
|
622 | + * @param string $time_format |
|
623 | + * @param bool $EVT_ID |
|
624 | + * @param bool $echo |
|
625 | + * @return string |
|
626 | + * @throws EE_Error |
|
627 | + * @throws ReflectionException |
|
628 | + */ |
|
629 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = false, $echo = true) |
|
630 | + { |
|
631 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
632 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
633 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
634 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
635 | + if ($echo) { |
|
636 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); // already escaped |
|
637 | + return ''; |
|
638 | + } |
|
639 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
640 | + } |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | if (! function_exists('espresso_event_date_range')) { |
644 | - /** |
|
645 | - * espresso_event_date_range |
|
646 | - * returns the first and last chronologically ordered dates for an event (if different) |
|
647 | - * |
|
648 | - * @param string $date_format |
|
649 | - * @param string $time_format |
|
650 | - * @param string $single_date_format |
|
651 | - * @param string $single_time_format |
|
652 | - * @param bool $EVT_ID |
|
653 | - * @param bool $echo |
|
654 | - * @return string |
|
655 | - * @throws EE_Error |
|
656 | - * @throws ReflectionException |
|
657 | - */ |
|
658 | - function espresso_event_date_range( |
|
659 | - $date_format = '', |
|
660 | - $time_format = '', |
|
661 | - $single_date_format = '', |
|
662 | - $single_time_format = '', |
|
663 | - $EVT_ID = false, |
|
664 | - $echo = true |
|
665 | - ) { |
|
666 | - // set and filter date and time formats when a range is returned |
|
667 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
668 | - $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
669 | - // get the start and end date with NO time portion |
|
670 | - $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
671 | - $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
672 | - // now we can determine if date range spans more than one day |
|
673 | - if ($the_event_date != $the_event_end_date) { |
|
674 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
675 | - $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
676 | - $html = sprintf( |
|
677 | - /* translators: 1: first event date, 2: last event date */ |
|
678 | - esc_html__('%1$s - %2$s', 'event_espresso'), |
|
679 | - EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
680 | - EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
681 | - ); |
|
682 | - } else { |
|
683 | - // set and filter date and time formats when only a single datetime is returned |
|
684 | - $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
685 | - $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
686 | - $single_date_format = |
|
687 | - apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
688 | - $single_time_format = |
|
689 | - apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
690 | - $html = |
|
691 | - EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
692 | - } |
|
693 | - if ($echo) { |
|
694 | - echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
695 | - return ''; |
|
696 | - } |
|
697 | - return $html; |
|
698 | - } |
|
644 | + /** |
|
645 | + * espresso_event_date_range |
|
646 | + * returns the first and last chronologically ordered dates for an event (if different) |
|
647 | + * |
|
648 | + * @param string $date_format |
|
649 | + * @param string $time_format |
|
650 | + * @param string $single_date_format |
|
651 | + * @param string $single_time_format |
|
652 | + * @param bool $EVT_ID |
|
653 | + * @param bool $echo |
|
654 | + * @return string |
|
655 | + * @throws EE_Error |
|
656 | + * @throws ReflectionException |
|
657 | + */ |
|
658 | + function espresso_event_date_range( |
|
659 | + $date_format = '', |
|
660 | + $time_format = '', |
|
661 | + $single_date_format = '', |
|
662 | + $single_time_format = '', |
|
663 | + $EVT_ID = false, |
|
664 | + $echo = true |
|
665 | + ) { |
|
666 | + // set and filter date and time formats when a range is returned |
|
667 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
668 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
669 | + // get the start and end date with NO time portion |
|
670 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
671 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
672 | + // now we can determine if date range spans more than one day |
|
673 | + if ($the_event_date != $the_event_end_date) { |
|
674 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
675 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
676 | + $html = sprintf( |
|
677 | + /* translators: 1: first event date, 2: last event date */ |
|
678 | + esc_html__('%1$s - %2$s', 'event_espresso'), |
|
679 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
680 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
681 | + ); |
|
682 | + } else { |
|
683 | + // set and filter date and time formats when only a single datetime is returned |
|
684 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
685 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
686 | + $single_date_format = |
|
687 | + apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
688 | + $single_time_format = |
|
689 | + apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
690 | + $html = |
|
691 | + EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
692 | + } |
|
693 | + if ($echo) { |
|
694 | + echo wp_kses($html, AllowedTags::getAllowedTags()); |
|
695 | + return ''; |
|
696 | + } |
|
697 | + return $html; |
|
698 | + } |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | if (! function_exists('espresso_next_upcoming_datetime_obj')) { |
702 | - /** |
|
703 | - * espresso_next_upcoming_datetime_obj |
|
704 | - * returns the next upcoming datetime object for an event |
|
705 | - * |
|
706 | - * @param int $EVT_ID |
|
707 | - * @return EE_Datetime|null |
|
708 | - * @throws EE_Error |
|
709 | - */ |
|
710 | - function espresso_next_upcoming_datetime_obj($EVT_ID = 0) |
|
711 | - { |
|
712 | - return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
713 | - } |
|
702 | + /** |
|
703 | + * espresso_next_upcoming_datetime_obj |
|
704 | + * returns the next upcoming datetime object for an event |
|
705 | + * |
|
706 | + * @param int $EVT_ID |
|
707 | + * @return EE_Datetime|null |
|
708 | + * @throws EE_Error |
|
709 | + */ |
|
710 | + function espresso_next_upcoming_datetime_obj($EVT_ID = 0) |
|
711 | + { |
|
712 | + return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
713 | + } |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | if (! function_exists('espresso_next_upcoming_datetime')) { |
717 | - /** |
|
718 | - * espresso_next_upcoming_datetime |
|
719 | - * returns the start date and time for the next upcoming event. |
|
720 | - * |
|
721 | - * @param string $date_format |
|
722 | - * @param string $time_format |
|
723 | - * @param int $EVT_ID |
|
724 | - * @param bool $echo |
|
725 | - * @return string |
|
726 | - * @throws EE_Error |
|
727 | - * @throws ReflectionException |
|
728 | - */ |
|
729 | - function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) |
|
730 | - { |
|
731 | - |
|
732 | - $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
733 | - $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
734 | - |
|
735 | - $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
736 | - $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
737 | - |
|
738 | - $datetime_format = trim($date_format . ' ' . $time_format); |
|
739 | - |
|
740 | - $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
741 | - |
|
742 | - if (! $datetime instanceof EE_Datetime) { |
|
743 | - return ''; |
|
744 | - } |
|
745 | - if ($echo) { |
|
746 | - echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format)); |
|
747 | - return ''; |
|
748 | - } |
|
749 | - return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
750 | - } |
|
717 | + /** |
|
718 | + * espresso_next_upcoming_datetime |
|
719 | + * returns the start date and time for the next upcoming event. |
|
720 | + * |
|
721 | + * @param string $date_format |
|
722 | + * @param string $time_format |
|
723 | + * @param int $EVT_ID |
|
724 | + * @param bool $echo |
|
725 | + * @return string |
|
726 | + * @throws EE_Error |
|
727 | + * @throws ReflectionException |
|
728 | + */ |
|
729 | + function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) |
|
730 | + { |
|
731 | + |
|
732 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
733 | + $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
734 | + |
|
735 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
736 | + $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
737 | + |
|
738 | + $datetime_format = trim($date_format . ' ' . $time_format); |
|
739 | + |
|
740 | + $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
741 | + |
|
742 | + if (! $datetime instanceof EE_Datetime) { |
|
743 | + return ''; |
|
744 | + } |
|
745 | + if ($echo) { |
|
746 | + echo esc_html($datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format)); |
|
747 | + return ''; |
|
748 | + } |
|
749 | + return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
750 | + } |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | if (! function_exists('espresso_event_date_as_calendar_page')) { |
754 | - /** |
|
755 | - * espresso_event_date_as_calendar_page |
|
756 | - * returns the primary date for an event, stylized to appear as the page of a calendar |
|
757 | - * |
|
758 | - * @param bool $EVT_ID |
|
759 | - * @return void |
|
760 | - * @throws EE_Error |
|
761 | - * @throws ReflectionException |
|
762 | - */ |
|
763 | - function espresso_event_date_as_calendar_page($EVT_ID = false) |
|
764 | - { |
|
765 | - EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
766 | - } |
|
754 | + /** |
|
755 | + * espresso_event_date_as_calendar_page |
|
756 | + * returns the primary date for an event, stylized to appear as the page of a calendar |
|
757 | + * |
|
758 | + * @param bool $EVT_ID |
|
759 | + * @return void |
|
760 | + * @throws EE_Error |
|
761 | + * @throws ReflectionException |
|
762 | + */ |
|
763 | + function espresso_event_date_as_calendar_page($EVT_ID = false) |
|
764 | + { |
|
765 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
766 | + } |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | |
770 | 770 | if (! function_exists('espresso_event_link_url')) { |
771 | - /** |
|
772 | - * espresso_event_link_url |
|
773 | - * |
|
774 | - * @param int $EVT_ID |
|
775 | - * @param bool $echo |
|
776 | - * @return string |
|
777 | - * @throws EE_Error |
|
778 | - * @throws ReflectionException |
|
779 | - */ |
|
780 | - function espresso_event_link_url($EVT_ID = 0, $echo = true) |
|
781 | - { |
|
782 | - if ($echo) { |
|
783 | - echo EEH_Event_View::event_link_url($EVT_ID); // already escaped |
|
784 | - return ''; |
|
785 | - } |
|
786 | - return EEH_Event_View::event_link_url($EVT_ID); |
|
787 | - } |
|
771 | + /** |
|
772 | + * espresso_event_link_url |
|
773 | + * |
|
774 | + * @param int $EVT_ID |
|
775 | + * @param bool $echo |
|
776 | + * @return string |
|
777 | + * @throws EE_Error |
|
778 | + * @throws ReflectionException |
|
779 | + */ |
|
780 | + function espresso_event_link_url($EVT_ID = 0, $echo = true) |
|
781 | + { |
|
782 | + if ($echo) { |
|
783 | + echo EEH_Event_View::event_link_url($EVT_ID); // already escaped |
|
784 | + return ''; |
|
785 | + } |
|
786 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
787 | + } |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | |
791 | 791 | if (! function_exists('espresso_event_has_content_or_excerpt')) { |
792 | - /** |
|
793 | - * espresso_event_has_content_or_excerpt |
|
794 | - * |
|
795 | - * @access public |
|
796 | - * @param bool $EVT_ID |
|
797 | - * @return boolean |
|
798 | - * @throws EE_Error |
|
799 | - * @throws ReflectionException |
|
800 | - */ |
|
801 | - function espresso_event_has_content_or_excerpt($EVT_ID = false) |
|
802 | - { |
|
803 | - return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
804 | - } |
|
792 | + /** |
|
793 | + * espresso_event_has_content_or_excerpt |
|
794 | + * |
|
795 | + * @access public |
|
796 | + * @param bool $EVT_ID |
|
797 | + * @return boolean |
|
798 | + * @throws EE_Error |
|
799 | + * @throws ReflectionException |
|
800 | + */ |
|
801 | + function espresso_event_has_content_or_excerpt($EVT_ID = false) |
|
802 | + { |
|
803 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
804 | + } |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | |
808 | 808 | if (! function_exists('espresso_event_content_or_excerpt')) { |
809 | - /** |
|
810 | - * espresso_event_content_or_excerpt |
|
811 | - * |
|
812 | - * @param int $num_words |
|
813 | - * @param null $more |
|
814 | - * @param bool $echo |
|
815 | - * @return string |
|
816 | - */ |
|
817 | - function espresso_event_content_or_excerpt($num_words = 55, $more = null, $echo = true) |
|
818 | - { |
|
819 | - if ($echo) { |
|
820 | - echo EEH_Event_View::event_content_or_excerpt($num_words, $more); // already escaped |
|
821 | - return ''; |
|
822 | - } |
|
823 | - return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
824 | - } |
|
809 | + /** |
|
810 | + * espresso_event_content_or_excerpt |
|
811 | + * |
|
812 | + * @param int $num_words |
|
813 | + * @param null $more |
|
814 | + * @param bool $echo |
|
815 | + * @return string |
|
816 | + */ |
|
817 | + function espresso_event_content_or_excerpt($num_words = 55, $more = null, $echo = true) |
|
818 | + { |
|
819 | + if ($echo) { |
|
820 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); // already escaped |
|
821 | + return ''; |
|
822 | + } |
|
823 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
824 | + } |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | |
828 | 828 | if (! function_exists('espresso_event_phone')) { |
829 | - /** |
|
830 | - * espresso_event_phone |
|
831 | - * |
|
832 | - * @param int $EVT_ID |
|
833 | - * @param bool $echo |
|
834 | - * @return string |
|
835 | - * @throws EE_Error |
|
836 | - * @throws ReflectionException |
|
837 | - */ |
|
838 | - function espresso_event_phone($EVT_ID = 0, $echo = true) |
|
839 | - { |
|
840 | - if ($echo) { |
|
841 | - echo EEH_Event_View::event_phone($EVT_ID); // already escaped |
|
842 | - return ''; |
|
843 | - } |
|
844 | - return EEH_Event_View::event_phone($EVT_ID); |
|
845 | - } |
|
829 | + /** |
|
830 | + * espresso_event_phone |
|
831 | + * |
|
832 | + * @param int $EVT_ID |
|
833 | + * @param bool $echo |
|
834 | + * @return string |
|
835 | + * @throws EE_Error |
|
836 | + * @throws ReflectionException |
|
837 | + */ |
|
838 | + function espresso_event_phone($EVT_ID = 0, $echo = true) |
|
839 | + { |
|
840 | + if ($echo) { |
|
841 | + echo EEH_Event_View::event_phone($EVT_ID); // already escaped |
|
842 | + return ''; |
|
843 | + } |
|
844 | + return EEH_Event_View::event_phone($EVT_ID); |
|
845 | + } |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | |
849 | 849 | if (! function_exists('espresso_edit_event_link')) { |
850 | - /** |
|
851 | - * espresso_edit_event_link |
|
852 | - * returns a link to edit an event |
|
853 | - * |
|
854 | - * @param int $EVT_ID |
|
855 | - * @param bool $echo |
|
856 | - * @return string |
|
857 | - * @throws EE_Error |
|
858 | - * @throws ReflectionException |
|
859 | - */ |
|
860 | - function espresso_edit_event_link($EVT_ID = 0, $echo = true) |
|
861 | - { |
|
862 | - if ($echo) { |
|
863 | - echo EEH_Event_View::edit_event_link($EVT_ID); // already escaped |
|
864 | - return ''; |
|
865 | - } |
|
866 | - return EEH_Event_View::edit_event_link($EVT_ID); |
|
867 | - } |
|
850 | + /** |
|
851 | + * espresso_edit_event_link |
|
852 | + * returns a link to edit an event |
|
853 | + * |
|
854 | + * @param int $EVT_ID |
|
855 | + * @param bool $echo |
|
856 | + * @return string |
|
857 | + * @throws EE_Error |
|
858 | + * @throws ReflectionException |
|
859 | + */ |
|
860 | + function espresso_edit_event_link($EVT_ID = 0, $echo = true) |
|
861 | + { |
|
862 | + if ($echo) { |
|
863 | + echo EEH_Event_View::edit_event_link($EVT_ID); // already escaped |
|
864 | + return ''; |
|
865 | + } |
|
866 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
867 | + } |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | |
871 | 871 | if (! function_exists('espresso_organization_name')) { |
872 | - /** |
|
873 | - * espresso_organization_name |
|
874 | - * |
|
875 | - * @param bool $echo |
|
876 | - * @return string |
|
877 | - * @throws EE_Error |
|
878 | - */ |
|
879 | - function espresso_organization_name($echo = true) |
|
880 | - { |
|
881 | - if ($echo) { |
|
882 | - echo EE_Registry::instance()->CFG->organization->get_pretty('name'); // already escaped |
|
883 | - return ''; |
|
884 | - } |
|
885 | - return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
886 | - } |
|
872 | + /** |
|
873 | + * espresso_organization_name |
|
874 | + * |
|
875 | + * @param bool $echo |
|
876 | + * @return string |
|
877 | + * @throws EE_Error |
|
878 | + */ |
|
879 | + function espresso_organization_name($echo = true) |
|
880 | + { |
|
881 | + if ($echo) { |
|
882 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); // already escaped |
|
883 | + return ''; |
|
884 | + } |
|
885 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
886 | + } |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | if (! function_exists('espresso_organization_address')) { |
890 | - /** |
|
891 | - * espresso_organization_address |
|
892 | - * |
|
893 | - * @param string $type |
|
894 | - * @return string |
|
895 | - */ |
|
896 | - function espresso_organization_address($type = 'inline') |
|
897 | - { |
|
898 | - if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
899 | - $address = new EventEspresso\core\domain\entities\GenericAddress( |
|
900 | - EE_Registry::instance()->CFG->organization->address_1, |
|
901 | - EE_Registry::instance()->CFG->organization->address_2, |
|
902 | - EE_Registry::instance()->CFG->organization->city, |
|
903 | - EE_Registry::instance()->CFG->organization->STA_ID, |
|
904 | - EE_Registry::instance()->CFG->organization->zip, |
|
905 | - EE_Registry::instance()->CFG->organization->CNT_ISO |
|
906 | - ); |
|
907 | - return EEH_Address::format($address, $type); |
|
908 | - } |
|
909 | - return ''; |
|
910 | - } |
|
890 | + /** |
|
891 | + * espresso_organization_address |
|
892 | + * |
|
893 | + * @param string $type |
|
894 | + * @return string |
|
895 | + */ |
|
896 | + function espresso_organization_address($type = 'inline') |
|
897 | + { |
|
898 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
899 | + $address = new EventEspresso\core\domain\entities\GenericAddress( |
|
900 | + EE_Registry::instance()->CFG->organization->address_1, |
|
901 | + EE_Registry::instance()->CFG->organization->address_2, |
|
902 | + EE_Registry::instance()->CFG->organization->city, |
|
903 | + EE_Registry::instance()->CFG->organization->STA_ID, |
|
904 | + EE_Registry::instance()->CFG->organization->zip, |
|
905 | + EE_Registry::instance()->CFG->organization->CNT_ISO |
|
906 | + ); |
|
907 | + return EEH_Address::format($address, $type); |
|
908 | + } |
|
909 | + return ''; |
|
910 | + } |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | if (! function_exists('espresso_organization_email')) { |
914 | - /** |
|
915 | - * espresso_organization_email |
|
916 | - * |
|
917 | - * @param bool $echo |
|
918 | - * @return string |
|
919 | - * @throws EE_Error |
|
920 | - */ |
|
921 | - function espresso_organization_email($echo = true) |
|
922 | - { |
|
923 | - if ($echo) { |
|
924 | - echo EE_Registry::instance()->CFG->organization->get_pretty('email'); // already escaped |
|
925 | - return ''; |
|
926 | - } |
|
927 | - return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
928 | - } |
|
914 | + /** |
|
915 | + * espresso_organization_email |
|
916 | + * |
|
917 | + * @param bool $echo |
|
918 | + * @return string |
|
919 | + * @throws EE_Error |
|
920 | + */ |
|
921 | + function espresso_organization_email($echo = true) |
|
922 | + { |
|
923 | + if ($echo) { |
|
924 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); // already escaped |
|
925 | + return ''; |
|
926 | + } |
|
927 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
928 | + } |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | if (! function_exists('espresso_organization_logo_url')) { |
932 | - /** |
|
933 | - * espresso_organization_logo_url |
|
934 | - * |
|
935 | - * @param bool $echo |
|
936 | - * @return string |
|
937 | - * @throws EE_Error |
|
938 | - */ |
|
939 | - function espresso_organization_logo_url($echo = true) |
|
940 | - { |
|
941 | - if ($echo) { |
|
942 | - echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); // already escaped |
|
943 | - return ''; |
|
944 | - } |
|
945 | - return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
946 | - } |
|
932 | + /** |
|
933 | + * espresso_organization_logo_url |
|
934 | + * |
|
935 | + * @param bool $echo |
|
936 | + * @return string |
|
937 | + * @throws EE_Error |
|
938 | + */ |
|
939 | + function espresso_organization_logo_url($echo = true) |
|
940 | + { |
|
941 | + if ($echo) { |
|
942 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); // already escaped |
|
943 | + return ''; |
|
944 | + } |
|
945 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
946 | + } |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | if (! function_exists('espresso_organization_facebook')) { |
950 | - /** |
|
951 | - * espresso_organization_facebook |
|
952 | - * |
|
953 | - * @param bool $echo |
|
954 | - * @return string |
|
955 | - * @throws EE_Error |
|
956 | - */ |
|
957 | - function espresso_organization_facebook($echo = true) |
|
958 | - { |
|
959 | - if ($echo) { |
|
960 | - echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); // already escaped |
|
961 | - return ''; |
|
962 | - } |
|
963 | - return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
964 | - } |
|
950 | + /** |
|
951 | + * espresso_organization_facebook |
|
952 | + * |
|
953 | + * @param bool $echo |
|
954 | + * @return string |
|
955 | + * @throws EE_Error |
|
956 | + */ |
|
957 | + function espresso_organization_facebook($echo = true) |
|
958 | + { |
|
959 | + if ($echo) { |
|
960 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); // already escaped |
|
961 | + return ''; |
|
962 | + } |
|
963 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
964 | + } |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | if (! function_exists('espresso_organization_twitter')) { |
968 | - /** |
|
969 | - * espresso_organization_twitter |
|
970 | - * |
|
971 | - * @param bool $echo |
|
972 | - * @return string |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - function espresso_organization_twitter($echo = true) |
|
976 | - { |
|
977 | - if ($echo) { |
|
978 | - echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); // already escaped |
|
979 | - return ''; |
|
980 | - } |
|
981 | - return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
982 | - } |
|
968 | + /** |
|
969 | + * espresso_organization_twitter |
|
970 | + * |
|
971 | + * @param bool $echo |
|
972 | + * @return string |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + function espresso_organization_twitter($echo = true) |
|
976 | + { |
|
977 | + if ($echo) { |
|
978 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); // already escaped |
|
979 | + return ''; |
|
980 | + } |
|
981 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
982 | + } |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | if (! function_exists('espresso_organization_linkedin')) { |
986 | - /** |
|
987 | - * espresso_organization_linkedin |
|
988 | - * |
|
989 | - * @param bool $echo |
|
990 | - * @return string |
|
991 | - * @throws EE_Error |
|
992 | - */ |
|
993 | - function espresso_organization_linkedin($echo = true) |
|
994 | - { |
|
995 | - if ($echo) { |
|
996 | - echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); // already escaped |
|
997 | - return ''; |
|
998 | - } |
|
999 | - return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
1000 | - } |
|
986 | + /** |
|
987 | + * espresso_organization_linkedin |
|
988 | + * |
|
989 | + * @param bool $echo |
|
990 | + * @return string |
|
991 | + * @throws EE_Error |
|
992 | + */ |
|
993 | + function espresso_organization_linkedin($echo = true) |
|
994 | + { |
|
995 | + if ($echo) { |
|
996 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); // already escaped |
|
997 | + return ''; |
|
998 | + } |
|
999 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
1000 | + } |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | if (! function_exists('espresso_organization_pinterest')) { |
1004 | - /** |
|
1005 | - * espresso_organization_pinterest |
|
1006 | - * |
|
1007 | - * @param bool $echo |
|
1008 | - * @return string |
|
1009 | - * @throws EE_Error |
|
1010 | - */ |
|
1011 | - function espresso_organization_pinterest($echo = true) |
|
1012 | - { |
|
1013 | - if ($echo) { |
|
1014 | - echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); // already escaped |
|
1015 | - return ''; |
|
1016 | - } |
|
1017 | - return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
1018 | - } |
|
1004 | + /** |
|
1005 | + * espresso_organization_pinterest |
|
1006 | + * |
|
1007 | + * @param bool $echo |
|
1008 | + * @return string |
|
1009 | + * @throws EE_Error |
|
1010 | + */ |
|
1011 | + function espresso_organization_pinterest($echo = true) |
|
1012 | + { |
|
1013 | + if ($echo) { |
|
1014 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); // already escaped |
|
1015 | + return ''; |
|
1016 | + } |
|
1017 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
1018 | + } |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | if (! function_exists('espresso_organization_google')) { |
1022 | - /** |
|
1023 | - * espresso_organization_google |
|
1024 | - * |
|
1025 | - * @param bool $echo |
|
1026 | - * @return string |
|
1027 | - * @throws EE_Error |
|
1028 | - */ |
|
1029 | - function espresso_organization_google($echo = true) |
|
1030 | - { |
|
1031 | - if ($echo) { |
|
1032 | - echo EE_Registry::instance()->CFG->organization->get_pretty('google'); // already escaped |
|
1033 | - return ''; |
|
1034 | - } |
|
1035 | - return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
1036 | - } |
|
1022 | + /** |
|
1023 | + * espresso_organization_google |
|
1024 | + * |
|
1025 | + * @param bool $echo |
|
1026 | + * @return string |
|
1027 | + * @throws EE_Error |
|
1028 | + */ |
|
1029 | + function espresso_organization_google($echo = true) |
|
1030 | + { |
|
1031 | + if ($echo) { |
|
1032 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); // already escaped |
|
1033 | + return ''; |
|
1034 | + } |
|
1035 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
1036 | + } |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | if (! function_exists('espresso_organization_instagram')) { |
1040 | - /** |
|
1041 | - * espresso_organization_instagram |
|
1042 | - * |
|
1043 | - * @param bool $echo |
|
1044 | - * @return string |
|
1045 | - * @throws EE_Error |
|
1046 | - */ |
|
1047 | - function espresso_organization_instagram($echo = true) |
|
1048 | - { |
|
1049 | - if ($echo) { |
|
1050 | - echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); // already escaped |
|
1051 | - return ''; |
|
1052 | - } |
|
1053 | - return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
1054 | - } |
|
1040 | + /** |
|
1041 | + * espresso_organization_instagram |
|
1042 | + * |
|
1043 | + * @param bool $echo |
|
1044 | + * @return string |
|
1045 | + * @throws EE_Error |
|
1046 | + */ |
|
1047 | + function espresso_organization_instagram($echo = true) |
|
1048 | + { |
|
1049 | + if ($echo) { |
|
1050 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); // already escaped |
|
1051 | + return ''; |
|
1052 | + } |
|
1053 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
1054 | + } |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | |
@@ -1059,345 +1059,345 @@ discard block |
||
1059 | 1059 | |
1060 | 1060 | |
1061 | 1061 | if (! function_exists('espresso_event_venues')) { |
1062 | - /** |
|
1063 | - * espresso_event_venues |
|
1064 | - * |
|
1065 | - * @return array all venues related to an event |
|
1066 | - * @throws EE_Error |
|
1067 | - * @throws ReflectionException |
|
1068 | - */ |
|
1069 | - function espresso_event_venues() |
|
1070 | - { |
|
1071 | - return EEH_Venue_View::get_event_venues(); |
|
1072 | - } |
|
1062 | + /** |
|
1063 | + * espresso_event_venues |
|
1064 | + * |
|
1065 | + * @return array all venues related to an event |
|
1066 | + * @throws EE_Error |
|
1067 | + * @throws ReflectionException |
|
1068 | + */ |
|
1069 | + function espresso_event_venues() |
|
1070 | + { |
|
1071 | + return EEH_Venue_View::get_event_venues(); |
|
1072 | + } |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | |
1076 | 1076 | if (! function_exists('espresso_venue_id')) { |
1077 | - /** |
|
1078 | - * espresso_venue_name |
|
1079 | - * |
|
1080 | - * @access public |
|
1081 | - * @param int $EVT_ID |
|
1082 | - * @return string |
|
1083 | - * @throws EE_Error |
|
1084 | - * @throws ReflectionException |
|
1085 | - */ |
|
1086 | - function espresso_venue_id($EVT_ID = 0) |
|
1087 | - { |
|
1088 | - $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
1089 | - return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
1090 | - } |
|
1077 | + /** |
|
1078 | + * espresso_venue_name |
|
1079 | + * |
|
1080 | + * @access public |
|
1081 | + * @param int $EVT_ID |
|
1082 | + * @return string |
|
1083 | + * @throws EE_Error |
|
1084 | + * @throws ReflectionException |
|
1085 | + */ |
|
1086 | + function espresso_venue_id($EVT_ID = 0) |
|
1087 | + { |
|
1088 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
1089 | + return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
1090 | + } |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
1094 | 1094 | if (! function_exists('espresso_is_venue_private')) { |
1095 | - /** |
|
1096 | - * Return whether a venue is private or not. |
|
1097 | - * |
|
1098 | - * @param int $VNU_ID optional, the venue id to check. |
|
1099 | - * |
|
1100 | - * @return bool | null |
|
1101 | - * @throws EE_Error |
|
1102 | - * @throws ReflectionException |
|
1103 | - * @see EEH_Venue_View::get_venue() for more info on expected return results. |
|
1104 | - */ |
|
1105 | - function espresso_is_venue_private($VNU_ID = 0) |
|
1106 | - { |
|
1107 | - return EEH_Venue_View::is_venue_private($VNU_ID); |
|
1108 | - } |
|
1095 | + /** |
|
1096 | + * Return whether a venue is private or not. |
|
1097 | + * |
|
1098 | + * @param int $VNU_ID optional, the venue id to check. |
|
1099 | + * |
|
1100 | + * @return bool | null |
|
1101 | + * @throws EE_Error |
|
1102 | + * @throws ReflectionException |
|
1103 | + * @see EEH_Venue_View::get_venue() for more info on expected return results. |
|
1104 | + */ |
|
1105 | + function espresso_is_venue_private($VNU_ID = 0) |
|
1106 | + { |
|
1107 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
1108 | + } |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | |
1112 | 1112 | if (! function_exists('espresso_venue_is_password_protected')) { |
1113 | - /** |
|
1114 | - * returns true or false if a venue is password protected or not |
|
1115 | - * |
|
1116 | - * @param int $VNU_ID optional, the venue id to check. |
|
1117 | - * @return bool |
|
1118 | - * @throws EE_Error |
|
1119 | - * @throws ReflectionException |
|
1120 | - */ |
|
1121 | - function espresso_venue_is_password_protected($VNU_ID = 0) |
|
1122 | - { |
|
1123 | - EE_Registry::instance()->load_helper('Venue_View'); |
|
1124 | - return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
1125 | - } |
|
1113 | + /** |
|
1114 | + * returns true or false if a venue is password protected or not |
|
1115 | + * |
|
1116 | + * @param int $VNU_ID optional, the venue id to check. |
|
1117 | + * @return bool |
|
1118 | + * @throws EE_Error |
|
1119 | + * @throws ReflectionException |
|
1120 | + */ |
|
1121 | + function espresso_venue_is_password_protected($VNU_ID = 0) |
|
1122 | + { |
|
1123 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
1124 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
1125 | + } |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | |
1129 | 1129 | if (! function_exists('espresso_password_protected_venue_form')) { |
1130 | - /** |
|
1131 | - * Returns a password form if venue is password protected. |
|
1132 | - * |
|
1133 | - * @param int $VNU_ID optional, the venue id to check. |
|
1134 | - * @return string |
|
1135 | - * @throws EE_Error |
|
1136 | - * @throws ReflectionException |
|
1137 | - */ |
|
1138 | - function espresso_password_protected_venue_form($VNU_ID = 0) |
|
1139 | - { |
|
1140 | - EE_Registry::instance()->load_helper('Venue_View'); |
|
1141 | - return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
1142 | - } |
|
1130 | + /** |
|
1131 | + * Returns a password form if venue is password protected. |
|
1132 | + * |
|
1133 | + * @param int $VNU_ID optional, the venue id to check. |
|
1134 | + * @return string |
|
1135 | + * @throws EE_Error |
|
1136 | + * @throws ReflectionException |
|
1137 | + */ |
|
1138 | + function espresso_password_protected_venue_form($VNU_ID = 0) |
|
1139 | + { |
|
1140 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
1141 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
1142 | + } |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | |
1146 | 1146 | if (! function_exists('espresso_venue_name')) { |
1147 | - /** |
|
1148 | - * espresso_venue_name |
|
1149 | - * |
|
1150 | - * @access public |
|
1151 | - * @param int $VNU_ID |
|
1152 | - * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
1153 | - * @param bool $echo |
|
1154 | - * @return string |
|
1155 | - * @throws EE_Error |
|
1156 | - * @throws ReflectionException |
|
1157 | - */ |
|
1158 | - function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = true) |
|
1159 | - { |
|
1160 | - if ($echo) { |
|
1161 | - echo EEH_Venue_View::venue_name($link_to, $VNU_ID); // already escaped |
|
1162 | - return ''; |
|
1163 | - } |
|
1164 | - return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
1165 | - } |
|
1147 | + /** |
|
1148 | + * espresso_venue_name |
|
1149 | + * |
|
1150 | + * @access public |
|
1151 | + * @param int $VNU_ID |
|
1152 | + * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
1153 | + * @param bool $echo |
|
1154 | + * @return string |
|
1155 | + * @throws EE_Error |
|
1156 | + * @throws ReflectionException |
|
1157 | + */ |
|
1158 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = true) |
|
1159 | + { |
|
1160 | + if ($echo) { |
|
1161 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); // already escaped |
|
1162 | + return ''; |
|
1163 | + } |
|
1164 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
1165 | + } |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | 1168 | |
1169 | 1169 | if (! function_exists('espresso_venue_link')) { |
1170 | - /** |
|
1171 | - * espresso_venue_link |
|
1172 | - * |
|
1173 | - * @access public |
|
1174 | - * @param int $VNU_ID |
|
1175 | - * @param string $text |
|
1176 | - * @return string |
|
1177 | - * @throws EE_Error |
|
1178 | - * @throws ReflectionException |
|
1179 | - */ |
|
1180 | - function espresso_venue_link($VNU_ID = 0, $text = '') |
|
1181 | - { |
|
1182 | - return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
1183 | - } |
|
1170 | + /** |
|
1171 | + * espresso_venue_link |
|
1172 | + * |
|
1173 | + * @access public |
|
1174 | + * @param int $VNU_ID |
|
1175 | + * @param string $text |
|
1176 | + * @return string |
|
1177 | + * @throws EE_Error |
|
1178 | + * @throws ReflectionException |
|
1179 | + */ |
|
1180 | + function espresso_venue_link($VNU_ID = 0, $text = '') |
|
1181 | + { |
|
1182 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
1183 | + } |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | |
1187 | 1187 | if (! function_exists('espresso_venue_description')) { |
1188 | - /** |
|
1189 | - * espresso_venue_description |
|
1190 | - * |
|
1191 | - * @access public |
|
1192 | - * @param bool $VNU_ID |
|
1193 | - * @param bool $echo |
|
1194 | - * @return string |
|
1195 | - * @throws EE_Error |
|
1196 | - * @throws ReflectionException |
|
1197 | - */ |
|
1198 | - function espresso_venue_description($VNU_ID = false, $echo = true) |
|
1199 | - { |
|
1200 | - if ($echo) { |
|
1201 | - echo EEH_Venue_View::venue_description($VNU_ID); // already escaped |
|
1202 | - return ''; |
|
1203 | - } |
|
1204 | - return EEH_Venue_View::venue_description($VNU_ID); |
|
1205 | - } |
|
1188 | + /** |
|
1189 | + * espresso_venue_description |
|
1190 | + * |
|
1191 | + * @access public |
|
1192 | + * @param bool $VNU_ID |
|
1193 | + * @param bool $echo |
|
1194 | + * @return string |
|
1195 | + * @throws EE_Error |
|
1196 | + * @throws ReflectionException |
|
1197 | + */ |
|
1198 | + function espresso_venue_description($VNU_ID = false, $echo = true) |
|
1199 | + { |
|
1200 | + if ($echo) { |
|
1201 | + echo EEH_Venue_View::venue_description($VNU_ID); // already escaped |
|
1202 | + return ''; |
|
1203 | + } |
|
1204 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
1205 | + } |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | |
1209 | 1209 | if (! function_exists('espresso_venue_excerpt')) { |
1210 | - /** |
|
1211 | - * espresso_venue_excerpt |
|
1212 | - * |
|
1213 | - * @access public |
|
1214 | - * @param int $VNU_ID |
|
1215 | - * @param bool $echo |
|
1216 | - * @return string |
|
1217 | - * @throws EE_Error |
|
1218 | - * @throws ReflectionException |
|
1219 | - */ |
|
1220 | - function espresso_venue_excerpt($VNU_ID = 0, $echo = true) |
|
1221 | - { |
|
1222 | - if ($echo) { |
|
1223 | - echo EEH_Venue_View::venue_excerpt($VNU_ID); // already escaped |
|
1224 | - return ''; |
|
1225 | - } |
|
1226 | - return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1227 | - } |
|
1210 | + /** |
|
1211 | + * espresso_venue_excerpt |
|
1212 | + * |
|
1213 | + * @access public |
|
1214 | + * @param int $VNU_ID |
|
1215 | + * @param bool $echo |
|
1216 | + * @return string |
|
1217 | + * @throws EE_Error |
|
1218 | + * @throws ReflectionException |
|
1219 | + */ |
|
1220 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = true) |
|
1221 | + { |
|
1222 | + if ($echo) { |
|
1223 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); // already escaped |
|
1224 | + return ''; |
|
1225 | + } |
|
1226 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1227 | + } |
|
1228 | 1228 | } |
1229 | 1229 | |
1230 | 1230 | |
1231 | 1231 | if (! function_exists('espresso_venue_categories')) { |
1232 | - /** |
|
1233 | - * espresso_venue_categories |
|
1234 | - * returns the terms associated with a venue |
|
1235 | - * |
|
1236 | - * @param int $VNU_ID |
|
1237 | - * @param bool $hide_uncategorized |
|
1238 | - * @param bool $echo |
|
1239 | - * @return string |
|
1240 | - * @throws EE_Error |
|
1241 | - * @throws ReflectionException |
|
1242 | - */ |
|
1243 | - function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = true, $echo = true) |
|
1244 | - { |
|
1245 | - if ($echo) { |
|
1246 | - echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); // already escaped |
|
1247 | - return ''; |
|
1248 | - } |
|
1249 | - return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1250 | - } |
|
1232 | + /** |
|
1233 | + * espresso_venue_categories |
|
1234 | + * returns the terms associated with a venue |
|
1235 | + * |
|
1236 | + * @param int $VNU_ID |
|
1237 | + * @param bool $hide_uncategorized |
|
1238 | + * @param bool $echo |
|
1239 | + * @return string |
|
1240 | + * @throws EE_Error |
|
1241 | + * @throws ReflectionException |
|
1242 | + */ |
|
1243 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = true, $echo = true) |
|
1244 | + { |
|
1245 | + if ($echo) { |
|
1246 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); // already escaped |
|
1247 | + return ''; |
|
1248 | + } |
|
1249 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1250 | + } |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | |
1254 | 1254 | if (! function_exists('espresso_venue_address')) { |
1255 | - /** |
|
1256 | - * espresso_venue_address |
|
1257 | - * returns a formatted block of html for displaying a venue's address |
|
1258 | - * |
|
1259 | - * @param string $type 'inline' or 'multiline' |
|
1260 | - * @param int $VNU_ID |
|
1261 | - * @param bool $echo |
|
1262 | - * @return string |
|
1263 | - * @throws EE_Error |
|
1264 | - * @throws ReflectionException |
|
1265 | - */ |
|
1266 | - function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1267 | - { |
|
1268 | - if ($echo) { |
|
1269 | - echo EEH_Venue_View::venue_address($type, $VNU_ID); // already escaped |
|
1270 | - return ''; |
|
1271 | - } |
|
1272 | - return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1273 | - } |
|
1255 | + /** |
|
1256 | + * espresso_venue_address |
|
1257 | + * returns a formatted block of html for displaying a venue's address |
|
1258 | + * |
|
1259 | + * @param string $type 'inline' or 'multiline' |
|
1260 | + * @param int $VNU_ID |
|
1261 | + * @param bool $echo |
|
1262 | + * @return string |
|
1263 | + * @throws EE_Error |
|
1264 | + * @throws ReflectionException |
|
1265 | + */ |
|
1266 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1267 | + { |
|
1268 | + if ($echo) { |
|
1269 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); // already escaped |
|
1270 | + return ''; |
|
1271 | + } |
|
1272 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1273 | + } |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 | |
1277 | 1277 | if (! function_exists('espresso_venue_raw_address')) { |
1278 | - /** |
|
1279 | - * espresso_venue_address |
|
1280 | - * returns an UN-formatted string containing a venue's address |
|
1281 | - * |
|
1282 | - * @param string $type 'inline' or 'multiline' |
|
1283 | - * @param int $VNU_ID |
|
1284 | - * @param bool $echo |
|
1285 | - * @return string |
|
1286 | - * @throws EE_Error |
|
1287 | - * @throws ReflectionException |
|
1288 | - */ |
|
1289 | - function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1290 | - { |
|
1291 | - if ($echo) { |
|
1292 | - echo EEH_Venue_View::venue_address($type, $VNU_ID, false, false); // already escaped |
|
1293 | - return ''; |
|
1294 | - } |
|
1295 | - return EEH_Venue_View::venue_address($type, $VNU_ID, false, false); |
|
1296 | - } |
|
1278 | + /** |
|
1279 | + * espresso_venue_address |
|
1280 | + * returns an UN-formatted string containing a venue's address |
|
1281 | + * |
|
1282 | + * @param string $type 'inline' or 'multiline' |
|
1283 | + * @param int $VNU_ID |
|
1284 | + * @param bool $echo |
|
1285 | + * @return string |
|
1286 | + * @throws EE_Error |
|
1287 | + * @throws ReflectionException |
|
1288 | + */ |
|
1289 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = true) |
|
1290 | + { |
|
1291 | + if ($echo) { |
|
1292 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, false, false); // already escaped |
|
1293 | + return ''; |
|
1294 | + } |
|
1295 | + return EEH_Venue_View::venue_address($type, $VNU_ID, false, false); |
|
1296 | + } |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | |
1300 | 1300 | if (! function_exists('espresso_venue_has_address')) { |
1301 | - /** |
|
1302 | - * espresso_venue_has_address |
|
1303 | - * returns TRUE or FALSE if a Venue has address information |
|
1304 | - * |
|
1305 | - * @param int $VNU_ID |
|
1306 | - * @return bool |
|
1307 | - * @throws EE_Error |
|
1308 | - * @throws ReflectionException |
|
1309 | - */ |
|
1310 | - function espresso_venue_has_address($VNU_ID = 0) |
|
1311 | - { |
|
1312 | - return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1313 | - } |
|
1301 | + /** |
|
1302 | + * espresso_venue_has_address |
|
1303 | + * returns TRUE or FALSE if a Venue has address information |
|
1304 | + * |
|
1305 | + * @param int $VNU_ID |
|
1306 | + * @return bool |
|
1307 | + * @throws EE_Error |
|
1308 | + * @throws ReflectionException |
|
1309 | + */ |
|
1310 | + function espresso_venue_has_address($VNU_ID = 0) |
|
1311 | + { |
|
1312 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1313 | + } |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | |
1317 | 1317 | if (! function_exists('espresso_venue_gmap')) { |
1318 | - /** |
|
1319 | - * espresso_venue_gmap |
|
1320 | - * returns a google map for the venue address |
|
1321 | - * |
|
1322 | - * @param int $VNU_ID |
|
1323 | - * @param bool $map_ID |
|
1324 | - * @param array $gmap |
|
1325 | - * @param bool $echo |
|
1326 | - * @return string |
|
1327 | - * @throws EE_Error |
|
1328 | - * @throws ReflectionException |
|
1329 | - */ |
|
1330 | - function espresso_venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [], $echo = true) |
|
1331 | - { |
|
1332 | - if ($echo) { |
|
1333 | - echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); // already escaped |
|
1334 | - return ''; |
|
1335 | - } |
|
1336 | - return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1337 | - } |
|
1318 | + /** |
|
1319 | + * espresso_venue_gmap |
|
1320 | + * returns a google map for the venue address |
|
1321 | + * |
|
1322 | + * @param int $VNU_ID |
|
1323 | + * @param bool $map_ID |
|
1324 | + * @param array $gmap |
|
1325 | + * @param bool $echo |
|
1326 | + * @return string |
|
1327 | + * @throws EE_Error |
|
1328 | + * @throws ReflectionException |
|
1329 | + */ |
|
1330 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = [], $echo = true) |
|
1331 | + { |
|
1332 | + if ($echo) { |
|
1333 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); // already escaped |
|
1334 | + return ''; |
|
1335 | + } |
|
1336 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1337 | + } |
|
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | |
1341 | 1341 | if (! function_exists('espresso_venue_phone')) { |
1342 | - /** |
|
1343 | - * espresso_venue_phone |
|
1344 | - * |
|
1345 | - * @param int $VNU_ID |
|
1346 | - * @param bool $echo |
|
1347 | - * @return string |
|
1348 | - * @throws EE_Error |
|
1349 | - * @throws ReflectionException |
|
1350 | - */ |
|
1351 | - function espresso_venue_phone($VNU_ID = 0, $echo = true) |
|
1352 | - { |
|
1353 | - if ($echo) { |
|
1354 | - echo EEH_Venue_View::venue_phone($VNU_ID); // already escaped |
|
1355 | - return ''; |
|
1356 | - } |
|
1357 | - return EEH_Venue_View::venue_phone($VNU_ID); |
|
1358 | - } |
|
1342 | + /** |
|
1343 | + * espresso_venue_phone |
|
1344 | + * |
|
1345 | + * @param int $VNU_ID |
|
1346 | + * @param bool $echo |
|
1347 | + * @return string |
|
1348 | + * @throws EE_Error |
|
1349 | + * @throws ReflectionException |
|
1350 | + */ |
|
1351 | + function espresso_venue_phone($VNU_ID = 0, $echo = true) |
|
1352 | + { |
|
1353 | + if ($echo) { |
|
1354 | + echo EEH_Venue_View::venue_phone($VNU_ID); // already escaped |
|
1355 | + return ''; |
|
1356 | + } |
|
1357 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
1358 | + } |
|
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | |
1362 | 1362 | if (! function_exists('espresso_venue_website')) { |
1363 | - /** |
|
1364 | - * espresso_venue_website |
|
1365 | - * |
|
1366 | - * @param int $VNU_ID |
|
1367 | - * @param bool $echo |
|
1368 | - * @return string |
|
1369 | - * @throws EE_Error |
|
1370 | - * @throws ReflectionException |
|
1371 | - */ |
|
1372 | - function espresso_venue_website($VNU_ID = 0, $echo = true) |
|
1373 | - { |
|
1374 | - if ($echo) { |
|
1375 | - echo EEH_Venue_View::venue_website_link($VNU_ID); // already escaped |
|
1376 | - return ''; |
|
1377 | - } |
|
1378 | - return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1379 | - } |
|
1363 | + /** |
|
1364 | + * espresso_venue_website |
|
1365 | + * |
|
1366 | + * @param int $VNU_ID |
|
1367 | + * @param bool $echo |
|
1368 | + * @return string |
|
1369 | + * @throws EE_Error |
|
1370 | + * @throws ReflectionException |
|
1371 | + */ |
|
1372 | + function espresso_venue_website($VNU_ID = 0, $echo = true) |
|
1373 | + { |
|
1374 | + if ($echo) { |
|
1375 | + echo EEH_Venue_View::venue_website_link($VNU_ID); // already escaped |
|
1376 | + return ''; |
|
1377 | + } |
|
1378 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1379 | + } |
|
1380 | 1380 | } |
1381 | 1381 | |
1382 | 1382 | |
1383 | 1383 | if (! function_exists('espresso_edit_venue_link')) { |
1384 | - /** |
|
1385 | - * espresso_edit_venue_link |
|
1386 | - * |
|
1387 | - * @param int $VNU_ID |
|
1388 | - * @param bool $echo |
|
1389 | - * @return string |
|
1390 | - * @throws EE_Error |
|
1391 | - * @throws ReflectionException |
|
1392 | - */ |
|
1393 | - function espresso_edit_venue_link($VNU_ID = 0, $echo = true) |
|
1394 | - { |
|
1395 | - if ($echo) { |
|
1396 | - echo EEH_Venue_View::edit_venue_link($VNU_ID); // already escaped |
|
1397 | - return ''; |
|
1398 | - } |
|
1399 | - return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1400 | - } |
|
1384 | + /** |
|
1385 | + * espresso_edit_venue_link |
|
1386 | + * |
|
1387 | + * @param int $VNU_ID |
|
1388 | + * @param bool $echo |
|
1389 | + * @return string |
|
1390 | + * @throws EE_Error |
|
1391 | + * @throws ReflectionException |
|
1392 | + */ |
|
1393 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = true) |
|
1394 | + { |
|
1395 | + if ($echo) { |
|
1396 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); // already escaped |
|
1397 | + return ''; |
|
1398 | + } |
|
1399 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1400 | + } |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | 1403 |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.015'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.015'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |