/**
  * 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;
 }
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
 public function migrateBlocks()
 {
     global $objUpdate, $_CONFIG;
     try {
         if (!\Cx\Lib\UpdateUtil::table_exist(DBPREFIX . 'module_block_rel_lang')) {
             return true;
         }
         if (empty($_SESSION['contrexx_update']['blocks_part_1_migrated'])) {
             // 3.0.3 : add new column `seperator`
             \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_block_categories', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'parent' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0', 'after' => 'id'), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'parent'), 'seperator' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'name'), 'order' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0', 'after' => 'seperator'), 'status' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '1', 'after' => 'order')));
             // migrate content -> related multi language
             \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_block_rel_lang_content', array('block_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'lang_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'after' => 'block_id'), 'content' => array('type' => 'mediumtext', 'after' => 'lang_id'), 'active' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'content')), array('id_lang' => array('fields' => array('block_id', 'lang_id'), 'type' => 'UNIQUE')));
             // Only from version 2
             if (!$objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '2.0.0')) {
                 $subQuery = '
                     IFNULL(
                         (
                             SELECT 1
                             FROM `' . DBPREFIX . 'module_block_rel_lang` as `rl`
                             WHERE `rl`.`block_id` = `b`.`id`
                             AND `rl`.`lang_id` = `l`.`id`
                         ), 0
                     ) as `active`
                 ';
             }
             \Cx\Lib\UpdateUtil::sql('
                 INSERT IGNORE INTO `' . DBPREFIX . 'module_block_rel_lang_content` (`block_id`, `lang_id`, `content`, `active`)
                 SELECT DISTINCT `b`.`id` AS `id`, `l`.`id` AS `lang_id`, `b`.`content` AS `content`, ' . (!empty($subQuery) ? $subQuery : 1) . '
                 FROM `' . DBPREFIX . 'languages` AS `l`, `' . DBPREFIX . 'module_block_blocks` AS `b`
                 WHERE `l`.`frontend` = \'1\'
                 ORDER BY `b`.`id`
             ');
             // Deactivate all blocks of which none of their content is active
             \Cx\Lib\UpdateUtil::sql('
                 UPDATE `' . DBPREFIX . 'module_block_blocks` AS tblBlock
                 SET tblBlock.`active` = 0
                 WHERE tblBlock.`id` NOT IN (
                     SELECT `block_id` FROM `' . DBPREFIX . 'module_block_rel_lang_content` WHERE `active` = 1
                 )
             ');
             // fetch active blocks
             $arrActiveBlockIds = array();
             $activeBlockList = '';
             $objResult = \Cx\Lib\UpdateUtil::sql('
                 SELECT `block_id`
                 FROM `' . DBPREFIX . 'module_block_rel_lang_content`
                 WHERE `active` = 1
             ');
             if ($objResult && !$objResult->EOF) {
                 while (!$objResult->EOF) {
                     $arrActiveBlockIds[] = $objResult->fields['block_id'];
                     $objResult->MoveNext();
                 }
                 $activeBlockList = join(', ', $arrActiveBlockIds);
             }
             // Activate block's content of system's default language for all blocks that have no active content at all
             \Cx\Lib\UpdateUtil::sql('
                 UPDATE `' . DBPREFIX . 'module_block_rel_lang_content` AS tblContent
                 SET tblContent.`active` = 1
                 WHERE tblContent.`lang_id` = ( SELECT CL.`id` FROM `' . DBPREFIX . 'languages` AS CL WHERE CL.`frontend` AND CL.`is_default` = \'true\' )
                 ' . ($activeBlockList ? 'AND tblContent.`block_id` NOT IN (' . $activeBlockList . ')' : ''));
             // Set the correct value for field global
             $activeLangIds = implode(',', \FWLanguage::getIdArray());
             $objResult = \Cx\Lib\UpdateUtil::sql('
                 SELECT `block_id`, `lang_id`, `all_pages`
                 FROM `' . DBPREFIX . 'module_block_rel_lang`
                 WHERE lang_id IN (' . $activeLangIds . ')
             ');
             // 1. drop old locale column `content`
             // 2. add several new columns
             // 3. add columns `direct`, `category`
             \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_block_blocks', array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'start' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0', 'after' => 'id'), 'end' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0', 'after' => 'start'), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'after' => 'end'), 'random' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'name'), 'random_2' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'random'), 'random_3' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'random_2'), 'random_4' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'random_3'), 'global' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'random_4'), 'category' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'global'), 'direct' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'category'), 'active' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'direct'), 'order' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '0', 'after' => 'active'), 'cat' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '0', 'after' => 'order'), 'wysiwyg_editor' => array('type' => 'INT(1)', 'notnull' => true, 'default' => '1', 'after' => 'cat')));
             if ($objResult->RecordCount()) {
                 $arrGlobalDefinitions = array();
                 while (!$objResult->EOF) {
                     $arrGlobalDefinitions[$objResult->fields['block_id']][$objResult->fields['lang_id']] = $objResult->fields['all_pages'];
                     $objResult->MoveNext();
                 }
                 foreach ($arrGlobalDefinitions as $blockId => $arrValues) {
                     // Set $global by default to 2
                     $global = 2;
                     // If all languages of the block are global, set $global to 1
                     if (!in_array(0, $arrValues)) {
                         // Language id's of blocks where field 'all_pages' (global) is set to 1
                         $globalLangIds = array_keys($arrValues);
                         sort($globalLangIds);
                         // Active language id's
                         $activeLangIds = \FWLanguage::getIdArray();
                         sort($activeLangIds);
                         if ($globalLangIds == $activeLangIds || !$objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '2.0.0')) {
                             $global = 1;
                         }
                     }
                     \Cx\Lib\UpdateUtil::sql('
                         UPDATE `' . DBPREFIX . 'module_block_blocks`
                         SET `global` = ' . $global . '
                         WHERE `id` = ' . $blockId . '
                     ');
                     // only for contrexx 2.x
                     if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0') && !$objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '2.0.0')) {
                         // use direct placeholder to set the pages where to show
                         // only do this if the global was set to 2 (show on each selected page)
                         $direct = $global == 2 ? 1 : 0;
                         // if there is no association from block to page and the global placeholder was set to
                         // "only show on"... the direct placeholder has been shown on any page
                         $objBlockPagesResult = \Cx\Lib\UpdateUtil::sql('SELECT COUNT(1) as `count`
                                 FROM `' . DBPREFIX . 'module_block_rel_pages`
                                     WHERE `block_id` = ?', array($blockId));
                         if ($objBlockPagesResult->fields['count'] == 0 && $direct == 1) {
                             $direct = 0;
                         }
                         \Cx\Lib\UpdateUtil::sql('
                             UPDATE `' . DBPREFIX . 'module_block_blocks`
                             SET `global` = ' . $global . ',
                                 `direct` = ' . $direct . '
                             WHERE `id` = ' . $blockId . '
                         ');
                     }
                 }
             }
             $_SESSION['contrexx_update']['blocks_part_1_migrated'] = true;
             if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                 return false;
             }
         }
         if (empty($_SESSION['contrexx_update']['blocks_part_2_migrated'])) {
             $activeLangIds = implode(',', \FWLanguage::getIdArray());
             if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_block_rel_pages', 'lang_id') || !empty($_SESSION['contrexx_update']['blocks_part_2_migrated_timeout'])) {
                 // create temporary table
                 \Cx\Lib\UpdateUtil::table(DBPREFIX . 'module_block_rel_pages_tmp', 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)));
                 \DBG::msg('BLOCK MIGRATION: GENERATED TEMPORARY TABLE');
                 if (\Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_block_rel_pages', 'lang_id')) {
                     \Cx\Lib\UpdateUtil::sql('
                         DELETE FROM `' . DBPREFIX . 'module_block_rel_pages`
                         WHERE `lang_id` NOT IN (' . $activeLangIds . ')
                     ');
                     // 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')));
                 }
                 // now the old page ids can be moved to the temporary table with the new page ids
                 $objResult = \Cx\Lib\UpdateUtil::sql('
                     SELECT `block_id`, `page_id`
                     FROM `' . DBPREFIX . 'module_block_rel_pages`
                 ');
                 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;
 }
Beispiel #5
0
 /**
  * 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;
 }