checkColumnExists('parameters_products', 'value_float'); } /** Params: Prepare columns for new values */ public function makeChanges_1() { sqlQuery('ALTER TABLE `parameters_products` ADD `value_float` FLOAT NULL DEFAULT NULL AFTER `value`, ADD `value_char` VARCHAR(50) NULL DEFAULT NULL AFTER `value`, ADD `value_list` INT NULL DEFAULT NULL AFTER `value`'); $this->upgradeOK(); } public function checkRightfulness_2() { return $this->checkTableExists('parameters_list'); } /** Params: Add new table for list parameters */ public function makeChanges_2() { sqlQuery('CREATE TABLE IF NOT EXISTS `parameters_list` ( `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_parameter` INT(10) UNSIGNED NOT NULL, `value` VARCHAR(50) NOT NULL, `position` INT(11) DEFAULT NULL, `description` TEXT NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=1'); sqlQuery('ALTER TABLE `parameters_list` ADD UNIQUE KEY `id_parameter` (`id_parameter`,`value`)'); sqlQuery('ALTER TABLE `parameters_list` ADD CONSTRAINT `parameters_list_ibfk_1` FOREIGN KEY (`id_parameter`) REFERENCES `parameters` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;'); sqlQuery('ALTER TABLE `parameters_products` ADD FOREIGN KEY (`value_list`) REFERENCES `parameters_list`(`id`) ON DELETE CASCADE ON UPDATE CASCADE'); $this->upgradeOK(); } public function checkRightfulness_3() { return !$this->checkColumnExists('parameters', 'value'); } /** Params: Migrate list values to new column types and remove old column */ public function makeChanges_3() { $lists = sqlQuery("SELECT * FROM `parameters` WHERE value_type='list'"); $pos = 0; foreach ($lists as $list) { $values = explode('|', $list['value']); foreach ($values as $value) { try { $this->insertSQL('parameters_list', ['id_parameter' => $list['id'], 'position' => $pos++, 'value' => $value]); } catch (Exception $e) { } } } sqlQuery('ALTER TABLE `parameters` DROP COLUMN `value`'); $this->upgradeOK(); } public function checkRightfulness_4() { return !$this->checkColumnExists('parameters_products', 'value'); } /** Params: Migrate product parameters values to new column types and remove old column */ public function makeChanges_4() { sqlQuery('UPDATE `parameters_products` pp LEFT JOIN `parameters` p ON p.id = pp.id_parameter SET pp.value_float=value WHERE p.value_type="int" OR p.value_type="float"'); sqlQuery('UPDATE `parameters_products` pp LEFT JOIN `parameters` p ON p.id = pp.id_parameter SET pp.value_char=value WHERE p.value_type="char" '); // Add missing list values $products = sqlQuery('SELECT DISTINCT pp.id_parameter, pp.value AS value FROM `parameters_products` pp LEFT JOIN `parameters` p ON p.id = pp.id_parameter LEFT JOIN `parameters_list` pl ON pl.id_parameter = pp.id_parameter AND pp.value =pl.value WHERE p.value_type="list" AND pl.id IS NULL'); foreach ($products as $product) { $this->insertSQL('parameters_list', ['id_parameter' => $product['id_parameter'], 'position' => 9999, 'value' => $product['value']]); } sqlQuery('UPDATE `parameters_products` pp LEFT JOIN `parameters` p ON p.id = pp.id_parameter LEFT JOIN `parameters_list` pl ON pl.id_parameter = pp.id_parameter AND pp.value =pl.value SET pp.value_list=pl.id WHERE p.value_type="list"'); sqlQuery('ALTER TABLE `parameters_products` DROP PRIMARY KEY'); sqlQuery('ALTER TABLE `parameters_products` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); sqlQuery('ALTER TABLE `parameters_products` DROP COLUMN `value`'); $this->upgradeOK(); } public function checkRightfulness_5() { return false; } public function makeChanges_5() { } public function checkRightfulness_6() { return $this->checkColumnExists('photos_articles_relation', 'position'); } /** Articles: Add position column for photo ordering, strip tags from articles annotation */ public function makeChanges_6() { sqlQuery("ALTER TABLE `photos_articles_relation` ADD `position` INT(11) NULL; UPDATE `photos_articles_relation` SET `position`='1' WHERE `show_in_lead`='N'; UPDATE `photos_articles_relation` SET `position`='0' WHERE `show_in_lead`='Y';"); // Strip tags from annotation foreach (sqlQuery('SELECT * FROM articles') as $product) { $product['lead_in'] = html_entity_decode(strip_tags($product['lead_in'])); sqlQuery('UPDATE articles SET lead_in = :lead_in WHERE id=:id', $product); } $this->upgradeOK(); } public function checkRightfulness_8() { global $cfg; return !isset($cfg['Photo']); } /** Move pictures settings from dbcfg to cfg */ public function makeChanges_8() { function testPhotoTypes(&$addToTypes, $name, $values, &$ok) { global $cfg; if (empty($cfg['Photo']['types'][$name])) { $addToTypes .= "'{$name}' => [
'size' => "; if (!empty($cfg['Images'][ucfirst($name)][0]) && !empty($cfg['Images'][ucfirst($name)][1])) { $addToTypes .= "[{$cfg['Images'][ucfirst($name)][0]}, {$cfg['Images'][ucfirst($name)][1]}],
],
"; } else { $addToTypes .= "[{$values}],
],
"; } $ok = false; } } global $cfg; $settings = Settings::createFromDB(); $addToTypes = ''; $ok = true; if (empty($cfg['Photo']['default'])) { $cut = (empty($cfg['Images']['Cut']) || is_array($cfg['Images']['Cut'])) ? 'false' : 'true'; $background = dechex($cfg['Images']['Background']); $watermark = ($cfg['Images']['Watermark'] == '../templates/images/watermark.png') ? 'true' : "'{$cfg['Images']['Watermark']}'"; $addToDefault = "'default' => [ 'crop' => {$cut}, 'background' => 0x{$background}, 'watermark' => false, 'logo' => false, 'png' => false, ],"; $ok = false; } else { $addToDefault = ''; } if (!empty($settings->prod_photo_big_width) && empty($cfg['Photo']['types']['product_large']['size'])) { $addToTypes .= "'product_large' => [ 'size' => [{$settings->prod_photo_big_width}, {$settings->prod_photo_big_height}], 'crop' => false, 'watermark' => {$watermark}, 'logo' => true, ],
"; $ok = false; } if (!empty($settings->prod_photo_small_lead_width) && empty($cfg['Photo']['types']['product_catalog']['size'])) { $addToTypes .= "'product_catalog' => [ ".(isset($cfg['Images']['Cut'][2]) ? "'crop' => {$cfg['Images']['Cut'][2]}," : '')." 'size' => [{$settings->prod_photo_small_lead_width}, {$settings->prod_photo_small_lead_height}], ],
"; $ok = false; } if (!empty($settings->prod_photo_medium_width) && empty($cfg['Photo']['types']['product_detail']['size'])) { $addToTypes .= "'product_detail' => [ ".(isset($cfg['Images']['Cut'][3]) ? "'crop' => {$cfg['Images']['Cut'][2]}," : '')." 'size' => [{$settings->prod_photo_medium_width}, {$settings->prod_photo_medium_height}], ],
"; $ok = false; } if (!empty($settings->prod_photo_small_other_width) && empty($cfg['Photo']['types']['product_gallery']['size'])) { $addToTypes .= "'product_gallery' => [ ".(isset($cfg['Images']['Cut'][4]) ? "'crop' => {$cfg['Images']['Cut'][2]}," : '')." 'size' => [{$settings->prod_photo_small_other_width}, {$settings->prod_photo_small_other_height}], ],
"; $ok = false; } testPhotoTypes($addToTypes, 'admin', '64, 48', $ok); testPhotoTypes($addToTypes, 'section', '80, 80', $ok); testPhotoTypes($addToTypes, 'producer', '120, 60', $ok); testPhotoTypes($addToTypes, 'payment', '60, 60', $ok); testPhotoTypes($addToTypes, 'delivery', '60, 60', $ok); if (empty($cfg['Photo']['id_to_type'])) { $addToIDToType = "'id_to_type' => [ 0 => 'product_large', 1 => 'product_gallery', 2 => 'product_catalog', 3 => 'product_detail', 4 => 'product_gallery', 5 => 'admin', 6 => 'section', 7 => 'producer', 8 => 'payment', 9 => 'delivery', ],"; $ok = false; } else { $addToIDToType = ''; } if (!empty($addToTypes)) { $addToTypes = "'types' => [ {$addToTypes} ],"; } if (!$ok) { $cfgstr = " \$cfg['Photo'] = [ {$addToDefault} {$addToTypes} {$addToIDToType} ]; A JESTE ZMENIT REWRITE: ".'RewriteRule ^data/tmp/\d+/\d+/(\d+)_(\d+).jpg launch.php?s=image&id=$1&size=$2 [L,QSA]'; exit('

