/** * Handles any kind of database errors * * Includes updating the payments table (I guess from version 1.2.0(?), * note that this is unconfirmed) to the current structure * @return boolean False. Always. * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Payment // Fix the Text and Zones tables first \Text::errorHandler(); Zones::errorHandler(); \Yellowpay::errorHandler(); $table_name = DBPREFIX . 'module_shop_payment'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'processor_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0'), 'fee' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'costs'), 'free_from' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'costs_free_sum'), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'sort_order'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'status')); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { // Migrate all Payment names to the Text table first \Text::deleteByKey('Shop', self::TEXT_NAME); $query = "\n SELECT `id`, `name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query Payment names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Payment name '{$name}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Update Payments that use obsolete PSPs: // - 05, 'Internal_CreditCard' // - 06, 'Internal_Debit', // Uses 04, Internal \Cx\Lib\UpdateUtil::sql("UPDATE {$table_name}\n SET `processor_id`=4 WHERE `processor_id` IN (5, 6)"); // - 07, 'Saferpay_Mastercard_Multipay_CAR', // - 08, 'Saferpay_Visa_Multipay_CAR', // Uses 01, Saferpay \Cx\Lib\UpdateUtil::sql("UPDATE {$table_name}\n SET `processor_id`=1 WHERE `processor_id` IN (7, 8)"); $table_name = DBPREFIX . 'module_shop_rel_payment'; $table_structure = array('payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true), 'zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'zones_id')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always return false; }
/** * Note: the body of this function is by intention not enclosed in a try/catch block. We wan't the calling sections to catch and handle exceptions themself. */ function newsletter_migrate_country_field() { /* TEST $countryId = 0; $text = 'Switzerland'; $objText= \Cx\Lib\UpdateUtil::sql("SELECT `id` FROM `".DBPREFIX."core_text` WHERE `section` = 'core' AND `key` = 'core_country_name' AND `text` = '".contrexx_raw2db($text)."'"); if (!$objResult->EOF) { $countryId = $objText->fields['id']; } \DBG::dump($countryId); return; */ /////////////////////////// // MIGRATE COUNTRY FIELD // /////////////////////////// // 1. backup country column to country_old if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'country')) { \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` CHANGE `country` `country_old` VARCHAR(255) NOT NULL DEFAULT \'\''); } // 2. add new column country_id (format int) if (!\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'country_id')) { \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` ADD `country_id` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT \'0\' AFTER `country_old`'); } // 3. migrate to new country format (using IDs) if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'country_old')) { $objResult = \Cx\Lib\UpdateUtil::sql('SELECT `id`, `country_old` FROM `' . DBPREFIX . 'module_newsletter_user` WHERE `country_id` = 0 AND `country_old` <> \'\''); if ($objResult->RecordCount()) { while (!$objResult->EOF) { // try setting country_id based on a guess from country_old $countryId = 0; $objText = \Cx\Lib\UpdateUtil::sql("SELECT `id` FROM `" . DBPREFIX . "core_text` WHERE `section` = 'core' AND `key` = 'core_country_name' AND `text` = '" . contrexx_raw2db($objResult->fields['country_old']) . "'"); if (!$objResult->EOF) { $countryId = $objText->fields['id']; } \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_newsletter_user` SET `country_id` = \'' . contrexx_raw2db($countryId) . '\', `country_old` = \'\' WHERE `id` = ' . $objResult->fields['id']); if (!checkTimeoutLimit()) { return 'timeout'; } $objResult->MoveNext(); } } // backup literal country name in field notes if (!\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'notes')) { if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_newsletter_user', 'fax')) { $column = 'fax'; } else { // versions pre 3.0.0 didn't have the column 'fax' yet $column = 'phone'; } \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` ADD `notes` text NOT NULL AFTER `' . $column . '`'); } \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_newsletter_user` SET `notes` = `country_old`'); // drop obsolete column country_old' \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_newsletter_user` DROP `country_old`'); } //////////////////////////////// // END: MIGRATE COUNTRY FIELD // //////////////////////////////// }
/** * Handles database errors * * Also migrates old Currency names to the Text class, * and inserts default Currencyes if necessary * @return boolean false Always! * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { global $objDatabase; // Currency \Text::errorHandler(); $table_name = DBPREFIX . 'module_shop_currencies'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'code' => array('type' => 'CHAR(3)', 'notnull' => true, 'default' => ''), 'symbol' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'rate' => array('type' => 'DECIMAL(10,4)', 'unsigned' => true, 'notnull' => true, 'default' => '1.0000'), 'increment' => array('type' => 'DECIMAL(6,5)', 'unsigned' => true, 'notnull' => true, 'default' => '0.01'), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'sort_order'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'renamefrom' => 'status'), 'default' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'is_default')); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { // Migrate all Currency names to the Text table first \Text::deleteByKey('Shop', self::TEXT_NAME); $query = "\n SELECT `id`, `code`, `name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query Currency names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Currency name '{$name}'"); } $objResult->MoveNext(); } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); return false; } // If the table did not exist, insert defaults $arrCurrencies = array('Schweizer Franken' => array('CHF', 'sFr.', 1.0, '0.05', 1, 1, 1), 'Euro' => array('EUR', html_entity_decode("€"), 1.18, '0.01', 2, 1, 0), 'United States Dollars' => array('USD', '$', 0.88, '0.01', 3, 1, 0)); // There is no previous version of this table! \Cx\Lib\UpdateUtil::table($table_name, $table_structure); // And there aren't even records to migrate, so foreach ($arrCurrencies as $name => $arrCurrency) { $query = "\n INSERT INTO `contrexx_module_shop_currencies` (\n `code`, `symbol`, `rate`, `increment`,\n `ord`, `active`, `default`\n ) VALUES (\n '" . join("','", $arrCurrency) . "'\n )"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to insert default Currencies"); } $id = $objDatabase->Insert_ID(); if (!\Text::replace($id, FRONTEND_LANG_ID, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to add Text for default Currency name '{$name}'"); } } // Always return false; }
/** * Handles database errors * * Also migrates old ProductAttribute to new Attribute structures, * including Text records. * @return boolean false Always! * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Attribute $default_lang_id = \FWLanguage::getDefaultLangId(); $table_name_old = DBPREFIX . 'module_shop_products_attributes_name'; $table_name_new = DBPREFIX . 'module_shop_attribute'; if (\Cx\Lib\UpdateUtil::table_exist($table_name_new)) { \Cx\Lib\UpdateUtil::drop_table($table_name_old); } else { $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'display_type')); $table_index = array(); if (\Cx\Lib\UpdateUtil::table_exist($table_name_old)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name_old, 'name')) { // Migrate all Product strings to the Text table first \Text::deleteByKey('Shop', self::TEXT_ATTRIBUTE_NAME); $query = "\n SELECT `id`, `name`\n FROM `{$table_name_old}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to to query Attribute names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_ATTRIBUTE_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Attribute name '{$name}'"); } $objResult->MoveNext(); } } } //DBG::activate(DBG_ADODB); \Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index); if (!\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new)) { throw new \Cx\Lib\Update_DatabaseException("Failed to rename Attribute table"); } } $table_name_old = DBPREFIX . 'module_shop_products_attributes_value'; $table_name_new = DBPREFIX . 'module_shop_option'; if (\Cx\Lib\UpdateUtil::table_exist($table_name_new)) { \Cx\Lib\UpdateUtil::drop_table($table_name_old); } else { $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'attribute_id' => array('type' => 'INT(10)', 'unsigned' => true, 'renamefrom' => 'name_id'), 'price' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00')); $table_index = array(); if (\Cx\Lib\UpdateUtil::table_exist($table_name_old)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name_old, 'value')) { // Migrate all Product strings to the Text table first \Text::deleteByKey('Shop', self::TEXT_OPTION_NAME); $query = "\n SELECT `id`, `value`\n FROM `{$table_name_old}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to to query option names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['value']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_OPTION_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to to migrate option Text '{$name}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index); if (!\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new)) { throw new \Cx\Lib\Update_DatabaseException("Failed to rename Option table"); } } $table_name_old = DBPREFIX . 'module_shop_products_attributes'; $table_name_new = DBPREFIX . 'module_shop_rel_product_attribute'; if (\Cx\Lib\UpdateUtil::table_exist($table_name_new)) { \Cx\Lib\UpdateUtil::drop_table($table_name_old); } else { $table_structure = array('product_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true), 'option_id' => array('type' => 'INT(10)', 'unsigned' => true, 'primary' => true, 'renamefrom' => 'attributes_value_id'), 'ord' => array('type' => 'INT(10)', 'default' => '0', 'renamefrom' => 'sort_id')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index); if (!\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new)) { throw new \Cx\Lib\Update_DatabaseException("Failed to rename Product-Attribute relation table {$table_name_old} to {$table_name_new}"); } } // Always return false; }
/** * Cloudrexx * * @link http://www.cloudrexx.com * @copyright Cloudrexx AG 2007-2015 * * According to our dual licensing model, this program can be used either * under the terms of the GNU Affero General Public License, version 3, * or under a proprietary license. * * The texts of the GNU Affero General Public License with an additional * permission and of our proprietary license can be found at and * in the LICENSE file you have received along with this program. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * "Cloudrexx" is a registered trademark of Cloudrexx AG. * The licensing of the program under the AGPLv3 does not imply a * trademark license. Therefore any rights, title and interest in * our trademarks remain entirely with us. */ function _contactUpdate() { global $objUpdate, $_CONFIG; try { \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_recipient', array('id' => array('type' => 'INT', 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'id_form' => array('type' => 'INT(11)', 'notnull' => true, 'default' => 0), 'name' => array('type' => 'VARCHAR(250)', 'notnull' => true, 'default' => ''), 'email' => array('type' => 'VARCHAR(250)', 'notnull' => true, 'default' => ''), 'sort' => array('type' => 'INT(11)', 'notnull' => true, 'default' => 0))); \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form_field', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'id_form' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'type' => array('type' => 'ENUM(\'text\',\'label\',\'checkbox\',\'checkboxGroup\',\'date\',\'file\',\'multi_file\',\'hidden\',\'password\',\'radio\',\'select\',\'textarea\',\'recipient\')', 'notnull' => true, 'default' => 'text'), 'attributes' => array('type' => 'TEXT'), 'is_required' => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '0'), 'check_type' => array('type' => 'INT(3)', 'notnull' => true, 'default' => '1'), 'order_id' => array('type' => 'SMALLINT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0'))); /**************************** * ADDED: Contrexx v3.0.0 * ****************************/ /* * Create new table 'module_contact_form_field_lang' * to store language patameters of each field */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form_field_lang', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'fieldID' => array('type' => 'INT(10)', 'unsigned' => true, 'after' => 'id'), 'langID' => array('type' => 'INT(10)', 'unsigned' => true, 'after' => 'fieldID'), 'name' => array('type' => 'VARCHAR(255)', 'after' => 'langID'), 'attributes' => array('type' => 'text', 'after' => 'name')), array('fieldID' => array('fields' => array('fieldID', 'langID'), 'type' => 'UNIQUE'))); /* * Migrate name and attributes fields from 'module_contact_form_field' table * to 'module_contact_form_field_lang' table for active frontend language. * For other languages empty string */ if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form_field', 'name') && \Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form', 'langId')) { $query = "SELECT `field`.`id`, `field`.`id_form`, `field`.`name`, `field`.`attributes`, `form`.`langId`\n FROM `" . DBPREFIX . "module_contact_form_field` AS `field`\n JOIN `" . DBPREFIX . "module_contact_form` AS `form`\n ON `form`.`id` = `field`.`id_form`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if ($objResult) { while (!$objResult->EOF) { $rowCountResult = \Cx\Lib\UpdateUtil::sql("SELECT 1\n FROM `" . DBPREFIX . "module_contact_form_field_lang`\n WHERE `fieldID` = " . $objResult->fields['id'] . "\n AND `langID` = " . $objResult->fields['langId'] . "\n LIMIT 1"); if ($rowCountResult->RecordCount() == 0) { $query = "INSERT INTO `" . DBPREFIX . "module_contact_form_field_lang` (\n `fieldID`, `langID`, `name`, `attributes`\n ) VALUES (\n " . $objResult->fields['id'] . ",\n " . $objResult->fields['langId'] . ",\n '" . addslashes($objResult->fields['name']) . "',\n '" . addslashes($objResult->fields['attributes']) . "')"; \Cx\Lib\UpdateUtil::sql($query); } $objResult->MoveNext(); } } } /* * Create table 'module_contact_recipient_lang' */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_recipient_lang', array('id' => array('type' => 'INT(10)', 'notnull' => true, 'unsigned' => true, 'primary' => true, 'auto_increment' => true), 'recipient_id' => array('type' => 'INT(10)', 'notnull' => true, 'unsigned' => true, 'after' => 'id'), 'langID' => array('type' => 'INT(11)', 'notnull' => true, 'after' => 'recipient_id'), 'name' => array('type' => 'VARCHAR(255)', 'after' => 'langID')), array('recipient_id' => array('fields' => array('recipient_id', 'langID'), 'type' => 'UNIQUE'))); /* * Transfer recipientId and name from 'module_contact_recipient' * to 'module_contact_recipient_lang' */ if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_recipient', 'name')) { $query = "SELECT `id`, `id_form`, `name` FROM `" . DBPREFIX . "module_contact_recipient`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); while (!$objResult->EOF) { $langId = 1; if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form', 'langId')) { $query = "SELECT `langId`\n FROM `" . DBPREFIX . "module_contact_form`\n WHERE `id` = " . $objResult->fields['id_form']; $formLangId = \Cx\Lib\UpdateUtil::sql($query); $langId = $formLangId->fields['langId'] != null ? $formLangId->fields['langId'] : 1; } else { $langId = 1; } /* * Check for row already exsist */ $rowCountResult = \Cx\Lib\UpdateUtil::sql("SELECT 1 as count\n FROM `" . DBPREFIX . "module_contact_recipient_lang`\n WHERE `recipient_id` = " . $objResult->fields['id'] . "\n AND `langID` = " . $langId . "\n LIMIT 1"); if ($rowCountResult->RecordCount() == 0) { $query = "INSERT INTO `" . DBPREFIX . "module_contact_recipient_lang` (\n `recipient_id`, `langID`, `name`\n ) VALUES (\n " . $objResult->fields['id'] . ",\n {$langId},\n '" . addslashes($objResult->fields['name']) . "')"; \Cx\Lib\UpdateUtil::sql($query); } $objResult->MoveNext(); } } /* * Drop column 'recipient name' from 'module_contact_recipient' */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_recipient', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'id_form' => array('type' => 'INT(11)', 'notnull' => true, 'default' => 0, 'after' => 'id'), 'email' => array('type' => 'VARCHAR(250)', 'notnull' => true, 'default' => '', 'after' => 'id_form'), 'sort' => array('type' => 'INT(11)', 'notnull' => true, 'default' => 0, 'after' => 'email'))); /* * Create new table 'module_contact_form_submit_data' */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form_submit_data', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'id_entry' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'after' => 'id'), 'id_field' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'after' => 'id_entry'), 'formlabel' => array('type' => 'TEXT', 'after' => 'id_field'), 'formvalue' => array('type' => 'TEXT', 'after' => 'formlabel'))); /* * Transfer 'data' field of 'module_contact_form_data' table to 'field_label' and 'field_value' * in 'module_contact_form_submit_data' after base64 decoding * Fetch fieldId from 'module_contact_form_field_lang' table by matching fieldLabel */ if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form_data', 'data')) { /* * Execute migrate script for every 30 dataset */ $query = "SELECT `id`, `id_form`, `data`\n FROM `" . DBPREFIX . "module_contact_form_data`\n WHERE `data` != ''\n LIMIT 30"; while (($objResult = \Cx\Lib\UpdateUtil::sql($query)) && $objResult->RecordCount()) { while (!$objResult->EOF) { $fields_attr = explode(";", $objResult->fields['data']); foreach ($fields_attr as $key => $value) { $field_attr = explode(",", $value); $field_label = base64_decode($field_attr[0]); $field_value = base64_decode($field_attr[1]); /* * In the contrexx 2.1.4, the recipient fields were stored as 'contactFormField_recipient' in the submitted data. */ if ($field_label == "contactFormField_recipient" && \Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form_field', 'name')) { $form_recipient_query = "SELECT `name`\n FROM `" . DBPREFIX . "module_contact_form_field`\n WHERE `type` = 'recipient'\n AND `id_form` = " . $objResult->fields['id_form'] . "\n LIMIT 1"; $formRecipientResult = \Cx\Lib\UpdateUtil::sql($form_recipient_query); $field_label = $formRecipientResult->fields['name']; } $form_label_query = ' SELECT `lang`.`fieldID` FROM `' . DBPREFIX . 'module_contact_form_field` AS `field` LEFT JOIN `' . DBPREFIX . 'module_contact_form_field_lang` AS `lang` ON `lang`.`fieldID` = `field`.`id` WHERE (`field`.`id_form` = ' . $objResult->fields['id_form'] . ') AND (`lang`.`name` = "' . contrexx_raw2db($field_label) . '") '; $formLabelResult = \Cx\Lib\UpdateUtil::sql($form_label_query); $fieldId = $formLabelResult->fields['fieldID'] != null ? $formLabelResult->fields['fieldID'] : 0; $submitCount = \Cx\Lib\UpdateUtil::sql("SELECT 1\n FROM `" . DBPREFIX . "module_contact_form_submit_data`\n WHERE `id_entry` = " . $objResult->fields['id'] . "\n AND `id_field` = " . $fieldId . "\n LIMIT 1"); if ($submitCount->RecordCount() == 0) { $submitQuery = "INSERT INTO `" . DBPREFIX . "module_contact_form_submit_data` (\n `id_entry`, `id_field`, `formlabel`, `formvalue`\n ) VALUES (\n " . $objResult->fields['id'] . ",\n " . $fieldId . ",\n '" . addslashes($field_label) . "',\n '" . addslashes($field_value) . "')"; \Cx\Lib\UpdateUtil::sql($submitQuery); } } /* * Empty column 'data' of the current dataset */ $updateQuery = "UPDATE `" . DBPREFIX . "module_contact_form_data`\n SET `data` = ''\n WHERE `id` = " . $objResult->fields['id']; \Cx\Lib\UpdateUtil::sql($updateQuery); $objResult->MoveNext(); } } } /* * Alter table 'module_contact_form_data' by dropping 'data' field and adding 'id_lang' */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form_data', array('id' => array('type' => 'INT(10)', 'notnull' => true, 'unsigned' => true, 'primary' => true, 'auto_increment' => true), 'id_form' => array('type' => 'INT(10)', 'notnull' => true, 'unsigned' => true, 'default' => 0, 'after' => 'id'), 'id_lang' => array('type' => 'INT(10)', 'notnull' => true, 'unsigned' => true, 'default' => 1, 'after' => 'id_form'), 'time' => array('type' => 'INT(14)', 'notnull' => true, 'unsigned' => true, 'default' => 0, 'after' => 'id_lang'), 'host' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'after' => 'time'), 'lang' => array('type' => 'VARCHAR(64)', 'notnull' => true, 'after' => 'host'), 'browser' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'after' => 'lang'), 'ipaddress' => array('type' => 'VARCHAR(15)', 'notnull' => true, 'after' => 'browser'))); /* * Alter table 'module_contact_form_field' by dropping name and attributes column * Add 'special_type' column */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form_field', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'id_form' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'after' => 'id'), 'type' => array('type' => 'ENUM(\'text\',\'label\',\'checkbox\',\'checkboxGroup\',\'country\',\'date\',\'file\',\'multi_file\',\'fieldset\',\'hidden\',\'horizontalLine\',\'password\',\'radio\',\'select\',\'textarea\',\'recipient\',\'special\')', 'notnull' => true, 'default' => 'text', 'after' => 'id_form'), 'special_type' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'after' => 'type'), 'is_required' => array('type' => 'SET(\'0\',\'1\')', 'notnull' => true, 'default' => '0', 'after' => 'special_type'), 'check_type' => array('type' => 'INT(3)', 'notnull' => true, 'default' => 1, 'after' => 'is_required'), 'order_id' => array('type' => 'SMALLINT(5)', 'notnull' => true, 'unsigned' => true, 'default' => 0, 'after' => 'check_type'))); /* * Update 'id_lang' column with form language id */ if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form', 'langId')) { $query = "SELECT `id`, `id_form` FROM `" . DBPREFIX . "module_contact_form_data`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if ($objResult) { while (!$objResult->EOF) { $query = "UPDATE `" . DBPREFIX . "module_contact_form_data`\n SET `id_lang` = (\n SELECT `langId` from `" . DBPREFIX . "module_contact_form`\n WHERE `id` = " . $objResult->fields['id_form'] . "\n ) WHERE `id` = " . $objResult->fields['id']; \Cx\Lib\UpdateUtil::sql($query); $objResult->MoveNext(); } } } /* * Create table 'module_contact_form_lang' */ \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form_lang', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'formID' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'after' => 'id'), 'langID' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'after' => 'formID'), 'is_active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => 1, 'after' => 'langID'), 'name' => array('type' => 'VARCHAR(255)', 'after' => 'is_active'), 'text' => array('type' => 'TEXT', 'after' => 'name'), 'feedback' => array('type' => 'TEXT', 'after' => 'text'), 'mailTemplate' => array('type' => 'TEXT', 'after' => 'feedback'), 'subject' => array('type' => 'VARCHAR(255)', 'after' => 'mailTemplate')), array('formID' => array('fields' => array('formID', 'langID'), 'type' => 'UNIQUE'))); /* * Migrate few fields from module_contact_form to module_contact_form_lang * and remaining fields to module_contact_form of new version */ if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form', 'name')) { $query = "SELECT `id`, `name`, `subject`, `text`, `feedback`, `langId`\n FROM `" . DBPREFIX . "module_contact_form`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); while (!$objResult->EOF) { /* * Check for row already exsist */ $rowCountResult = \Cx\Lib\UpdateUtil::sql("SELECT 1\n FROM `" . DBPREFIX . "module_contact_form_lang`\n WHERE `formID` = " . $objResult->fields['id'] . "\n AND `langID` = " . $objResult->fields['langId'] . "\n LIMIT 1"); if ($rowCountResult->RecordCount() == 0) { $formLangQuery = "INSERT INTO `" . DBPREFIX . "module_contact_form_lang` (\n `formID`,\n `langID`,\n `is_active`,\n `name`,\n `text`,\n `feedback`,\n `mailTemplate`,\n `subject`\n ) VALUES (\n " . $objResult->fields['id'] . ",\n " . $objResult->fields['langId'] . ",\n 1,\n '" . addslashes($objResult->fields['name']) . "',\n '" . addslashes($objResult->fields['text']) . "',\n '" . addslashes($objResult->fields['feedback']) . "',\n '" . addslashes('<table> <tbody> <!-- BEGIN form_field --> <tr> <td> [[FIELD_LABEL]] </td> <td> [[FIELD_VALUE]] </td> </tr> <!-- END form_field --> </tbody> </table>') . "',\n '" . addslashes($objResult->fields['subject']) . "'\n )"; \Cx\Lib\UpdateUtil::sql($formLangQuery); } $objResult->MoveNext(); } } /* * Alter table 'module_contact_form' by dropping name, subject, feedback and form text * Add new column 'html_mail' */ if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_contact_form', 'html_mail')) { $htmlMailIsNew = false; } else { $htmlMailIsNew = true; } \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form', array('id' => array('type' => 'INT(10)', 'notnull' => true, 'unsigned' => true, 'primary' => true, 'auto_increment' => true), 'mails' => array('type' => 'TEXT', 'after' => 'id'), 'showForm' => array('type' => 'TINYINT(1)', 'notnull' => true, 'unsigned' => true, 'default' => 0, 'after' => 'mails'), 'use_captcha' => array('type' => 'TINYINT(1)', 'notnull' => true, 'unsigned' => true, 'default' => 1, 'after' => 'showForm'), 'use_custom_style' => array('type' => 'TINYINT(1)', 'notnull' => true, 'unsigned' => true, 'default' => 0, 'after' => 'use_captcha'), 'send_copy' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => 0, 'after' => 'use_custom_style'), 'use_email_of_sender' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => 0, 'after' => 'send_copy'), 'html_mail' => array('type' => 'TINYINT(1)', 'notnull' => true, 'unsigned' => true, 'default' => 1, 'after' => 'use_email_of_sender'), 'send_attachment' => array('type' => 'TINYINT(1)', 'notnull' => true, 'unsigned' => true, 'default' => '0'))); if ($htmlMailIsNew) { \Cx\Lib\UpdateUtil::sql('UPDATE ' . DBPREFIX . 'module_contact_form SET html_mail = 0'); } if (!$objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '2.1.5')) { // for all versions >= 2.2.0 // change all fields currently set to 'file' to 'multi_file' ('multi_file' is same as former 'file' in previous versions) \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "module_contact_form_field` SET `type` = 'multi_file' WHERE `type` = 'file'"); } /** * Update the content pages */ if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0')) { $em = \Env::get('em'); $cl = \Env::get('ClassLoader'); $cl->loadFile(ASCMS_CORE_MODULE_PATH . '/contact/admin.class.php'); $pageRepo = $em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $Contact = new \ContactManager(); $Contact->initContactForms(); foreach ($Contact->arrForms as $id => $form) { foreach ($form['lang'] as $langId => $lang) { if ($lang['is_active'] == true) { $page = $pageRepo->findOneByModuleCmdLang('contact', $id, $langId); if ($page) { $page->setContent($Contact->_getSourceCode($id, $langId)); $page->setUpdatedAtToNow(); $em->persist($page); } } } } $em->flush(); } /******************************************* * EXTENSION: Database structure changes * * ADDED: Contrexx v3.1.0 * *******************************************/ if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.1.0')) { \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_contact_form', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'mails' => array('type' => 'text', 'after' => 'id'), 'showForm' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'mails'), 'use_captcha' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'after' => 'showForm'), 'use_custom_style' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'use_captcha'), 'save_data_in_crm' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'use_custom_style'), 'send_copy' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'save_data_in_crm'), 'use_email_of_sender' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'send_copy'), 'html_mail' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'after' => 'use_email_of_sender'), 'send_attachment' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'html_mail'))); } } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } return true; }
/** * Tries to fix any database problems * @return boolean False. Always. * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { //die("Discount::errorHandler(): Disabled!<br />"); // Discount \Text::errorHandler(); $table_name = DBPREFIX . 'module_shop_article_group'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true)); $table_index = array(); //\DBG::activate(DBG_DB); if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) { \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { \Text::deleteByKey('Shop', self::TEXT_NAME_GROUP_ARTICLE); $query = "\n SELECT `id`, `name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query article group names", $query); } while (!$objResult->EOF) { $group_id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_NAME_GROUP_ARTICLE, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate article group names"); } $objResult->MoveNext(); } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } $table_name = DBPREFIX . 'module_shop_customer_group'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true)); $table_index = array(); if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) { \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { \Text::deleteByKey('Shop', self::TEXT_NAME_GROUP_CUSTOMER); $query = "\n SELECT `id`, `name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query customer group names", $query); } while (!$objResult->EOF) { $group_id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_NAME_GROUP_CUSTOMER, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate customer group names"); } $objResult->MoveNext(); } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } $table_name = DBPREFIX . 'module_shop_rel_discount_group'; $table_structure = array('customer_group_id' => array('type' => 'int(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'primary' => true), 'article_group_id' => array('type' => 'int(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'primary' => true), 'rate' => array('type' => 'decimal(9,2)', 'notnull' => true, 'default' => '0.00')); $table_index = array(); if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) { \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } $table_name = DBPREFIX . 'module_shop_discountgroup_count_name'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true)); $table_index = array(); if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) { \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { \Text::deleteByKey('Shop', self::TEXT_NAME_GROUP_COUNT); \Text::deleteByKey('Shop', self::TEXT_UNIT_GROUP_COUNT); $query = "\n SELECT `id`, `name`, `unit`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query count group names", $query); } while (!$objResult->EOF) { $group_id = $objResult->fields['id']; $name = $objResult->fields['name']; $unit = $objResult->fields['unit']; if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_NAME_GROUP_COUNT, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate count group names"); } if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_UNIT_GROUP_COUNT, $unit)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate count group units"); } $objResult->MoveNext(); } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); } $table_name = DBPREFIX . 'module_shop_discountgroup_count_rate'; $table_structure = array('group_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'primary' => true), 'count' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => 1, 'primary' => true), 'rate' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => true, 'default' => '0.00')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always return false; }
public function migrateStatistics() { global $objUpdate, $_CONFIG; // only execute this part for versions < 2.1.5 if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '2.1.5')) { if (!\Cx\Lib\UpdateUtil::table_exist(DBPREFIX . 'content')) { return true; } try { //2.1.5: new field contrexx_stats_requests.pageTitle needs to be added and filled if (!\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'stats_requests', 'pageTitle')) { \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'stats_requests` ADD `pageTitle` varchar(250) NOT NULL AFTER `sid`'); } //fill pageTitle with current titles \Cx\Lib\UpdateUtil::sql('UPDATE ' . DBPREFIX . 'stats_requests SET pageTitle = ( SELECT title FROM ' . DBPREFIX . 'content WHERE id=pageId ) WHERE EXISTS ( SELECT title FROM ' . DBPREFIX . 'content WHERE id=pageId ) AND pageTitle = \'\''); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } } return true; }
function _docsysUpdate() { global $objDatabase, $_ARRAYLANG; try { \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_docsys_entry_category', array('entry' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true), 'category' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true))); if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_docsys', 'catid')) { $query = "SELECT `id`, `catid` FROM `" . DBPREFIX . "module_docsys`"; $objResult = $objDatabase->Execute($query); if ($objResult !== false) { while (!$objResult->EOF) { $query = "SELECT 1 FROM `" . DBPREFIX . "module_docsys_entry_category` WHERE `entry` = " . $objResult->fields['id'] . " AND `category` = " . $objResult->fields['catid']; $objCheck = $objDatabase->SelectLimit($query, 1); if ($objCheck !== false) { if ($objCheck->RecordCount() == 0) { $query = "INSERT INTO `" . DBPREFIX . "module_docsys_entry_category` (`entry`, `category`) VALUES ('" . $objResult->fields['id'] . "', '" . $objResult->fields['catid'] . "')"; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } } else { return _databaseError($query, $objDatabase->ErrorMsg()); } $objResult->MoveNext(); } } else { return _databaseError($query, $objDatabase->ErrorMsg()); } } // Fix some fuckup that UpdatUtil can't do.. make sure that "id" is unique before attempting // to make it a primary key $duplicateIDs_sql = "SELECT COUNT(*) as c, id FROM " . DBPREFIX . "module_docsys GROUP BY id HAVING c > 1"; $duplicateIDs = $objDatabase->Execute($duplicateIDs_sql); if ($duplicateIDs === false) { return _databaseError($duplicateIDs_sql, $objDatabase->ErrorMsg()); } $fix_queries = array(); while (!$duplicateIDs->EOF) { $id = $duplicateIDs->fields['id']; $entries_sql = "SELECT * FROM " . DBPREFIX . "module_docsys WHERE id = {$id}"; $entries = $objDatabase->Execute($entries_sql); if ($entries === false) { return _databaseError($entries_sql, $objDatabase->ErrorMsg()); } // NOW: put them all in an array, DELETE them and then re-INSERT them // without id. the auto_increment will take care of the rest. The first one we // re-insert can keep it's id. $entries_sql = "SELECT * FROM " . DBPREFIX . "module_docsys WHERE id = {$id}"; $entries = $objDatabase->Execute($entries_sql); if ($entries === false) { return _databaseError($entries_sql, $objDatabase->ErrorMsg()); } $is_first = true; $fix_queries[] = "DELETE FROM " . DBPREFIX . "module_docsys WHERE id = {$id}"; while (!$entries->EOF) { $pairs = array(); foreach ($entries->fields as $k => $v) { // only first may keep it's id if ($k == 'id' and !$is_first) { continue; } $pairs[] = "{$k} = '" . addslashes($v) . "'"; } $fix_queries[] = "INSERT INTO " . DBPREFIX . "module_docsys SET " . join(', ', $pairs); $is_first = false; $entries->MoveNext(); } $duplicateIDs->MoveNext(); } // Now run all of these queries. basically DELETE, INSERT,INSERT, DELETE,INSERT... foreach ($fix_queries as $insert_query) { if ($objDatabase->Execute($insert_query) === false) { return _databaseError($insert_query, $objDatabase->ErrorMsg()); } } // alter column startdate from date to int $arrColumns = $objDatabase->MetaColumns(DBPREFIX . 'module_docsys'); if ($arrColumns === false) { setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'module_docsys')); return false; } if (isset($arrColumns['STARTDATE'])) { if ($arrColumns['STARTDATE']->type == 'date') { if (!isset($arrColumns['STARTDATE_NEW'])) { $query = 'ALTER TABLE `' . DBPREFIX . 'module_docsys` ADD `startdate_new` INT(14) UNSIGNED NOT NULL DEFAULT \'0\' AFTER `startdate`'; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } $query = 'UPDATE `' . DBPREFIX . 'module_docsys` SET `startdate_new` = UNIX_TIMESTAMP(`startdate`) WHERE `startdate` != \'0000-00-00\''; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } $query = 'ALTER TABLE `' . DBPREFIX . 'module_docsys` DROP `startdate`'; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } } $arrColumns = $objDatabase->MetaColumns(DBPREFIX . 'module_docsys'); if ($arrColumns === false) { setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'module_docsys')); return false; } if (!isset($arrColumns['STARTDATE'])) { $query = 'ALTER TABLE `' . DBPREFIX . 'module_docsys` CHANGE `startdate_new` `startdate` INT(14) UNSIGNED NOT NULL DEFAULT \'0\''; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } // alter column enddate from date to int $arrColumns = $objDatabase->MetaColumns(DBPREFIX . 'module_docsys'); if ($arrColumns === false) { setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'module_docsys')); return false; } if (isset($arrColumns['ENDDATE'])) { if ($arrColumns['ENDDATE']->type == 'date') { if (!isset($arrColumns['ENDDATE_NEW'])) { $query = 'ALTER TABLE `' . DBPREFIX . 'module_docsys` ADD `enddate_new` INT(14) UNSIGNED NOT NULL DEFAULT \'0\' AFTER `enddate`'; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } $query = 'UPDATE `' . DBPREFIX . 'module_docsys` SET `enddate_new` = UNIX_TIMESTAMP(`enddate`) WHERE `enddate` != \'0000-00-00\''; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } $query = 'ALTER TABLE `' . DBPREFIX . 'module_docsys` DROP `enddate`'; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } } $arrColumns = $objDatabase->MetaColumns(DBPREFIX . 'module_docsys'); if ($arrColumns === false) { setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_GETTING_DATABASE_TABLE_STRUCTURE'], DBPREFIX . 'module_docsys')); return false; } if (!isset($arrColumns['ENDDATE'])) { $query = 'ALTER TABLE `' . DBPREFIX . 'module_docsys` CHANGE `enddate_new` `enddate` INT(14) UNSIGNED NOT NULL DEFAULT \'0\''; if ($objDatabase->Execute($query) === false) { return _databaseError($query, $objDatabase->ErrorMsg()); } } \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_docsys', array('id' => array('type' => 'INT(6)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'date' => array('type' => 'INT(14)', 'notnull' => false), 'title' => array('type' => 'VARCHAR(250)'), 'author' => array('type' => 'VARCHAR(150)'), 'text' => array('type' => 'MEDIUMTEXT', 'notnull' => true), 'source' => array('type' => 'VARCHAR(250)'), 'url1' => array('type' => 'VARCHAR(250)'), 'url2' => array('type' => 'VARCHAR(250)'), 'lang' => array('type' => 'INT(2)', 'unsigned' => true, 'default' => '0'), 'userid' => array('type' => 'INT(6)', 'unsigned' => true, 'default' => '0'), 'startdate' => array('type' => 'INT(14)', 'unsigned' => true, 'default' => '0'), 'enddate' => array('type' => 'INT(14)', 'unsigned' => true, 'default' => '0'), 'status' => array('type' => 'TINYINT(4)', 'default' => '1'), 'changelog' => array('type' => 'INT(14)', 'default' => '0')), array('newsindex' => array('fields' => array('title', 'text'), 'type' => 'FULLTEXT'))); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } return true; }
function _calendarUpdate() { global $objDatabase; try { \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_calendar', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'active' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'id'), 'catid' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'active'), 'startdate' => array('type' => 'INT(14)', 'notnull' => false, 'after' => 'catid'), 'enddate' => array('type' => 'INT(14)', 'notnull' => false, 'after' => 'startdate'), 'priority' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '3', 'after' => 'enddate'), 'access' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'priority'), 'name' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => '', 'after' => 'access'), 'comment' => array('type' => 'text', 'after' => 'name'), 'placeName' => array('type' => 'VARCHAR(255)', 'after' => 'comment'), 'link' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => 'http://', 'after' => 'placeName'), 'pic' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'link'), 'attachment' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'pic'), 'placeStreet' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'attachment'), 'placeZip' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'placeStreet'), 'placeCity' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'placeZip'), 'placeLink' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'placeCity'), 'placeMap' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'placeLink'), 'organizerName' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'placeMap'), 'organizerStreet' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'organizerName'), 'organizerZip' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'organizerStreet'), 'organizerPlace' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'organizerZip'), 'organizerMail' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'organizerPlace'), 'organizerLink' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'organizerMail'), 'key' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'organizerLink'), 'num' => array('type' => 'INT(5)', 'notnull' => true, 'default' => '0', 'after' => 'key'), 'mailTitle' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'num'), 'mailContent' => array('type' => 'text', 'after' => 'mailTitle'), 'registration' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'mailContent'), 'groups' => array('type' => 'text', 'after' => 'registration'), 'all_groups' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'groups'), 'public' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'all_groups'), 'notification' => array('type' => 'INT(1)', 'after' => 'public'), 'notification_address' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'notification'), 'series_status' => array('type' => 'TINYINT(4)', 'after' => 'notification_address'), 'series_type' => array('type' => 'INT(11)', 'after' => 'series_status'), 'series_pattern_count' => array('type' => 'INT(11)', 'after' => 'series_type'), 'series_pattern_weekday' => array('type' => 'VARCHAR(7)', 'after' => 'series_pattern_count'), 'series_pattern_day' => array('type' => 'INT(11)', 'after' => 'series_pattern_weekday'), 'series_pattern_week' => array('type' => 'INT(11)', 'after' => 'series_pattern_day'), 'series_pattern_month' => array('type' => 'INT(11)', 'after' => 'series_pattern_week'), 'series_pattern_type' => array('type' => 'INT(11)', 'after' => 'series_pattern_month'), 'series_pattern_dourance_type' => array('type' => 'INT(11)', 'after' => 'series_pattern_type'), 'series_pattern_end' => array('type' => 'INT(11)', 'after' => 'series_pattern_dourance_type'), 'series_pattern_begin' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_end'), 'series_pattern_exceptions' => array('type' => 'longtext', 'after' => 'series_pattern_begin')), array('name' => array('fields' => array('name', 'comment', 'placeName'), 'type' => 'FULLTEXT'))); } catch (\Cx\Lib\UpdateException $e) { // we COULD do something else here.. DBG::trace(); return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } //2.1.1 $query = "SELECT status FROM " . DBPREFIX . "modules WHERE id='21'"; $objResultCheck = $objDatabase->SelectLimit($query, 1); if ($objResultCheck !== false) { if ($objResultCheck->fields['status'] == 'y') { $calendarStatus = true; } else { $calendarStatus = false; } } else { return _databaseError($query, $objDatabase->ErrorMsg()); } if ($calendarStatus) { $arrContentSites = array(); $arrContentSites[0]['module'] = 'calendar'; $arrContentSites[0]['cmd'] = ''; $arrContentSites[1]['module'] = 'calendar'; $arrContentSites[1]['cmd'] = 'eventlist'; $arrContentSites[2]['module'] = 'calendar'; $arrContentSites[2]['cmd'] = 'boxes'; //insert new link placeholder in content, if module is active foreach ($arrContentSites as $key => $siteArray) { $module = $siteArray['module']; $cmd = $siteArray['cmd']; try { \Cx\Lib\UpdateUtil::migrateContentPage($module, $cmd, '<a href="index.php?section=calendar&cmd=event&id={CALENDAR_ID}">{CALENDAR_TITLE}</a>', '{CALENDAR_DETAIL_LINK}', '3.0.0'); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } } try { \Cx\Lib\UpdateUtil::migrateContentPage('calendar', 'sign', '<input type="hidden" name="id" value="{CALENDAR_NOTE_ID}" />', '<input type="hidden" name="id" value="{CALENDAR_NOTE_ID}" /><input type="hidden" name="date" value="{CALENDAR_NOTE_DATE}" />', '3.0.0'); \Cx\Lib\UpdateUtil::migrateContentPage('calendar', 'sign', '<a href="index.php?section=calendar&id={CALENDAR_NOTE_ID}">{TXT_CALENDAR_BACK}</a>', '{CALENDAR_LINK_BACK}', '3.0.0'); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } } try { // delete obsolete table contrexx_module_calendar_access \Cx\Lib\UpdateUtil::drop_table(DBPREFIX . 'module_calendar_access'); \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_calendar_form_data', array('reg_id' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0'), 'field_id' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0'), 'data' => array('type' => 'TEXT', 'notnull' => true))); \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_calendar_form_fields', array('id' => array('type' => 'INT(7)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'note_id' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0'), 'name' => array('type' => 'TEXT'), 'type' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0'), 'required' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0'), 'order' => array('type' => 'INT(3)', 'notnull' => true, 'default' => '0'), 'key' => array('type' => 'INT(7)', 'notnull' => true, 'default' => '0'))); \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_calendar_registrations', array('id' => array('type' => 'INT(7)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'note_id' => array('type' => 'INT(7)', 'notnull' => true, 'default' => '0'), 'note_date' => array('type' => 'INT(11)', 'notnull' => true, 'after' => 'note_id'), 'time' => array('type' => 'INT(14)', 'notnull' => true, 'default' => '0'), 'host' => array('type' => 'VARCHAR(255)'), 'ip_address' => array('type' => 'VARCHAR(15)'), 'type' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0'))); } catch (\Cx\Lib\UpdateException $e) { // we COULD do something else here.. DBG::trace(); return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } global $objUpdate; if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.1.0')) { $CalendarUpdate31 = new CalendarUpdate31(); $calendarUpdateFeedback = $CalendarUpdate31->run(); if ($calendarUpdateFeedback !== true) { return $calendarUpdateFeedback; } } if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.2.0')) { try { \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_calendar_event', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'id'), 'startdate' => array('type' => 'INT(14)', 'notnull' => false, 'after' => 'type'), 'enddate' => array('type' => 'INT(14)', 'notnull' => false, 'after' => 'startdate'), 'startdate_timestamp' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'enddate'), 'enddate_timestamp' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'startdate_timestamp'), 'use_custom_date_display' => array('type' => 'TINYINT(1)', 'after' => 'enddate_timestamp'), 'showStartDateList' => array('type' => 'INT(1)', 'after' => 'use_custom_date_display'), 'showEndDateList' => array('type' => 'INT(1)', 'after' => 'showStartDateList'), 'showStartTimeList' => array('type' => 'INT(1)', 'after' => 'showEndDateList'), 'showEndTimeList' => array('type' => 'INT(1)', 'after' => 'showStartTimeList'), 'showTimeTypeList' => array('type' => 'INT(1)', 'after' => 'showEndTimeList'), 'showStartDateDetail' => array('type' => 'INT(1)', 'after' => 'showTimeTypeList'), 'showEndDateDetail' => array('type' => 'INT(1)', 'after' => 'showStartDateDetail'), 'showStartTimeDetail' => array('type' => 'INT(1)', 'after' => 'showEndDateDetail'), 'showEndTimeDetail' => array('type' => 'INT(1)', 'after' => 'showStartTimeDetail'), 'showTimeTypeDetail' => array('type' => 'INT(1)', 'after' => 'showEndTimeDetail'), 'google' => array('type' => 'INT(11)', 'after' => 'showTimeTypeDetail'), 'access' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'google'), 'priority' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '3', 'after' => 'access'), 'price' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'priority'), 'link' => array('type' => 'VARCHAR(255)', 'after' => 'price'), 'pic' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'link'), 'attach' => array('type' => 'VARCHAR(255)', 'after' => 'pic'), 'place_mediadir_id' => array('type' => 'INT(11)', 'after' => 'attach'), 'catid' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'place_mediadir_id'), 'show_in' => array('type' => 'VARCHAR(255)', 'after' => 'catid'), 'invited_groups' => array('type' => 'VARCHAR(45)', 'notnull' => false, 'after' => 'show_in'), 'invited_mails' => array('type' => 'mediumtext', 'notnull' => false, 'after' => 'invited_groups'), 'invitation_sent' => array('type' => 'INT(1)', 'after' => 'invited_mails'), 'invitation_email_template' => array('type' => 'VARCHAR(255)', 'after' => 'invitation_sent'), 'registration' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'invitation_email_template'), 'registration_form' => array('type' => 'INT(11)', 'after' => 'registration'), 'registration_num' => array('type' => 'VARCHAR(45)', 'notnull' => false, 'after' => 'registration_form'), 'registration_notification' => array('type' => 'VARCHAR(1024)', 'notnull' => false, 'after' => 'registration_num'), 'email_template' => array('type' => 'VARCHAR(255)', 'after' => 'registration_notification'), 'ticket_sales' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'email_template'), 'num_seating' => array('type' => 'text', 'after' => 'ticket_sales'), 'series_status' => array('type' => 'TINYINT(4)', 'notnull' => true, 'default' => '0', 'after' => 'num_seating'), 'series_type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_status'), 'series_pattern_count' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_type'), 'series_pattern_weekday' => array('type' => 'VARCHAR(7)', 'after' => 'series_pattern_count'), 'series_pattern_day' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_weekday'), 'series_pattern_week' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_day'), 'series_pattern_month' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_week'), 'series_pattern_type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_month'), 'series_pattern_dourance_type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_type'), 'series_pattern_end' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_dourance_type'), 'series_pattern_end_date' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'series_pattern_end'), 'series_pattern_begin' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_end_date'), 'series_pattern_exceptions' => array('type' => 'longtext', 'after' => 'series_pattern_begin'), 'status' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'series_pattern_exceptions'), 'confirmed' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'status'), 'author' => array('type' => 'VARCHAR(255)', 'after' => 'confirmed'), 'all_day' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'author'), 'location_type' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'all_day'), 'place' => array('type' => 'VARCHAR(255)', 'after' => 'location_type'), 'place_id' => array('type' => 'INT(11)', 'after' => 'place'), 'place_street' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'place_id'), 'place_zip' => array('type' => 'VARCHAR(10)', 'notnull' => false, 'after' => 'place_street'), 'place_city' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'place_zip'), 'place_country' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'place_city'), 'place_link' => array('type' => 'VARCHAR(255)', 'after' => 'place_country'), 'place_map' => array('type' => 'VARCHAR(255)', 'after' => 'place_link'), 'host_type' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'place_map'), 'org_name' => array('type' => 'VARCHAR(255)', 'after' => 'host_type'), 'org_street' => array('type' => 'VARCHAR(255)', 'after' => 'org_name'), 'org_zip' => array('type' => 'VARCHAR(10)', 'after' => 'org_street'), 'org_city' => array('type' => 'VARCHAR(255)', 'after' => 'org_zip'), 'org_country' => array('type' => 'VARCHAR(255)', 'after' => 'org_city'), 'org_link' => array('type' => 'VARCHAR(255)', 'after' => 'org_country'), 'org_email' => array('type' => 'VARCHAR(255)', 'after' => 'org_link'), 'host_mediadir_id' => array('type' => 'INT(11)', 'after' => 'org_email')), array('fk_contrexx_module_calendar_notes_contrexx_module_calendar_ca1' => array('fields' => array('catid')))); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } try { \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_calendar_event` SET `startdate_timestamp` = FROM_UNIXTIME(`startdate`), `enddate_timestamp` = FROM_UNIXTIME(`enddate`)'); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } try { \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_calendar_event', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'id'), 'startdate' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'type'), 'enddate' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'startdate'), 'startdate_timestamp' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'enddate'), 'enddate_timestamp' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'startdate_timestamp'), 'use_custom_date_display' => array('type' => 'TINYINT(1)', 'after' => 'enddate_timestamp'), 'showStartDateList' => array('type' => 'INT(1)', 'after' => 'use_custom_date_display'), 'showEndDateList' => array('type' => 'INT(1)', 'after' => 'showStartDateList'), 'showStartTimeList' => array('type' => 'INT(1)', 'after' => 'showEndDateList'), 'showEndTimeList' => array('type' => 'INT(1)', 'after' => 'showStartTimeList'), 'showTimeTypeList' => array('type' => 'INT(1)', 'after' => 'showEndTimeList'), 'showStartDateDetail' => array('type' => 'INT(1)', 'after' => 'showTimeTypeList'), 'showEndDateDetail' => array('type' => 'INT(1)', 'after' => 'showStartDateDetail'), 'showStartTimeDetail' => array('type' => 'INT(1)', 'after' => 'showEndDateDetail'), 'showEndTimeDetail' => array('type' => 'INT(1)', 'after' => 'showStartTimeDetail'), 'showTimeTypeDetail' => array('type' => 'INT(1)', 'after' => 'showEndTimeDetail'), 'google' => array('type' => 'INT(11)', 'after' => 'showTimeTypeDetail'), 'access' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'google'), 'priority' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '3', 'after' => 'access'), 'price' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'priority'), 'link' => array('type' => 'VARCHAR(255)', 'after' => 'price'), 'pic' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'link'), 'attach' => array('type' => 'VARCHAR(255)', 'after' => 'pic'), 'place_mediadir_id' => array('type' => 'INT(11)', 'after' => 'attach'), 'catid' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'place_mediadir_id'), 'show_in' => array('type' => 'VARCHAR(255)', 'after' => 'catid'), 'invited_groups' => array('type' => 'VARCHAR(45)', 'notnull' => false, 'after' => 'show_in'), 'invited_mails' => array('type' => 'mediumtext', 'notnull' => false, 'after' => 'invited_groups'), 'invitation_sent' => array('type' => 'INT(1)', 'after' => 'invited_mails'), 'invitation_email_template' => array('type' => 'VARCHAR(255)', 'after' => 'invitation_sent'), 'registration' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'invitation_email_template'), 'registration_form' => array('type' => 'INT(11)', 'after' => 'registration'), 'registration_num' => array('type' => 'VARCHAR(45)', 'notnull' => false, 'after' => 'registration_form'), 'registration_notification' => array('type' => 'VARCHAR(1024)', 'notnull' => false, 'after' => 'registration_num'), 'email_template' => array('type' => 'VARCHAR(255)', 'after' => 'registration_notification'), 'ticket_sales' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'email_template'), 'num_seating' => array('type' => 'text', 'after' => 'ticket_sales'), 'series_status' => array('type' => 'TINYINT(4)', 'notnull' => true, 'default' => '0', 'after' => 'num_seating'), 'series_type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_status'), 'series_pattern_count' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_type'), 'series_pattern_weekday' => array('type' => 'VARCHAR(7)', 'after' => 'series_pattern_count'), 'series_pattern_day' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_weekday'), 'series_pattern_week' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_day'), 'series_pattern_month' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_week'), 'series_pattern_type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_month'), 'series_pattern_dourance_type' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_type'), 'series_pattern_end' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_dourance_type'), 'series_pattern_end_date' => array('type' => 'timestamp', 'notnull' => true, 'default' => '0000-00-00 00:00:00', 'after' => 'series_pattern_end'), 'series_pattern_begin' => array('type' => 'INT(11)', 'notnull' => true, 'default' => '0', 'after' => 'series_pattern_end_date'), 'series_pattern_exceptions' => array('type' => 'longtext', 'after' => 'series_pattern_begin'), 'status' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'series_pattern_exceptions'), 'confirmed' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'status'), 'author' => array('type' => 'VARCHAR(255)', 'after' => 'confirmed'), 'all_day' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'author'), 'location_type' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'all_day'), 'place' => array('type' => 'VARCHAR(255)', 'after' => 'location_type'), 'place_id' => array('type' => 'INT(11)', 'after' => 'place'), 'place_street' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'place_id'), 'place_zip' => array('type' => 'VARCHAR(10)', 'notnull' => false, 'after' => 'place_street'), 'place_city' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'place_zip'), 'place_country' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'place_city'), 'place_link' => array('type' => 'VARCHAR(255)', 'after' => 'place_country'), 'place_map' => array('type' => 'VARCHAR(255)', 'after' => 'place_link'), 'host_type' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'place_map'), 'org_name' => array('type' => 'VARCHAR(255)', 'after' => 'host_type'), 'org_street' => array('type' => 'VARCHAR(255)', 'after' => 'org_name'), 'org_zip' => array('type' => 'VARCHAR(10)', 'after' => 'org_street'), 'org_city' => array('type' => 'VARCHAR(255)', 'after' => 'org_zip'), 'org_country' => array('type' => 'VARCHAR(255)', 'after' => 'org_city'), 'org_link' => array('type' => 'VARCHAR(255)', 'after' => 'org_country'), 'org_email' => array('type' => 'VARCHAR(255)', 'after' => 'org_link'), 'host_mediadir_id' => array('type' => 'INT(11)', 'after' => 'org_email')), array('fk_contrexx_module_calendar_notes_contrexx_module_calendar_ca1' => array('fields' => array('catid')))); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } try { \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_calendar_event` SET `startdate` = `startdate_timestamp`, `enddate` = `enddate_timestamp`'); if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_calendar_event', 'startdate_timestamp')) { \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_calendar_event` DROP COLUMN `startdate_timestamp`'); } if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_calendar_event', 'enddate_timestamp')) { \Cx\Lib\UpdateUtil::sql('ALTER TABLE `' . DBPREFIX . 'module_calendar_event` DROP COLUMN `enddate_timestamp`'); } \Cx\LIb\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_calendar_event` SET `series_pattern_end_date` = FROM_UNIXTIME(`series_pattern_end`)'); } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } } // update calendar data to version 3.2.0 if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.2.0')) { $languages = FWLanguage::getLanguageArray(); try { $result = \Cx\Lib\UpdateUtil::sql('SELECT `id`, `invitation_email_template`, `email_template` FROM `' . DBPREFIX . 'module_calendar_event`'); if ($result && $result->RecordCount() > 0) { while (!$result->EOF) { // if the event has been already migrated, continue if (intval($result->fields['invitation_email_template']) != $result->fields['invitation_email_template']) { $result->MoveNext(); continue; } $invitationEmailTemplate = array(); $emailTemplate = array(); foreach ($languages as $langId => $langData) { $invitationEmailTemplate[$langId] = $result->fields['invitation_email_template']; $emailTemplate[$langId] = $result->fields['email_template']; } $invitationEmailTemplate = json_encode($invitationEmailTemplate); $emailTemplate = json_encode($emailTemplate); \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_calendar_event` SET `invitation_email_template`=\'' . contrexx_raw2db($invitationEmailTemplate) . '\', `email_template`=\'' . contrexx_raw2db($emailTemplate) . '\' WHERE `id`=' . intval($result->fields['id'])); $result->MoveNext(); } } } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } } return true; }
/** * Tries to fix database problems * * Also migrates text fields to the new structure. * Note that no VAT classes are added here (yet), so neither the old * nor the new table exists to begin with, the new structure will be * created with no records. * @return boolean False. Always. * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Vat $table_name = DBPREFIX . 'module_shop_vat'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'rate' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => true, 'default' => '0.00', 'renamefrom' => 'percent')); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name, 'class')) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'class')) { // Migrate all Vat classes to the Text table first \Text::deleteByKey('Shop', self::TEXT_CLASS); $query = "\n SELECT `id`, `class`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); while (!$objResult->EOF) { $id = $objResult->fields['id']; $class = $objResult->fields['class']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_CLASS, $class)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate VAT class '{$class}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always return false; }
/** * Handles any kind of database error * @throws Cx\Lib\Update_DatabaseException * @return boolean False. Always. */ static function errorHandler() { // ShopCategory // Fix the Text and Settings table first \Text::errorHandler(); ShopSettings::errorHandler(); $default_lang_id = \FWLanguage::getDefaultLangId(); $table_name = DBPREFIX . 'module_shop_categories'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'catid'), 'parent_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'parentid'), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'catsorting'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'catstatus'), 'picture' => array('type' => 'VARCHAR(255)', 'default' => ''), 'flags' => array('type' => 'VARCHAR(255)', 'default' => '')); $table_index = array('flags' => array('fields' => 'flags', 'type' => 'FULLTEXT')); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'catname')) { // Migrate all ShopCategory names to the Text table first \Text::deleteByKey('Shop', self::TEXT_NAME); \Text::deleteByKey('Shop', self::TEXT_DESCRIPTION); $query = "\n SELECT `catid`, `catname`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query ShopCategory names"); } while (!$objResult->EOF) { $id = $objResult->fields['catid']; $name = $objResult->fields['catname']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate ShopCategory name '{$name}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always return false; }
/** * Handles database errors * * Also migrates text fields to the new structure * @return boolean False. Always. * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Zones // Fix the Zone-Payment relation table $table_name = DBPREFIX . 'module_shop_rel_payment'; $table_structure = array('zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'zones_id'), 'payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true)); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Fix the Text table \Text::errorHandler(); $table_name = DBPREFIX . 'module_shop_zones'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'zones_id'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'activation_status')); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'zones_name')) { // Migrate all Zone names to the Text table first \Text::deleteByKey('Shop', self::TEXT_NAME); $query = "\n SELECT `zones_id`, `zones_name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query Zone names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['zones_id']; $name = $objResult->fields['zones_name']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Zone name '{$name}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); $table_name_old = DBPREFIX . 'module_shop_rel_shipment'; $table_name_new = DBPREFIX . 'module_shop_rel_shipper'; if (!\Cx\Lib\UpdateUtil::table_exist($table_name_new) && \Cx\Lib\UpdateUtil::table_exist($table_name_old)) { \Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new); } $table_structure = array('shipper_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'shipment_id'), 'zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'zones_id')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name_new, $table_structure, $table_index); $table_name = DBPREFIX . 'module_shop_rel_countries'; $table_structure = array('country_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'countries_id'), 'zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'zones_id')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always return false; }
// decode the urls of newsletter module try { $objResult = \Cx\Lib\UpdateUtil::sql('SELECT `id`, `url` FROM `' . DBPREFIX . 'module_newsletter_email_link`'); if ($objResult !== false && $objResult->RecordCount() > 0) { while (!$objResult->EOF) { \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'module_newsletter_email_link` SET `url` = ? WHERE `id` = ?', array(html_entity_decode($objResult->fields['url'], ENT_QUOTES, CONTREXX_CHARSET), $objResult->fields['id'])); $objResult->MoveNext(); } } $_SESSION['contrexx_update']['newsletter_links_decoded'] = true; } catch (\Cx\Lib\UpdateException $e) { return \Cx\Lib\UpdateUtil::DefaultActionHandler($e); } // shop $table_name = DBPREFIX . 'module_shop_currencies'; if (\Cx\Lib\UpdateUtil::table_exist($table_name) && \Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { $query = "\n UPDATE `{$table_name}`\n SET sort_order = 0 WHERE sort_order IS NULL"; \Cx\Lib\UpdateUtil::sql($query); // Currencies table fields \Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'code' => array('type' => 'CHAR(3)', 'notnull' => true, 'default' => ''), 'symbol' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'name' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''), 'rate' => array('type' => 'DECIMAL(10,4)', 'unsigned' => true, 'notnull' => true, 'default' => '1.0000'), 'sort_order' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'is_default' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0'))); } $table_name = DBPREFIX . 'module_shop_payment_processors'; if (Cx\Lib\UpdateUtil::table_exist($table_name)) { \Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'ENUM(\'internal\',\'external\')', 'notnull' => true, 'default' => 'internal'), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'description' => array('type' => 'TEXT'), 'company_url' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'picture' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''))); } } if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.1.0')) { // contact core_module // update the content pages $em = \Env::get('em'); $cl = \Env::get('ClassLoader');
/** * Handles database errors * * Also migrates text fields to the new structure * @return boolean False. Always. * @static * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Product // Fix the Text, Discount, and Manufacturer tables first \Text::errorHandler(); // Discount::errorHandler(); // Called by Customer::errorHandler(); Manufacturer::errorHandler(); $table_name = DBPREFIX . 'module_shop_products'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'normalprice' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'), 'resellerprice' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'), 'discountprice' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'), 'discount_active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'is_special_offer'), 'stock' => array('type' => 'INT(10)', 'default' => '10'), 'stock_visible' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'stock_visibility'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'status'), 'b2b' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1'), 'b2c' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1'), 'date_start' => array('type' => 'TIMESTAMP', 'default' => '0000-00-00 00:00:00', 'renamefrom' => 'startdate'), 'date_end' => array('type' => 'TIMESTAMP', 'default' => '0000-00-00 00:00:00', 'renamefrom' => 'enddate'), 'weight' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'category_id' => array('type' => 'VARCHAR(255)', 'default' => '', 'renamefrom' => 'catid'), 'vat_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'manufacturer_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'manufacturer'), 'group_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'article_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'usergroup_ids' => array('type' => 'VARCHAR(4096)', 'notnull' => false, 'default' => null), 'ord' => array('type' => 'INT(10)', 'default' => '0', 'renamefrom' => 'sort_order'), 'distribution' => array('type' => 'VARCHAR(16)', 'default' => '', 'renamefrom' => 'handler'), 'picture' => array('type' => 'VARCHAR(4096)', 'notnull' => false, 'default' => null), 'flags' => array('type' => 'VARCHAR(4096)', 'notnull' => false, 'default' => null), 'minimum_order_quantity' => array('type' => 'INT(10)', 'unsigned' => false, 'default' => '0')); $table_index = array('group_id' => array('fields' => array('group_id')), 'article_id' => array('fields' => array('article_id')), 'flags' => array('fields' => array('flags'), 'type' => 'FULLTEXT')); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'title')) { // Migrate all Product strings to the Text table first \Text::deleteByKey('Shop', self::TEXT_NAME); \Text::deleteByKey('Shop', self::TEXT_SHORT); \Text::deleteByKey('Shop', self::TEXT_LONG); \Text::deleteByKey('Shop', self::TEXT_CODE); \Text::deleteByKey('Shop', self::TEXT_URI); \Text::deleteByKey('Shop', self::TEXT_KEYS); $query = "\n SELECT `id`, `title`, `shortdesc`, `description`,\n `product_id`, `external_link`, `keywords`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query Product strings", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['title']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product name '{$name}'"); } $short = $objResult->fields['shortdesc']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_SHORT, $short)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product short '{$short}'"); } $long = $objResult->fields['description']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_LONG, $long)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product long '{$long}'"); } $code = $objResult->fields['product_id']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_CODE, $code)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product code '{$code}'"); } $uri = $objResult->fields['external_link']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_URI, $uri)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product uri '{$uri}'"); } $keys = $objResult->fields['keywords']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_KEYS, $keys)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product keys '{$keys}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Also fix Customer and some related tables Customer::errorHandler(); // Always return false; }
/** * Handles database errors * * Also migrates old Shop Customers to the User accounts and adds * all new settings * @return boolean false Always! * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Customer $table_name_old = DBPREFIX . "module_shop_customers"; // If the old Customer table is missing, the migration has completed // successfully already if (!\Cx\Lib\UpdateUtil::table_exist($table_name_old)) { return false; } // Ensure that the ShopSettings (including \Cx\Core\Setting) and Order tables // are ready first! //DBG::log("Customer::errorHandler(): Adding settings"); ShopSettings::errorHandler(); // \Cx\Core\Country\Controller\Country::errorHandler(); // Called by Order::errorHandler(); Order::errorHandler(); Discount::errorHandler(); \Cx\Core\Setting\Controller\Setting::init('Shop', 'config'); $objUser = \FWUser::getFWUserObject()->objUser; // Create new User_Profile_Attributes $index_notes = \Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_notes', 'Shop'); if (!$index_notes) { //DBG::log("Customer::errorHandler(): Adding notes attribute..."); // $objProfileAttribute = new \User_Profile_Attribute(); $objProfileAttribute = $objUser->objAttribute->getById(0); //DBG::log("Customer::errorHandler(): NEW notes attribute: ".var_export($objProfileAttribute, true)); $objProfileAttribute->setNames(array(1 => 'Notizen', 2 => 'Notes', 3 => 'Notes', 4 => 'Notes', 5 => 'Notes', 6 => 'Notes')); $objProfileAttribute->setType('text'); $objProfileAttribute->setMultiline(true); $objProfileAttribute->setParent(0); $objProfileAttribute->setProtection(array(1)); //DBG::log("Customer::errorHandler(): Made notes attribute: ".var_export($objProfileAttribute, true)); if (!$objProfileAttribute->store()) { throw new \Cx\Lib\Update_DatabaseException("Failed to create User_Profile_Attribute 'notes'"); } //Re initialize shop setting \Cx\Core\Setting\Controller\Setting::init('Shop', 'config'); //DBG::log("Customer::errorHandler(): Stored notes attribute, ID ".$objProfileAttribute->getId()); if (!(\Cx\Core\Setting\Controller\Setting::set('user_profile_attribute_notes', $objProfileAttribute->getId()) && \Cx\Core\Setting\Controller\Setting::update('user_profile_attribute_notes'))) { throw new \Cx\Lib\Update_DatabaseException("Failed to update User_Profile_Attribute 'notes' setting"); } //DBG::log("Customer::errorHandler(): Stored notes attribute ID setting"); } $index_group = \Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_customer_group_id', 'Shop'); if (!$index_group) { // $objProfileAttribute = new \User_Profile_Attribute(); $objProfileAttribute = $objUser->objAttribute->getById(0); $objProfileAttribute->setNames(array(1 => 'Kundenrabattgruppe', 2 => 'Discount group', 3 => 'Kundenrabattgruppe', 4 => 'Kundenrabattgruppe', 5 => 'Kundenrabattgruppe', 6 => 'Kundenrabattgruppe')); $objProfileAttribute->setType('text'); $objProfileAttribute->setParent(0); $objProfileAttribute->setProtection(array(1)); if (!$objProfileAttribute->store()) { throw new \Cx\Lib\Update_DatabaseException("Failed to create User_Profile_Attribute 'notes'"); } //Re initialize shop setting \Cx\Core\Setting\Controller\Setting::init('Shop', 'config'); if (!(\Cx\Core\Setting\Controller\Setting::set('user_profile_attribute_customer_group_id', $objProfileAttribute->getId()) && \Cx\Core\Setting\Controller\Setting::update('user_profile_attribute_customer_group_id'))) { throw new \Cx\Lib\Update_DatabaseException("Failed to update User_Profile_Attribute 'customer_group_id' setting"); } } // For the migration, a temporary flag is needed in the orders table // in order to prevent mixing up old and new customer_id values. $table_order_name = DBPREFIX . "module_shop_orders"; if (!\Cx\Lib\UpdateUtil::column_exist($table_order_name, 'migrated')) { $query = "\n ALTER TABLE `{$table_order_name}`\n ADD `migrated` TINYINT(1) unsigned NOT NULL default 0"; \Cx\Lib\UpdateUtil::sql($query); } // Create missing UserGroups for customers and resellers $objGroup = null; $group_id_customer = \Cx\Core\Setting\Controller\Setting::getValue('usergroup_id_customer', 'Shop'); if ($group_id_customer) { $objGroup = \FWUser::getFWUserObject()->objGroup->getGroup($group_id_customer); } if (!$objGroup || $objGroup->EOF) { $objGroup = \FWUser::getFWUserObject()->objGroup->getGroups(array('group_name' => 'Shop Endkunden')); } if (!$objGroup || $objGroup->EOF) { $objGroup = new \UserGroup(); $objGroup->setActiveStatus(true); $objGroup->setDescription('Online Shop Endkunden'); $objGroup->setName('Shop Endkunden'); $objGroup->setType('frontend'); } //DBG::log("Group: ".var_export($objGroup, true)); if (!$objGroup) { throw new \Cx\Lib\Update_DatabaseException("Failed to create UserGroup for customers"); } //DBG::log("Customer::errorHandler(): Made customer usergroup: ".var_export($objGroup, true)); if (!$objGroup->store() || !$objGroup->getId()) { throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup for customers"); } //DBG::log("Customer::errorHandler(): Stored customer usergroup, ID ".$objGroup->getId()); \Cx\Core\Setting\Controller\Setting::set('usergroup_id_customer', $objGroup->getId()); if (!\Cx\Core\Setting\Controller\Setting::update('usergroup_id_customer')) { throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup ID for customers"); } $group_id_customer = $objGroup->getId(); $objGroup = null; $group_id_reseller = \Cx\Core\Setting\Controller\Setting::getValue('usergroup_id_reseller', 'Shop'); if ($group_id_reseller) { $objGroup = \FWUser::getFWUserObject()->objGroup->getGroup($group_id_reseller); } if (!$objGroup || $objGroup->EOF) { $objGroup = \FWUser::getFWUserObject()->objGroup->getGroups(array('group_name' => 'Shop Wiederverkäufer')); } if (!$objGroup || $objGroup->EOF) { $objGroup = new \UserGroup(); $objGroup->setActiveStatus(true); $objGroup->setDescription('Online Shop Wiederverkäufer'); $objGroup->setName('Shop Wiederverkäufer'); $objGroup->setType('frontend'); } if (!$objGroup) { throw new \Cx\Lib\Update_DatabaseException("Failed to create UserGroup for resellers"); } //DBG::log("Customer::errorHandler(): Made reseller usergroup: ".var_export($objGroup, true)); if (!$objGroup->store() || !$objGroup->getId()) { throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup for resellers"); } \Cx\Core\Setting\Controller\Setting::set('usergroup_id_reseller', $objGroup->getId()); if (!\Cx\Core\Setting\Controller\Setting::update('usergroup_id_reseller')) { throw new \Cx\Lib\Update_DatabaseException("Failed to store UserGroup ID for resellers"); } $group_id_reseller = $objGroup->getId(); $default_lang_id = \FWLanguage::getDefaultLangId(); $query = "\n SELECT `customer`.`customerid`,\n `customer`.`prefix`, `customer`.`firstname`,\n `customer`.`lastname`,\n `customer`.`company`, `customer`.`address`,\n `customer`.`city`, `customer`.`zip`,\n `customer`.`country_id`,\n `customer`.`phone`, `customer`.`fax`,\n `customer`.`email`,\n `customer`.`username`, `customer`.`password`,\n `customer`.`company_note`,\n `customer`.`is_reseller`,\n `customer`.`customer_status`, `customer`.`register_date`,\n `customer`.`group_id`\n FROM `{$table_name_old}` AS `customer`\n ORDER BY `customer`.`customerid` ASC"; $objResult = \Cx\Lib\UpdateUtil::sql($query); while (!$objResult->EOF) { $old_customer_id = $objResult->fields['customerid']; if (empty($objResult->fields['email'])) { $objResult->fields['email'] = $objResult->fields['username']; } $email = $objResult->fields['email']; $objUser = \FWUser::getFWUserObject()->objUser->getUsers(array('email' => array(0 => $email))); // TODO: See whether a User with that username (but different e-mail address) exists! $objUser_name = \FWUser::getFWUserObject()->objUser->getUsers(array('username' => array(0 => $objResult->fields['username']))); if ($objUser && $objUser_name) { $objUser = $objUser_name; } $objCustomer = null; if ($objUser) { $objCustomer = self::getById($objUser->getId()); } if (!$objCustomer) { $lang_id = Order::getLanguageIdByCustomerId($old_customer_id); $lang_id = \FWLanguage::getLangIdByIso639_1($lang_id); if (!$lang_id) { $lang_id = $default_lang_id; } $objCustomer = new Customer(); if (preg_match('/^(?:frau|mad|mme|signora|miss)/i', $objResult->fields['prefix'])) { $objCustomer->gender('gender_female'); } elseif (preg_match('/^(?:herr|mon|signore|mister|mr)/i', $objResult->fields['prefix'])) { $objCustomer->gender('gender_male'); // } else { // Other "genders", like "family", "thing", or "it" won't be matched // and are left on "gender_unknown". //DBG::log("*** Prefix {$objResult->fields['prefix']}, UNKNOWN GENDER!"); } //DBG::log("Prefix {$objResult->fields['prefix']}, made gender ".$objCustomer->gender()); $objCustomer->company($objResult->fields['company']); $objCustomer->firstname($objResult->fields['firstname']); $objCustomer->lastname($objResult->fields['lastname']); $objCustomer->address($objResult->fields['address']); $objCustomer->city($objResult->fields['city']); $objCustomer->zip($objResult->fields['zip']); $objCustomer->country_id($objResult->fields['country_id']); $objCustomer->phone($objResult->fields['phone']); $objCustomer->fax($objResult->fields['fax']); $objCustomer->email($objResult->fields['email']); $objCustomer->companynote($objResult->fields['company_note']); $objCustomer->active($objResult->fields['customer_status']); // Handled by a UserGroup now, see below //$objCustomer->setResellerStatus($objResult->fields['is_reseller']); $objCustomer->register_date($objResult->fields['register_date']); $objCustomer->group_id($objResult->fields['group_id']); // NOTE: Mind that the User class has been modified to accept e-mail addresses // as usernames! $objCustomer->username($objResult->fields['username']); // Copy the md5 hash of the password! $objCustomer->password = $objResult->fields['password']; $objCustomer->setFrontendLanguage($lang_id); } if ($objResult->fields['is_reseller']) { $objCustomer->setGroups($objCustomer->getAssociatedGroupIds() + array($group_id_reseller)); //DBG::log("Customer::errorHandler(): Added reseller: ".$objCustomer->id()); } else { $objCustomer->setGroups($objCustomer->getAssociatedGroupIds() + array($group_id_customer)); //DBG::log("Customer::errorHandler(): Added customer: ".$objCustomer->id()); } if (!$objCustomer->store()) { //DBG::log(var_export($objCustomer, true)); throw new \Cx\Lib\Update_DatabaseException("Failed to migrate existing Customer ID " . $old_customer_id . " to Users (Messages: " . join(', ', $objCustomer->error_msg) . ")"); } // Update the Orders table with the new Customer ID. // Note that we use the ambiguous old customer ID that may // coincide with a new User ID, so to prevent inconsistencies, // migrated Orders are marked as such. $query = "\n UPDATE `{$table_order_name}`\n SET `customer_id`=" . $objCustomer->id() . ",\n `migrated`=1\n WHERE `customer_id`={$old_customer_id}\n AND `migrated`=0"; \Cx\Lib\UpdateUtil::sql($query); // Drop migrated $query = "\n DELETE FROM `{$table_name_old}`\n WHERE `customerid`={$old_customer_id}"; \Cx\Lib\UpdateUtil::sql($query); $objResult->MoveNext(); if (!checkMemoryLimit() || !checkTimeoutLimit()) { return false; } } // Remove the flag, it's no longer needed. // (You could also verify that all records have been migrated by // querying them with "[...] WHERE `migrated`=0", which *MUST* result // in an empty recordset. This is left as an exercise for the reader.) $query = "\n ALTER TABLE `{$table_order_name}`\n DROP `migrated`"; \Cx\Lib\UpdateUtil::sql($query); \Cx\Lib\UpdateUtil::drop_table($table_name_old); //DBG::log("Updated Customer table and related stuff"); // Always return false; }
/** * Handles database errors * * Also migrates old names to the new structure * @return boolean False. Always. * @static * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Shipment static $break = false; if ($break) { die("\n Shipment::errorHandler(): Recursion detected while handling an error.<br /><br />\n This should not happen. We are very sorry for the inconvenience.<br />\n Please contact customer support: helpdesk@comvation.com"); } $break = true; //die("Shipment::errorHandler(): Disabled!<br />"); // Fix the Zones table first Zones::errorHandler(); $table_name = DBPREFIX . 'module_shop_shipper'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'ord' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'renamefrom' => 'status')); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name)) { if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { \Text::deleteByKey('Shop', self::TEXT_NAME); $query = "\n SELECT `id`, `name`\n FROM `{$table_name}`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); if (!$objResult) { throw new \Cx\Lib\Update_DatabaseException("Failed to query names", $query); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['name']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate name '{$name}'"); } $objResult->MoveNext(); } } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); $table_name = DBPREFIX . 'module_shop_shipment_cost'; $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'shipper_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'max_weight' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'fee' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'cost'), 'free_from' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'price_free')); $table_index = array(); \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); // Always! return false; }
/** * Handles database errors * * Also migrates the old Manufacturers to the new structure * @return boolean False. Always. * @throws Cx\Lib\Update_DatabaseException */ static function errorHandler() { // Manufacturer // Fix the Text table first \Text::errorHandler(); $table_name = DBPREFIX . 'module_shop_manufacturer'; // Note: As this table uses a single column, the primary key will // have to be added separately below. Otherwise, UpdateUtil::table() // will drop the id column first, then try to drop all the others, // which obviously won't work. // In that context, the "AUTO_INCREMENT" has to be dropped as well, // for that only applies to a primary key column. $table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true)); $table_index = array(); $default_lang_id = \FWLanguage::getDefaultLangId(); if (\Cx\Lib\UpdateUtil::table_exist($table_name) && \Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) { // Get rid of bodies \Text::deleteByKey('Shop', self::TEXT_NAME); \Text::deleteByKey('Shop', self::TEXT_URI); // Migrate all Manufacturer text fields to the Text table $query = "\n SELECT `id`, `name`, `url`\n FROM `" . DBPREFIX . "module_shop_manufacturer`"; $objResult = \Cx\Lib\UpdateUtil::sql($query); while (!$objResult->EOF) { $id = $objResult->fields['id']; $name = $objResult->fields['name']; $uri = $objResult->fields['url']; if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Manufacturer name '{$name}'"); } if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_URI, $uri)) { throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Manufacturer URI '{$uri}'"); } $objResult->MoveNext(); } } \Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index); \Cx\Lib\UpdateUtil::sql("\n ALTER TABLE `{$table_name}`\n ADD PRIMARY KEY (`id`)"); \Cx\Lib\UpdateUtil::sql("\n ALTER TABLE `{$table_name}`\n CHANGE `id` `id` int(10) unsigned NOT NULL AUTO_INCREMENT"); // Always return false; }