public function can_migrate_from_version($version_array)
 {
     $core_version_string = $version_array['Core'];
     $calendar_version_string = isset($version_array['Calendar']) ? $version_array['Calendar'] : '0.0.0';
     //find if the ee3 table for calendar data exists or not
     if (!EEH_Activation::table_exists("events_category_detail")) {
         //ee3 category tables don't exist still
         $an_ee3_table_exists = false;
     } else {
         $an_ee3_table_exists = true;
     }
     if (get_option('ee_data_migration_script_Core.4.1.0')) {
         $core_4_1_0_migrations_ran = true;
     } else {
         $core_4_1_0_migrations_ran = false;
     }
     if ($core_version_string >= '4.1.0' && $calendar_version_string < '3.0.0' && $an_ee3_table_exists && $core_4_1_0_migrations_ran) {
         return true;
     } else {
         //migration doesnt' apply.
         //eg they installed ee4.1.0 and then activated calendar, but no previous version of ee3
         //or they installed ee3, then ee4.1, but deleted their ee3 tables, then activated teh calendar
         return false;
     }
 }
 protected function _migrate_old_row($old_row)
 {
     //foreach ticket row we add the id for the current logged in user.
     global $wpdb;
     $user_id = EEH_Activation::get_default_creator_id();
     $updated = $wpdb->update($this->_old_table, array('PRC_wp_user' => $user_id), array('PRC_ID' => $old_row['PRC_ID']), array('%d'), array('%d'));
     if (FALSE === $updated) {
         $this->add_error(sprintf(__("Error in updating table {$this->_old_table} setting PRC_wp_user = %d where PRC_ID = %d", 'event_espresso'), $user_id, $old_row['PRC_ID']));
     }
 }
 /**
  * OK's the creation of the esp_new_addon table, because this hooks in AFTER EE_UNitTestCase's callback on this same hook
  * @global type $wpdb
  * @param array $whitelisted_tables
  * @return array
  */
 public function dont_short_circuit_new_addon_table($short_circuit = FALSE, $table_name = '', $create_sql = '')
 {
     if (in_array($table_name, array('esp_new_addon_thing', 'esp_new_addon_attendee_meta')) && !EEH_Activation::table_exists($table_name)) {
         //			echo "\r\n\r\nDONT shortcircuit $sql";
         //it's not altering. it's ok to allow this
         return FALSE;
     } else {
         //			echo "3\r\n\r\nshort circuit:$sql";
         return $short_circuit;
     }
 }
 /**
  * @param array $version_array
  * @return bool
  */
 public function can_migrate_from_version($version_array)
 {
     $version_string = $version_array['Core'];
     if ($version_string <= '4.7.0' && $version_string >= '4.6.0' || $version_string >= '4.7.0' && !EEH_Activation::table_exists('esp_registration_payment') && EEH_Activation::table_exists('esp_registration')) {
         return true;
     } elseif (!$version_string) {
         //no version string provided... this must be pre 4.3
         return false;
         //changed mind. dont want people thinking they should migrate yet because they cant
     } else {
         return false;
     }
 }
    /**
     * Checks that there is at least one active gateway. If not, add a notice
     */
    public function check_payment_gateway_setup()
    {
        //ONLY do this check if models can query
        //and avoid a bug where when we nuke EE4's data that this causes a fatal error
        //because the tables are deleted just before this request runs. see https://events.codebasehq.com/projects/event-espresso/tickets/7539
        if (!EE_Maintenance_Mode::instance()->models_can_query() || !EEH_Activation::table_exists(EEM_Payment_Method::instance()->table())) {
            return;
        }
        // ensure Payment_Method model is loaded
        EE_Registry::instance()->load_model('Payment_Method');
        $actives = EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart);
        if ($actives < 1) {
            $url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_PAYMENTS_ADMIN_URL);
            echo '<div class="error">
				 <p>' . sprintf(__("There are no Active Payment Methods setup for Event Espresso. Please %s activate at least one.%s", "event_espresso"), "<a href='{$url}'>", "</a>") . '</p>
			 </div>';
        }
    }
 /**
  * Upon brand-new activation, if this is a new activation of CAF, we want to add
  * some global prices that will show off EE4's capabilities. However, if they're upgrading
  * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
  * This action should only be called when EE 4.x.0.P is initially activated.
  * Right now the only CAF content are these global prices. If there's more in the future, then
  * we should probably create a caf file to contain it all instead just a function like this.
  * Right now, we ASSUME the only price types in the system are default ones
  * @global type $wpdb
  */
 function initialize_caf_db_content()
 {
     //		echo "initialize caf db content!";
     global $wpdb;
     //use same method of getting creator id as the version introducing the change
     $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
     $price_type_table = $wpdb->prefix . "esp_price_type";
     $price_table = $wpdb->prefix . "esp_price";
     if (EEH_Activation::table_exists($price_type_table)) {
         $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';
         //include trashed price types
         $tax_price_type_count = $wpdb->get_var($SQL);
         if ($tax_price_type_count <= 1) {
             $result = $wpdb->insert($price_type_table, array('PRT_name' => __("Regional Tax", "event_espresso"), 'PBT_ID' => 4, 'PRT_is_percent' => true, 'PRT_order' => 60, 'PRT_deleted' => false, 'PRT_wp_user' => $default_creator_id), array('%s', '%d', '%d', '%d', '%d', '%d'));
             //federal tax
             $result = $wpdb->insert($price_type_table, array('PRT_name' => __("Federal Tax", "event_espresso"), 'PBT_ID' => 4, 'PRT_is_percent' => true, 'PRT_order' => 70, 'PRT_deleted' => false, 'PRT_wp_user' => $default_creator_id), array('%s', '%d', '%d', '%d', '%d', '%d'));
             if ($result) {
                 $wpdb->insert($price_table, array('PRT_ID' => $wpdb->insert_id, 'PRC_amount' => 15.0, 'PRC_name' => __("Sales Tax", "event_espresso"), 'PRC_desc' => '', 'PRC_is_default' => true, 'PRC_overrides' => NULL, 'PRC_deleted' => false, 'PRC_order' => 50, 'PRC_parent' => null, 'PRC_wp_user' => $default_creator_id), array('%d', '%f', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d'));
             }
         }
     }
 }
    public function schema_changes_before_migration()
    {
        //relies on 4.1's EEH_Activation::create_table
        require_once EE_HELPERS . 'EEH_Activation.helper.php';
        $table_name = 'esp_answer';
        $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tREG_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tANS_value TEXT NOT NULL,\n\t\t\t\t\tPRIMARY KEY  (ANS_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_attendee_meta';
        $sql = "ATTM_ID INT(10) UNSIGNED NOT\tNULL AUTO_INCREMENT,\n\t\t\t\t\t\tATT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\t\tATT_fname VARCHAR(45) NOT NULL,\n\t\t\t\t\t\tATT_lname VARCHAR(45) NOT\tNULL,\n\t\t\t\t\t\tATT_address VARCHAR(255) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_address2 VARCHAR(255) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_city VARCHAR(45) DEFAULT\tNULL,\n\t\t\t\t\t\tSTA_ID INT(10) DEFAULT\tNULL,\n\t\t\t\t\t\tCNT_ISO VARCHAR(45) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_zip VARCHAR(12) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_email VARCHAR(255) NOT NULL,\n\t\t\t\t\t\tATT_phone VARCHAR(45) DEFAULT NULL,\n\t\t\t\t\t\t\tPRIMARY KEY  (ATTM_ID),\n\t\t\t\t\t\t\t\tKEY ATT_fname (ATT_fname),\n\t\t\t\t\t\t\t\tKEY ATT_lname (ATT_lname),\n\t\t\t\t\t\t\t\tKEY ATT_email (ATT_email)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_country';
        $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL,\n\t\t\t\t\t  CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  CNT_cur_code VARCHAR(6) COLLATE utf8_bin DEFAULT 'USD',\n\t\t\t\t\t  CNT_cur_single VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollar',\n\t\t\t\t\t  CNT_cur_plural VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollars',\n\t\t\t\t\t  CNT_cur_sign VARCHAR(45) COLLATE utf8_bin DEFAULT '\$',\n\t\t\t\t\t  CNT_cur_sign_b4 TINYINT(1) DEFAULT '1',\n\t\t\t\t\t  CNT_cur_dec_plc TINYINT(3) UNSIGNED NOT NULL DEFAULT '2',\n\t\t\t\t\t  CNT_cur_dec_mrk VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT '.',\n\t\t\t\t\t  CNT_cur_thsnds VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT ',',\n\t\t\t\t\t  CNT_tel_code VARCHAR(12) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  CNT_is_EU TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  CNT_active TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (CNT_ISO)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_datetime';
        $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t  EVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t  DTT_name VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t  DTT_description TEXT NOT NULL,\n\t\t\t\t  DTT_EVT_start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t  DTT_EVT_end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t  DTT_reg_limit MEDIUMINT(8) DEFAULT -1,\n\t\t\t\t  DTT_sold MEDIUMINT(8) UNSIGNED DEFAULT 0,\n\t\t\t\t  DTT_is_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  DTT_order MEDIUMINT(3) UNSIGNED DEFAULT 0,\n\t\t\t\t  DTT_parent INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t  DTT_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t\tPRIMARY KEY  (DTT_ID),\n\t\t\t\t\t\tKEY EVT_ID (EVT_ID),\n\t\t\t\t\t\tKEY DTT_is_primary (DTT_is_primary)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_meta';
        $sql = "\n\t\t\tEVTM_ID INT NOT NULL AUTO_INCREMENT,\n\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\tEVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tEVT_display_ticket_selector TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tEVT_visible_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\tEVT_default_registration_status VARCHAR(3),\n\t\t\tEVT_phone VARCHAR(45) DEFAULT NULL,\n\t\t\tEVT_additional_limit TINYINT UNSIGNED NULL,\n\t\t\tEVT_member_only TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\tEVT_allow_overflow TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\tEVT_timezone_string VARCHAR(45) NULL,\n\t\t\tEVT_external_URL VARCHAR(200) NULL,\n\t\t\tEVT_donations TINYINT(1) NULL,\n\t\t\tPRIMARY KEY  (EVTM_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_question_group';
        $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\tQSG_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tEQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (EQG_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_venue';
        $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\tVNU_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\tEVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\tPRIMARY KEY  (EVV_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_extra_meta';
        $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tOBJ_ID INT(11) DEFAULT NULL,\n\t\t\t\tEXM_type VARCHAR(45) DEFAULT NULL,\n\t\t\t\tEXM_key VARCHAR(45) DEFAULT NULL,\n\t\t\t\tEXM_value TEXT,\n\t\t\t\tPRIMARY KEY  (EXM_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_line_item';
        $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tLIN_code VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\tTXN_ID INT(11) DEFAULT NULL,\n\t\t\t\tLIN_name VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\tLIN_desc VARCHAR(245) DEFAULT NULL,\n\t\t\t\tLIN_unit_price DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\tLIN_percent DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\tLIN_is_taxable TINYINT(1) DEFAULT 0,\n\t\t\t\tLIN_order int DEFAULT 0,\n\t\t\t\tLIN_parent int DEFAULT 0,\n\t\t\t\tLIN_type VARCHAR(25) NOT NULL,\n\t\t\t\tLIN_total DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\tLIN_quantity INT(10) DEFAULT NULL,\n\t\t\t\tOBJ_ID INT(11) DEFAULT NULL,\n\t\t\t\tOBJ_type VARCHAR(45)DEFAULT NULL,\n\t\t\t\tPRIMARY KEY  (LIN_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_message_template';
        $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tGRP_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\tMTP_context VARCHAR(50) NOT NULL,\n\t\t\t\t\tMTP_template_field VARCHAR(30) NOT NULL,\n\t\t\t\t\tMTP_content TEXT NOT NULL,\n\t\t\t\t\tPRIMARY KEY  (MTP_ID),\n\t\t\t\t\tKEY GRP_ID (GRP_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_message_template_group';
        $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tEVT_ID BIGINT(20) UNSIGNED DEFAULT NULL,\n\t\t\t\t\tMTP_user_id INT(10) NOT NULL DEFAULT '1',\n\t\t\t\t\tMTP_messenger VARCHAR(30) NOT NULL,\n\t\t\t\t\tMTP_message_type VARCHAR(50) NOT NULL,\n\t\t\t\t\tMTP_is_global TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_is_override TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_deleted TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_is_active TINYINT(1) NOT NULL DEFAULT '1',\n\t\t\t\t\tPRIMARY KEY  (GRP_ID),\n\t\t\t\t\tKEY EVT_ID (EVT_ID),\n\t\t\t\t\tKEY MTP_user_id (MTP_user_id)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_payment';
        $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tTXN_ID INT(10) UNSIGNED DEFAULT NULL,\n\t\t\t\t\tSTS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\tPAY_method VARCHAR(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_amount DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\t\tPAY_gateway VARCHAR(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_gateway_response TEXT COLLATE utf8_bin,\n\t\t\t\t\tPAY_txn_id_chq_nmbr VARCHAR(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_po_number VARCHAR(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_extra_accntng VARCHAR(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_via_admin TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tPAY_details TEXT COLLATE utf8_bin,\n\t\t\t\t\tPRIMARY KEY  (PAY_ID),\n\t\t\t\t\tKEY TXN_ID (TXN_ID),\n\t\t\t\t\tKEY PAY_timestamp (PAY_timestamp)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = "esp_ticket";
        $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TTM_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  TKT_name VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\t\t  TKT_description TEXT NOT NULL,\n\t\t\t\t\t  TKT_qty MEDIUMINT(8) DEFAULT NULL,\n\t\t\t\t\t  TKT_sold MEDIUMINT(8) NOT NULL DEFAULT 0,\n\t\t\t\t\t  TKT_uses TINYINT NOT NULL DEFAULT '-1',\n\t\t\t\t\t  TKT_min TINYINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_max TINYINT NOT NULL DEFAULT '-1',\n\t\t\t\t\t  TKT_price DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  TKT_start_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  TKT_end_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  TKT_taxable TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_row TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_is_default TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_parent INT(10) UNSIGNED DEFAULT '0',\n\t\t\t\t\t  TKT_deleted TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (TKT_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_ticket_price";
        $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TKT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRC_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (TKP_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_datetime_ticket";
        $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  DTT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  TKT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (DTK_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_ticket_template";
        $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TTM_name VARCHAR(45) NOT NULL,\n\t\t\t\t\t  TTM_description TEXT,\n\t\t\t\t\t  TTM_file VARCHAR(45),\n\t\t\t\t\t  PRIMARY KEY  (TTM_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_price";
        $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  PRT_ID TINYINT(3) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  PRC_name VARCHAR(245) NOT NULL,\n\t\t\t\t\t  PRC_desc TEXT,\n\t\t\t\t\t  PRC_is_default TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',\n\t\t\t\t\t  PRC_overrides INT(10) UNSIGNED DEFAULT NULL,\n\t\t\t\t\t  PRC_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRC_parent INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\t  PRIMARY KEY  (PRC_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_price_type";
        $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t  PRT_name VARCHAR(45) NOT NULL,\n\t\t\t\t  PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',\n\t\t\t\t  PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t  PRT_order TINYINT UNSIGNED NULL,\n\t\t\t\t  PRT_deleted TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t  UNIQUE KEY PRT_name_UNIQUE (PRT_name),\n\t\t\t\t  PRIMARY KEY  (PRT_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question';
        $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
					QST_display_text TEXT NOT NULL,
					QST_admin_label VARCHAR(255) NOT NULL,
					QST_system VARCHAR(25) DEFAULT NULL,
					QST_type VARCHAR(25) NOT NULL DEFAULT "TEXT",
					QST_required TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
					QST_required_text VARCHAR(100) NULL,
					QST_order TINYINT UNSIGNED NOT NULL DEFAULT 0,
					QST_admin_only TINYINT(1) NOT NULL DEFAULT 0,
					QST_wp_user BIGINT UNSIGNED NULL,
					QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0,
					PRIMARY KEY  (QST_ID)';
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        EEH_Activation::drop_index('esp_question_group', 'QSG_identifier_UNIQUE');
        $table_name = 'esp_question_group';
        $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
					QSG_name VARCHAR(255) NOT NULL,
					QSG_identifier VARCHAR(100) NOT NULL,
					QSG_desc TEXT NULL,
					QSG_order TINYINT UNSIGNED NOT NULL DEFAULT 0,
					QSG_show_group_name TINYINT(1) NOT NULL,
					QSG_show_group_desc TINYINT(1) NOT NULL,
					QSG_system TINYINT NULL,
					QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
					PRIMARY KEY  (QSG_ID),
					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question_group_question';
        $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tQSG_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQGQ_order INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (QGQ_ID) ";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question_option';
        $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tQSO_value VARCHAR(255) NOT NULL,\n\t\t\t\t\tQSO_desc TEXT NOT NULL,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (QSO_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_registration';
        $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  EVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\t  ATT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\t  TXN_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  TKT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL DEFAULT 'RPP',\n\t\t\t\t\t  REG_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  REG_final_price DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  REG_session VARCHAR(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  REG_code VARCHAR(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  REG_url_link VARCHAR(64) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  REG_count TINYINT(4) DEFAULT '1',\n\t\t\t\t\t  REG_group_size TINYINT(4) DEFAULT '1',\n\t\t\t\t\t  REG_att_is_going TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  REG_deleted TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (REG_ID),\n\t\t\t\t\t  KEY EVT_ID (EVT_ID),\n\t\t\t\t\t  KEY ATT_ID (ATT_ID),\n\t\t\t\t\t  KEY TXN_ID (TXN_ID),\n\t\t\t\t\t  KEY TKT_ID (TKT_ID),\n\t\t\t\t\t  KEY STS_ID (STS_ID),\n\t\t\t\t\t  KEY REG_url_link (REG_url_link),\n\t\t\t\t\t  KEY REG_code (REG_code)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_checkin';
        $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tREG_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\tDTT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\tCHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\t\t\tCHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\tPRIMARY KEY  (CHK_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_state';
        $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_active TINYINT(1) DEFAULT '1',\n\t\t\t\t\t  PRIMARY KEY  (STA_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_status';
        $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_can_edit TINYINT(1) NOT NULL DEFAULT 0,\n\t\t\t\t\t  STS_desc TINYTEXT COLLATE utf8_bin,\n\t\t\t\t\t  STS_open TINYINT(1) NOT NULL DEFAULT 1,\n\t\t\t\t\t  UNIQUE KEY STS_ID_UNIQUE (STS_ID),\n\t\t\t\t\t  KEY STS_type (STS_type)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_transaction';
        $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  TXN_total DECIMAL(10,3) DEFAULT '0.00',\n\t\t\t\t\t  TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  STS_ID VARCHAR(3) NOT NULL DEFAULT 'TOP',\n\t\t\t\t\t  TXN_session_data TEXT COLLATE utf8_bin,\n\t\t\t\t\t  TXN_hash_salt VARCHAR(250) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  PRIMARY KEY  (TXN_ID),\n\t\t\t\t\t  KEY TXN_timestamp (TXN_timestamp),\n\t\t\t\t\t  KEY STS_ID (STS_ID)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_venue_meta';
        $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\tVNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\tVNU_address VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_address2 VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_city VARCHAR(100) DEFAULT NULL,\n\t\t\tSTA_ID INT(11) DEFAULT NULL,\n\t\t\tCNT_ISO VARCHAR(2) DEFAULT NULL,\n\t\t\tVNU_zip VARCHAR(45) DEFAULT NULL,\n\t\t\tVNU_phone VARCHAR(45) DEFAULT NULL,\n\t\t\tVNU_capacity INT(11) DEFAULT NULL,\n\t\t\tVNU_url VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_virtual_phone VARCHAR(45) DEFAULT NULL,\n\t\t\tVNU_virtual_url VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_enable_for_gmap TINYINT(1) DEFAULT '0',\n\t\t\tVNU_google_map_link VARCHAR(255) DEFAULT NULL,\n\t\t\tPRIMARY KEY  (VNUM_ID),\n\t\t\tKEY STA_ID (STA_ID),\n\t\t\tKEY CNT_ISO (CNT_ISO)";
        $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB');
        $script_with_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
        //setting up the DEFAULT stats and countries is also essential for the data migrations to run
        //(because many need to convert old string states to foreign keys into the states table)
        $script_with_defaults->insert_default_states();
        $script_with_defaults->insert_default_countries();
        //setting up DEFAULT prices, price types, and tickets is also essential for the price migrations
        $script_with_defaults->insert_default_price_types();
        $script_with_defaults->insert_default_prices();
        $script_with_defaults->insert_default_tickets();
        //setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
        EE_Config::instance()->update_espresso_config(false, true);
        return true;
    }
    public function schema_changes_before_migration()
    {
        //relies on 4.1's EEH_Activation::create_table
        require_once EE_HELPERS . 'EEH_Activation.helper.php';
        $table_name = 'esp_answer';
        $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tREG_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tANS_value TEXT NOT NULL ,\n\t\t\t\t\tPRIMARY KEY  (ANS_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_attendee_meta';
        $sql = "ATTM_ID int(10) unsigned NOT\tNULL AUTO_INCREMENT,\n\t\t\t\t\t\tATT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t\tATT_fname varchar(45) NOT NULL,\n\t\t\t\t\t\tATT_lname varchar(45) NOT\tNULL,\n\t\t\t\t\t\tATT_address varchar(45) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_address2 varchar(45) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_city varchar(45) DEFAULT\tNULL,\n\t\t\t\t\t\tSTA_ID int(10) DEFAULT\tNULL,\n\t\t\t\t\t\tCNT_ISO varchar(45) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_zip varchar(12) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_email varchar(100) NOT NULL,\n\t\t\t\t\t\tATT_phone varchar(45) DEFAULT NULL,\n\t\t\t\t\t\t\tPRIMARY KEY  (ATTM_ID),\n\t\t\t\t\t\t\t\tKEY ATT_fname (ATT_fname),\n\t\t\t\t\t\t\t\tKEY ATT_lname (ATT_lname),\n\t\t\t\t\t\t\t\tKEY ATT_email (ATT_email)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_country';
        $sql = "CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  CNT_ISO3 varchar(3) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  RGN_ID tinyint(3) unsigned DEFAULT NULL,\n\t\t\t\t\t  CNT_name varchar(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  CNT_cur_code varchar(6) COLLATE utf8_bin DEFAULT 'USD',\n\t\t\t\t\t  CNT_cur_single varchar(45) COLLATE utf8_bin DEFAULT 'dollar',\n\t\t\t\t\t  CNT_cur_plural varchar(45) COLLATE utf8_bin DEFAULT 'dollars',\n\t\t\t\t\t  CNT_cur_sign varchar(45) COLLATE utf8_bin DEFAULT '\$',\n\t\t\t\t\t  CNT_cur_sign_b4 tinyint(1) DEFAULT '1',\n\t\t\t\t\t  CNT_cur_dec_plc tinyint(3) unsigned NOT NULL DEFAULT '2',\n\t\t\t\t\t  CNT_cur_dec_mrk varchar(1) COLLATE utf8_bin NOT NULL DEFAULT '.',\n\t\t\t\t\t  CNT_cur_thsnds varchar(1) COLLATE utf8_bin NOT NULL DEFAULT ',',\n\t\t\t\t\t  CNT_tel_code varchar(12) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  CNT_is_EU tinyint(1) DEFAULT '0',\n\t\t\t\t\t  CNT_active tinyint(1) DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (CNT_ISO)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_datetime';
        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t  EVT_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t  DTT_EVT_start datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t  DTT_EVT_end datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t  DTT_reg_limit mediumint(8) DEFAULT -1,\n\t\t\t\t  DTT_sold mediumint(8) unsigned DEFAULT 0,\n\t\t\t\t  DTT_is_primary tinyint(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  DTT_order mediumint(3) unsigned DEFAULT 0,\n\t\t\t\t  DTT_parent int(10) unsigned DEFAULT 0,\n\t\t\t\t  DTT_deleted tinyint(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t\tPRIMARY KEY  (DTT_ID),\n\t\t\t\t\t\tKEY EVT_ID (EVT_ID),\n\t\t\t\t\t\tKEY DTT_is_primary (DTT_is_primary)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_meta';
        $sql = "\n\t\t\tEVTM_ID INT NOT NULL AUTO_INCREMENT,\n\t\t\tEVT_ID int(11) unsigned NOT NULL,\n\t\t\tEVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 ,\n\t\t\tEVT_display_ticket_selector TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 ,\n\t\t\tEVT_visible_on datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\tEVT_default_registration_status VARCHAR(3),\n\t\t\tEVT_phone varchar(45) DEFAULT NULL,\n\t\t\tEVT_additional_limit TINYINT UNSIGNED NULL ,\n\t\t\tEVT_member_only TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 ,\n\t\t\tEVT_allow_overflow TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 ,\n\t\t\tEVT_timezone_string VARCHAR(45) NULL ,\n\t\t\tEVT_external_URL VARCHAR(200) NULL ,\n\t\t\tEVT_donations TINYINT(1) NULL,\n\t\t\tPRIMARY KEY  (EVTM_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_question_group';
        $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tEVT_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tQSG_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tEQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (EQG_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_venue';
        $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT ,\n\t\t\t\tEVT_ID INT(11) NOT NULL ,\n\t\t\t\tVNU_ID INT(11) NOT NULL ,\n\t\t\t\tEVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\tPRIMARY KEY  (EVV_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_extra_meta';
        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tOBJ_ID int(11) DEFAULT NULL,\n\t\t\t\tEXM_type varchar(45) DEFAULT NULL,\n\t\t\t\tEXM_key varchar(45) DEFAULT NULL,\n\t\t\t\tEXM_value text,\n\t\t\t\tPRIMARY KEY  (EXM_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_line_item';
        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tLIN_code varchar(245) NOT NULL DEFAULT '',\n\t\t\t\tTXN_ID int(11) DEFAULT NULL,\n\t\t\t\tLIN_name varchar(245) NOT NULL DEFAULT '',\n\t\t\t\tLIN_desc varchar(245) DEFAULT NULL,\n\t\t\t\tLIN_unit_price decimal(10,3) DEFAULT NULL,\n\t\t\t\tLIN_percent decimal(10,3) DEFAULT NULL,\n\t\t\t\tLIN_is_taxable tinyint(1) DEFAULT 0,\n\t\t\t\tLIN_order int DEFAULT 0,\n\t\t\t\tLIN_parent int DEFAULT 0,\n\t\t\t\tLIN_type varchar(25) NOT NULL,\n\t\t\t\tLIN_total decimal(10,3) DEFAULT NULL,\n\t\t\t\tLIN_quantity int(10) DEFAULT NULL,\n\t\t\t\tOBJ_ID int(11) DEFAULT NULL,\n\t\t\t\tOBJ_type varchar(45)DEFAULT NULL,\n\t\t\t\tPRIMARY KEY  (LIN_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_message_template';
        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tGRP_ID int(10) unsigned NOT NULL,\n\t\t\t\t\tMTP_context varchar(50) NOT NULL,\n\t\t\t\t\tMTP_template_field varchar(30) NOT NULL,\n\t\t\t\t\tMTP_content text NOT NULL,\n\t\t\t\t\tPRIMARY KEY  (MTP_ID),\n\t\t\t\t\tKEY GRP_ID (GRP_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_message_template_group';
        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tEVT_ID int(10) unsigned DEFAULT NULL,\n\t\t\t\t\tMTP_user_id int(10) NOT NULL DEFAULT '1',\n\t\t\t\t\tMTP_messenger varchar(30) NOT NULL,\n\t\t\t\t\tMTP_message_type varchar(50) NOT NULL,\n\t\t\t\t\tMTP_is_global tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_is_override tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_deleted tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_is_active tinyint(1) NOT NULL DEFAULT '1',\n\t\t\t\t\tPRIMARY KEY  (GRP_ID),\n\t\t\t\t\tKEY EVT_ID (EVT_ID),\n\t\t\t\t\tKEY MTP_user_id (MTP_user_id)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_payment';
        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tTXN_ID int(10) unsigned DEFAULT NULL,\n\t\t\t\t\tSTS_ID varchar(3) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_timestamp datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\tPAY_method varchar(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_amount decimal(10,3) DEFAULT NULL,\n\t\t\t\t\tPAY_gateway varchar(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_gateway_response text COLLATE utf8_bin,\n\t\t\t\t\tPAY_txn_id_chq_nmbr varchar(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_po_number varchar(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_extra_accntng varchar(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_via_admin tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tPAY_details text COLLATE utf8_bin,\n\t\t\t\t\tPRIMARY KEY  (PAY_ID),\n\t\t\t\t\tKEY TXN_ID (TXN_ID),\n\t\t\t\t\tKEY PAY_timestamp (PAY_timestamp)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_promotion';
        $sql = "PRO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tPRC_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tPRO_scope VARCHAR(16) NOT NULL DEFAULT 'event' ,\n\t\t\t\t\tPRO_start DATETIME NULL DEFAULT NULL ,\n\t\t\t\t\tPRO_end DATETIME NULL DEFAULT NULL ,\n\t\t\t\t\tPRO_code VARCHAR(45) NULL DEFAULT NULL ,\n\t\t\t\t\tPRO_uses SMALLINT UNSIGNED NULL DEFAULT NULL ,\n\t\t\t\t\tPRO_global TINYINT(1) NOT NULL DEFAULT 0 ,\n\t\t\t\t\tPRO_global_uses SMALLINT UNSIGNED NOT NULL DEFAULT 0 ,\n\t\t\t\t\tPRO_exclusive TINYINT(1) NOT NULL DEFAULT 0 ,\n\t\t\t\t\tPRO_accept_msg TINYTEXT NULL DEFAULT NULL ,\n\t\t\t\t\tPRO_decline_msg TINYTEXT NULL DEFAULT NULL ,\n\t\t\t\t\tPRO_default TINYINT(1) NOT NULL DEFAULT 0 ,\n\t\t\t\t\tPRO_order TINYINT UNSIGNED NOT NULL DEFAULT 40 ,\n\t\t\t\t\tPRIMARY KEY  (PRO_ID) ,\n\t\t\t\t\tKEY PRC_ID (PRC_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_promotion_object';
        $sql = "POB_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\tPRO_ID INT UNSIGNED NOT NULL,\n\t\t\tOBJ_ID INT UNSIGNED NOT NULL,\n\t\t\tPOB_type VARCHAR(45) NULL,\n\t\t\tPOB_used INT NULL,\n\t\t\tPRIMARY KEY  (POB_ID),\n\t\t\tKEY OBJ_ID (OBJ_ID),\n\t\t\tKEY PRO_ID (PRO_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_promotion_applied';
        $sql = "PRA_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\tPRO_ID INT UNSIGNED NOT NULL,\n\t\t\tOBJ_ID INT UNSIGNED NOT NULL,\n\t\t\tPOB_type VARCHAR(45) NULL,\n\t\t\tPRIMARY KEY  (PRA_ID),\n\t\t\tKEY OBJ_ID (OBJ_ID),\n\t\t\tKEY PRO_ID (PRO_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_promotion_rule';
        $sql = "PRR_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tPRO_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tRUL_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tPRR_order TINYINT UNSIGNED NOT NULL DEFAULT 1,\n\t\t\t\t\tPRR_add_rule_comparison ENUM('AND','OR') NULL DEFAULT 'AND',\n\t\t\t\t\tPRIMARY KEY  (PRR_ID) ,\n\t\t\t\t\tKEY PRO_ID (PRO_ID),\n\t\t\t\t\tKEY RUL_ID (RUL_ID) ";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_rule';
        $sql = "RUL_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tRUL_name VARCHAR(45) NOT NULL ,\n\t\t\t\t\tRUL_desc TEXT NULL ,\n\t\t\t\t\tRUL_trigger VARCHAR(45) NOT NULL ,\n\t\t\t\t\tRUL_trigger_type VARCHAR(45) NULL DEFAULT NULL ,\n\t\t\t\t\tRUL_comparison ENUM('=','!=','<','>') NOT NULL DEFAULT '=' ,\n\t\t\t\t\tRUL_value VARCHAR(45) NOT NULL ,\n\t\t\t\t\tRUL_value_type VARCHAR(45) NULL DEFAULT NULL ,\n\t\t\t\t\tRUL_is_active TINYINT(1) NOT NULL DEFAULT 1 ,\n\t\t\t\t\tRUL_archived TINYINT(1) NOT NULL DEFAULT 0 ,\n\t\t\t\t\tPRIMARY KEY  (RUL_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = "esp_ticket";
        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TTM_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  TKT_name varchar(100) NOT NULL DEFAULT '',\n\t\t\t\t\t  TKT_description TEXT NOT NULL DEFAULT '',\n\t\t\t\t\t  TKT_qty mediumint(8) DEFAULT NULL,\n\t\t\t\t\t  TKT_sold mediumint(8) NOT NULL DEFAULT 0,\n\t\t\t\t\t  TKT_uses tinyint NOT NULL DEFAULT '-1',\n\t\t\t\t\t  TKT_min tinyint unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_max tinyint NOT NULL DEFAULT '-1',\n\t\t\t\t\t  TKT_price decimal(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  TKT_start_date datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\t  TKT_end_date datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\t  TKT_taxable tinyint(1) unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_order tinyint(3) unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_row tinyint(3) unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_is_default tinyint(1) unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_parent int(10) unsigned DEFAULT '0',\n\t\t\t\t\t  TKT_deleted tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (TKT_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_ticket_price";
        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TKT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  PRC_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (TKP_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_datetime_ticket";
        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  DTT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  TKT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (DTK_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_ticket_template";
        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TTM_name varchar(45) NOT NULL,\n\t\t\t\t\t  TTM_description text,\n\t\t\t\t\t  TTM_file varchar(45),\n\t\t\t\t\t  PRIMARY KEY  (TTM_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_price";
        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  PRT_ID tinyint(3) unsigned NOT NULL,\n\t\t\t\t\t  PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  PRC_name varchar(45) NOT NULL,\n\t\t\t\t\t  PRC_desc text,\n\t\t\t\t\t  PRC_is_default tinyint(1) unsigned NOT NULL DEFAULT '1',\n\t\t\t\t\t  PRC_overrides int(10) unsigned DEFAULT NULL,\n\t\t\t\t\t  PRC_deleted tinyint(1) unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRC_order tinyint(3) unsigned NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRC_parent int(10) unsigned DEFAULT 0,\n\t\t\t\t\t  PRIMARY KEY  (PRC_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_price_type";
        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t  PRT_name VARCHAR(45) NOT NULL ,\n\t\t\t\t  PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',\n\t\t\t\t  PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t  PRT_order tinyint UNSIGNED NULL,\n\t\t\t\t  PRT_deleted tinyint(1) NOT NULL DEFAULT '0',\n\t\t\t\t  UNIQUE KEY PRT_name_UNIQUE (PRT_name),\n\t\t\t\t  PRIMARY KEY  (PRT_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question';
        $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
					QST_display_text TEXT NOT NULL,
					QST_admin_label VARCHAR(255) NOT NULL,
					QST_system varchar(25) DEFAULT NULL,
					QST_type VARCHAR(25) NOT NULL DEFAULT "TEXT",
					QST_required TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
					QST_required_text VARCHAR(100) NULL,
					QST_order TINYINT UNSIGNED NOT NULL DEFAULT 0,
					QST_admin_only TINYINT(1) NOT NULL DEFAULT 0,
					QST_wp_user BIGINT UNSIGNED NULL,
					QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0,
					PRIMARY KEY  (QST_ID)';
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        EEH_Activation::drop_index('esp_question_group', 'QSG_identifier_UNIQUE');
        $table_name = 'esp_question_group';
        $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
					QSG_name VARCHAR(255) NOT NULL,
					QSG_identifier VARCHAR(100) NOT NULL,
					QSG_desc TEXT NULL,
					QSG_order TINYINT UNSIGNED NOT NULL DEFAULT 0,
					QSG_show_group_name TINYINT(1) NOT NULL,
					QSG_show_group_desc TINYINT(1) NOT NULL,
					QSG_system TINYINT NULL,
					QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
					PRIMARY KEY  (QSG_ID),
					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question_group_question';
        $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tQSG_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tPRIMARY KEY  (QGQ_ID) ";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question_option';
        $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tQSO_value VARCHAR(255) NOT NULL ,\n\t\t\t\t\tQSO_desc TEXT NOT NULL ,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL ,\n\t\t\t\t\tQSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 ,\n\t\t\t\t\tPRIMARY KEY  (QSO_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_registration';
        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  EVT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  ATT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  TXN_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  TKT_ID int(10) unsigned NOT NULL,\n\t\t\t\t\t  STS_ID varchar(3) COLLATE utf8_bin NOT NULL DEFAULT 'RPP',\n\t\t\t\t\t  REG_date datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\t  REG_final_price decimal(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  REG_session varchar(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  REG_code varchar(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  REG_url_link varchar(64) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  REG_count tinyint(4) DEFAULT '1',\n\t\t\t\t\t  REG_group_size tinyint(4) DEFAULT '1',\n\t\t\t\t\t  REG_att_is_going tinyint(1) DEFAULT '0',\n\t\t\t\t\t  REG_deleted tinyint(1) DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (REG_ID),\n\t\t\t\t\t  KEY EVT_ID (EVT_ID),\n\t\t\t\t\t  KEY ATT_ID (ATT_ID),\n\t\t\t\t\t  KEY TXN_ID (TXN_ID),\n\t\t\t\t\t  KEY TKT_ID (TKT_ID),\n\t\t\t\t\t  KEY STS_ID (STS_ID),\n\t\t\t\t\t  KEY REG_url_link (REG_url_link),\n\t\t\t\t\t  KEY REG_code (REG_code)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_checkin';
        $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t\tREG_ID INT(10) unsigned NOT NULL ,\n\t\t\t\t\tDTT_ID INT(10) unsigned NOT NULL ,\n\t\t\t\t\tCHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 ,\n\t\t\t\t\tCHK_timestamp datetime NOT NULL default '0000-00-00 00:00:00' ,\n\t\t\t\t\tPRIMARY KEY  (CHK_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_state';
        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  CNT_ISO varchar(2) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_abbrev varchar(6) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_name varchar(100) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_active tinyint(1) DEFAULT '1',\n\t\t\t\t\t  PRIMARY KEY  (STA_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_status';
        $sql = "STS_ID varchar(3) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_code varchar(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_can_edit tinyint(1) NOT NULL DEFAULT 0,\n\t\t\t\t\t  STS_desc tinytext COLLATE utf8_bin,\n\t\t\t\t\t  STS_open tinyint(1) NOT NULL DEFAULT 1,\n\t\t\t\t\t  UNIQUE KEY STS_ID_UNIQUE (STS_ID),\n\t\t\t\t\t  KEY STS_type (STS_type)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_transaction';
        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TXN_timestamp datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\t  TXN_total decimal(10,3) DEFAULT '0.00',\n\t\t\t\t\t  TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  STS_ID varchar(3) NOT NULL DEFAULT 'TOP',\n\t\t\t\t\t  TXN_session_data text COLLATE utf8_bin,\n\t\t\t\t\t  TXN_hash_salt varchar(250) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  PRIMARY KEY  (TXN_ID),\n\t\t\t\t\t  KEY TXN_timestamp (TXN_timestamp),\n\t\t\t\t\t  KEY STS_ID (STS_ID)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_venue_meta';
        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,\n\t\t\tVNU_ID int(11) DEFAULT NULL,\n\t\t\tVNU_address varchar(100) DEFAULT NULL,\n\t\t\tVNU_address2 varchar(100) DEFAULT NULL,\n\t\t\tVNU_city varchar(100) DEFAULT NULL,\n\t\t\tSTA_ID int(11) DEFAULT NULL,\n\t\t\tCNT_ISO varchar(2) DEFAULT NULL,\n\t\t\tVNU_zip varchar(45) DEFAULT NULL,\n\t\t\tVNU_phone varchar(45) DEFAULT NULL,\n\t\t\tVNU_capacity int(11) DEFAULT NULL,\n\t\t\tVNU_url varchar(255) DEFAULT NULL,\n\t\t\tVNU_virtual_phone varchar(45) DEFAULT NULL,\n\t\t\tVNU_virtual_url varchar(255) DEFAULT NULL,\n\t\t\tVNU_enable_for_gmap tinyint(1) DEFAULT '0',\n\t\t\tVNU_google_map_link varchar(255) DEFAULT NULL,\n\t\t\tPRIMARY KEY  (VNUM_ID),\n\t\t\tKEY STA_ID (STA_ID),\n\t\t\tKEY CNT_ISO (CNT_ISO)";
        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        //setting up the default stats and countries is also essential for the data migrations to run
        //(because many need to convert old string states to foreign keys into the states table)
        $this->insert_default_states();
        $this->insert_default_countries();
        //setting up default prices, price types, and tickets is also essential for the price migrations
        $this->insert_default_price_types();
        $this->insert_default_prices();
        $this->insert_default_tickets();
        //setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre
        EE_Config::instance()->update_espresso_config(false, true);
        return true;
    }
 /**
  *  Handles creating new default templates.
  *
  * @param string $template_pack This corresponds to a template pack class reference
  *                              which will contain information about where to obtain the templates.
  * @return mixed (array|bool) 	success array or false.
  */
 protected function _create_new_templates($template_pack)
 {
     $this->_set_templates($template_pack);
     //necessary properties are set, let's save the default templates
     if (empty($this->_GRP_ID)) {
         $main_template_data = array('MTP_messenger' => $this->_messenger->name, 'MTP_message_type' => $this->_message_type->name, 'MTP_is_override' => 0, 'MTP_deleted' => 0, 'MTP_is_global' => 1, 'MTP_user_id' => EEH_Activation::get_default_creator_id(), 'MTP_is_active' => 1);
         //let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID
         $grp_id = $this->_message_template_group_model->insert($main_template_data);
         if (empty($grp_id)) {
             return $grp_id;
         }
         $this->_GRP_ID = $grp_id;
     }
     $template_data = array('GRP_ID' => $this->_GRP_ID);
     foreach ($this->_contexts as $context => $details) {
         foreach ($this->_fields as $field => $field_type) {
             if ($field != 'extra') {
                 $template_data['MTP_context'] = $context;
                 $template_data['MTP_template_field'] = $field;
                 $template_data['MTP_content'] = $this->_templates[$context][$field];
                 $MTP = $this->_message_template_model->insert($template_data);
                 if (!$MTP) {
                     EE_Error::add_error(sprintf(__('There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', 'event_espresso'), $this->_messenger->name, $this->_message_type->name, $context, $field), __FILE__, __FUNCTION__, __LINE__);
                     return false;
                 }
             }
         }
     }
     return array('GRP_ID' => $this->_GRP_ID, 'MTP_context' => key($this->_contexts));
 }
 /**
  * 	perform_activations_upgrades_and_migrations
  *
  *  	@access public
  *  	@return 	void
  */
 public function perform_activations_upgrades_and_migrations()
 {
     //first check if we had previously attempted to setup EE's directories but failed
     if (EEH_Activation::upload_directories_incomplete()) {
         EEH_Activation::create_upload_directories();
     }
     do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
 }
Example #11
0
/**
 * 	espresso_plugin_deactivation
 */
function espresso_plugin_deactivation()
{
    espresso_load_required('EEH_Activation', EE_HELPERS . 'EEH_Activation.helper.php');
    EEH_Activation::plugin_deactivation();
}
 /**
  * Asserts the table (even temporary one) does not exist
  * We really should implement this function in the proper PHPunit style
  * @see http://php-and-symfony.matthiasnoback.nl/2012/02/phpunit-writing-a-custom-assertion/
  * @global WPDB $wpdb
  * @param string $table_name with or without $wpdb->prefix
  * @param string $model_name the model's name (only used for error reporting)
  */
 function assertTableDoesNotExist($table_name, $model_name = 'Unknown')
 {
     if (EEH_Activation::table_exists($table_name)) {
         $this->fail(sprintf(__('Table like %1$s SHOULD NOT exist. It was apparently defined on the model "%2$s"', 'event_espresso'), $table_name, $model_name));
     }
 }
 /**
  * verifies each of the new currencies exists that somehow we missed in 4.6
  */
 public function verify_new_currencies()
 {
     //a list of countries (and specifically some which were missed in another list):https://gist.github.com/adhipg/1600028
     //how many decimal places? https://en.wikipedia.org/wiki/ISO_4217
     //currency symbols: http://www.xe.com/symbols.php
     // CUR_code, CUR_single, CUR_plural, CUR_sign, CUR_dec_plc, CUR_active
     //( 'EUR',  'Euro',  'Euros',  '€',  2,1),
     $newer_currencies = array(array('RSD', 'Dinar', 'Dinars', '', 3, 1));
     global $wpdb;
     $currency_table = $wpdb->prefix . "esp_currency";
     $currency_format = array("CUR_code" => '%s', "CUR_single" => '%s', "CUR_plural" => '%s', "CUR_sign" => '%s', "CUR_dec_plc" => '%d', "CUR_active" => '%d');
     if (EEH_Activation::table_exists($currency_table)) {
         foreach ($newer_currencies as $currency) {
             $SQL = "SELECT COUNT('CUR_code') FROM {$currency_table} WHERE CUR_code='{$currency[0]}' LIMIT 1";
             $countries = $wpdb->get_var($SQL);
             if (!$countries) {
                 $wpdb->insert($currency_table, array_combine(array_keys($currency_format), $currency), $currency_format);
             }
         }
     }
 }
 /**
  * Resets the registry.
  *
  * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
  * is used in a multisite install.  Here is a list of things that are NOT reset.
  *
  * - $_dependency_map
  * - $_class_abbreviations
  * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
  * - $REQ:  Still on the same request so no need to change.
  * - $CAP: There is no site specific state in the EE_Capability class.
  * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
  *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
  * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
  *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
  *             switch or on the restore.
  * - $modules
  * - $shortcodes
  * - $widgets
  *
  * @param boolean $hard whether to reset data in the database too, or just refresh
  * the Registry to its state at the beginning of the request
  * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too,
  * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
  * currently reinstantiate the singletons at the moment)
  * @param   bool    $reset_models    Defaults to true.  When false, then the models are not reset.  This is so client
  *                                  code instead can just change the model context to a different blog id if necessary
  *
  * @return EE_Registry
  */
 public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
 {
     $instance = self::instance();
     EEH_Activation::reset();
     //properties that get reset
     $instance->_cache_on = true;
     $instance->CFG = EE_Config::reset($hard, $reinstantiate);
     $instance->CART = null;
     $instance->MRM = null;
     $instance->LIB = new stdClass();
     //messages reset
     EED_Messages::reset();
     if ($reset_models) {
         foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
             $instance->reset_model($model_name);
         }
     }
     return $instance;
 }
 /**
  * Ensure getting default creator works as expected
  * @since 4.6.0
  */
 public function test_get_default_creator_id()
 {
     //clear out any previous users that may be lurking in teh system
     foreach (get_users() as $wp_user) {
         wp_delete_user($wp_user->ID);
     }
     //set some users; and just make it interesting by having the first user NOT be an admin
     $non_admin_users = $this->factory->user->create_many(2);
     $users = $this->factory->user->create_many(2);
     //make users administrators.
     foreach ($users as $user_id) {
         $user = $this->factory->user->get_object_by_id($user_id);
         //verify
         $this->assertInstanceOf('WP_User', $user);
         //add role
         $user->add_role('administrator');
     }
     //get all users so we know who is the first one that we should be expecting.
     $expected_id = reset($users);
     $this->assertEquals(EEH_Activation::get_default_creator_id(), $expected_id);
     /**
      * ok now let's verify EEH_Activation::reset() properly clears the cache
      * on EEH_Activation. This is important for subsequent unit tests (because
      * EEH_Activation::reset() is called beween unit tests), but also when an admin
      * resets their EE database, or when anyone wants to reset that cache)
      * clear out any previous users that may be lurking in teh system
      */
     EEH_Activation::reset();
     foreach (get_users() as $wp_user) {
         wp_delete_user($wp_user->ID);
     }
     //set some users; and just make it interesting by having the first user NOT be an admin
     $this->factory->user->create_many(2);
     $users_created_after_reset = $this->factory->user->create_many(2);
     //make users administrators.
     foreach ($users_created_after_reset as $user_id) {
         $user = $this->factory->user->get_object_by_id($user_id);
         //verify
         $this->assertInstanceOf('WP_User', $user);
         //add role
         $user->add_role('administrator');
     }
     //get all users so we know who is the first one that we should be expecting.
     $new_expected_id = reset($users_created_after_reset);
     $this->assertEquals(EEH_Activation::get_default_creator_id(), $new_expected_id);
 }
 /**
  *    class constructor
  *
  * @access    public
  * @param string $CNT_ISO
  * @return \EE_Currency_Config
  */
 public function __construct($CNT_ISO = '')
 {
     // get country code from organization settings or use default
     $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ? EE_Registry::instance()->CFG->organization->CNT_ISO : '';
     // but override if requested
     $CNT_ISO = !empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
     // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
     if (!empty($CNT_ISO) && EE_Maintenance_Mode::instance()->models_can_query() && EEH_Activation::table_exists(EE_Registry::instance()->load_model('Country')->table())) {
         // retrieve the country settings from the db, just in case they have been customized
         $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
         if ($country instanceof EE_Country) {
             $this->code = $country->currency_code();
             // currency code: USD, CAD, EUR
             $this->name = $country->currency_name_single();
             // Dollar
             $this->plural = $country->currency_name_plural();
             // Dollars
             $this->sign = $country->currency_sign();
             // currency sign: $
             $this->sign_b4 = $country->currency_sign_before();
             // currency sign before or after: $TRUE  or  FALSE$
             $this->dec_plc = $country->currency_decimal_places();
             // decimal places: 2 = 0.00  3 = 0.000
             $this->dec_mrk = $country->currency_decimal_mark();
             // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
             $this->thsnds = $country->currency_thousands_separator();
             // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
         }
     }
     // fallback to hardcoded defaults, in case the above failed
     if (empty($this->code)) {
         // set default currency settings
         $this->code = 'USD';
         // currency code: USD, CAD, EUR
         $this->name = __('Dollar', 'event_espresso');
         // Dollar
         $this->plural = __('Dollars', 'event_espresso');
         // Dollars
         $this->sign = '$';
         // currency sign: $
         $this->sign_b4 = true;
         // currency sign before or after: $TRUE  or  FALSE$
         $this->dec_plc = 2;
         // decimal places: 2 = 0.00  3 = 0.000
         $this->dec_mrk = '.';
         // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
         $this->thsnds = ',';
         // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
     }
 }
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
 /**
  * 	get list of registration statuses
  * @access private
  * @param array $exclude
  * @return array
  */
 private function _get_registration_status_array($exclude = array())
 {
     //in the very rare circumstance that we are deleting a model's table's data
     //and the table hasn't actually been created, this could have an error
     /** @type WPDB $wpdb */
     global $wpdb;
     EE_Registry::instance()->load_helper('Activation');
     if (EEH_Activation::table_exists($wpdb->prefix . 'esp_status')) {
         $SQL = 'SELECT STS_ID, STS_code FROM ' . $wpdb->prefix . 'esp_status WHERE STS_type = "registration"';
         $results = $wpdb->get_results($SQL);
         self::$_reg_status = array();
         foreach ($results as $status) {
             if (!in_array($status->STS_ID, $exclude)) {
                 self::$_reg_status[$status->STS_ID] = $status->STS_code;
             }
         }
     }
 }
 /**
  * insert DEFAULT ticket
  * Almost identical to EE_DMS_Core_4_1_0::insert_default_tickets, except is aware of the TKT_required field
  *
  * @access public
  * @static
  * @return void
  */
 public function insert_default_tickets()
 {
     global $wpdb;
     $ticket_table = $wpdb->prefix . "esp_ticket";
     if (EEH_Activation::table_exists($ticket_table)) {
         $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table;
         $tickets_exist = $wpdb->get_var($SQL);
         if (!$tickets_exist) {
             $SQL = "INSERT INTO {$ticket_table}\n\t\t\t\t\t( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES\n\t\t\t\t\t( 1, 0, '" . __("Free Ticket", "event_espresso") . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);";
             $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL);
             $wpdb->query($SQL);
         }
     }
     $ticket_price_table = $wpdb->prefix . "esp_ticket_price";
     if (EEH_Activation::table_exists($ticket_price_table)) {
         $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table;
         $ticket_prc_exist = $wpdb->get_var($SQL);
         if (!$ticket_prc_exist) {
             $SQL = "INSERT INTO {$ticket_price_table}\n\t\t\t\t( TKP_ID, TKT_ID, PRC_ID ) VALUES\n\t\t\t\t( 1, 1, 1 )\n\t\t\t\t";
             $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL);
             $wpdb->query($SQL);
         }
     }
 }
 function test_get_cron_tasks__all()
 {
     add_filter('FHEE__EEH_Activation__get_cron_tasks', array($this, 'change_cron_tasks'));
     $old_cron_tasks = EEH_Activation::get_cron_tasks('all');
     $this->assertArrayHasKey(self::expired_cron_task_name, $old_cron_tasks);
     $this->assertArrayHasKey(self::current_cron_task_name, $old_cron_tasks);
 }
 /**
  * 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;
 }
 public function add_default_admin_only_payments()
 {
     global $wpdb;
     $table_name = $wpdb->prefix . "esp_payment_method";
     $user_id = EEH_Activation::get_default_creator_id();
     if ($wpdb->get_var("SHOW TABLES LIKE '" . $table_name . "'") == $table_name) {
         $SQL = "SELECT COUNT( * ) FROM {$table_name}";
         $existing_payment_methods = $wpdb->get_var($SQL);
         $default_admin_only_payment_methods = apply_filters('FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods', array(__("Bank", 'event_espresso') => __("Bank Draft", 'event_espresso'), __("Cash", 'event_espresso') => __("Cash Delivered Physically", 'event_espresso'), __("Check", 'event_espresso') => __("Paper Check", 'event_espresso'), __("Credit Card", 'event_espresso') => __("Offline Credit Card Payment", 'event_espresso'), __("Debit Card", 'event_espresso') => __("Offline Debit Payment", 'event_espresso'), __("Invoice", 'event_espresso') => __("Invoice received with monies included", 'event_espresso'), __("Money Order", 'event_espresso') => '', __("Paypal", 'event_espresso') => __("Paypal eCheck, Invoice, etc", 'event_espresso'), __('Other', 'event_espresso') => __('Other method of payment', 'event_espresso')));
         //make sure we hae payment method records for the following
         //so admins can record payments for them from the admin page
         foreach ($default_admin_only_payment_methods as $nicename => $description) {
             $slug = sanitize_key($nicename);
             //check that such a payment method exists
             $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$table_name} WHERE PMD_slug = %s", $slug));
             if (!$exists) {
                 $values = array('PMD_type' => 'Admin_Only', 'PMD_name' => $nicename, 'PMD_admin_name' => $nicename, 'PMD_admin_desc' => $description, 'PMD_slug' => $slug, 'PMD_wp_user' => $user_id, 'PMD_scope' => serialize(array('ADMIN')));
                 $success = $wpdb->insert($table_name, $values, array('%s', '%s', '%s', '%s', '%s', '%d', '%s'));
                 if (!$success) {
                     $this->add_error(sprintf(__("Could not insert new admin-only payment method with values %s during migration", "event_espresso"), $this->_json_encode($values)));
                 }
             }
         }
     }
 }
 /**
  * Takes care of double-checking that we're not in maintenance mode, and then
  * initializing this addon's necessary initial data. This is called by default on new activations
  * and reactivations
  * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
  * 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($verify_schema = true)
 {
     if ($verify_schema === '') {
         //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
         //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
         //calls them with an argument of an empty string (ie ""), which evaluates to false
         //so we need to treat the empty string as if nothing had been passed, and should instead use the default
         $verify_schema = true;
     }
     if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
         if ($verify_schema) {
             $this->initialize_db();
         }
         $this->initialize_default_data();
         //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
         EE_Data_Migration_Manager::instance()->update_current_database_state_to(array('slug' => $this->name(), 'version' => $this->version()));
         /* make sure core's data is a-ok
          * (at the time of writing, we especially want to verify all the caps are present
          * because payment method type capabilities are added dynamically, and it's
          * possible this addon added a payment method. But it's also possible
          * other data needs to be verified)
          */
         EEH_Activation::initialize_db_content();
         update_option('ee_flush_rewrite_rules', TRUE);
         //in case there are lots of addons being activated at once, let's force garbage collection
         //to help avoid memory limit errors
         //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
         gc_collect_cycles();
     } else {
         //ask the data migration manager to init this addon's data
         //when migrations are finished because we can't do it now
         EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
     }
 }
 /**
  * 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;
  *		however,
  * @param boolean $verify_db_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);
         EEH_Activation::system_initialization();
         if ($verify_schema) {
             EEH_Activation::initialize_db_and_folders();
         }
         EEH_Activation::initialize_db_content();
         if ($initialize_addons_too) {
             //foreach registered addon, make sure its db is up-to-date too
             foreach (EE_Registry::instance()->addons as $addon) {
                 $addon->initialize_db_if_no_migrations_required();
             }
         }
     } 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);
     }
 }
    /**
     * @return bool
     */
    public function schema_changes_before_migration()
    {
        $now_in_mysql = current_time('mysql', true);
        $table_name = 'esp_answer';
        $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tREG_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tANS_value TEXT NOT NULL,\n\t\t\t\t\tPRIMARY KEY  (ANS_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_attendee_meta';
        $sql = "ATTM_ID INT(10) UNSIGNED NOT\tNULL AUTO_INCREMENT,\n\t\t\t\t\t\tATT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\t\tATT_fname VARCHAR(45) NOT NULL,\n\t\t\t\t\t\tATT_lname VARCHAR(45) NOT\tNULL,\n\t\t\t\t\t\tATT_address VARCHAR(255) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_address2 VARCHAR(255) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_city VARCHAR(45) DEFAULT\tNULL,\n\t\t\t\t\t\tSTA_ID INT(10) DEFAULT\tNULL,\n\t\t\t\t\t\tCNT_ISO VARCHAR(45) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_zip VARCHAR(12) DEFAULT\tNULL,\n\t\t\t\t\t\tATT_email VARCHAR(255) NOT NULL,\n\t\t\t\t\t\tATT_phone VARCHAR(45) DEFAULT NULL,\n\t\t\t\t\t\t\tPRIMARY KEY  (ATTM_ID),\n\t\t\t\t\t\t\t\tKEY ATT_fname (ATT_fname),\n\t\t\t\t\t\t\t\tKEY ATT_lname (ATT_lname),\n\t\t\t\t\t\t\t\tKEY ATT_email (ATT_email)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_country';
        $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL,\n\t\t\t\t\t  CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  CNT_cur_code VARCHAR(6) COLLATE utf8_bin DEFAULT 'USD',\n\t\t\t\t\t  CNT_cur_single VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollar',\n\t\t\t\t\t  CNT_cur_plural VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollars',\n\t\t\t\t\t  CNT_cur_sign VARCHAR(45) COLLATE utf8_bin DEFAULT '\$',\n\t\t\t\t\t  CNT_cur_sign_b4 TINYINT(1) DEFAULT '1',\n\t\t\t\t\t  CNT_cur_dec_plc TINYINT(3) UNSIGNED NOT NULL DEFAULT '2',\n\t\t\t\t\t  CNT_cur_dec_mrk VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT '.',\n\t\t\t\t\t  CNT_cur_thsnds VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT ',',\n\t\t\t\t\t  CNT_tel_code VARCHAR(12) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  CNT_is_EU TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  CNT_active TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (CNT_ISO)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_currency';
        $sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL,\n\t\t\t\tCUR_single VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollar',\n\t\t\t\tCUR_plural VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollars',\n\t\t\t\tCUR_sign VARCHAR(45) COLLATE utf8_bin DEFAULT '\$',\n\t\t\t\tCUR_dec_plc VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT '2',\n\t\t\t\tCUR_active TINYINT(1) DEFAULT '0',\n\t\t\t\tPRIMARY KEY  (CUR_code)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_currency_payment_method';
        $sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tCUR_code  VARCHAR(6) COLLATE utf8_bin NOT NULL,\n\t\t\t\tPMD_ID INT(11) NOT NULL,\n\t\t\t\tPRIMARY KEY  (CPM_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_datetime';
        $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t  EVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t  DTT_name VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t  DTT_description TEXT NOT NULL,\n\t\t\t\t  DTT_EVT_start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t  DTT_EVT_end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t  DTT_reg_limit MEDIUMINT(8) DEFAULT -1,\n\t\t\t\t  DTT_sold MEDIUMINT(8) UNSIGNED DEFAULT 0,\n\t\t\t\t  DTT_is_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t  DTT_order MEDIUMINT(3) UNSIGNED DEFAULT 0,\n\t\t\t\t  DTT_parent INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t  DTT_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t\tPRIMARY KEY  (DTT_ID),\n\t\t\t\t\t\tKEY EVT_ID (EVT_ID),\n\t\t\t\t\t\tKEY DTT_is_primary (DTT_is_primary)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_meta';
        $sql = "\n\t\t\tEVTM_ID INT NOT NULL AUTO_INCREMENT,\n\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\tEVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tEVT_display_ticket_selector TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\tEVT_visible_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\tEVT_default_registration_status VARCHAR(3),\n\t\t\tEVT_phone VARCHAR(45) DEFAULT NULL,\n\t\t\tEVT_additional_limit TINYINT UNSIGNED NULL,\n\t\t\tEVT_member_only TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\tEVT_allow_overflow TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\tEVT_timezone_string VARCHAR(45) NULL,\n\t\t\tEVT_external_URL VARCHAR(200) NULL,\n\t\t\tEVT_donations TINYINT(1) NULL,\n\t\t\tPRIMARY KEY  (EVTM_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_question_group';
        $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\tQSG_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tEQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (EQG_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_venue';
        $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\tVNU_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\tEVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\tPRIMARY KEY  (EVV_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_extra_meta';
        $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tOBJ_ID INT(11) DEFAULT NULL,\n\t\t\t\tEXM_type VARCHAR(45) DEFAULT NULL,\n\t\t\t\tEXM_key VARCHAR(45) DEFAULT NULL,\n\t\t\t\tEXM_value TEXT,\n\t\t\t\tPRIMARY KEY  (EXM_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_line_item';
        $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tLIN_code VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\tTXN_ID INT(11) DEFAULT NULL,\n\t\t\t\tLIN_name VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\tLIN_desc TEXT DEFAULT NULL,\n\t\t\t\tLIN_unit_price DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\tLIN_percent DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\tLIN_is_taxable TINYINT(1) DEFAULT 0,\n\t\t\t\tLIN_order int DEFAULT 0,\n\t\t\t\tLIN_parent int DEFAULT 0,\n\t\t\t\tLIN_type VARCHAR(25) NOT NULL,\n\t\t\t\tLIN_total DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\tLIN_quantity INT(10) DEFAULT NULL,\n\t\t\t\tOBJ_ID INT(11) DEFAULT NULL,\n\t\t\t\tOBJ_type VARCHAR(45)DEFAULT NULL,\n\t\t\t\tLIN_timestamp DATETIME NOT NULL DEFAULT '{$now_in_mysql}',\n\t\t\t\tPRIMARY KEY  (LIN_ID)";
        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_log';
        $sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tLOG_time DATETIME DEFAULT NULL,\n\t\t\t\tOBJ_ID VARCHAR(45) DEFAULT NULL,\n\t\t\t\tOBJ_type VARCHAR(45) DEFAULT NULL,\n\t\t\t\tLOG_type VARCHAR(45) DEFAULT NULL,\n\t\t\t\tLOG_message TEXT,\n\t\t\t\tLOG_wp_user INT(11) DEFAULT NULL,\n\t\t\t\tPRIMARY KEY  (LOG_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_message_template';
        $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tGRP_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\tMTP_context VARCHAR(50) NOT NULL,\n\t\t\t\t\tMTP_template_field VARCHAR(30) NOT NULL,\n\t\t\t\t\tMTP_content TEXT NOT NULL,\n\t\t\t\t\tPRIMARY KEY  (MTP_ID),\n\t\t\t\t\tKEY GRP_ID (GRP_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        EEH_Activation::drop_index('esp_message_template_group', 'EVT_ID');
        $table_name = 'esp_message_template_group';
        $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tMTP_user_id INT(10) NOT NULL DEFAULT '1',\n\t\t\t\t\tMTP_name VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\t\tMTP_description VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\t\tMTP_messenger VARCHAR(30) NOT NULL,\n\t\t\t\t\tMTP_message_type VARCHAR(50) NOT NULL,\n\t\t\t\t\tMTP_is_global TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_is_override TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_deleted TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\tMTP_is_active TINYINT(1) NOT NULL DEFAULT '1',\n\t\t\t\t\tPRIMARY KEY  (GRP_ID),\n\t\t\t\t\tKEY MTP_user_id (MTP_user_id)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_event_message_template';
        $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tEVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tGRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (EMT_ID),\n\t\t\t\t\tKEY EVT_ID (EVT_ID),\n\t\t\t\t\tKEY GRP_ID (GRP_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_payment';
        $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tTXN_ID INT(10) UNSIGNED DEFAULT NULL,\n\t\t\t\t\tSTS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\tPAY_source VARCHAR(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_amount DECIMAL(10,3) DEFAULT NULL,\n\t\t\t\t\tPMD_ID INT(11) DEFAULT NULL,\n\t\t\t\t\tPAY_gateway_response TEXT COLLATE utf8_bin,\n\t\t\t\t\tPAY_txn_id_chq_nmbr VARCHAR(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_po_number VARCHAR(32) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_extra_accntng VARCHAR(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\tPAY_details TEXT COLLATE utf8_bin,\n\t\t\t\t\tPAY_redirect_url VARCHAR(300),\n\t\t\t\t\tPAY_redirect_args TEXT,\n\t\t\t\t\tPRIMARY KEY  (PAY_ID),\n\t\t\t\t\tKEY TXN_ID (TXN_ID),\n\t\t\t\t\tKEY PAY_timestamp (PAY_timestamp)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_payment_method';
        $sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tPMD_type VARCHAR(124) DEFAULT NULL,\n\t\t\t\tPMD_name VARCHAR(255) DEFAULT NULL,\n\t\t\t\tPMD_desc TEXT,\n\t\t\t\tPMD_admin_name VARCHAR(255) DEFAULT NULL,\n\t\t\t\tPMD_admin_desc TEXT,\n\t\t\t\tPMD_slug VARCHAR(124) DEFAULT NULL,\n\t\t\t\tPMD_order INT(11) DEFAULT NULL,\n\t\t\t\tPMD_debug_mode TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\tPMD_wp_user INT(11) NOT NULL DEFAULT '0',\n\t\t\t\tPMD_open_by_default TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\tPMD_button_url VARCHAR(1012) DEFAULT NULL,\n\t\t\t\tPMD_scope VARCHAR(255) NULL DEFAULT 'frontend',\n\t\t\t\tPRIMARY KEY  (PMD_ID),\n\t\t\t\tUNIQUE KEY PMD_slug_UNIQUE (PMD_slug)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = "esp_ticket_price";
        $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TKT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRC_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (TKP_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_datetime_ticket";
        $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  DTT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  TKT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRIMARY KEY  (DTK_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_ticket_template";
        $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TTM_name VARCHAR(45) NOT NULL,\n\t\t\t\t\t  TTM_description TEXT,\n\t\t\t\t\t  TTM_file VARCHAR(45),\n\t\t\t\t\t  PRIMARY KEY  (TTM_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question';
        $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
					QST_display_text TEXT NOT NULL,
					QST_admin_label VARCHAR(255) NOT NULL,
					QST_system VARCHAR(25) DEFAULT NULL,
					QST_type VARCHAR(25) NOT NULL DEFAULT "TEXT",
					QST_required TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
					QST_required_text VARCHAR(100) NULL,
					QST_order TINYINT UNSIGNED NOT NULL DEFAULT 0,
					QST_admin_only TINYINT(1) NOT NULL DEFAULT 0,
					QST_wp_user BIGINT UNSIGNED NULL,
					QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0,
					PRIMARY KEY  (QST_ID)';
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question_group_question';
        $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tQSG_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQGQ_order INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (QGQ_ID) ";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_question_option';
        $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tQSO_value VARCHAR(255) NOT NULL,\n\t\t\t\t\tQSO_desc TEXT NOT NULL,\n\t\t\t\t\tQST_ID INT UNSIGNED NOT NULL,\n\t\t\t\t\tQSO_order INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tQSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\tPRIMARY KEY  (QSO_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_registration';
        $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  EVT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\t  ATT_ID BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t\t  TXN_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  TKT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL DEFAULT 'RPP',\n\t\t\t\t\t  REG_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  REG_final_price DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  REG_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  REG_session VARCHAR(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  REG_code VARCHAR(45) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  REG_url_link VARCHAR(64) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  REG_count TINYINT UNSIGNED DEFAULT '1',\n\t\t\t\t\t  REG_group_size TINYINT UNSIGNED DEFAULT '1',\n\t\t\t\t\t  REG_att_is_going TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  REG_deleted TINYINT(1) DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (REG_ID),\n\t\t\t\t\t  KEY EVT_ID (EVT_ID),\n\t\t\t\t\t  KEY ATT_ID (ATT_ID),\n\t\t\t\t\t  KEY TXN_ID (TXN_ID),\n\t\t\t\t\t  KEY TKT_ID (TKT_ID),\n\t\t\t\t\t  KEY STS_ID (STS_ID),\n\t\t\t\t\t  KEY REG_url_link (REG_url_link),\n\t\t\t\t\t  KEY REG_code (REG_code)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_registration_payment';
        $sql = "RPY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  REG_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  PAY_ID INT(10) UNSIGNED NULL,\n\t\t\t\t\t  RPY_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  PRIMARY KEY  (RPY_ID),\n\t\t\t\t\t  KEY REG_ID (REG_ID),\n\t\t\t\t\t  KEY PAY_ID (PAY_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = 'esp_checkin';
        $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tREG_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\tDTT_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\tCHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,\n\t\t\t\t\tCHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\tPRIMARY KEY  (CHK_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_state';
        $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_abbrev VARCHAR(24) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STA_active TINYINT(1) DEFAULT '1',\n\t\t\t\t\t  PRIMARY KEY  (STA_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_status';
        $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,\n\t\t\t\t\t  STS_can_edit TINYINT(1) NOT NULL DEFAULT 0,\n\t\t\t\t\t  STS_desc TINYTEXT COLLATE utf8_bin,\n\t\t\t\t\t  STS_open TINYINT(1) NOT NULL DEFAULT 1,\n\t\t\t\t\t  UNIQUE KEY STS_ID_UNIQUE (STS_ID),\n\t\t\t\t\t  KEY STS_type (STS_type)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_transaction';
        $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  TXN_total DECIMAL(10,3) DEFAULT '0.00',\n\t\t\t\t\t  TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  STS_ID VARCHAR(3) NOT NULL DEFAULT 'TOP',\n\t\t\t\t\t  TXN_session_data TEXT COLLATE utf8_bin,\n\t\t\t\t\t  TXN_hash_salt VARCHAR(250) COLLATE utf8_bin DEFAULT NULL,\n\t\t\t\t\t  PMD_ID INT(11) DEFAULT NULL,\n\t\t\t\t\t  TXN_reg_steps TEXT,\n\t\t\t\t\t  PRIMARY KEY  (TXN_ID),\n\t\t\t\t\t  KEY TXN_timestamp (TXN_timestamp),\n\t\t\t\t\t  KEY STS_ID (STS_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = 'esp_venue_meta';
        $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\tVNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,\n\t\t\tVNU_address VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_address2 VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_city VARCHAR(100) DEFAULT NULL,\n\t\t\tSTA_ID INT(11) DEFAULT NULL,\n\t\t\tCNT_ISO VARCHAR(2) DEFAULT NULL,\n\t\t\tVNU_zip VARCHAR(45) DEFAULT NULL,\n\t\t\tVNU_phone VARCHAR(45) DEFAULT NULL,\n\t\t\tVNU_capacity INT(11) DEFAULT NULL,\n\t\t\tVNU_url VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_virtual_phone VARCHAR(45) DEFAULT NULL,\n\t\t\tVNU_virtual_url VARCHAR(255) DEFAULT NULL,\n\t\t\tVNU_enable_for_gmap TINYINT(1) DEFAULT '0',\n\t\t\tVNU_google_map_link VARCHAR(255) DEFAULT NULL,\n\t\t\tPRIMARY KEY  (VNUM_ID),\n\t\t\tKEY STA_ID (STA_ID),\n\t\t\tKEY CNT_ISO (CNT_ISO)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        //modified tables
        $table_name = "esp_price";
        $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  PRT_ID TINYINT(3) UNSIGNED NOT NULL,\n\t\t\t\t\t  PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  PRC_name VARCHAR(245) NOT NULL,\n\t\t\t\t\t  PRC_desc TEXT,\n\t\t\t\t\t  PRC_is_default TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',\n\t\t\t\t\t  PRC_overrides INT(10) UNSIGNED DEFAULT NULL,\n\t\t\t\t\t  PRC_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRC_wp_user BIGINT UNSIGNED NULL,\n\t\t\t\t\t  PRC_parent INT(10) UNSIGNED DEFAULT 0,\n\t\t\t\t\t  PRIMARY KEY  (PRC_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        $table_name = "esp_price_type";
        $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t  PRT_name VARCHAR(45) NOT NULL,\n\t\t\t\t  PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',\n\t\t\t\t  PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t  PRT_order TINYINT UNSIGNED NULL,\n\t\t\t\t  PRT_wp_user BIGINT UNSIGNED NULL,\n\t\t\t\t  PRT_deleted TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t  UNIQUE KEY PRT_name_UNIQUE (PRT_name),\n\t\t\t\t  PRIMARY KEY  (PRT_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
        $table_name = "esp_ticket";
        $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  TTM_ID INT(10) UNSIGNED NOT NULL,\n\t\t\t\t\t  TKT_name VARCHAR(245) NOT NULL DEFAULT '',\n\t\t\t\t\t  TKT_description TEXT NOT NULL,\n\t\t\t\t\t  TKT_qty MEDIUMINT(8) DEFAULT NULL,\n\t\t\t\t\t  TKT_sold MEDIUMINT(8) NOT NULL DEFAULT 0,\n\t\t\t\t\t  TKT_uses TINYINT NOT NULL DEFAULT '-1',\n\t\t\t\t\t  TKT_required TINYINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_min TINYINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_max TINYINT NOT NULL DEFAULT '-1',\n\t\t\t\t\t  TKT_price DECIMAL(10,3) NOT NULL DEFAULT '0.00',\n\t\t\t\t\t  TKT_start_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  TKT_end_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t\t\t  TKT_taxable TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_row TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_is_default TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\t  TKT_wp_user BIGINT UNSIGNED NULL,\n\t\t\t\t\t  TKT_parent INT(10) UNSIGNED DEFAULT '0',\n\t\t\t\t\t  TKT_deleted TINYINT(1) NOT NULL DEFAULT '0',\n\t\t\t\t\t  PRIMARY KEY  (TKT_ID)";
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        EEH_Activation::drop_index('esp_question_group', 'QSG_identifier_UNIQUE');
        $table_name = 'esp_question_group';
        $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
					QSG_name VARCHAR(255) NOT NULL,
					QSG_identifier VARCHAR(100) NOT NULL,
					QSG_desc TEXT NULL,
					QSG_order TINYINT UNSIGNED NOT NULL DEFAULT 0,
					QSG_show_group_name TINYINT(1) NOT NULL,
					QSG_show_group_desc TINYINT(1) NOT NULL,
					QSG_system TINYINT NULL,
					QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
					QSG_wp_user BIGINT UNSIGNED NULL,
					PRIMARY KEY  (QSG_ID),
					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)';
        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
        //(because many need to convert old string states to foreign keys into the states table)
        $script_4_1_defaults->insert_default_states();
        $script_4_1_defaults->insert_default_countries();
        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
        $script_4_5_defaults->insert_default_price_types();
        $script_4_5_defaults->insert_default_prices();
        $script_4_5_defaults->insert_default_tickets();
        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
        $script_4_6_defaults->add_default_admin_only_payments();
        $script_4_6_defaults->insert_default_currencies();
        $this->verify_new_countries();
        $this->verify_new_currencies();
        return true;
    }
 /**
  * Resets the cache on EEH_Activation
  */
 public static function reset()
 {
     self::$_default_creator_id = NULL;
     self::$_initialized_db_content_already_in_this_request = false;
 }
 /**
  * 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;
     }
 }
 protected function _espresso_page_settings()
 {
     // Check to make sure all of the main pages are setup properly,
     // if not create the default pages and display an admin notice
     EEH_Activation::verify_default_pages_exist();
     $this->_transient_garbage_collection();
     $this->_template_args['values'] = $this->_yes_no_values;
     $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) ? EE_Registry::instance()->CFG->core->reg_page_id : NULL;
     $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) : FALSE;
     $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) ? EE_Registry::instance()->CFG->core->txn_page_id : NULL;
     $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) : FALSE;
     $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) ? EE_Registry::instance()->CFG->core->thank_you_page_id : NULL;
     $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) : FALSE;
     $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) ? EE_Registry::instance()->CFG->core->cancel_page_id : NULL;
     $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) : FALSE;
     $this->_set_add_edit_form_tags('update_espresso_page_settings');
     $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE);
     $this->_template_args['admin_page_content'] = EEH_Template::display_template(GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', $this->_template_args, TRUE);
     $this->display_admin_page_with_sidebar();
 }
 /**
  * sets up EE4 to rerun the migrations from ee3 to ee4
  */
 public function _rerun_migration_from_ee3()
 {
     EE_Registry::instance()->load_helper('Activation');
     EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
     EEH_Activation::delete_all_espresso_cpt_data();
     EEH_Activation::delete_all_espresso_tables_and_data(false);
     //set the db state to something that will require migrations
     update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
     EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
     $this->_redirect_after_action(true, __("Database", 'event_espresso'), __("reset", 'event_espresso'));
 }