Chybi v configu:

'.$cfgstr); } $this->upgradeOK(); } public function checkRightfulness_9() { return Settings::getDefault()->user_rights_version == 2; } /** New modules - products[price_common], products_collections, products_related, links, attachments */ public function makeChanges_9() { if ($this->verbose) { if (!$this->checkTableIsEmpty('products_related') && !findModule('products_related')) { exit('

Chybi v configu: $cfg[\'Modules\'][\'products_related\'] = true;

'); } if (!$this->checkTableIsEmpty('attachments') && !findModule('attachments')) { exit('

Chybi v configu: $cfg[\'Modules\'][\'attachments\'] = true;

'); } if (!$this->checkTableIsEmpty('links') && !findModule('links')) { exit('

Chybi v configu: $cfg[\'Modules\'][\'links\'] = true;

'); } if (!$this->checkTableIsEmpty('products_collections') && !findModule('products_collections')) { exit('

Chybi v configu: $cfg[\'Modules\'][\'products_collections\'] = true;

'); } if (!$this->checkColumnIsEmpty('products', 'price_common') && findModule('products', 'price_common') === null) { exit('

Chybi v configu: $cfg[\'Modules\'][\'products\'] = [\'price_common\' => true];

'); } } sqlQuery('UPDATE delivery_type SET price_dont_countin_from = NULL WHERE price_dont_countin_from = 0'); $this->commitDataMigration(3); $this->upgradeOK(); } public function checkRightfulness_10() { return $this->checkTableExists('section_producer'); } /** Add section_producer table for frontend */ public function makeChanges_10() { sqlQuery('CREATE TABLE IF NOT EXISTS `section_producer` ( `id_section` INT(11) NOT NULL, `id_producer` INT(11) UNSIGNED NOT NULL, `text` TEXT, `id_slider` INT(11) DEFAULT NULL ) ENGINE=InnoDB;'); sqlQuery('ALTER TABLE `section_producer` ADD PRIMARY KEY (`id_section`,`id_producer`), ADD KEY `id_producer` (`id_producer`), ADD KEY `id_slider` (`id_slider`); '); sqlQuery('ALTER TABLE `section_producer` ADD CONSTRAINT `section_producer_ibfk_1` FOREIGN KEY (`id_section`) REFERENCES `sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `section_producer_ibfk_2` FOREIGN KEY (`id_producer`) REFERENCES `producers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `section_producer_ibfk_3` FOREIGN KEY (`id_slider`) REFERENCES `sliders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; '); $this->upgradeOK(); } public function checkRightfulness_11() { return $this->checkColumnDefault('sections', 'lead_figure', 'N'); } /** Set category.lead_figure default to N */ public function makeChanges_11() { sqlQuery("ALTER TABLE `sections` CHANGE `lead_figure` `lead_figure` ENUM('Y','N') NOT NULL DEFAULT 'N'"); $this->upgradeOK(); } public function checkRightfulness_12() { return false; } /** Add column for minimal price in discount */ public function makeChanges_12() { sqlQuery('ALTER TABLE `discounts` ADD `min_price` INT(11) NULL ;'); $this->upgradeOK(); } public function checkRightfulness_13() { return false; } /** Remove settings->prod_photo_... from dbcfg */ public function makeChanges_13() { $settings = Settings::createFromDB(); $settings->deleteValue('prod_photo_big_width'); $settings->deleteValue('prod_photo_big_height'); $settings->deleteValue('prod_photo_small_lead_width'); $settings->deleteValue('prod_photo_small_lead_height'); $settings->deleteValue('prod_photo_medium_width'); $settings->deleteValue('prod_photo_medium_height'); $settings->deleteValue('prod_photo_small_other_width'); $settings->deleteValue('prod_photo_small_other_height'); $this->upgradeOK(); } public function checkRightfulness_14() { return findModule('eshop_delivery') && findModule('abra') && $this->checkTableExists('abra_deliveries'); } /** Abra sync - add abra deliveries and payments sync tables */ public function makeChanges_14() { sqlQuery('CREATE TABLE '.getTableName('abra_deliveries').' ( `id_abra` VARCHAR(30) NOT NULL, `id_delivery` INT(11) NOT NULL ) ENGINE=InnoDB'); sqlQuery('ALTER TABLE `abra_deliveries` ADD KEY `id_abra` (`id_abra`)'); sqlQuery('ALTER TABLE `abra_deliveries` ADD CONSTRAINT `abra_deliveries_ibfk_1` FOREIGN KEY (`id_delivery`) REFERENCES `delivery_type_delivery` (`id`) ON DELETE CASCADE ON UPDATE CASCADE'); sqlQuery('CREATE TABLE '.getTableName('abra_payments').' ( `id_abra` VARCHAR(30) NOT NULL, `id_payment` INT(11) NOT NULL ) ENGINE=InnoDB'); sqlQuery('ALTER TABLE `abra_payments` ADD KEY `id_abra` (`id_abra`)'); sqlQuery('ALTER TABLE `abra_payments` ADD CONSTRAINT `abra_payments_ibfk_1` FOREIGN KEY (`id_payment`) REFERENCES `delivery_type_payment` (`id`) ON DELETE CASCADE ON UPDATE CASCADE'); } public function checkRightfulness_15() { // return findModule('eshop_delivery') && $this->checkColumnExists('delivery_type_delivery', 'countries'); return false; } /** Delivery - limit to only some countries */ public function makeChanges_15() { sqlQuery('ALTER TABLE `delivery_type_delivery` ADD `countries` VARCHAR(200) NULL DEFAULT NULL'); } public function checkRightfulness_16() { return $this->checkEnumExists('discounts', 'condition_type', 'order'); } /** Add 'pricelevel' to discount options */ public function makeChanges_16() { $this->checkEnumExists('discounts', 'condition_type', 'order', $pricelevels); $pricelevels = str_replace(')', ",'order')", $pricelevels); sqlQuery("ALTER TABLE discounts CHANGE `condition_type` `condition_type` {$pricelevels} NOT NULL DEFAULT 'price'"); $this->upgradeOK(); } public function checkRightfulness_18() { return $this->checkColumnExists('section_producer', 'meta_title'); } /** Add meta_title and meta_description to section_producer */ public function makeChanges_18() { sqlQuery('ALTER TABLE section_producer ADD `meta_title` VARCHAR(70) DEFAULT NULL; ALTER TABLE section_producer ADD `meta_description` VARCHAR(250) DEFAULT NULL;'); $this->upgradeOK(); } }