/**
  * @param Ess_M2ePro_Model_Upgrade_MySqlSetup $installer
  * @return $this
  */
 public function setInstaller(Ess_M2ePro_Model_Upgrade_MySqlSetup $installer)
 {
     $this->installer = $installer;
     $this->connection = $installer->getConnection();
     $this->tablesObject = $installer->getTablesObject();
     return $this;
 }
function dropIndexes(Ess_M2ePro_Model_Upgrade_MySqlSetup $installer, $tableName, $indexesToDrop)
{
    $tempTable = $installer->getTable($tableName);
    if (!$tempTable) {
        return;
    }
    $tempTableIndexesList = $installer->getConnection()->getIndexList($tempTable);
    foreach ($indexesToDrop as $indexToDrop) {
        if (isset($tempTableIndexesList[strtoupper($indexToDrop)])) {
            $installer->getConnection()->dropKey($tempTable, $indexToDrop);
        }
    }
}
Exemple #3
0
    private function processSynchronizationConfigTable()
    {
        $connection = $this->installer->getConnection();
        $tempTable = $this->installer->getTable('m2epro_synchronization_config');
        $tempQuery = "SELECT * FROM `{$tempTable}` WHERE `group` IS NULL AND `key` = 'last_access'";
        $tempRow = $connection->query($tempQuery)->fetch();
        if ($tempRow === false) {
            $this->installer->run(<<<SQL

INSERT INTO `m2epro_synchronization_config` (`group`,`key`,`value`,`notice`,`update_date`,`create_date`) VALUES
(NULL, 'last_access', NULL, NULL, '2014-01-01 00:00:00', '2014-01-01 00:00:00'),
(NULL, 'last_run', NULL, NULL, '2014-01-01 00:00:00', '2014-01-01 00:00:00');

SQL
);
        }
        $where = "(`key` = 'max_deactivate_time') ";
        $where .= "OR (`group` = '/feedbacks/') ";
        $where .= "OR (`group` = '/marketplaces/') ";
        $where .= "OR (`group` = '/orders/') ";
        $where .= "OR (`group` = '/other_listings/') ";
        $where .= "OR (`group` = '/policies/') ";
        $where .= "OR (`group` = '/templates/') ";
        $where .= "OR (`group` = '/defaults/processing/') ";
        $where .= "OR (`group` = '/settings/profiler/')";
        $connection->delete($tempTable, $where);
        $connection->update($tempTable, array('key' => 'type'), "`group` = '/defaults/inspector/product_changes/' AND `key` = 'mode'");
        $subWhere = "`group` = '/amazon/orders/reserve_cancellation/' ";
        $subWhere .= "OR `group` = '/ebay/feedbacks/receive/' ";
        $subWhere .= "OR `group` = '/ebay/feedbacks/response/' ";
        $subWhere .= "OR `group` = '/ebay/orders/cancellation/' ";
        $subWhere .= "OR `group` = '/ebay/orders/reserve_cancellation/'";
        $connection->update($tempTable, array('key' => 'last_time'), "`key` = 'last_access' AND ({$subWhere})");
    }
 private function processProcessingRequestTable()
 {
     $connection = $this->installer->getConnection();
     $tempTable = $this->installer->getTable('m2epro_processing_request');
     $connection->update($tempTable, array('responser_model' => new Zend_Db_Expr("REPLACE(`responser_model`,'_Tasks','')")));
     $connection->update($tempTable, array('responser_model' => 'M2ePro/Amazon_Synchronization_Orders_Receive_Responser'), array("responser_model = 'M2ePro/Amazon_Synchronization_Orders_Responser'"));
 }
Exemple #5
0
 private function getStoreCategoryPathById($categoryId, $accountId, $delimiter = ' -> ')
 {
     if (empty($categoryId) || empty($accountId)) {
         return '';
     }
     $ebayStoreCategoryTable = $this->installer->getTable('m2epro' . self::PREFIX_TABLE_BACKUP . '_ebay_account_store_category');
     $categories = $this->installer->getConnection()->select()->from($ebayStoreCategoryTable, '*')->where('account_id = ?', $accountId)->where('category_id = ?', $categoryId)->query()->fetchAll();
     $path = array();
     while (true) {
         $currentCategory = NULL;
         foreach ($categories as $category) {
             if ($category['category_id'] == $categoryId) {
                 $currentCategory = $category;
                 break;
             }
         }
         if (is_null($currentCategory)) {
             break;
         }
         $path[] = $currentCategory['title'];
         if ($currentCategory['parent_id'] == 0) {
             break;
         }
         $categoryId = $currentCategory['parent_id'];
     }
     return implode($delimiter, array_reverse($path));
 }
 private function processProductActions()
 {
     $connection = $this->installer->getConnection();
     $processingTable = $this->installer->getTable('m2epro_processing_request');
     $oldProcessingRows = $connection->query("\n            SELECT * FROM `{$processingTable}`\n            WHERE responser_model REGEXP '^M2ePro\\/Connector_(Amazon|Buy|Play){1}_Product_*'\n        ")->fetchAll();
     $newProcessingRows = array();
     foreach ($oldProcessingRows as $row) {
         $responserParams = $row['responser_params'] ? json_decode($row['responser_params'], true) : array();
         if (empty($responserParams)) {
             $newProcessingRows[] = $row;
             continue;
         }
         if (!isset($responserParams['action_identifier'], $responserParams['listing_log_action'])) {
             $newProcessingRows[] = $row;
             continue;
         }
         $responserParams['lock_identifier'] = $responserParams['action_identifier'];
         $responserParams['action_type'] = $responserParams['lock_identifier'];
         $responserParams['action_type'] == 'stop_and_remove' && ($responserParams['action_type'] = 'stop');
         $responserParams['action_type'] == 'delete_and_remove' && ($responserParams['action_type'] = 'delete');
         $responserParams['action_type'] = $this->getActionType($responserParams['action_type']);
         unset($responserParams['action_identifier']);
         $responserParams['logs_action'] = $responserParams['listing_log_action'];
         unset($responserParams['listing_log_action']);
         if (empty($responserParams['products']) || !is_array($responserParams['products'])) {
             $row['responser_params'] = json_encode($responserParams);
             $newProcessingRows[] = $row;
             continue;
         }
         $newProducts = array();
         foreach ($responserParams['products'] as $id => $product) {
             $newProducts[$id] = $product['request']['sended_data'];
         }
         $responserParams['products'] = $newProducts;
         $row['responser_params'] = json_encode($responserParams);
         $newProcessingRows[] = $row;
     }
     if (!empty($newProcessingRows)) {
         $connection->insertOnDuplicate($processingTable, $newProcessingRows);
     }
 }
    private function deleteOldData()
    {
        $connection = $this->installer->getConnection();
        $this->installer->run(<<<SQL

    DROP TABLE IF EXISTS `m2epro_listing_category`;
    DROP TABLE IF EXISTS `m2epro_ebay_listing_auto_category`;
    DROP TABLE IF EXISTS `m2epro_ebay_listing_auto_category_group`;

SQL
);
        $oldTable = $this->installer->getTable('m2epro_temp_ebay_listing_auto_category_group');
        $newTable = $this->installer->getTable('m2epro_ebay_listing_auto_category_group');
        if ($this->installer->tableExists($oldTable) && !$this->installer->tableExists($newTable)) {
            $connection->query("RENAME TABLE `{$oldTable}` TO `{$newTable}`");
        }
        $tempTable = $this->installer->getTable('m2epro_ebay_listing');
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if (isset($tempTableIndexList[strtoupper('auto_mode')])) {
            $connection->dropKey($tempTable, 'auto_mode');
        }
        if (isset($tempTableIndexList[strtoupper('auto_global_adding_mode')])) {
            $connection->dropKey($tempTable, 'auto_global_adding_mode');
        }
        if (isset($tempTableIndexList[strtoupper('auto_website_adding_mode')])) {
            $connection->dropKey($tempTable, 'auto_website_adding_mode');
        }
        if (isset($tempTableIndexList[strtoupper('auto_website_deleting_mode')])) {
            $connection->dropKey($tempTable, 'auto_website_deleting_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'auto_mode') !== false) {
            $connection->dropColumn($tempTable, 'auto_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'auto_global_adding_mode') !== false) {
            $connection->dropColumn($tempTable, 'auto_global_adding_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'auto_website_adding_mode') !== false) {
            $connection->dropColumn($tempTable, 'auto_website_adding_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'auto_website_deleting_mode') !== false) {
            $connection->dropColumn($tempTable, 'auto_website_deleting_mode');
        }
        $tempTable = $this->installer->getTable('m2epro_listing');
        if ($connection->tableColumnExists($tempTable, 'categories_add_action') !== false) {
            $connection->dropColumn($tempTable, 'categories_add_action');
        }
        if ($connection->tableColumnExists($tempTable, 'categories_delete_action') !== false) {
            $connection->dropColumn($tempTable, 'categories_delete_action');
        }
    }
    private function processWizard()
    {
        $tempTable = $this->installer->getTable('m2epro_wizard');
        $tempQuery = "SELECT * FROM `{$tempTable}` WHERE `nick` = 'migrationNewAmazon'";
        $tempRow = $this->installer->getConnection()->query($tempQuery)->fetch();
        if ($tempRow !== false) {
            return;
        }
        $this->getInstaller()->run(<<<SQL

    INSERT INTO `m2epro_wizard` (`nick`, `view`, `status`, `step`, `type`, `priority`)
    VALUES ('migrationNewAmazon', 'common', 0, NULL, 0, 6);

SQL
);
    }
Exemple #9
0
 private function processOrderLogTable()
 {
     $connection = $this->installer->getConnection();
     $tempTable = $this->installer->getTable('m2epro_order_log');
     $tempTableIndexList = $connection->getIndexList($tempTable);
     if ($connection->tableColumnExists($tempTable, 'type') !== false) {
         $connection->changeColumn($tempTable, 'type', 'type', 'TINYINT(2) UNSIGNED NOT NULL DEFAULT 2');
     }
     if ($connection->tableColumnExists($tempTable, 'message') !== false) {
         $connection->changeColumn($tempTable, 'message', 'message', 'TEXT NOT NULL AFTER `initiator`');
     }
     if (!isset($tempTableIndexList[strtoupper('component_mode')])) {
         $connection->addKey($tempTable, 'component_mode', 'component_mode');
     }
     $offset = 5;
     $connection->update($tempTable, array('type' => new Zend_Db_Expr('`type` + ' . $offset)), '`type` IN (0,2)');
     $connection->update($tempTable, array('type' => 2), '`type` = ' . (0 + $offset));
     $connection->update($tempTable, array('type' => 4), '`type` = ' . (2 + $offset));
 }
    private function processAmazonMarketplace()
    {
        $connection = $this->installer->getConnection();
        $tempTable = $this->installer->getTable('m2epro_amazon_marketplace');
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if ($connection->tableColumnExists($tempTable, 'is_asin_available') === false) {
            $connection->addColumn($tempTable, 'is_asin_available', 'tinyint(2) UNSIGNED NOT NULL DEFAULT 1 AFTER default_currency');
        }
        if (!isset($tempTableIndexList[strtoupper('is_asin_available')])) {
            $connection->addKey($tempTable, 'is_asin_available', 'is_asin_available');
        }
        $this->installer->run(<<<SQL

    UPDATE `m2epro_amazon_marketplace`
    SET is_asin_available = 0
    WHERE marketplace_id = 24;

SQL
);
    }
    private function prepareOrdersConfigTable()
    {
        $connection = $this->installer->getConnection();
        $tempTable = $this->installer->getTable('m2epro_config');
        $tempQuery = <<<SQL
    SELECT * FROM `{$tempTable}`
    WHERE `group` = '/ebay/order/migration_to_v611/'
    AND   `key` = 'is_need_migrate'
SQL;
        $tempRow = $connection->query($tempQuery)->fetch();
        if ($tempRow === false) {
            $this->installer->run(<<<SQL

INSERT INTO `m2epro_config` (`group`,`key`,`value`,`notice`,`update_date`,`create_date`) VALUES
('/ebay/order/migration_to_v611/', 'is_need_migrate', '1', null, '2013-09-18 00:00:00', '2013-09-18 00:00:00');

SQL
);
        }
    }
Exemple #12
0
    private function processBuyShipping()
    {
        $this->installer->run(<<<SQL

UPDATE `m2epro_buy_listing`
SET shipping_standard_mode = 3
WHERE shipping_standard_mode = 0;

UPDATE `m2epro_buy_listing`
SET shipping_expedited_mode = 3
WHERE shipping_expedited_mode = 0;

UPDATE `m2epro_buy_listing`
SET shipping_one_day_mode = 3
WHERE shipping_one_day_mode = 0;

UPDATE `m2epro_buy_listing`
SET shipping_two_day_mode = 3
WHERE shipping_two_day_mode = 0;

SQL
);
    }
 /**
  * @title "Remove Config Duplicates"
  * @description "Remove Configuration Duplicates"
  * @confirm "Are you sure?"
  * @new_line
  */
 public function removeConfigDuplicatesAction()
 {
     /** @var $installerInstance Ess_M2ePro_Model_Upgrade_MySqlSetup */
     $installerInstance = new Ess_M2ePro_Model_Upgrade_MySqlSetup('M2ePro_setup');
     $installerInstance->removeConfigDuplicates();
     Mage::helper('M2ePro/Module')->clearCache();
     $this->_getSession()->addSuccess('Remove duplicates was successfully completed.');
     $this->_redirectUrl(Mage::helper('M2ePro/View_Development')->getPageToolsTabUrl());
 }
 /**
  * @title "Remove Config Duplicates"
  * @description "Remove Configuration Duplicates"
  * @group "Development"
  * @confirm "Are you sure?"
  */
 public function removeConfigDuplicatesAction()
 {
     /** @var $installerInstance Ess_M2ePro_Model_Upgrade_MySqlSetup */
     $installerInstance = new Ess_M2ePro_Model_Upgrade_MySqlSetup('M2ePro_setup');
     $installerInstance->removeConfigDuplicates();
     Mage::helper('M2ePro/Module')->clearCache();
     Mage::helper('M2ePro')->setSessionValue('success_message', 'Remove duplicates was successfully completed.');
     $this->_redirectUrl($this->getUrl('*/adminhtml_cmd/index'));
 }
    private function processAmazonTemplates()
    {
        $this->installer->run(<<<SQL

CREATE TABLE IF NOT EXISTS `m2epro_amazon_template_description` (
  template_description_id INT(11) UNSIGNED NOT NULL,
  marketplace_id INT(11) UNSIGNED NOT NULL,
  is_new_asin_accepted TINYINT(2) UNSIGNED DEFAULT 0,
  product_data_nick VARCHAR(255) DEFAULT NULL,
  category_path VARCHAR(255) DEFAULT NULL,
  browsenode_id DECIMAL(20, 0) UNSIGNED DEFAULT NULL,
  registered_parameter VARCHAR(25) DEFAULT NULL,
  worldwide_id_mode TINYINT(2) UNSIGNED DEFAULT 0,
  worldwide_id_custom_attribute VARCHAR(255) DEFAULT NULL,
  item_package_quantity_mode TINYINT(2) UNSIGNED DEFAULT 0,
  item_package_quantity_custom_value VARCHAR(255) DEFAULT NULL,
  item_package_quantity_custom_attribute VARCHAR(255) DEFAULT NULL,
  number_of_items_mode TINYINT(2) UNSIGNED DEFAULT 0,
  number_of_items_custom_value VARCHAR(255) DEFAULT NULL,
  number_of_items_custom_attribute VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (template_description_id),
  INDEX marketplace_id (marketplace_id),
  INDEX is_new_asin_accepted (is_new_asin_accepted),
  INDEX product_data_nick (product_data_nick),
  INDEX browsenode_id (browsenode_id)
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `m2epro_amazon_template_description_definition` (
  template_description_id INT(11) UNSIGNED NOT NULL,
  title_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  title_template VARCHAR(255) NOT NULL,
  brand_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  brand_custom_value VARCHAR(255) DEFAULT NULL,
  brand_custom_attribute VARCHAR(255) DEFAULT NULL,
  manufacturer_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  manufacturer_custom_value VARCHAR(255) DEFAULT NULL,
  manufacturer_custom_attribute VARCHAR(255) DEFAULT NULL,
  manufacturer_part_number_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  manufacturer_part_number_custom_value VARCHAR(255) NOT NULL,
  manufacturer_part_number_custom_attribute VARCHAR(255) NOT NULL,
  item_dimensions_volume_mode TINYINT(2) UNSIGNED DEFAULT 0,
  item_dimensions_volume_length_custom_value VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_width_custom_value VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_height_custom_value VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_length_custom_attribute VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_width_custom_attribute VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_height_custom_attribute VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_unit_of_measure_mode TINYINT(2) UNSIGNED DEFAULT 0,
  item_dimensions_volume_unit_of_measure_custom_value VARCHAR(255) DEFAULT NULL,
  item_dimensions_volume_unit_of_measure_custom_attribute VARCHAR(255) DEFAULT NULL,
  item_dimensions_weight_mode TINYINT(2) UNSIGNED DEFAULT 0,
  item_dimensions_weight_custom_value DECIMAL(10, 2) UNSIGNED DEFAULT NULL,
  item_dimensions_weight_custom_attribute VARCHAR(255) DEFAULT NULL,
  item_dimensions_weight_unit_of_measure_mode TINYINT(2) UNSIGNED DEFAULT 0,
  item_dimensions_weight_unit_of_measure_custom_value VARCHAR(255) DEFAULT NULL,
  item_dimensions_weight_unit_of_measure_custom_attribute VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_mode TINYINT(2) UNSIGNED DEFAULT 0,
  package_dimensions_volume_length_custom_value VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_width_custom_value VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_height_custom_value VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_length_custom_attribute VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_width_custom_attribute VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_height_custom_attribute VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_unit_of_measure_mode TINYINT(2) UNSIGNED DEFAULT 0,
  package_dimensions_volume_unit_of_measure_custom_value VARCHAR(255) DEFAULT NULL,
  package_dimensions_volume_unit_of_measure_custom_attribute VARCHAR(255) DEFAULT NULL,
  shipping_weight_mode TINYINT(2) UNSIGNED DEFAULT 0,
  shipping_weight_custom_value DECIMAL(10, 2) UNSIGNED DEFAULT NULL,
  shipping_weight_custom_attribute VARCHAR(255) DEFAULT NULL,
  shipping_weight_unit_of_measure_mode TINYINT(2) UNSIGNED DEFAULT 1,
  shipping_weight_unit_of_measure_custom_value VARCHAR(255) DEFAULT NULL,
  shipping_weight_unit_of_measure_custom_attribute VARCHAR(255) DEFAULT NULL,
  package_weight_mode TINYINT(2) UNSIGNED DEFAULT 0,
  package_weight_custom_value DECIMAL(10, 2) UNSIGNED DEFAULT NULL,
  package_weight_custom_attribute VARCHAR(255) DEFAULT NULL,
  package_weight_unit_of_measure_mode TINYINT(2) UNSIGNED DEFAULT 1,
  package_weight_unit_of_measure_custom_value VARCHAR(255) DEFAULT NULL,
  package_weight_unit_of_measure_custom_attribute VARCHAR(255) DEFAULT NULL,
  target_audience_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  target_audience TEXT NOT NULL,
  search_terms_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  search_terms TEXT NOT NULL,
  bullet_points_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  bullet_points TEXT NOT NULL,
  description_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  description_template LONGTEXT NOT NULL,
  image_main_mode TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
  image_main_attribute VARCHAR(255) NOT NULL,
  gallery_images_mode TINYINT(2) UNSIGNED NOT NULL,
  gallery_images_limit TINYINT(2) UNSIGNED NOT NULL DEFAULT 1,
  gallery_images_attribute VARCHAR(255) NOT NULL,
  update_date DATETIME DEFAULT NULL,
  create_date DATETIME DEFAULT NULL,
  PRIMARY KEY (template_description_id)
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `m2epro_amazon_template_description_specific` (
  id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  template_description_id INT(11) UNSIGNED NOT NULL,
  xpath VARCHAR(255) NOT NULL,
  mode VARCHAR(25) NOT NULL,
  recommended_value VARCHAR(255) DEFAULT NULL,
  custom_value VARCHAR(255) DEFAULT NULL,
  custom_attribute VARCHAR(255) DEFAULT NULL,
  type VARCHAR(25) DEFAULT NULL,
  attributes TEXT DEFAULT NULL,
  update_date DATETIME DEFAULT NULL,
  create_date DATETIME DEFAULT NULL,
  PRIMARY KEY (id),
  INDEX template_description_id (template_description_id)
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci;

SQL
);
    }
Exemple #16
0
 private function checkToSkipStep($nextTable)
 {
     $nextTable = $this->installer->getTable($nextTable);
     return (bool) $this->installer->tableExists($nextTable);
 }
    private function alterTables()
    {
        $connection = $this->installer->getConnection();
        $tempTable = $this->installer->getTable('m2epro_amazon_template_description');
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if ($connection->tableColumnExists($tempTable, 'title') !== false) {
            $connection->dropColumn($tempTable, 'title');
        }
        if ($connection->tableColumnExists($tempTable, 'create_date') !== false) {
            $connection->dropColumn($tempTable, 'create_date');
        }
        if ($connection->tableColumnExists($tempTable, 'update_date') !== false) {
            $connection->dropColumn($tempTable, 'update_date');
        }
        if ($connection->tableColumnExists($tempTable, 'node_title') !== false) {
            $connection->dropColumn($tempTable, 'node_title');
        }
        if ($connection->tableColumnExists($tempTable, 'xsd_hash') !== false) {
            $connection->dropColumn($tempTable, 'xsd_hash');
        }
        if ($connection->tableColumnExists($tempTable, 'identifiers') !== false) {
            $connection->dropColumn($tempTable, 'identifiers');
        }
        if ($connection->tableColumnExists($tempTable, 'id') !== false && $connection->tableColumnExists($tempTable, 'template_description_id') === false) {
            $this->installer->run(<<<SQL

ALTER TABLE `m2epro_amazon_template_description`
    CHANGE COLUMN id template_description_id int(11) UNSIGNED NOT NULL,
    DROP PRIMARY KEY,
    ADD PRIMARY KEY (template_description_id);

SQL
);
        }
        if ($connection->tableColumnExists($tempTable, 'category_path') !== false) {
            $connection->changeColumn($tempTable, 'category_path', 'category_path', 'VARCHAR(255) DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'is_new_asin_accepted') === false) {
            $connection->addColumn($tempTable, 'is_new_asin_accepted', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER marketplace_id');
        }
        if ($connection->tableColumnExists($tempTable, 'product_data_nick') === false) {
            $connection->addColumn($tempTable, 'product_data_nick', 'VARCHAR(255) DEFAULT NULL AFTER is_new_asin_accepted');
        }
        if ($connection->tableColumnExists($tempTable, 'browsenode_id') === false) {
            $connection->addColumn($tempTable, 'browsenode_id', 'DECIMAL(20, 0) UNSIGNED DEFAULT NULL AFTER category_path');
        }
        if (!isset($tempTableIndexList[strtoupper('is_new_asin_accepted')])) {
            $connection->addKey($tempTable, 'is_new_asin_accepted', 'is_new_asin_accepted');
        }
        if (!isset($tempTableIndexList[strtoupper('product_data_nick')])) {
            $connection->addKey($tempTable, 'product_data_nick', 'product_data_nick');
        }
        if (!isset($tempTableIndexList[strtoupper('browsenode_id')])) {
            $connection->addKey($tempTable, 'browsenode_id', 'browsenode_id');
        }
        // ------------------------------
        $tempTable = $this->installer->getTable('m2epro_amazon_template_description_definition');
        if ($connection->tableColumnExists($tempTable, 'template_new_product_id') !== false && $connection->tableColumnExists($tempTable, 'template_description_id') === false) {
            $this->installer->run(<<<SQL

ALTER TABLE `m2epro_amazon_template_description_definition`
    CHANGE COLUMN template_new_product_id template_description_id int(11) UNSIGNED NOT NULL,
    DROP PRIMARY KEY,
    ADD PRIMARY KEY (template_description_id);

SQL
);
        }
        if ($connection->tableColumnExists($tempTable, 'brand_custom_attribute') === false && $connection->tableColumnExists($tempTable, 'brand_template') !== false) {
            $connection->changeColumn($tempTable, 'brand_template', 'brand_custom_attribute', 'VARCHAR(255) DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'manufacturer_custom_attribute') === false && $connection->tableColumnExists($tempTable, 'manufacturer_template') !== false) {
            $connection->changeColumn($tempTable, 'manufacturer_template', 'manufacturer_custom_attribute', 'VARCHAR(255) DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'target_audience') === false && $connection->tableColumnExists($tempTable, 'target_audience_custom_value') !== false) {
            $connection->changeColumn($tempTable, 'target_audience_custom_value', 'target_audience', 'TEXT NOT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'brand_custom_value') === false) {
            $connection->addColumn($tempTable, 'brand_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER `brand_mode`');
        }
        if ($connection->tableColumnExists($tempTable, 'manufacturer_custom_value') === false) {
            $connection->addColumn($tempTable, 'manufacturer_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER manufacturer_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'target_audience_custom_attribute') !== false) {
            $connection->dropColumn($tempTable, 'target_audience_custom_attribute');
        }
        // -----
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_mode') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_mode', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER manufacturer_part_number_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_length_custom_value') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_length_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_width_custom_value') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_width_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_length_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_height_custom_value') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_height_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_width_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_length_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_length_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_height_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_width_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_width_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_length_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_height_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_height_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_width_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_unit_of_measure_mode') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_unit_of_measure_mode', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER item_dimensions_volume_height_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_unit_of_measure_custom_value') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_unit_of_measure_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_unit_of_measure_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_volume_unit_of_measure_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_volume_unit_of_measure_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_volume_unit_of_measure_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_weight_mode') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_weight_mode', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER item_dimensions_volume_unit_of_measure_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_weight_custom_value') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_weight_custom_value', 'DECIMAL(10, 2) UNSIGNED DEFAULT NULL AFTER item_dimensions_weight_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_weight_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_weight_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_weight_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_weight_unit_of_measure_mode') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_weight_unit_of_measure_mode', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER item_dimensions_weight_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_weight_unit_of_measure_custom_value') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_weight_unit_of_measure_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_weight_unit_of_measure_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'item_dimensions_weight_unit_of_measure_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'item_dimensions_weight_unit_of_measure_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER item_dimensions_weight_unit_of_measure_custom_value');
        }
        // -----
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_mode') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_mode', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER item_dimensions_weight_unit_of_measure_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_length_custom_value') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_length_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_mode');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_width_custom_value') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_width_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_length_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_height_custom_value') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_height_custom_value', 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_width_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_length_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_length_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_height_custom_value');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_width_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_width_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_length_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_height_custom_attribute') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_height_custom_attribute', 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_width_custom_attribute');
        }
        if ($connection->tableColumnExists($tempTable, 'package_dimensions_volume_unit_of_measure_mode') === false) {
            $connection->addColumn($tempTable, 'package_dimensions_volume_unit_of_measure_mode', 'TINYINT(2) UNSIGNED DEFAULT 0 AFTER package_dimensions_volume_height_custom_attribute');
        }
        $columnName = 'package_dimensions_volume_unit_of_measure_custom_value';
        if ($connection->tableColumnExists($tempTable, $columnName) === false) {
            $connection->addColumn($tempTable, $columnName, 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_unit_of_measure_mode');
        }
        $columnName = 'package_dimensions_volume_unit_of_measure_custom_attribute';
        if ($connection->tableColumnExists($tempTable, $columnName) === false) {
            $connection->addColumn($tempTable, $columnName, 'VARCHAR(255) DEFAULT NULL AFTER package_dimensions_volume_unit_of_measure_custom_value');
        }
        // ------------------------------
        $tempTable = $this->installer->getTable('m2epro_amazon_template_description_specific');
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if (isset($tempTableIndexList[strtoupper('template_new_product_id')])) {
            $connection->dropKey($tempTable, 'template_new_product_id');
        }
        if ($connection->tableColumnExists($tempTable, 'template_new_product_id') !== false && $connection->tableColumnExists($tempTable, 'template_description_id') === false) {
            $connection->changeColumn($tempTable, 'template_new_product_id', 'template_description_id', 'int(11) UNSIGNED NOT NULL');
        }
        if (!isset($tempTableIndexList[strtoupper('template_description_id')])) {
            $connection->addKey($tempTable, 'template_description_id', 'template_description_id');
        }
        // ------------------------------
    }
    private function processSearch()
    {
        $connection = $this->installer->getConnection();
        $tempTable = $this->installer->getTable('m2epro_amazon_listing_product');
        if ($connection->tableColumnExists($tempTable, 'general_id_search_status') !== false) {
            $this->installer->run(<<<SQL

UPDATE `m2epro_amazon_listing_product`
SET general_id_search_status = 0,
    general_id_search_suggest_data = NULL;

UPDATE `m2epro_buy_listing_product`
SET general_id_search_status = 0,
    general_id_search_suggest_data = NULL;

UPDATE `m2epro_play_listing_product`
SET general_id_search_status = 0,
    general_id_search_suggest_data = NULL;
SQL
);
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_status') !== false && $connection->tableColumnExists($tempTable, 'search_settings_status') === false) {
            $connection->changeColumn($tempTable, 'general_id_search_status', 'search_settings_status', 'TINYINT(2) UNSIGNED DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_suggest_data') !== false && $connection->tableColumnExists($tempTable, 'search_settings_data') === false) {
            $connection->changeColumn($tempTable, 'general_id_search_suggest_data', 'search_settings_data', 'TEXT DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_info') === false) {
            $connection->addColumn($tempTable, 'general_id_search_info', 'TEXT DEFAULT NULL AFTER general_id');
        }
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if (isset($tempTableIndexList[strtoupper('general_id_search_status')])) {
            $connection->dropKey($tempTable, 'general_id_search_status');
        }
        if (!isset($tempTableIndexList[strtoupper('search_settings_status')])) {
            $connection->addKey($tempTable, 'search_settings_status', 'search_settings_status');
        }
        $tempTable = $this->installer->getTable('m2epro_buy_listing_product');
        if ($connection->tableColumnExists($tempTable, 'general_id_search_status') !== false && $connection->tableColumnExists($tempTable, 'search_settings_status') === false) {
            $connection->changeColumn($tempTable, 'general_id_search_status', 'search_settings_status', 'TINYINT(2) UNSIGNED DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_suggest_data') !== false && $connection->tableColumnExists($tempTable, 'search_settings_data') === false) {
            $connection->changeColumn($tempTable, 'general_id_search_suggest_data', 'search_settings_data', 'TEXT DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_info') === false) {
            $connection->addColumn($tempTable, 'general_id_search_info', 'TEXT DEFAULT NULL AFTER general_id');
        }
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if (isset($tempTableIndexList[strtoupper('general_id_search_status')])) {
            $connection->dropKey($tempTable, 'general_id_search_status');
        }
        if (!isset($tempTableIndexList[strtoupper('search_settings_status')])) {
            $connection->addKey($tempTable, 'search_settings_status', 'search_settings_status');
        }
        $tempTable = $this->installer->getTable('m2epro_play_listing_product');
        if ($connection->tableColumnExists($tempTable, 'general_id_search_status') !== false && $connection->tableColumnExists($tempTable, 'search_settings_status') === false) {
            $connection->changeColumn($tempTable, 'general_id_search_status', 'search_settings_status', 'TINYINT(2) UNSIGNED DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_suggest_data') !== false && $connection->tableColumnExists($tempTable, 'search_settings_data') === false) {
            $connection->changeColumn($tempTable, 'general_id_search_suggest_data', 'search_settings_data', 'TEXT DEFAULT NULL');
        }
        if ($connection->tableColumnExists($tempTable, 'general_id_search_info') === false) {
            $connection->addColumn($tempTable, 'general_id_search_info', 'TEXT DEFAULT NULL AFTER link_info');
        }
        $tempTableIndexList = $connection->getIndexList($tempTable);
        if (isset($tempTableIndexList[strtoupper('general_id_search_status')])) {
            $connection->dropKey($tempTable, 'general_id_search_status');
        }
        if (!isset($tempTableIndexList[strtoupper('search_settings_status')])) {
            $connection->addKey($tempTable, 'search_settings_status', 'search_settings_status');
        }
    }