public function test_register() { //make sure nobody else interfers with this test $this->_stop_pretending_addon_hook_time(); remove_all_filters('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders'); $pretend_addon_name = 'More_Core'; $args = array('dms_paths' => array(EE_TESTS_DIR . 'mocks/core/data_migration_scripts')); //try registering at wrong time try { EE_Register_Data_Migration_Scripts::register($pretend_addon_name, $args); $this->fail('We should have had a warning saying that we are setting up the ee addon at the wrong time'); } catch (PHPUnit_Framework_Error_Notice $e) { $this->assertTrue(True); } //and check we didn't actually register the DMSs (because we attempted to do so at teh wrong time) $DMSs_available = EE_Data_Migration_Manager::reset()->get_all_data_migration_scripts_available(); $this->assertArrayNotHasKey('EE_DMS_Core_1_0_0', $DMSs_available); //ok now pretend we're registering the DMS at the right time $this->_pretend_addon_hook_time(); EE_Register_Data_Migration_Scripts::register($pretend_addon_name, $args); $DMSs_available = EE_Data_Migration_Manager::reset()->get_all_data_migration_scripts_available(); $this->assertArrayHasKey('EE_DMS_Core_1_0_0', $DMSs_available); //now deregister it EE_Register_Data_Migration_Scripts::deregister($pretend_addon_name); $DMSs_available = EE_Data_Migration_Manager::reset()->get_all_data_migration_scripts_available(); $this->assertArrayNotHasKey('EE_DMS_Core_1_0_0', $DMSs_available); $this->_stop_pretending_addon_hook_time(); }
protected function _migrate_old_row($old_row) { $term_id = EE_Data_Migration_Manager::instance()->get_mapping_new_pk('Core_4_1_0', $this->_old_table, $old_row['id'], $this->_new_table); if (!$term_id) { $this->add_error(sprintf(__("Could not migrate metadata for old category '%s' with id '%d' because there is no EE4 category (term) for it.", "event_espresso"), $old_row['category_name'], $old_row['id'])); return false; } $metadata = maybe_unserialize($old_row['category_meta']); if (!is_array($metadata)) { return; } if (isset($metadata['use_pickers'])) { $this->_add_extra_meta_to_term($term_id, 'use_color_picker', $metadata['use_pickers'] == 'Y'); } if (isset($metadata['event_background'])) { $this->_add_extra_meta_to_term($term_id, 'background_color', $metadata['event_background']); } if (isset($metadata['event_text_color'])) { $this->_add_extra_meta_to_term($term_id, 'text_color', $metadata['event_text_color']); } }
/** * loads data_migration_scripts * * @access public * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 * @param mixed $arguments * @return EE_Data_Migration_Script_Base */ public function load_dms($class_name, $arguments = array()) { // retrieve instantiated class return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, FALSE, FALSE, FALSE); }
public function tearDown() { if (isset($this->_addon_name) && isset(EE_Registry::instance()->addons->EE_New_Addon)) { $main_file_path_before_deregistration = EE_Registry::instance()->addons->EE_New_Addon->get_main_plugin_file_basename(); EE_Register_Addon::deregister($this->_addon_name); try { EE_Registry::instance()->addons->EE_New_Addon; $this->fail('EE_New_Addon is still registered. Deregister failed'); } catch (PHPUnit_Framework_Error_Notice $e) { $this->assertEquals(EE_UnitTestCase::error_code_undefined_property, $e->getCode()); } //verify the deactvation hook was removed $this->assertFalse(has_action('deactivate_' . $main_file_path_before_deregistration)); //verify the models were deregistered EE_System::instance()->load_core_configuration(); $this->assertArrayDoesNotContain('EEM_New_Addon_Thing', EE_Registry::instance()->non_abstract_db_models); $this->assertArrayDoesNotContain('EEM_New_Addon_Thing', EE_Registry::instance()->models); EE_Registry::instance()->reset_model('Attendee'); //verify that the model and class extensions have been removed $this->assertFalse($this->_class_has_been_extended()); $this->assertFalse($this->_model_has_been_extended()); } //verify DMSs deregistered $DMSs_available = EE_Data_Migration_Manager::reset()->get_all_data_migration_scripts_available(); $this->assertArrayNotHasKey('EE_DMS_New_Addon_1_0_0', $DMSs_available); $this->_stop_pretending_addon_hook_time(); $this->_stop_pretending_after_plugin_activation(); remove_all_filters('AHEE__EE_System__load_espresso_addons'); parent::tearDown(); }
public function _confirm_migration_crash_report_sent() { try { $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); } catch (EE_Error $e) { EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); //now, just so we can display the page correctly, make a error migration script stage object //and also put the error on it. It only persists for the duration of this request $most_recent_migration = new EE_DMS_Unknown_1_0_0(); $most_recent_migration->add_error($e->getMessage()); } $success = $this->_req_data['success'] == '1' ? true : false; $this->_template_args['success'] = $success; $this->_template_args['most_recent_migration'] = $most_recent_migration; $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), EE_MAINTENANCE_ADMIN_URL); $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), EE_MAINTENANCE_ADMIN_URL); $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), EE_MAINTENANCE_ADMIN_URL); $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, $this->_template_args, TRUE); $this->display_admin_page_with_sidebar(); }
/** * Determines if we need to put EE in maintenance mode because the database needs updating * @return boolean true if DB is old and maintenance mode was triggered; false otherwise */ public function set_maintenance_mode_if_db_old() { EE_Registry::instance()->load_core('Data_Migration_Manager'); if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); return true; } elseif ($this->level() == self::level_2_complete_maintenance) { //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run //then we shouldn't be in mm2. (Maybe an addon got deactivated?) update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); return false; } else { return false; } }
/** * Returns the version that this script migrates to, based on the script's name. * Cannot be overwritten because lots of code needs to know which version a script * migrates to knowing only its name. * @return array where the first key is the plugin's slug, the 2nd is the version of that plugin * that will be updated to. Eg array('Core','4.1.0') */ public final function migrates_to_version() { return EE_Data_Migration_Manager::instance()->script_migrates_to_version(get_class($this)); }
/** * Used to setup this addon's database tables, but not necessarily any default * data in them. The default is to actually use the most up-to-date data migration script * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() * methods to setup the db. */ public function initialize_db() { //find the migration script that sets the database to be compatible with the code $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); if ($current_dms_name) { $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); $current_data_migration_script->set_migrating(FALSE); $current_data_migration_script->schema_changes_before_migration(); $current_data_migration_script->schema_changes_after_migration(); if ($current_data_migration_script->get_errors()) { foreach ($current_data_migration_script->get_errors() as $error) { EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); } } } //if not DMS was found that should be ok. This addon just doesn't require any database changes EE_Data_Migration_Manager::instance()->update_current_database_state_to(array('slug' => $this->name(), 'version' => $this->version())); }
/** * @group 8328 */ public function test_database_needs_updating_to__current_version_is_lower() { EE_Data_Migration_Manager::instance()->update_current_database_state_to(array('slug' => 'Core', 'version' => '4.9.0')); $this->assertFalse(EE_Data_Migration_Manager::instance()->database_needs_updating_to(array('slug' => 'Core', 'version' => '4.4.0.p'))); }
/** * resets the singleton to its brand-new state (but does NOT delete old references to the old singleton. Meaning, * all new usages of the singleton should be made with Classname::instance()) and returns it * @return EE_Data_Migration_Manager */ public static function reset() { self::$_instance = NULL; return self::instance(); }
/** * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed * @return EE_Data_Migration_Script_Base[] */ function get_ee_migration_history() { $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); $presentable_migration_scripts = array(); foreach ($options as $option_array) { $presentable_migration_scripts[str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name'])] = maybe_unserialize($option_array['option_value']); } return $presentable_migration_scripts; // return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran(); }
/** * restore the epsresso_db_update option */ function tearDown() { update_option('espresso_db_update', $this->_original_espresso_db_update); EE_System::reset()->detect_req_type(); EE_Data_Migration_Manager::reset(); update_option(EE_Data_Migration_Manager::current_database_state, $this->_original_db_state); parent::tearDown(); }
private function _remove_mock_dms() { remove_filter('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', array($this, 'add_mock_dms')); EE_Data_Migration_Manager::reset(); }
/** * the DMS manager maintains a bit of state in order to be more efficient, which we want to lose between tests */ public function setUp() { EE_Data_Migration_Manager::reset(); parent::setUp(); }
/** * create_database_tables * * @access public * @static * @throws EE_Error * @return boolean success (whether database is setup properly or not) */ public static function create_database_tables() { EE_Registry::instance()->load_core('Data_Migration_Manager'); //find the migration script that sets the database to be compatible with the code $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); if ($dms_name) { $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); $current_data_migration_script->set_migrating(false); $current_data_migration_script->schema_changes_before_migration(); $current_data_migration_script->schema_changes_after_migration(); if ($current_data_migration_script->get_errors()) { if (WP_DEBUG) { foreach ($current_data_migration_script->get_errors() as $error) { EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); } } else { EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso')); } return false; } EE_Data_Migration_Manager::instance()->update_current_database_state_to(); } else { EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); return false; } return true; }
/** * Resets the registry and everything in it (eventually, getting it to properly * reset absolutely everything will probably be tricky. right now it just resets * the config, data migration manager, and the models) * @param boolean $hard whether to reset data in the database too, or just refresh * the Registry to its state at the bginning of the request * @param boolean $reinstantiate whether to create new instances of EE_REgistry's singletons too, * or just reset without reinstantiating (handy to set to FALSE if you're not sure if you CAN * currently reinstantiate the singletons at the moment) * @return EE_Registry */ public static function reset($hard = FALSE, $reinstantiate = TRUE) { $instance = self::instance(); $instance->load_helper('Activation'); EEH_Activation::reset(); $instance->CFG = EE_Config::reset($hard, $reinstantiate); $instance->LIB->EE_Data_Migration_Manager = EE_Data_Migration_Manager::reset(); $instance->LIB = new stdClass(); foreach (array_keys($instance->non_abstract_db_models) as $model_name) { $instance->reset_model($model_name); } return $instance; }
/** * Does the traditional work of setting up the plugin's database and adding default data. * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. * NOTE: if we're in maintenance mode (which would be the case if we detect there are data * migration scripts that need to be run and a version change happens), enqueues core for database initialization, * so that it will be done when migrations are finished * * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; * @param boolean $verify_schema if true will re-check the database tables have the correct schema. * This is a resource-intensive job * so we prefer to only do it when necessary * @return void */ public function initialize_db_if_no_migrations_required($initialize_addons_too = FALSE, $verify_schema = true) { $request_type = $this->detect_req_type(); //only initialize system if we're not in maintenance mode. if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { update_option('ee_flush_rewrite_rules', TRUE); if ($verify_schema) { EEH_Activation::initialize_db_and_folders(); } EEH_Activation::initialize_db_content(); EEH_Activation::system_initialization(); if ($initialize_addons_too) { $this->initialize_addons(); } } else { EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); } if ($request_type == EE_System::req_type_new_activation || $request_type == EE_System::req_type_reactivation || $request_type == EE_System::req_type_upgrade) { add_action('AHEE__EE_System__load_CPTs_and_session__start', array($this, 'redirect_to_about_ee'), 9); } }
/** * create_database_tables * * @access public * @static * @return void */ public static function create_database_tables() { //find the migration script that sets the database to be compatible with the code $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); if ($dms_name) { $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); $current_data_migration_script->schema_changes_before_migration(); $current_data_migration_script->schema_changes_after_migration(); EE_Data_Migration_Manager::instance()->update_current_database_state_to(); } else { throw new EE_Error(sprintf(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso'))); } }