@@ -15,103 +15,103 @@ |
||
| 15 | 15 | class EE_Register_Data_Migration_Scripts implements EEI_Plugin_API |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Holds values for registered DMSs |
|
| 20 | - * |
|
| 21 | - * @var array[][] |
|
| 22 | - */ |
|
| 23 | - protected static $_settings = array(); |
|
| 18 | + /** |
|
| 19 | + * Holds values for registered DMSs |
|
| 20 | + * |
|
| 21 | + * @var array[][] |
|
| 22 | + */ |
|
| 23 | + protected static $_settings = array(); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Method for registering new Data Migration Scripts |
|
| 28 | - * |
|
| 29 | - * @since 4.3.0 |
|
| 30 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 31 | - * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 32 | - * @param array $setup_args { |
|
| 33 | - * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
| 34 | - * } |
|
| 35 | - * @throws EE_Error |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 39 | - { |
|
| 40 | - // required fields MUST be present, so let's make sure they are. |
|
| 41 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
| 42 | - throw new EE_Error( |
|
| 43 | - esc_html__( |
|
| 44 | - 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
| 45 | - 'event_espresso' |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - // make sure we don't register twice |
|
| 50 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - // make sure this was called in the right place! |
|
| 54 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 55 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 56 | - ) { |
|
| 57 | - EE_Error::doing_it_wrong( |
|
| 58 | - __METHOD__, |
|
| 59 | - esc_html__( |
|
| 60 | - 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
| 61 | - 'event_espresso' |
|
| 62 | - ), |
|
| 63 | - '4.3.0' |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - // setup $_settings array from incoming values. |
|
| 67 | - self::$_settings[ $addon_name ] = array( |
|
| 68 | - 'dms_paths' => (array) $setup_args['dms_paths'], |
|
| 69 | - ); |
|
| 70 | - // setup DMS |
|
| 71 | - $filters_set = has_filter( |
|
| 72 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 73 | - ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
| 74 | - ); |
|
| 75 | - if (! $filters_set) { |
|
| 76 | - add_filter( |
|
| 77 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 78 | - ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - } |
|
| 26 | + /** |
|
| 27 | + * Method for registering new Data Migration Scripts |
|
| 28 | + * |
|
| 29 | + * @since 4.3.0 |
|
| 30 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 31 | + * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 32 | + * @param array $setup_args { |
|
| 33 | + * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
| 34 | + * } |
|
| 35 | + * @throws EE_Error |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 39 | + { |
|
| 40 | + // required fields MUST be present, so let's make sure they are. |
|
| 41 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
| 42 | + throw new EE_Error( |
|
| 43 | + esc_html__( |
|
| 44 | + 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
| 45 | + 'event_espresso' |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + // make sure we don't register twice |
|
| 50 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + // make sure this was called in the right place! |
|
| 54 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 55 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 56 | + ) { |
|
| 57 | + EE_Error::doing_it_wrong( |
|
| 58 | + __METHOD__, |
|
| 59 | + esc_html__( |
|
| 60 | + 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
| 61 | + 'event_espresso' |
|
| 62 | + ), |
|
| 63 | + '4.3.0' |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + // setup $_settings array from incoming values. |
|
| 67 | + self::$_settings[ $addon_name ] = array( |
|
| 68 | + 'dms_paths' => (array) $setup_args['dms_paths'], |
|
| 69 | + ); |
|
| 70 | + // setup DMS |
|
| 71 | + $filters_set = has_filter( |
|
| 72 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 73 | + ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
| 74 | + ); |
|
| 75 | + if (! $filters_set) { |
|
| 76 | + add_filter( |
|
| 77 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 78 | + ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @param array $dms_paths |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - public static function add_data_migration_script_folders($dms_paths = array()) |
|
| 89 | - { |
|
| 90 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 91 | - $wildcards = 0; |
|
| 92 | - foreach ($settings['dms_paths'] as $dms_path) { |
|
| 93 | - // since we are using the addon name for the array key |
|
| 94 | - // we need to ensure that the key is unique, |
|
| 95 | - // so if for some reason an addon has multiple dms paths, |
|
| 96 | - // we append one or more * to the classname |
|
| 97 | - // which will get stripped out later on |
|
| 98 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 99 | - $wildcards++; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - return $dms_paths; |
|
| 103 | - } |
|
| 84 | + /** |
|
| 85 | + * @param array $dms_paths |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + public static function add_data_migration_script_folders($dms_paths = array()) |
|
| 89 | + { |
|
| 90 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 91 | + $wildcards = 0; |
|
| 92 | + foreach ($settings['dms_paths'] as $dms_path) { |
|
| 93 | + // since we are using the addon name for the array key |
|
| 94 | + // we need to ensure that the key is unique, |
|
| 95 | + // so if for some reason an addon has multiple dms paths, |
|
| 96 | + // we append one or more * to the classname |
|
| 97 | + // which will get stripped out later on |
|
| 98 | + $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 99 | + $wildcards++; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + return $dms_paths; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
| 108 | - * |
|
| 109 | - * @since 4.3.0 |
|
| 110 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 111 | - * @return void |
|
| 112 | - */ |
|
| 113 | - public static function deregister($addon_name = '') |
|
| 114 | - { |
|
| 115 | - unset(self::$_settings[ $addon_name ]); |
|
| 116 | - } |
|
| 106 | + /** |
|
| 107 | + * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
| 108 | + * |
|
| 109 | + * @since 4.3.0 |
|
| 110 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 111 | + * @return void |
|
| 112 | + */ |
|
| 113 | + public static function deregister($addon_name = '') |
|
| 114 | + { |
|
| 115 | + unset(self::$_settings[ $addon_name ]); |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | ); |
| 48 | 48 | } |
| 49 | 49 | // make sure we don't register twice |
| 50 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 50 | + if (isset(self::$_settings[$addon_name])) { |
|
| 51 | 51 | return; |
| 52 | 52 | } |
| 53 | 53 | // make sure this was called in the right place! |
| 54 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 54 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 55 | 55 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
| 56 | 56 | ) { |
| 57 | 57 | EE_Error::doing_it_wrong( |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | ); |
| 65 | 65 | } |
| 66 | 66 | // setup $_settings array from incoming values. |
| 67 | - self::$_settings[ $addon_name ] = array( |
|
| 67 | + self::$_settings[$addon_name] = array( |
|
| 68 | 68 | 'dms_paths' => (array) $setup_args['dms_paths'], |
| 69 | 69 | ); |
| 70 | 70 | // setup DMS |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
| 73 | 73 | ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
| 74 | 74 | ); |
| 75 | - if (! $filters_set) { |
|
| 75 | + if ( ! $filters_set) { |
|
| 76 | 76 | add_filter( |
| 77 | 77 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
| 78 | 78 | ['EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders'] |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | // so if for some reason an addon has multiple dms paths, |
| 96 | 96 | // we append one or more * to the classname |
| 97 | 97 | // which will get stripped out later on |
| 98 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 98 | + $dms_paths[$addon_name.str_repeat('*', $wildcards)] = $dms_path; |
|
| 99 | 99 | $wildcards++; |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -112,6 +112,6 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public static function deregister($addon_name = '') |
| 114 | 114 | { |
| 115 | - unset(self::$_settings[ $addon_name ]); |
|
| 115 | + unset(self::$_settings[$addon_name]); |
|
| 116 | 116 | } |
| 117 | 117 | } |