Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }