/** * Just wraps EEH_Activation::create_table, but catches any errors it may throw and adds them as errors on the DMS * @param string $table_name * @param string $table_definition_sql * @param string $engine_string * @param boolean $drop_pre_existing_tables */ private function _create_table_and_catch_errors($table_name, $table_definition_sql, $engine_string = 'ENGINE=MyISAM', $drop_pre_existing_tables = FALSE) { EE_Registry::instance()->load_helper('Activation'); try { EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables); } catch (EE_Error $e) { $message = $e->getMessage() . '<br>Stack Trace:' . $e->getTraceAsString(); $this->add_error($message); $this->_feedback_message .= $message; } }
/** * tests that we're correctly detecting activation or upgrades in registered * addons. * @group agg */ function test_detect_activations_or_upgrades__new_install_on_core_and_addon_simultaneously() { ob_start(); error_log('message taht shouldnt be outputte dbut is'); ob_end_clean(); global $wp_actions, $wpdb; //pretend core was just activated delete_option('espresso_db_update'); update_option('ee_espresso_activation', TRUE); delete_option('ee_pers_admin_notices'); //its activation history wp option shouldn't exist $this->assertWPOptionDoesNotExist($this->_addon->get_activation_history_option_name()); //and it also shouldn't be in the current db state $current_db_state = get_option(EE_Data_Migration_Manager::current_database_state); //just for assurance, make sure New Addon is the only existing addon $this->assertArrayNotHasKey($this->_addon_name, $current_db_state); $times_addon_new_install_hook_fired = isset($wp_actions["AHEE__{$this->_addon_classname}__new_install"]) ? $wp_actions["AHEE__{$this->_addon_classname}__new_install"] : 0; $times_core_new_install_hook_fired = isset($wp_actions['AHEE__EE_System__detect_if_activation_or_upgrade__new_activation']) ? $wp_actions['AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'] : 0; //set the activator option update_option($this->_addon->get_activation_indicator_option_name(), TRUE); $this->assertWPOptionExists($this->_addon->get_activation_indicator_option_name()); $this->assertTableDoesNotExist('esp_new_addon_thing'); EE_System::reset(); $this->assertEquals(EE_System::req_type_new_activation, EE_System::instance()->detect_req_type()); $this->assertEquals(EE_System::req_type_new_activation, $this->_addon->detect_req_type()); $this->assertEquals($times_addon_new_install_hook_fired + 1, $wp_actions["AHEE__{$this->_addon_classname}__new_install"]); $this->assertEquals($times_core_new_install_hook_fired + 1, $wp_actions['AHEE__EE_System__detect_if_activation_or_upgrade__new_activation']); $this->assertWPOptionDoesNotExist($this->_addon->get_activation_indicator_option_name()); $this->assertWPOptionDoesNotExist('ee_espresso_activation'); $this->assertTableExists('esp_new_addon_thing'); //verify we haven't remarked that there we tried adding a duplicate table $notices = get_option('ee_pers_admin_notices', array()); $this->assertArrayNotHasKey('bad_table_' . $wpdb->prefix . 'esp_new_addon_thing_detected', $notices); //double-check that when we intentionally try to add a table we just asserted exists //that the warning gets sent out global $track_it; $track_it = TRUE; try { EEH_Activation::create_table('esp_new_addon_thing', 'BORKED SQL', 'ENGINE=MyISAM ', TRUE); $this->fail('Borked SQL didnt\'t cause EEH_Activation::create_table to throw an EE_Error. It should have'); } catch (EE_Error $e) { $this->assertTrue(TRUE); } }
/** * Please see description of _table_is_new_in_this_version. This function will only set * EEH_Activation::create_table's $drop_pre_existing_tables to TRUE if it's a brand * new activation. Otherwise, we'll always set $drop_pre_existing_tables to FALSE * because the table should have existed. Note, if the table is being MODIFIED in this * version being activated or migrated to, then this is the right option (because * you wouldn't want to nuke ALL the table's old info just because you're adding a column, right?) * @param string $table_name * @param string $table_definition_sql * @param string $engine_string */ protected function _table_should_exist_previously($table_name, $table_definition_sql, $engine_string = 'ENGINE=MyISAM') { if (in_array($this->_get_req_type_for_plugin_corresponding_to_this_dms(), array(EE_System::req_type_new_activation))) { $drop_pre_existing_tables = true; } else { $drop_pre_existing_tables = false; } EE_Registry::instance()->load_helper('Activation'); EEH_Activation::create_table($table_name, $table_definition_sql, $engine_string, $drop_pre_existing_tables); }
public function setUp() { parent::setUp(); EE_Registry::instance()->load_helper('Activation'); //whitelist the table we're about to add add_filter('FHEE__EEH_Activation__create_table__short_circuit', array($this, 'dont_short_circuit_mock_table'), 25, 3); //add table from related DMS EEH_Activation::create_table('esp_mock_attendee_meta', ' MATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, ATT_ID int(10) unsigned NOT NULL, ATT_foobar int(10) unsigned NOT NULL, PRIMARY KEY (MATTM_ID)'); $this->assertTableExists('esp_mock_attendee_meta'); EE_Register_Model_Extensions::deregister($this->_model_group); }