本文整理匯總了PHP中Cx\Lib\UpdateUtil::table_rename方法的典型用法代碼示例。如果您正苦於以下問題:PHP UpdateUtil::table_rename方法的具體用法?PHP UpdateUtil::table_rename怎麽用?PHP UpdateUtil::table_rename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cx\Lib\UpdateUtil
的用法示例。
在下文中一共展示了UpdateUtil::table_rename方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: errorHandler
/**
* Handles all kinds of database errors
*
* Creates the processors' table, and creates default entries if necessary
* @return boolean False. Always.
* @global ADOConnection $objDatabase
*/
static function errorHandler()
{
// PaymentProcessing
$table_name_old = DBPREFIX . 'module_shop_processors';
$table_name_new = DBPREFIX . 'module_shop_payment_processors';
if (\Cx\Lib\UpdateUtil::table_exist($table_name_old)) {
\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new);
}
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'ENUM("internal", "external")', 'default' => 'internal'), 'name' => array('type' => 'VARCHAR(255)', 'default' => ''), 'description' => array('type' => 'TEXT', 'default' => ''), 'company_url' => array('type' => 'VARCHAR(255)', 'default' => ''), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => 1), 'picture' => array('type' => 'VARCHAR(255)', 'default' => ''));
\Cx\Lib\UpdateUtil::table($table_name_new, $table_structure);
$arrPsp = array(array(1, 'external', 'saferpay', 'Saferpay is a comprehensive Internet payment platform, specially developed for commercial applications. It provides a guarantee of secure payment processes over the Internet for merchants as well as for cardholders. Merchants benefit from the easy integration of the payment method into their e-commerce platform, and from the modularity with which they can take account of current and future requirements. Cardholders benefit from the security of buying from any shop that uses Saferpay.', 'http://www.saferpay.com/', 1, 'logo_saferpay.gif'), array(2, 'external', 'paypal', 'With more than 40 million member accounts in over 45 countries worldwide, PayPal is the world\'s largest online payment service. PayPal makes sending money as easy as sending email! Any PayPal member can instantly and securely send money to anyone in the U.S. with an email address. PayPal can also be used on a web-enabled cell phone. In the future, PayPal will be available to use on web-enabled pagers and other handheld devices.', 'http://www.paypal.com/', 1, 'logo_paypal.gif'), array(3, 'external', 'yellowpay', 'PostFinance vereinfacht das Inkasso im Online-Shop.', 'http://www.postfinance.ch/', 1, 'logo_postfinance.gif'), array(4, 'internal', 'internal', 'Internal no forms', '', 1, ''), array(9, 'internal', 'internal_lsv', 'LSV with internal form', '', 1, ''), array(10, 'external', 'datatrans', 'Die professionelle und komplette Payment-Lösung', 'http://datatrans.biz/', 1, 'logo_datatrans.gif'), array(11, 'external', 'mobilesolutions', 'PostFinance Mobile', 'https://postfinance.mobilesolutions.ch/', 1, 'logo_postfinance_mobile.gif'));
$query_template = "\n REPLACE INTO `{$table_name_new}` (\n `id`, `type`, `name`,\n `description`,\n `company_url`, `status`, `picture`\n ) VALUES (\n ?, ?, ?, ?, ?, ?, ?\n )";
foreach ($arrPsp as $psp) {
\Cx\Lib\UpdateUtil::sql($query_template, $psp);
}
if (\Cx\Lib\UpdateUtil::table_exist($table_name_old)) {
\Cx\Lib\UpdateUtil::drop_table($table_name_old);
}
// Drop obsolete PSPs -- see Payment::errorHandler()
\Cx\Lib\UpdateUtil::sql("\n DELETE FROM `" . DBPREFIX . "module_shop_payment_processors`\n WHERE `id` IN (5, 6, 7, 8)");
// Always
return false;
}
示例3: 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;
}
示例4: migrateBlocks
//.........這裏部分代碼省略.........
');
if ($objResult->RecordCount()) {
// get the page repository
$pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page');
// loop through all old entries
while (!$objResult->EOF) {
$blockId = $objResult->fields['block_id'];
$oldPageId = $objResult->fields['page_id'];
$aliasPage = $pageRepo->findOneBy(array('type' => \Cx\Core\ContentManager\Model\Entity\Page::TYPE_ALIAS, 'slug' => 'legacy_page_' . $oldPageId), true);
// make new entry
if ($aliasPage) {
$page = $pageRepo->getTargetPage($aliasPage);
if ($page) {
\Cx\Lib\UpdateUtil::sql('
INSERT IGNORE INTO `' . DBPREFIX . 'module_block_rel_pages_tmp` (`page_id`, `block_id`, `placeholder`)
VALUES (?, ?, ?)
', array($page->getId(), $blockId, 'global'));
// only for contrexx 2.x
if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0') && !$objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '2.0.0')) {
// do page association for direct placeholder
\Cx\Lib\UpdateUtil::sql('
INSERT IGNORE INTO `' . DBPREFIX . 'module_block_rel_pages_tmp` (`page_id`, `block_id`, `placeholder`)
VALUES (?, ?, ?)
', array($page->getId(), $blockId, 'direct'));
}
\DBG::msg('BLOCK MIGRATION: inserted to temporary table, blockid: ' . $blockId . ', pageid: ' . $page->getId());
}
}
// delte old entry
\Cx\Lib\UpdateUtil::sql('DELETE FROM `' . DBPREFIX . 'module_block_rel_pages` WHERE `block_id` = ? AND `page_id` = ?', array($blockId, $oldPageId));
// check for memory limit and timeout limit
if (!checkMemoryLimit() || !checkTimeoutLimit()) {
$_SESSION['contrexx_update']['blocks_part_2_migrated_timeout'] = true;
return 'timeout';
}
$objResult->MoveNext();
}
}
// move the temporary table to the new table
\Cx\Lib\UpdateUtil::drop_table(DBPREFIX . 'module_block_rel_pages');
\Cx\Lib\UpdateUtil::table_rename(DBPREFIX . 'module_block_rel_pages_tmp', DBPREFIX . 'module_block_rel_pages');
\DBG::msg('BLOCK MIGRATION: REMOVED TEMPORARY TABLE');
} else {
// 3.0.3 : add new column `placeholder`
\Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_block_rel_pages', array('block_id' => array('type' => 'INT(7)', 'notnull' => true, 'default' => '0'), 'page_id' => array('type' => 'INT(7)', 'notnull' => true, 'default' => '0', 'after' => 'block_id'), 'placeholder' => array('type' => 'ENUM(\'global\',\'direct\',\'category\')', 'notnull' => true, 'default' => 'global', 'after' => 'page_id')));
}
// IMPORTANT: add primary key after migration, not used anymore (temporary table)
// \Cx\Lib\UpdateUtil::table(
// DBPREFIX.'module_block_rel_pages',
// array(
// 'block_id' => array('type' => 'INT(7)', 'notnull' => true, 'default' => '0', 'primary' => true),
// 'page_id' => array('type' => 'INT(7)', 'notnull' => true, 'default' => '0', 'after' => 'block_id', 'primary' => true),
// 'placeholder' => array('type' => 'ENUM(\'global\',\'direct\',\'category\')', 'notnull' => true, 'default' => 'global', 'after' => 'page_id', 'primary' => true)
// )
// );
$_SESSION['contrexx_update']['blocks_part_2_migrated'] = true;
}
if (empty($_SESSION['contrexx_update']['blocks_part_3_migrated'])) {
$activeLangIds = implode(',', \FWLanguage::getIdArray());
$objResult = \Cx\Lib\UpdateUtil::sql('
SELECT `block_id`, `lang_id`
FROM `' . DBPREFIX . 'module_block_blocks` AS `b`
INNER JOIN `' . DBPREFIX . 'module_block_rel_lang` AS `rl`
ON `b`.`id` = `rl`.`block_id`
WHERE `b`.`global` = 2
AND `rl`.`all_pages` = 1
AND `rl`.`lang_id` IN (' . $activeLangIds . ')
');
if ($objResult->RecordCount()) {
$langIds = array();
$pageIds = array();
while (!$objResult->EOF) {
$langIds[$objResult->fields['block_id']] = $objResult->fields['lang_id'];
$objResult->MoveNext();
}
$uniqueLangIds = array_unique($langIds);
foreach ($uniqueLangIds as $langId) {
$pageRepo = self::$em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page');
$pages = $pageRepo->findBy(array('lang' => $langId), true);
foreach ($pages as $page) {
$pageIds[$langId][] = $page->getId();
}
}
foreach ($langIds as $blockId => $langId) {
foreach ($pageIds[$langId] as $pageId) {
\Cx\Lib\UpdateUtil::sql('
INSERT IGNORE INTO `' . DBPREFIX . 'module_block_rel_pages` (`block_id`, `page_id`)
VALUES (' . $blockId . ', ' . $pageId . ')
');
}
}
}
$_SESSION['contrexx_update']['blocks_part_3_migrated'] = true;
}
} catch (\Cx\Lib\UpdateException $e) {
\Cx\Lib\UpdateUtil::DefaultActionHandler($e);
return false;
}
return true;
}
示例5: errorHandler
/**
* Handles database errors
*
* Also migrates the old database structure to the new one
* @return boolean False. Always.
*/
static function errorHandler()
{
// Order
ShopSettings::errorHandler();
\Cx\Core\Country\Controller\Country::errorHandler();
$table_name = DBPREFIX . 'module_shop_order_items';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'order_items_id'), 'order_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'orderid'), 'product_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'productid'), 'product_name' => array('type' => 'VARCHAR(255)', 'default' => ''), 'price' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0.00'), 'quantity' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0'), 'vat_rate' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'vat_percent'), 'weight' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0'));
$table_index = array('order' => array('fields' => array('order_id')));
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
$table_name = DBPREFIX . 'module_shop_order_attributes';
if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) {
$table_name_old = DBPREFIX . 'module_shop_order_items_attributes';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'orders_items_attributes_id'), 'item_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'order_items_id'), 'attribute_name' => array('type' => 'VARCHAR(255)', 'default' => '', 'renamefrom' => 'product_option_name'), 'option_name' => array('type' => 'VARCHAR(255)', 'default' => '', 'renamefrom' => 'product_option_value'), 'price' => array('type' => 'DECIMAL(9,2)', 'unsigned' => false, 'default' => '0.00', 'renamefrom' => 'product_option_values_price'));
$table_index = array('item_id' => array('fields' => array('item_id')));
\Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index);
\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name);
}
// LSV
$table_name = DBPREFIX . 'module_shop_lsv';
$table_structure = array('order_id' => array('type' => 'INT(10)', 'unsigned' => true, 'primary' => true, 'renamefrom' => 'id'), 'holder' => array('type' => 'tinytext', 'default' => ''), 'bank' => array('type' => 'tinytext', 'default' => ''), 'blz' => array('type' => 'tinytext', 'default' => ''));
$table_index = array();
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
$table_name = DBPREFIX . 'module_shop_orders';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'orderid'), 'customer_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'customerid'), 'currency_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'selected_currency_id'), 'shipment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'shipping_id'), 'payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0'), 'lang_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'customer_lang'), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'order_status'), 'sum' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0.00', 'renamefrom' => 'currency_order_sum'), 'vat_amount' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0.00', 'renamefrom' => 'tax_price'), 'shipment_amount' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0.00', 'renamefrom' => 'currency_ship_price'), 'payment_amount' => array('type' => 'DECIMAL(9,2)', 'unsigned' => true, 'default' => '0.00', 'renamefrom' => 'currency_payment_price'), 'billing_gender' => array('type' => 'VARCHAR(50)', 'notnull' => false, 'default' => null), 'billing_company' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default' => null), 'billing_firstname' => array('type' => 'VARCHAR(40)', 'notnull' => false, 'default' => null), 'billing_lastname' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default' => null), 'billing_address' => array('type' => 'VARCHAR(40)', 'notnull' => false, 'default' => null), 'billing_city' => array('type' => 'VARCHAR(50)', 'notnull' => false, 'default' => null), 'billing_zip' => array('type' => 'VARCHAR(10)', 'notnull' => false, 'default' => null), 'billing_country_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'billing_phone' => array('type' => 'VARCHAR(20)', 'notnull' => false, 'default' => null), 'billing_fax' => array('type' => 'VARCHAR(20)', 'notnull' => false, 'default' => null), 'billing_email' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'default' => null), 'gender' => array('type' => 'VARCHAR(50)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_prefix'), 'company' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_company'), 'firstname' => array('type' => 'VARCHAR(40)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_firstname'), 'lastname' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_lastname'), 'address' => array('type' => 'VARCHAR(40)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_address'), 'city' => array('type' => 'VARCHAR(50)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_city'), 'zip' => array('type' => 'VARCHAR(10)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_zip'), 'country_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_country_id'), 'phone' => array('type' => 'VARCHAR(20)', 'notnull' => false, 'default' => null, 'renamefrom' => 'ship_phone'), 'ip' => array('type' => 'VARCHAR(50)', 'default' => '', 'renamefrom' => 'customer_ip'), 'host' => array('type' => 'VARCHAR(100)', 'default' => '', 'renamefrom' => 'customer_host'), 'browser' => array('type' => 'VARCHAR(255)', 'default' => '', 'renamefrom' => 'customer_browser'), 'note' => array('type' => 'TEXT', 'default' => '', 'renamefrom' => 'customer_note'), 'date_time' => array('type' => 'TIMESTAMP', 'default' => '0000-00-00 00:00:00', 'renamefrom' => 'order_date'), 'modified_on' => array('type' => 'TIMESTAMP', 'default' => null, 'notnull' => false, 'renamefrom' => 'last_modified'), 'modified_by' => array('type' => 'VARCHAR(50)', 'notnull' => false, 'default' => null));
$table_index = array('status' => array('fields' => array('status')));
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// TODO: TEST
// Migrate present Customer addresses to the new billing address fields.
// Note that this method is also called in Customer::errorHandler() *before*
// any Customer is modified. Thus, we can safely depend on the old
// Customer table in one way -- if it doesn't exist, all Orders and Customers
// have been successfully migrated already.
$table_name_customer = DBPREFIX . "module_shop_customers";
if (\Cx\Lib\UpdateUtil::table_exist($table_name_customer)) {
// On the other hand, there may have been an error somewhere in between
// altering the Orders table and moving Customers to the Users table.
// So, to be on the safe side, we will only update Orders where the billing
// address fields are all NULL, as is the case just after the alteration
// of the Orders table above.
// Also note that any inconsistencies involving missing Customer records will
// be left over as-is and may later be handled in the backend.
$objResult = \Cx\Lib\UpdateUtil::sql("\n SELECT DISTINCT `customer_id`,\n `customer`.`prefix`,\n `customer`.`firstname`, `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 FROM `{$table_name}`\n JOIN `{$table_name_customer}` AS `customer`\n ON `customerid`=`customer_id`\n WHERE `billing_gender` IS NULL\n AND `billing_company` IS NULL\n AND `billing_firstname` IS NULL\n AND `billing_lastname` IS NULL\n AND `billing_address` IS NULL\n AND `billing_city` IS NULL\n AND `billing_zip` IS NULL\n AND `billing_country_id` IS NULL\n AND `billing_phone` IS NULL\n AND `billing_fax` IS NULL\n AND `billing_email` IS NULL");
while ($objResult && !$objResult->EOF) {
$customer_id = $objResult->fields['customer_id'];
$gender = 'gender_unknown';
if (preg_match('/^(?:frau|mad|mme|signora|miss)/i', $objResult->fields['prefix'])) {
$gender = 'gender_female';
} elseif (preg_match('/^(?:herr|mon|signore|mister|mr)/i', $objResult->fields['prefix'])) {
$gender = 'gender_male';
}
\Cx\Lib\UpdateUtil::sql("\n UPDATE `{$table_name}`\n SET `billing_gender`='" . addslashes($gender) . "',\n `billing_company`='" . addslashes($objResult->fields['company']) . "',\n `billing_firstname`='" . addslashes($objResult->fields['firstname']) . "',\n `billing_lastname`='" . addslashes($objResult->fields['lastname']) . "',\n `billing_address`='" . addslashes($objResult->fields['address']) . "',\n `billing_city`='" . addslashes($objResult->fields['city']) . "',\n `billing_zip`='" . addslashes($objResult->fields['zip']) . "',\n `billing_country_id`=" . intval($objResult->fields['country_id']) . ",\n `billing_phone`='" . addslashes($objResult->fields['phone']) . "',\n `billing_fax`='" . addslashes($objResult->fields['fax']) . "',\n `billing_email`='" . addslashes($objResult->fields['email']) . "'\n WHERE `customer_id`={$customer_id}\n AND `billing_gender` IS NULL\n AND `billing_company` IS NULL\n AND `billing_firstname` IS NULL\n AND `billing_lastname` IS NULL\n AND `billing_address` IS NULL\n AND `billing_city` IS NULL\n AND `billing_zip` IS NULL\n AND `billing_country_id` IS NULL\n AND `billing_phone` IS NULL\n AND `billing_fax` IS NULL\n AND `billing_email` IS NULL");
$objResult->MoveNext();
}
}
// Finally, update the migrated Order records with the proper gender
// strings as used in the User class hierarchy as well
$objResult = \Cx\Lib\UpdateUtil::sql("\n SELECT `id`, `gender`\n FROM `{$table_name}`\n WHERE `gender` NOT IN\n ('gender_male', 'gender_female', 'gender_undefined')");
while ($objResult && !$objResult->EOF) {
$gender = 'gender_unknown';
if (preg_match('/^(?:frau|mad|mme|signora|miss)/i', $objResult->fields['gender'])) {
$gender = 'gender_female';
} elseif (preg_match('/^(?:herr|mon|signore|mister|mr)/i', $objResult->fields['gender'])) {
$gender = 'gender_male';
}
\Cx\Lib\UpdateUtil::sql("\n UPDATE `{$table_name}`\n SET `gender`='" . addslashes($gender) . "'\n WHERE `id`=" . $objResult->fields['id']);
$objResult->MoveNext();
}
// Always
return false;
}