本文整理汇总了PHP中Cx\Lib\UpdateUtil::column_exist方法的典型用法代码示例。如果您正苦于以下问题:PHP UpdateUtil::column_exist方法的具体用法?PHP UpdateUtil::column_exist怎么用?PHP UpdateUtil::column_exist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cx\Lib\UpdateUtil
的用法示例。
在下文中一共展示了UpdateUtil::column_exist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: errorHandler
/**
* 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;
}
示例2: newsletter_migrate_country_field
/**
* 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 //
////////////////////////////////
}
示例3: errorHandler
/**
* 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;
}
示例4: errorHandler
/**
* 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;
}
示例5: _contactUpdate
/**
* 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
//.........这里部分代码省略.........
示例6: errorHandler
/**
* 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;
}
示例7: migrateStatistics
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;
}
示例8: _docsysUpdate
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) {
//.........这里部分代码省略.........
示例9: errorHandler
/**
* 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;
}
示例10: errorHandler
/**
* 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;
}
示例11: errorHandler
/**
* 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;
}
示例12: while
// 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');
示例13: errorHandler
/**
* 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;
}
示例14: errorHandler
/**
* 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());
//.........这里部分代码省略.........
示例15: errorHandler
/**
* 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;
}