first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
<?php
use Symfony\Component\Filesystem\Filesystem;
class ShopFoldersUpgrade extends UpgradeNew
{
protected $priority = -1001;
protected function isAllowed()
{
return !defined('UPGRADE_DB_ONLY');
}
public function check_webBundlesFolder()
{
$path = $this->getShopDir().'web';
if (!file_exists($path)) {
return true;
}
return false;
}
/** Create './shop/web' folder for bundles */
public function upgrade_webBundlesFolder()
{
$path = $this->getShopDir().'web';
if (!file_exists($path)) {
mkdir($path);
chmod($path, 0777);
}
$this->upgradeOK();
}
public function check_engineFolder()
{
global $cfg;
$target = @readlink($this->getShopDir().'engine');
return $target != '../engine';
}
/** Update './engine' link in web directory */
public function upgrade_engineFolder()
{
global $cfg;
$file = $this->getShopDir().'engine';
$fs = new Filesystem();
$fs->remove($file);
symlink('../engine', $file);
$this->upgradeOK();
}
public function check_staticDir()
{
if (isFunctionalTests() || findModule(\Modules::COMPONENTS)) {
return false;
}
global $cfg;
$target = @readlink($this->getShopDir().'static');
return $target != "../{$cfg['Program']['version']['folder']}/web/templates/{$cfg['Path']['smarty_tpl']['theme']}/static/";
}
/** Update './static' link in web directory */
public function upgrade_staticDir()
{
global $cfg;
$file = $this->getShopDir().'static';
$fs = new Filesystem();
$fs->remove($file);
symlink("../{$cfg['Program']['version']['folder']}/web/templates/{$cfg['Path']['smarty_tpl']['theme']}/static/", $file);
$this->upgradeOK();
}
public function check_removeStaticDir()
{
if (!findModule(\Modules::COMPONENTS)) {
return false;
}
return file_exists($this->getShopDir().'static');
}
/** Remove './static' link in web directory */
public function upgrade_removeStaticDir()
{
$file = $this->getShopDir().'static';
$fs = new Filesystem();
$fs->remove($file);
$this->upgradeOK();
}
public function check_commonFolder()
{
if (defined('TEST_SUITE')) {
return false;
}
global $cfg;
$target = @readlink(getcwd().'/'.$cfg['Path']['web_root'].'common');
return $target != "../{$cfg['Program']['version']['folder']}/web/common/";
}
/** Update './common' link in web directory */
public function upgrade_commonFolder()
{
global $cfg;
$file = $cfg['Path']['web_root'].'common';
$fs = new Filesystem();
$fs->remove($file);
symlink("../{$cfg['Program']['version']['folder']}/web/common/", $file);
$this->upgradeOK();
}
public function check_adminStatic()
{
if (defined('TEST_SUITE')) {
return false;
}
global $cfg;
$target = @readlink($this->getShopDir().'admin/static');
return $target != "../../{$cfg['Program']['version']['folder']}/admin/static/";
}
/** Update './static' link in admin directory */
public function upgrade_adminStatic()
{
global $cfg;
$file = $this->getShopDir().'admin/static';
$fs = new Filesystem();
$fs->remove($file);
symlink("../../{$cfg['Program']['version']['folder']}/admin/static/", $file);
$this->upgradeOK();
}
public function check_ckeditor()
{
$target = @readlink($this->getShopDir().'ckeditor');
return $target != '../ckeditor4/';
}
/** Update './ckeditor' symlink */
public function upgrade_ckeditor()
{
@unlink($this->getShopDir().'ckeditor');
@symlink('../ckeditor4/', $this->getShopDir().'ckeditor');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,146 @@
<?php
class Upgrade1 extends UpgradeNew
{
protected $priority = -1000;
protected function isAllowed()
{
return !defined('UPGRADE_DB_ONLY');
}
private function runCommand($command, $dir)
{
$cwd = getcwd();
chdir($dir);
exec($command, $out, $return);
$out = join("\n", $out);
if ($return != 0) {
echo "Execution failed: {$command}\n{$out}\n";
}
chdir($cwd);
return $out;
}
public function check_DBExists()
{
if (isFunctionalTests()) {
return false;
}
$connection = sqlGetConnection();
$db = $connection->getDatabase();
return $this->ensureDbExists($db);
}
/** Create database */
public function upgrade_DBExists()
{
$this->upgradeOK();
}
public function check_LoadDumpReview()
{
return file_exists('./review_dump.sql.bz2') && $this->checkTableExists('products');
}
/** Load database dump from review */
public function upgrade_LoadDumpReview()
{
global $cfg;
$command = sprintf(
'bzcat %s | mysql -u %s -p%s -h%s %s',
'./review_dump.sql.bz2',
$cfg['Connection']['user'],
$cfg['Connection']['password'],
$cfg['Connection']['host'],
$cfg['Connection']['database']
);
exec($command, $output, $return);
// Turn off CDN
sqlQuery('UPDATE settings SET value = JSON_SET(value, "$.active", "N") WHERE key_name = "cdn"');
$this->addNote("Import exit code: {$return}, output: {$output}");
}
public function check_SymlinkDumpReview()
{
return file_exists('./review_dump.sql.bz2');
}
/** Symlink database dump from review */
public function upgrade_SymlinkDumpReview()
{
mkdir('./data/backup');
symlink(realpath('./review_dump.sql.bz2'), './data/backup/review_dump.sql.bz2');
$this->upgradeOK();
}
public function check_LoadUpstreamDump()
{
return isDevelopment() && $this->checkTableExists('products');
}
/** Load database dump using dump_database */
public function upgrade_LoadUpstreamDump()
{
$command = 'AUTO_DUMP=0 dump_database.sh 2>&1';
passthru($command, $return);
$this->addNote("Import exit code: {$return}");
}
public function check_LoadDump()
{
if (isFunctionalTests()) {
return false;
}
return $this->checkTableExists('products');
}
/** Load database dump */
public function upgrade_LoadDump()
{
global $cfg;
$command = sprintf(
'engine/bin/import_demo.sh %s %s %s %s',
$cfg['Connection']['user'],
$cfg['Connection']['password'],
$cfg['Connection']['host'],
$cfg['Connection']['database']
);
exec($command, $output, $return);
$output = join("\n", $output);
$this->addNote("Import exit code: {$return}, output: {$output}");
}
public function check_ClearCache()
{
// Clearovat cache je třeba jen na local dev, na produkci se cache invaliduje použitím jinýho prefixu s BUILD_ID
return isDevelopment();
}
/** Clear cache */
public function upgrade_ClearCache()
{
clearCache('', true);
global $dbcfg;
try {
$dbcfg = Settings::getDefault();
} catch (Exception $e) {
}
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,28 @@
<?php
class Upgrade2 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'show_raw_price') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery("ALTER TABLE `products` ADD `show_raw_price` ENUM( 'Y', 'N' ) NOT NULL DEFAULT 'N';");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,30 @@
<?php
class Upgrade3 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products_variations_choices_values'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'code') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').' ADD `code` VARCHAR(32) NOT NULL;');
sqlQuery('UPDATE '.getTableName('products_variations_choices_values').' SET code=value;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,28 @@
<?php
class Upgrade4 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'show_raw_price') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('products')." ADD `show_raw_price` ENUM( 'Y', 'N' ) NOT NULL DEFAULT 'N', ADD `tollfree` ENUM( 'Y', 'N' ) NOT NULL DEFAULT 'N';");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,28 @@
<?php
class Upgrade5 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('menu_links'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'parent') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('menu_links')." ADD parent INT NOT NULL DEFAULT '0' AFTER id;");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,30 @@
<?php
class Upgrade6 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('order_items'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'note') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('order_items')." ADD note TINYTEXT NOT NULL DEFAULT '' AFTER date;");
sqlQuery('ALTER TABLE '.getTableName('cart')." ADD note TINYTEXT NOT NULL DEFAULT '' AFTER date;");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,30 @@
<?php
class Upgrade7 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'ean') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('products').' ADD ean BIGINT NULL AFTER code;');
sqlQuery('ALTER TABLE '.getTableName('products_variations').' ADD ean BIGINT NULL AFTER id_product;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,68 @@
<?php
class Upgrade8 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products_variations'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'price') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('products_variations').' ADD price INT NULL AFTER delivery_time;');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products_variations_choices_values'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'id_product') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('UPDATE '.getTableName('products_variations_combination').' pvc
JOIN '.getTableName('products_variations_choices_values').' pvcv2 ON pvc.id_value=pvcv2.id
SET pvc.id_value = (
SELECT MIN(pvcv.id)
FROM '.getTableName('products_variations_choices_values').' pvcv
WHERE pvcv.value = pvcv2.value AND pvc.id_label = pvcv.id_label
);', '@');
sqlQuery('CREATE TEMPORARY TABLE tmp_variation AS SELECT MIN(id) AS id,id_label,value,code FROM '.getTableName('products_variations_choices_values').' pvcv GROUP BY value,id_label', '@');
sqlQuery('DELETE pvcv FROM '.getTableName('products_variations_choices_values').' pvcv LEFT JOIN tmp_variation USING(id) WHERE tmp_variation.id IS NULL;', '@');
sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').' DROP FOREIGN KEY `products_variations_choices_values_ibfk_2`;', '@');
sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').' DROP id_product;', '@');
sqlQuery('DROP TABLE tmp_variation;', '@');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,37 @@
<?php
class Upgrade9 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('orders_history', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('CREATE TABLE '.getTableName('orders_history')." (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id_order` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`id_status` INT(2) UNSIGNED NOT NULL DEFAULT '0',
`date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`comment` TEXT,
PRIMARY KEY (`id`),
KEY `id_order` (`id_order`),
FOREIGN KEY (`id_order`) REFERENCES ".getTableName('orders').' (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;');
$SQL = sqlQuery('ALTER TABLE '.getTableName('order_items').'
ADD FOREIGN KEY ( `id_order` ) REFERENCES '.getTableName('orders').' (`id`) ON DELETE CASCADE ON UPDATE CASCADE;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,98 @@
<?php
class Upgrade10 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery("SELECT 1
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA='".$GLOBALS['cfg']['Connection']['database']."' AND CONSTRAINT_TYPE='FOREIGN KEY' AND TABLE_NAME='".getTableName('products_in_sections', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
// Add constraint to categories
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' ADD FOREIGN KEY ( `id_section` ) REFERENCES `sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ;');
// Add constraint to photos
// Ensure validity
sqlQuery('DELETE ppr.*
FROM '.getTableName('photos_products_relation').' ppr
LEFT JOIN '.getTableName('products').' p ON ppr.id_product=p.id
WHERE p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation')." CHANGE `id_product` `id_product` INT( 11 ) NOT NULL DEFAULT '0'");
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' ADD FOREIGN KEY ( `id_photo` ) REFERENCES `photos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ;');
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' ADD FOREIGN KEY ( `id_product` ) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ;');
// Products in categories
// Ensure validity
sqlQuery('DELETE ppr.*
FROM '.getTableName('products_in_sections').' ppr
LEFT JOIN '.getTableName('products').' p ON ppr.id_product=p.id
WHERE p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('products_in_sections').' ENGINE = InnoDB');
sqlQuery('ALTER TABLE '.getTableName('products_in_sections')."
CHANGE `id_product` `id_product` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `id_section` `id_section` INT( 11 ) NOT NULL DEFAULT '0'");
sqlQuery('ALTER TABLE '.getTableName('products_in_sections').' ADD FOREIGN KEY ( `id_product` ) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ;');
sqlQuery('ALTER TABLE '.getTableName('products_in_sections').' ADD FOREIGN KEY ( `id_section` ) REFERENCES `sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ;');
// Users
$SQL = sqlQuery('ALTER TABLE '.getTableName('users').'
DROP INDEX `login` ,
ADD UNIQUE `login` ( `login` )');
sqlQuery('ALTER TABLE '.getTableName('sections').' DROP INDEX `id`');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('order_items'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'id_variation') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
// Add variation index to item order
sqlQuery('ALTER TABLE '.getTableName('order_items').' CHANGE id_product id_product INT( 11 ) NULL DEFAULT NULL');
$SQL = sqlQuery('ALTER TABLE '.getTableName('order_items').' ADD id_variation INT( 11 ) NULL DEFAULT NULL AFTER id_product;');
sqlQuery('UPDATE '.getTableName('order_items').' oi LEFT JOIN '.getTableName('products').'p ON p.id=oi.id_product SET oi.id_product=NULL WHERE p.id IS NULL;');
// add constrain
sqlQuery('ALTER TABLE '.getTableName('order_items').'
ADD FOREIGN KEY ( id_product ) REFERENCES products (id) ON DELETE SET NULL ON UPDATE CASCADE,
ADD FOREIGN KEY ( id_variation ) REFERENCES products_variations (id) ON DELETE SET NULL ON UPDATE CASCADE ;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,56 @@
<?php
class Upgrade12 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('sections'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'photo') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
// Add constraint to photos
$SQL = sqlQuery('ALTER TABLE '.getTableName('sections').'
ADD `photo` VARCHAR(50) DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('orders_history'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'notified') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
// Add constraint to photos
$SQL = sqlQuery('ALTER TABLE '.getTableName('orders_history').'
ADD `notified` TINYINT(1) NOT NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,66 @@
<?php
class Upgrade13 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return false;
// return $this->checkColumnType('products_variations_choices_values', 'code', 'VARCHAR(32)');
}
// provest samotny upgrade
// public function makeChanges_1()
// {
// sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').'
// CHANGE `code` `code` VARCHAR( 32 ) NULL DEFAULT NULL');
// sqlQuery('UPDATE '.getTableName('products_variations_choices_values')."
// SET code=NULL WHERE code=''");
// zakomenteny unique (id_value, value), protoze to kolidovalo s jinou migraci
// $SQL = sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').'
// ADD UNIQUE (`id_label` ,`code`),
// ADD UNIQUE (`id_label` ,`value`);');
// Zakomentovany, protože to nejdřív vytvořilo a pak hned smazalo o 6 řádků níž index
// $SQL = sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').'
// ADD UNIQUE (`id_label` ,`code`);');
// try {
// sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').'
// DROP INDEX value', '@');
// } catch (Exception $e) {
// }
// sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').'
// DROP INDEX id_label', '@');
// $this->upgradeOK();
// }
// overi, jestli je opravnene provest upgrade
// public function checkRightfulness_2()
// {
// $change = true;
//
// $SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products_variations_choices_values'));
// while ($row = sqlFetchArray($SQL)) {
// if ($row['Field'] == 'sort') {
// $change = false;
// break;
// }
// }
//
// return $change;
// }
//
// // provest samotny upgrade
// public function makeChanges_2()
// {
// // Add order field to support sorting
// $SQL = sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').'
// ADD `sort` INT(11) NOT NULL');
//
// $this->upgradeOK();
// }
}

View File

@@ -0,0 +1,79 @@
<?php
class Upgrade14 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('order_items'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'id_product' && $row['Null'] == 'NO') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('order_items').' CHANGE `note` `note` TINYTEXT NULL');
$SQL = sqlQuery('ALTER TABLE '.getTableName('cart').' CHANGE `note` `note` TINYTEXT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
if (!findModule('order_edit')) {
return false;
}
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('order_edit', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
// Add order field to support sorting
$SQL = sqlQuery("CREATE TABLE IF NOT EXISTS `order_edit` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`id_item` INT(10) UNSIGNED NOT NULL,
`id_order` INT(10) UNSIGNED NOT NULL,
`id_product` INT(11) DEFAULT NULL,
`id_variation` INT(11) DEFAULT NULL,
`pieces` MEDIUMINT(9) NOT NULL DEFAULT '1',
`pieces_reserved` MEDIUMINT(9) NOT NULL DEFAULT '0',
`piece_price` FLOAT NOT NULL DEFAULT '0',
`total_price` FLOAT NOT NULL DEFAULT '0',
`descr` TINYTEXT NOT NULL,
`tax` FLOAT NOT NULL DEFAULT '0',
`date` DATETIME NOT NULL DEFAULT '0000-00-00',
`note` TINYTEXT,
PRIMARY KEY (`id`),
KEY `id_invoice` (`id_order`),
KEY `id_product` (`id_product`),
KEY `id_variation` (`id_variation`)
) ENGINE=InnoDB COMMENT='editace objednavky'");
sqlQuery('ALTER TABLE `order_edit`
ADD CONSTRAINT `order_edit_ibfk_1` FOREIGN KEY (`id_order`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `order_edit_ibfk_2` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
ADD CONSTRAINT `order_edit_ibfk_3` FOREIGN KEY (`id_variation`) REFERENCES `products_variations` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
ADD CONSTRAINT `order_edit_ibfk_4` FOREIGN KEY (`id_item`) REFERENCES `order_items` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,122 @@
<?php
class Upgrade15 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('orders_history'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'admin') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('orders_history').'
ADD `admin` INT(11) NULL');
$SQL = sqlQuery('ALTER TABLE '.getTableName('orders_history').'
ADD CONSTRAINT `orders_history_ibfk_2` FOREIGN KEY (`admin`) REFERENCES `admins` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('orders'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'id_user' && $row['Null'] == 'NO') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('orders').' CHANGE `id_user` `id_user` INT(11) UNSIGNED DEFAULT NULL');
$SQL = sqlQuery('UPDATE '.getTableName('orders').' o
LEFT JOIN '.getTableName('users').' u ON o.id_user = u.id
SET o.id_user = NULL
WHERE o.id_user IS NOT NULL AND u.id IS NULL');
$SQL = sqlQuery('ALTER TABLE '.getTableName('orders').'
ADD FOREIGN KEY ( `id_user` ) REFERENCES `users` ( `id` ) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'producer' && $row['Null'] == 'NO') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_3()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('producers').' ENGINE = InnoDB');
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').' CHANGE `producer` `producer` INT(11) UNSIGNED DEFAULT NULL');
$SQL = sqlQuery('UPDATE '.getTableName('products').' p
LEFT JOIN '.getTableName('producers').' pp ON p.producer = pp.id
SET p.producer = NULL
WHERE p.producer IS NOT NULL AND pp.id IS NULL');
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').'
ADD FOREIGN KEY ( `producer` ) REFERENCES `producers` ( `id` ) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products_variations_choices_values'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'code' && $row['Null'] == 'NO') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_4()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_values').' CHANGE `code` `code` VARCHAR( 32 ) NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,235 @@
<?php
class Upgrade16 extends Upgrade
{
public function upgrade()
{
$changed = false;
if (findModule('products_suppliers') || findModule('automatic_import')) {
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
if ($this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
if ($this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
if ($this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
}
if (findModule('stock_in') && $this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = false;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('stock_in_suppliers', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = true;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('RENAME TABLE stock_in_suppliers TO suppliers ;');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('suppliers', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
$SQL = sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('suppliers').' (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30) NOT NULL,
`order_url` TEXT NULL,
`address` VARCHAR(50) NULL,
`phone` VARCHAR(15) NULL,
`email` VARCHAR(30) NULL,
`ico` VARCHAR(15) NULL,
`dic` VARCHAR(15) NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ico` (`ico`)
) ENGINE=InnoDB');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('products_of_suppliers', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_3()
{
$SQL = sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('products_of_suppliers')." (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id_product` INT(11) NOT NULL,
`id_variation` INT(11) DEFAULT NULL,
`id_supplier` INT(11) NOT NULL,
`code` VARCHAR(25) NULL,
`in_store` INT(11) NOT NULL DEFAULT '0',
`last_sync` DATETIME NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_product_2` (`id_product`,`id_variation`,`id_supplier`),
KEY `id_variation` (`id_variation`),
KEY `id_supplier` (`id_supplier`),
KEY `id_product` (`id_product`)
) ENGINE=InnoDB");
sqlQuery('ALTER TABLE `products_of_suppliers` ADD FOREIGN KEY ( `id_product` ) REFERENCES `products` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `products_of_suppliers` ADD FOREIGN KEY ( `id_variation` ) REFERENCES `products_variations` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `products_of_suppliers` ADD FOREIGN KEY ( `id_supplier` ) REFERENCES `suppliers` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return (findModule(Modules::PRODUCTS_SUPPLIERS)
|| findModule(Modules::SUPPLIERS)
|| findModule(Modules::STOCK_IN)) && $this->checkTableExists('products_of_suppliers');
}
// provest samotny upgrade
public function makeChanges_4()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('products_of_suppliers')."
ADD (
`in_store` INT(11) NOT NULL DEFAULT '0',
`last_sync` DATETIME NULL
)");
// Delete old records nonexistent product/variation
sqlQuery('DELETE pos FROM products_of_suppliers pos
LEFT JOIN products p ON p.id=pos.id_product
LEFT JOIN products_variations pv ON pv.id=pos.id_variation
WHERE p.id IS NULL OR pv.id IS NULL');
sqlQuery('ALTER TABLE `products_of_suppliers` ADD FOREIGN KEY ( `id_product` ) REFERENCES `products` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `products_of_suppliers` ADD FOREIGN KEY ( `id_variation` ) REFERENCES `products_variations` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `products_of_suppliers` ADD FOREIGN KEY ( `id_supplier` ) REFERENCES `suppliers` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
return $this->checkTableExists('stock_in');
}
// provest samotny upgrade
public function makeChanges_5()
{
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('stock_in')." (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`number` INT(11) NOT NULL,
`code` INT(11) NOT NULL,
`closed` TINYINT(1) NOT NULL DEFAULT '0',
`date_created` DATETIME NOT NULL,
`id_supplier` INT(11) NOT NULL,
`total_price` DOUBLE NOT NULL DEFAULT '0',
`transport_price` DOUBLE NOT NULL DEFAULT '0',
`date_expiration` DATE DEFAULT NULL,
`date_issued` DATE DEFAULT NULL,
`payment_method` ENUM('dobirka','prevodem') NOT NULL DEFAULT 'dobirka',
`paid` TINYINT(1) NOT NULL DEFAULT '0',
`note` VARCHAR(50) DEFAULT NULL,
`discount` DOUBLE NOT NULL DEFAULT '0',
`finished` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`,`id_supplier`),
KEY `supplier` (`id_supplier`)
) ENGINE=InnoDB");
sqlQuery('ALTER TABLE '.getTableName('stock_in').'
ADD CONSTRAINT `stock_in_ibfk_1` FOREIGN KEY (`id_supplier`) REFERENCES `suppliers` (`id`)');
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('stock_in_items').' (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) DEFAULT NULL,
`id_stock_in` INT(11) NOT NULL,
`id_product` INT(11) DEFAULT NULL,
`id_variation` INT(11) DEFAULT NULL,
`quantity` INT(11) NOT NULL,
`price` DOUBLE NOT NULL,
PRIMARY KEY (`id`),
KEY `id_stock_in` (`id_stock_in`),
KEY `id_product` (`id_product`),
KEY `id_variation` (`id_variation`)
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE '.getTableName('stock_in_items').'
ADD CONSTRAINT `stock_in_items_ibfk_1` FOREIGN KEY (`id_stock_in`) REFERENCES `stock_in` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `stock_in_items_ibfk_4` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
ADD CONSTRAINT `stock_in_items_ibfk_5` FOREIGN KEY (`id_variation`) REFERENCES `products_variations` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,49 @@
<?php
class Upgrade17 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
if (!findModule(\Modules::AUTOMATIC_IMPORT)) {
return false;
}
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('import', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('import').' (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`id_supplier` INT(11) NOT NULL,
`source` TEXT NULL,
`type` INT(11) NOT NULL,
`transformation` LONGTEXT NULL,
`last_sync` DATETIME NULL,
`last_count` INT(11) NULL,
`interval` DECIMAL(5,2) NOT NULL,
`add_new` BOOLEAN NOT NULL,
`delete_old` DECIMAL(5,2) NULL,
`modify_in_store` BOOLEAN NOT NULL,
`params` VARCHAR( 200 ) NULL,
PRIMARY KEY (`id`),
KEY `id_supplier` (`id_supplier`)
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE '.getTableName('import').'
ADD CONSTRAINT `import_ibfk_1`
FOREIGN KEY (`id_supplier`) REFERENCES `suppliers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,241 @@
<?php
class Upgrade18 extends Upgrade
{
public function upgrade()
{
$changed = false;
if (findModule('price_levels')) {
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
}
// jestlize je opravnene udelat upgrade, tak provest
if (findModule('products_suppliers') || findModule('automatic_import')) {
if ($this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
global $cfg;
if (!empty($cfg['Modules']['products']['showMax'])) {
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_6()) {
$this->makeChanges_6();
$changed = true;
}
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('price_levels_producers', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('price_levels_producers')." (
`id_price_level` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`id_producer` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`discount` FLOAT NOT NULL DEFAULT '0',
`unit` ENUM('perc','price') NOT NULL DEFAULT 'perc',
PRIMARY KEY (`id_price_level`,`id_producer`),
KEY `id_product` (`id_producer`)
) ENGINE=InnoDB COMMENT='cenove hladiny eshopu'");
sqlQuery('ALTER TABLE '.getTableName('price_levels_producers').'
ADD CONSTRAINT `price_levels_producers_ibfk_2` FOREIGN KEY (`id_producer`) REFERENCES `producers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `price_levels_producers_ibfk_1` FOREIGN KEY (`id_price_level`) REFERENCES `price_levels` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'vat' && $row['Null'] == 'YES') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('products').' CHANGE `vat` `vat` INT( 11 ) UNSIGNED NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('products').' ADD INDEX ( `vat` ) ');
sqlQuery('ALTER TABLE '.getTableName('vats').' ENGINE = InnoDB');
sqlQuery('UPDATE '.getTableName('products').' p
LEFT JOIN vats v ON p.vat=v.id
SET p.vat = 1
WHERE v.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('products').' ADD FOREIGN KEY ( `vat` ) REFERENCES '.getTableName('vats').' (
`id`
) ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
$change = true;
$SQL = sqlQuery("SELECT 1
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA='".$GLOBALS['cfg']['Connection']['database']."' AND CONSTRAINT_TYPE='UNIQUE' AND TABLE_NAME='".getTableName('products_of_suppliers', false)."'");
if (sqlNumRows($SQL) > 1) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_3()
{
$SQL = false;
try {
$SQL = sqlQuery('ALTER TABLE '.getTableName('products_of_suppliers').' ADD UNIQUE (
`id_supplier` ,
`code`
)');
} catch (Exception $e) {
}
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'code' && $row['Null'] == 'NO') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_4()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').' CHANGE `code` `code` VARCHAR( 20 ) NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('photos_products_relation'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'id_variation') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_5()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' ADD `id_variation` INT(11) NULL DEFAULT NULL AFTER `id_product`');
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' ADD UNIQUE KEY `id_photo` (`id_photo`,`id_product`,`id_variation`)');
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' ADD FOREIGN KEY ( `id_variation` ) REFERENCES '.getTableName('products_variations').' (
`id`
) ON UPDATE CASCADE ON DELETE SET NULL');
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' DROP PRIMARY KEY');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_6()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'in_store_show_max') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_6()
{
sqlQuery('ALTER TABLE '.getTableName('products').'
ADD `in_store_show_max` INT(11) DEFAULT NULL');
sqlQuery('ALTER TABLE '.getTableName('products_variations').'
ADD `in_store_show_max` INT(11) DEFAULT NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,227 @@
<?php
class Upgrade19 extends Upgrade
{
public function upgrade()
{
$changed = false;
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if (findModule('payments')) {
if ($this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
}
if (findModule('order_payment')) {
if ($this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
if ($this->checkRightfulness_6()) {
$this->makeChanges_6();
$changed = true;
}
}
if ($this->checkRightfulness_7()) {
$this->makeChanges_7();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'position') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').' ADD `position` INT NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('discounts'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'unit') {
$change = strpos($row['Type'], 'product') === false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('discounts')." CHANGE `unit` `unit` ENUM( 'perc', 'price', 'product' ) NOT NULL DEFAULT 'perc'");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return false; // Overriden by later update
$change = false;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('order_items'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'note' && $row['Null'] == 'NO') {
$change = true;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('order_items').'
CHANGE `note` `note` TINYTEXT NULL DEFAULT NULL ');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('delivery_type'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'payment_class') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('delivery_type').'
ADD `payment_class` VARCHAR(20) NULL DEFAULT NULL ');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('order_payments', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_5()
{
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('order_payments').' (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id_order` INT(11) UNSIGNED NOT NULL,
`price` DOUBLE NOT NULL,
`date` DATE NOT NULL,
`note` VARCHAR(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_order` (`id_order`)
) ENGINE=InnoDB ');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_6()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('order_payments'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'status') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_6()
{
sqlQuery('ALTER TABLE '.getTableName('order_payments').'
ADD `status` INT(11) NOT NULL DEFAULT 0,
ADD `payment_data` TEXT NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_7()
{
return sqlNumRows(sqlQuery('SELECT * FROM '.getTableName('admins')." WHERE `privilege` LIKE '%PROD_STOCK%'")) == 0
&& Settings::getDefault()->user_rights_version == 0;
}
// provest samotny upgrade
public function makeChanges_7()
{
sqlQuery('UPDATE '.getTableName('admins')." SET privilege=REPLACE(privilege, 'PROD_EDIT', 'PROD_EDIT|PROD_STOCK')");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,207 @@
<?php
class Upgrade20 extends Upgrade
{
public function upgrade()
{
$changed = false;
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
if ($this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
if (findModule('products_parameters')) {
if ($this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
}
if ($this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
if (findModule('automatic_import')) {
if ($this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'meta_title') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_1()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').' ADD
(`meta_title` VARCHAR(50) NULL DEFAULT NULL,
`meta_description` VARCHAR(50) NULL DEFAULT NULL,
`meta_keywords` VARCHAR(50) NULL DEFAULT NULL)');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('sections'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'meta_title') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_2()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('sections').' ADD
(`meta_title` VARCHAR(50) NULL DEFAULT NULL,
`meta_description` VARCHAR(50) NULL DEFAULT NULL,
`meta_keywords` VARCHAR(50) NULL DEFAULT NULL)');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
$change = !$this->checkColumnExists('parameters_products', 'value');
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('parameters_products'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'value' && substr($row['Type'], 0, 7) == 'varchar') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('parameters_products').' ADD INDEX ( `unit` )');
sqlQuery('ALTER TABLE '.getTableName('parameters_products').' CHANGE `value` `value` VARCHAR( 100 ) NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('parameters_products').' ADD INDEX ( `value` )');
sqlQuery('ALTER TABLE '.getTableName('parameters_products').' ADD INDEX ( `id_product` )');
sqlQuery('ALTER TABLE '.getTableName('parameters_products')." CHANGE `id_product` `id_product` INT( 11 ) NOT NULL DEFAULT '0'");
sqlQuery('DELETE pp FROM '.getTableName('parameters_products').' pp
LEFT JOIN '.getTableName('products').' p ON p.id = pp.id_product
WHERE p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('parameters_products').' ADD FOREIGN KEY ( `id_product` ) REFERENCES `products` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;');
sqlQuery('ALTER TABLE '.getTableName('parameters_products').' ADD FOREIGN KEY ( `id_parameter` ) REFERENCES `parameters` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;');
sqlQuery('ALTER TABLE '.getTableName('parameters_sections').' ADD FOREIGN KEY ( `id_parameter` ) REFERENCES `parameters` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;');
sqlQuery('ALTER TABLE '.getTableName('parameters_sections').' ADD FOREIGN KEY ( `id_section` ) REFERENCES `sections` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
$change = true;
$SQL = sqlQuery("SHOW TABLES LIKE '".getTableName('products_variations_sections', false)."'");
if (sqlNumRows($SQL) > 0) {
$change = false;
}
return $change;
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('products_variations_sections').' (
`id_label` INT(11) NOT NULL,
`id_section` INT(11) NOT NULL,
`weight` INT(11) DEFAULT NULL,
PRIMARY KEY (`id_label`, `id_section`)
) ENGINE=InnoDB ');
sqlQuery('ALTER TABLE '.getTableName('products_variations_sections').' ADD FOREIGN KEY ( `id_label` ) REFERENCES `products_variations_choices_labels` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;');
sqlQuery('ALTER TABLE '.getTableName('products_variations_sections').' ADD FOREIGN KEY ( `id_section` ) REFERENCES `sections` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
$change = true;
$SQL = sqlQuery('SHOW FIELDS FROM '.getTableName('import'));
while ($row = sqlFetchArray($SQL)) {
if ($row['Field'] == 'pair') {
$change = false;
break;
}
}
return $change;
}
// provest samotny upgrade
public function makeChanges_5()
{
sqlQuery('ALTER TABLE '.getTableName('import').' ADD `pair` BOOLEAN NOT NULL DEFAULT TRUE');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,129 @@
<?php
class Upgrade21 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return !$this->checkTableExists('paymuzo_payments') || !$this->checkTableExists('homecredit_payments') || !$this->checkTableExists('ebanka_payments');
}
// provest samotny upgrade
public function makeChanges_1()
{
if (!$this->checkTableExists('homecredit_payments')) {
sqlQuery('DROP TABLE '.getTableName('homecredit_payments'));
}
if (!$this->checkTableExists('homecredit_delivery_type_relation')) {
sqlQuery('DROP TABLE '.getTableName('homecredit_delivery_type_relation'));
}
if (!$this->checkTableExists('ebanka_payments')) {
sqlQuery('DROP TABLE '.getTableName('ebanka_payments'));
}
if (!$this->checkTableExists('multiservis_delivery_type_relation')) {
sqlQuery('DROP TABLE '.getTableName('multiservis_delivery_type_relation'));
}
if (!$this->checkTableExists('multiservis_payments')) {
sqlQuery('DROP TABLE '.getTableName('multiservis_payments'));
}
if (!$this->checkTableExists('paymuzo_delivery_type_relation')) {
sqlQuery('DROP TABLE '.getTableName('paymuzo_delivery_type_relation'));
}
if (!$this->checkTableExists('paymuzo_payments')) {
sqlQuery('DROP TABLE '.getTableName('paymuzo_payments'));
}
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
return $this->checkColumnExists('products', 'show_in_feed');
}
// provest samotny upgrade
public function makeChanges_2()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').' ADD
(`show_in_feed` BOOLEAN NOT NULL DEFAULT 1,
`max_cpc` DOUBLE NOT NULL DEFAULT 0)');
sqlQuery('UPDATE '.getTableName('products')."
SET max_cpc=IF(tollfree='Y', 1, 0)");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return !$this->checkColumnExists('products', 'tollfree');
}
// provest samotny upgrade
public function makeChanges_3()
{
// Drop tollfree column
$SQL = sqlQuery('ALTER TABLE '.getTableName('products').' DROP tollfree');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return $this->checkConstraintWithColumnExists('parameters_products', 'PRIMARY', 'value') && !$this->checkColumnExists('parameters_products', 'value');
}
// provest samotny upgrade
public function makeChanges_4()
{
// Drop tollfree column
$SQL = sqlQuery('ALTER TABLE '.getTableName('parameters_products').' DROP PRIMARY KEY ,
ADD PRIMARY KEY ( `id_product` , `id_parameter` , `value` )');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
return $this->checkColumnType('sections', 'meta_title', 'varchar(70)');
}
// provest samotny upgrade
public function makeChanges_5()
{
// Make SEO fields wider
sqlQuery('ALTER TABLE '.getTableName('sections').' CHANGE `meta_title` `meta_title` VARCHAR( 70 ) NULL DEFAULT NULL ,
CHANGE `meta_description` `meta_description` VARCHAR( 250 ) NULL DEFAULT NULL ,
CHANGE `meta_keywords` `meta_keywords` VARCHAR( 100 ) NULL DEFAULT NULL');
sqlQuery('ALTER TABLE '.getTableName('products').' CHANGE `meta_title` `meta_title` VARCHAR( 70 ) NULL DEFAULT NULL ,
CHANGE `meta_description` `meta_description` VARCHAR( 250 ) NULL DEFAULT NULL ,
CHANGE `meta_keywords` `meta_keywords` VARCHAR( 100 ) NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_6()
{
return $this->checkColumnIsNull('parameters_products', 'unit', true);
}
// provest samotny upgrade
public function makeChanges_6()
{
// Make SEO fields wider
sqlQuery('ALTER TABLE '.getTableName('parameters_products').'
CHANGE `unit` `unit` VARCHAR( 20 ) NULL DEFAULT NULL ,
CHANGE `weight` `weight` INT( 11 ) NULL DEFAULT NULL');
sqlQuery('UPDATE '.getTableName('parameters_products').' SET weight=NULL WHERE weight=0');
sqlQuery('UPDATE '.getTableName('parameters_products')." SET unit=NULL WHERE unit='' OR unit='Array'");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,104 @@
<?php
class Upgrade22 extends Upgrade
{
public function upgrade()
{
$changed = false;
// jestlize je opravnene udelat upgrade, tak provest
if (findModule('producers') && findModule('products_parameters') && $this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
if (findModule('producers') && $this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
if (findModule('products_variations') && $this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
if (findModule('eshop_delivery') && $this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return $this->checkTableExists('parameters_producers');
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('CREATE TABLE '.getTableName('parameters_producers')." (
`id_parameter` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`id_producer` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`weight` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id_parameter`,`id_producer`),
KEY `weight` (`weight`),
KEY `id_producer` (`id_producer`)
) ENGINE=InnoDB ");
sqlQuery('ALTER TABLE '.getTableName('parameters_producers').'
ADD CONSTRAINT `parameters_producers_ibfk_1` FOREIGN KEY (`id_parameter`) REFERENCES `parameters` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `parameters_producers_ibfk_2` FOREIGN KEY (`id_producer`) REFERENCES `producers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
// return $this->checkColumnType('producers', 'descr', 'text') && $this->checkColumnType('producers', 'descr', 'mediumtext');
return false;
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('producers').' CHANGE `descr` `descr` TEXT NOT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return $this->checkColumnExists('products_variations', 'figure');
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('products_variations')." ADD `figure` ENUM( 'Y', 'N' ) NOT NULL DEFAULT 'Y';");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return $this->checkColumnExists('delivery_type', 'format');
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('delivery_type').' ADD `format` VARCHAR(20) NULL DEFAULT NULL;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,140 @@
<?php
class Upgrade23 extends Upgrade
{
public function upgrade()
{
$changed = false;
if (findModule('stock_in') && $this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
if (findModule('stock_in') && $this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
if (findModule('stock_in') && $this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
if ($this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
if (findModule('inventory') && $this->checkRightfulness_6()) {
$this->makeChanges_6();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
return $this->checkColumnExists('stock_in', 'id_index');
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('stock_in')." ADD `id_index` INT(11) NOT NULL DEFAULT '1' AFTER `id`");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return $this->checkColumnExists('stock_in_items', 'name');
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('stock_in_items').' ADD `name` VARCHAR(100) NULL DEFAULT NULL AFTER `id`');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return $this->checkColumnExists('stock_in', 'number');
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('stock_in').' ADD `number` INT(11) NOT NULL AFTER `id`');
sqlQuery('UPDATE '.getTableName('stock_in').' si
SET number=id');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
return $this->checkColumnExists('products_variations', 'code') && !$this->checkTableExists('products_variations');
}
// provest samotny upgrade
public function makeChanges_5()
{
sqlQuery('ALTER TABLE '.getTableName('products_variations').' ADD `code` VARCHAR(20) DEFAULT NULL AFTER `id_product`');
sqlQuery('ALTER TABLE '.getTableName('products_variations').'
ADD UNIQUE KEY `code` (`code`)');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_6()
{
return $this->checkTableExists('inventory');
}
// provest samotny upgrade
public function makeChanges_6()
{
sqlQuery('CREATE TABLE '.getTableName('inventory')." (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`note` VARCHAR(50) DEFAULT NULL,
`finished` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB ");
sqlQuery('CREATE TABLE '.getTableName('inventory_items').' (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id_inventory` INT(11) NOT NULL,
`id_product` INT(11) NOT NULL,
`id_variation` INT(11) DEFAULT NULL,
`quantity` INT(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `id_inventory` (`id_inventory`),
KEY `id_product` (`id_product`),
KEY `id_variation` (`id_variation`)
) ENGINE=InnoDB ');
sqlQuery('ALTER TABLE '.getTableName('inventory_items').'
ADD CONSTRAINT `inventory_items_ibfk_1` FOREIGN KEY (`id_inventory`) REFERENCES `inventory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `inventory_items_ibfk_2` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `inventory_items_ibfk_3` FOREIGN KEY (`id_variation`) REFERENCES `products_variations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,162 @@
<?php
class Upgrade24 extends Upgrade
{
public function upgrade()
{
$changed = false;
// jestlize je opravnene udelat upgrade, tak provest
if (findModule('feeds') && $this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
if (findModule('feeds') && $this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
if (findModule('products_parameters') && $this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
if ($this->checkRightfulness_4() && (
findModule(Modules::PRODUCTS_SUPPLIERS)
|| findModule(Modules::SUPPLIERS)
)) {
$this->makeChanges_4();
$changed = true;
}
if (findModule('sliders') && $this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
if ($this->checkRightfulness_8()) {
$this->makeChanges_8();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return $this->checkColumnExists('sections', 'feed_heureka');
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('sections').' ADD `feed_heureka` INT(11) NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
return $this->checkColumnExists('sections', 'feed_google');
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('sections').' ADD `feed_google` INT(11) NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return $this->checkColumnType('parameters', 'descr', 'text') && $this->checkColumnType('parameters', 'descr', 'mediumtext');
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('parameters').' CHANGE `descr` `descr` TEXT NOT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return $this->checkColumnExists('products_of_suppliers', 'price_buy');
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('products_of_suppliers').'
ADD `price_buy` DOUBLE NULL DEFAULT NULL,
ADD `price_sell` DOUBLE NULL DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
return $this->checkTableExists('sliders');
}
// provest samotny upgrade
public function makeChanges_5()
{
sqlQuery('CREATE TABLE '.getTableName('sliders').' (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB ');
sqlQuery('CREATE TABLE '.getTableName('sliders_images')." (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id_slider` INT(11) NOT NULL,
`image` VARCHAR(50) NOT NULL,
`position` INT(11) NOT NULL DEFAULT '1',
`description` TEXT,
`link` TEXT,
PRIMARY KEY (`id`),
KEY `id_slider` (`id_slider`)
) ENGINE=InnoDB");
sqlQuery('ALTER TABLE '.getTableName('sliders_images').'
ADD CONSTRAINT `sliders_images_ibfk_1` FOREIGN KEY (`id_slider`) REFERENCES `sliders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('INSERT INTO '.getTableName('sliders')." (`id`, `name`) VALUES (1, 'Úvod')");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_8()
{
return $this->checkForeignKeyExists('articles_authors_admins', 'id_admin');
}
// provest samotny upgrade
public function makeChanges_8()
{
sqlQuery('ALTER TABLE '.getTableName('articles_authors_admins').' ADD FOREIGN KEY ( `id_admin` ) REFERENCES `admins` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE '.getTableName('articles_authors_admins').' ADD FOREIGN KEY ( `id_auth` ) REFERENCES `articles_authors` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,218 @@
<?php
class Upgrade25 extends Upgrade
{
public function upgrade()
{
$changed = false;
// jestlize je opravnene udelat upgrade, tak provest
if (findModule('stock_in') && $this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
global $cfg;
if (!empty($cfg['Order']['Flags'])) {
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_5()) {
$this->makeChanges_5();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_6()) {
$this->makeChanges_6();
$changed = true;
}
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_7()) {
$this->makeChanges_7();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return false;
}
// provest samotny upgrade
public function makeChanges_1()
{
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
global $cfg;
$type = '';
$this->checkEnumExists('products', 'campaign', 'bžet', $type);
foreach ($cfg['Products']['Flags'] as $name => $flag) {
if (strstr($type, "'{$name}'") === false) {
return true;
}
}
}
// provest samotny upgrade
public function makeChanges_2()
{
global $cfg;
$type = '';
$this->checkEnumExists('products', 'campaign', 'bžet', $type);
foreach ($cfg['Products']['Flags'] as $name => $flag) {
if (strstr($type, "'{$name}'") === false) {
$type = str_replace(')', ",'{$name}')", $type);
}
}
sqlQuery('ALTER TABLE '.getTableName('products')." CHANGE `campaign` `campaign` {$type} NOT NULL");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return $this->checkConstraintWithColumnExists('products_related', 'products_related_ibfk_1', 'id_top_product');
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('DELETE pr FROM '.getTableName('products_related').' pr
LEFT JOIN '.getTableName('products').' p ON pr.id_top_product=p.id
WHERE p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('products_related').' CHANGE `id_top_product` `id_top_product` INT(11) NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('products_related').'
ADD CONSTRAINT `products_related_ibfk_1` FOREIGN KEY (`id_top_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return $this->checkConstraintWithColumnExists('products_related', 'products_related_ibfk_2', 'id_rel_product');
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('DELETE pr FROM '.getTableName('products_related').' pr
LEFT JOIN '.getTableName('products').' p ON pr.id_rel_product=p.id
WHERE p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('products_related').' CHANGE `id_rel_product` `id_rel_product` INT(11) NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('products_related').'
ADD CONSTRAINT `products_related_ibfk_2` FOREIGN KEY (`id_rel_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
return $this->checkColumnExists('orders', 'flags');
}
// provest samotny upgrade
public function makeChanges_5()
{
global $cfg;
sqlQuery('ALTER TABLE '.getTableName('orders')." ADD `flags` SET('".join("','", array_keys($cfg['Order']['Flags']))."') NOT NULL");
sqlQuery('ALTER TABLE '.getTableName('orders').' ADD INDEX(`flags`)');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_6()
{
global $cfg;
$type = '';
$this->checkEnumExists('orders', 'flags', 'bžet', $type);
foreach ($cfg['Order']['Flags'] as $name => $flag) {
if (strstr($type, "'{$name}'") === false) {
return true;
}
}
}
// provest samotny upgrade
public function makeChanges_6()
{
global $cfg;
$type = '';
$this->checkEnumExists('orders', 'flags', 'bžet', $type);
foreach ($cfg['Order']['Flags'] as $name => $flag) {
if (strstr($type, "'{$name}'") === false) {
$type = str_replace(')', ",'{$name}')", $type);
}
}
sqlQuery('ALTER TABLE '.getTableName('orders')." CHANGE `flags` `flags` {$type} NOT NULL");
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_7()
{
return $this->checkEnumExists('products', 'campaign', 'M');
}
// provest samotny upgrade
public function makeChanges_7()
{
$type = '';
$this->checkEnumExists('products', 'campaign', 'M', $type);
$type = str_replace(')', ",'M')", $type);
sqlQuery('ALTER TABLE '.getTableName('products')." CHANGE `campaign` `campaign` {$type} NOT NULL");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,95 @@
<?php
class Upgrade27 extends Upgrade
{
public function upgrade()
{
$changed = false;
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_1()) {
$this->makeChanges_1();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_2()) {
$this->makeChanges_2();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if (findModule('order_edit') && $this->checkRightfulness_3()) {
$this->makeChanges_3();
$changed = true;
}
// jestlize je opravnene udelat upgrade, tak provest
if ($this->checkRightfulness_4()) {
$this->makeChanges_4();
$changed = true;
}
if ($changed == false) {
$this->noChanges();
}
$this->printResult();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return $this->checkColumnIsNull('order_items', 'note', false) || $this->checkColumnType('order_items', 'note', 'TEXT');
}
// provest samotny upgrade
public function makeChanges_1()
{
sqlQuery('ALTER TABLE '.getTableName('order_items').' CHANGE `note` `note` TEXT NOT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
return $this->checkColumnIsNull('cart', 'note', false) || $this->checkColumnType('cart', 'note', 'TEXT');
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('cart').' CHANGE `note` `note` TEXT NOT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return $this->checkColumnIsNull('order_edit', 'note', false) || $this->checkColumnType('order_edit', 'note', 'TEXT');
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('order_edit').' CHANGE `note` `note` TEXT NOT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return $this->checkColumnType('users', 'passw', 'VARCHAR(256)');
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('users')." CHANGE `passw` `passw` VARCHAR(256) NOT NULL DEFAULT ''");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,156 @@
<?php
class Upgrade28 extends UpgradeNew
{
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_1()
{
return findModule(\Modules::MISSING_PRODUCTS) && $this->checkColumnExists('products_variations', 'in_store_min');
}
// provest samotny upgrade
public function makeChanges_1()
{
try {
sqlQuery('ALTER TABLE products ADD `in_store_min` INT(11) DEFAULT NULL');
} catch (Exception $e) {
}
sqlQuery('ALTER TABLE products_variations ADD `in_store_min` INT(11) DEFAULT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_2()
{
return $this->checkColumnExists('sections_relation', 'position');
}
// provest samotny upgrade
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' ADD `position` INT(11) NOT NULL DEFAULT 0');
sqlQuery('UPDATE '.getTableName('sections_relation').' sr
LEFT JOIN '.getTableName('sections').' s ON s.id=sr.id_section
SET sr.`position`=COALESCE(s.menu_order, 0)');
global $cfg;
require_once $cfg['Path']['shared_version'].'admin/lists/SectionsList.php';
foreach (sqlQuery('SELECT id FROM '.getTableName('sections').'') as $row) {
SectionsList::orderTreeLevel($row['id']);
}
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_3()
{
return $this->checkColumnIsNull('sections_relation', 'id_topsection', true);
}
// provest samotny upgrade
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' ADD INDEX(`id_section`)');
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' DROP PRIMARY KEY');
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' CHANGE `id_topsection` `id_topsection` INT(11) NULL DEFAULT NULL');
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' ADD UNIQUE( `id_section`, `id_topsection`)');
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' DROP INDEX `id_section`');
sqlQuery('INSERT INTO '.getTableName('sections_relation').'
SELECT s.id, NULL
FROM '.getTableName('sections').' s
LEFT JOIN '.getTableName('sections_relation').' sr ON s.id=sr.id_section
WHERE sr.id_section IS NULL');
sqlQuery('UPDATE '.getTableName('sections_relation').' sr
LEFT JOIN '.getTableName('sections').' s ON s.id=sr.id_topsection
SET id_topsection=NULL
WHERE s.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('sections_relation').'
ADD CONSTRAINT `sections_ibfk_2` FOREIGN KEY (`id_topsection`) REFERENCES '.getTableName('sections').' (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE '.getTableName('sections_relation').' DROP FOREIGN KEY `sections_ibfk_2`');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_4()
{
return !$this->checkColumnExists('sections', 'menu_figure', true);
}
// provest samotny upgrade
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('sections').' DROP `menu_figure`');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_5()
{
return !$this->checkColumnExists('sections', 'menu_order', true);
}
// provest samotny upgrade
public function makeChanges_5()
{
sqlQuery('ALTER TABLE '.getTableName('sections').' DROP `menu_order`');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_6()
{
return $this->checkColumnIsNull('menu_links', 'parent', true);
}
// provest samotny upgrade
public function makeChanges_6()
{
sqlQuery('ALTER TABLE '.getTableName('menu_links').' CHANGE `parent` `parent` INT(11) NULL DEFAULT NULL');
sqlQuery('UPDATE '.getTableName('menu_links').' ml
LEFT JOIN '.getTableName('menu_links').' ml2 ON ml.parent=ml2.id
SET ml.parent=NULL
WHERE ml2.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('menu_links').'
ADD CONSTRAINT `menu_links_ibfk_1` FOREIGN KEY (`parent`) REFERENCES '.getTableName('menu_links').' (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function checkRightfulness_7()
{
return $this->checkColumnExists('sections_relation', 'position');
}
// provest samotny upgrade
public function makeChanges_7()
{
$SQL = sqlQuery('SELECT id_topsection FROM '.getTableName('sections_relation').' GROUP BY id_topsection');
global $cfg;
require_once $cfg['Path']['shared_version'].'admin/list/SectionsList.php';
foreach ($SQL as $row) {
SectionsList::orderTreeLevel($row['id_topsection']);
}
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,236 @@
<?php
class Upgrade29 extends UpgradeNew
{
public function checkRightfulness_1()
{
return false;
}
public function checkRightfulness_2()
{
return false;
}
public function checkRightfulness_3()
{
return $this->checkConstraintWithColumnExists('products_variations_choices_labels', 'label', 'label');
}
/** Add unique key 'label' to products_variations_choices_labels */
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('products_variations_choices_labels').' ADD UNIQUE(label)');
$this->upgradeOK();
}
public function checkRightfulness_4()
{
return findModule('products_suppliers') && $this->checkConstraintWithColumnExists('suppliers', 'name', 'name');
}
/** Make suppliers name unique */
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('suppliers').' ADD UNIQUE(name)');
$this->upgradeOK();
}
public function checkRightfulness_5()
{
return $this->checkConstraintWithColumnExists('producers', 'name', 'name');
}
/** Make producers name unique */
public function makeChanges_5()
{
sqlQuery('ALTER TABLE '.getTableName('producers').' ADD UNIQUE(`name`)');
sqlQuery('ALTER TABLE '.getTableName('producers').' CHANGE `name` `name` VARCHAR(100) NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('producers').' CHANGE `photo` `photo` VARCHAR(50) NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('producers').' DROP INDEX id');
$this->upgradeOK();
}
public function checkRightfulness_6()
{
$target = @readlink($this->getShopDir().'templates/functions.js');
return $target;
}
/** Drop link to functions.js */
public function makeChanges_6()
{
unlink($this->getShopDir().'functions.js');
$this->upgradeOK();
}
public function checkRightfulness_7()
{
return $this->checkColumnType('admins', 'password', 'VARCHAR(256)');
}
/** Make admin password field long enough to hold better hashed password */
public function makeChanges_7()
{
sqlQuery('ALTER TABLE '.getTableName('admins').' CHANGE `password` `password` VARCHAR(256) NOT NULL');
$this->upgradeOK();
}
public function checkRightfulness_8()
{
return $this->checkTableExists('products_sets') && $this->checkModule('products_sets');
}
/** Create 'products_sets' table */
public function makeChanges_8()
{
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('products_sets').' (
`id_product` INT(11) NOT NULL,
`id_product_set` INT(11) NOT NULL,
`price` DECIMAL(15,4) DEFAULT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE '.getTableName('products_sets').'
ADD PRIMARY KEY (`id_product`,`id_product_set`), ADD KEY `id_product_set` (`id_product_set`)');
sqlQuery('ALTER TABLE `products_sets`
ADD CONSTRAINT `products_sets_ibfk_2` FOREIGN KEY (`id_product_set`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `products_sets_ibfk_1` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_ProductSetsPriceColumn(): bool
{
if (!findModule(Modules::PRODUCT_SETS)) {
return false;
}
return $this->checkColumnType('products_sets', 'price', 'DECIMAL(15,4)');
}
/** Change `products_sets.price` type to DECIMAL(15,4) */
public function upgrade_ProductSetsPriceColumn(): void
{
sqlQuery('ALTER TABLE products_sets MODIFY price DECIMAL(15,4) DEFAULT NULL');
$this->upgradeOK();
}
public function check_ProductsSetsIDVariation()
{
if (!findModule('products_sets')) {
return false;
}
return $this->checkColumnExists('products_sets', 'id_variation');
}
/** Add id_variation column into products_sets */
public function upgrade_ProductsSetsIDVariation()
{
sqlQuery('ALTER TABLE products_sets ADD COLUMN id_variation INT(11) DEFAULT NULL');
if (findModule(\Modules::PRODUCTS_VARIATIONS)) {
sqlQuery('ALTER TABLE products_sets ADD CONSTRAINT products_sets_ibfk_3 FOREIGN KEY (id_variation) REFERENCES products_variations(id) ON DELETE CASCADE ON UPDATE CASCADE');
}
$this->upgradeOK();
}
public function check_ProductsSetsPieces()
{
if (!findModule('products_sets')) {
return false;
}
return $this->checkColumnExists('products_sets', 'pieces');
}
/** Add pieces column into products_sets */
public function upgrade_ProductsSetsPieces()
{
sqlQuery('ALTER TABLE products_sets ADD COLUMN pieces INT(11) DEFAULT 1');
$this->upgradeOK();
}
public function checkRightfulness_9()
{
return $this->checkColumnType('orders', 'delivery_type', 'varchar(200)');
}
/** Make order 'delivery_type' much longer. */
public function makeChanges_9()
{
sqlQuery('ALTER TABLE '.getTableName('orders').' CHANGE `delivery_type` `delivery_type` VARCHAR(200) NOT NULL');
$this->upgradeOK();
}
public function checkRightfulness_10()
{
return $this->checkColumnExists('orders', 'id_delivery');
}
/** Add delivery_type foreign key to order */
public function makeChanges_10()
{
sqlQuery('ALTER TABLE '.getTableName('orders').' ADD `id_delivery` INT(10) UNSIGNED NULL AFTER `delivery_type`');
sqlQuery('ALTER TABLE '.getTableName('orders').' ADD INDEX(`delivery_type`)');
sqlQuery('ALTER TABLE '.getTableName('orders').' ADD FOREIGN KEY (`id_delivery`) REFERENCES `delivery_type`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_11()
{
global $cfg;
return !empty($cfg['Modules']['products']['note']) && $this->checkColumnExists('products', 'note');
}
/** Add 'note' fields to product and variation */
public function makeChanges_11()
{
sqlQuery('ALTER TABLE '.getTableName('products').' ADD `note` VARCHAR(50) DEFAULT NULL');
sqlQuery('ALTER TABLE '.getTableName('products_variations').' ADD `note` VARCHAR(50) DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_12()
{
global $cfg;
return !empty($cfg['Modules']['products_variations']['variationCode']) && $this->checkColumnType('products_variations', 'code', 'VARCHAR(50)');
}
/** Make 'products_variations.code' field larger (50 chars) */
public function makeChanges_12()
{
sqlQuery('ALTER TABLE '.getTableName('products_variations').' CHANGE `code` `code` VARCHAR(50) DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_13()
{
return $this->checkColumnType('products', 'code', 'VARCHAR(50)') && $this->checkColumnType('products', 'code', 'VARCHAR(200)');
}
/** Make 'product.code' field larger (50 chars) */
public function makeChanges_13()
{
sqlQuery('ALTER TABLE '.getTableName('products').' CHANGE `code` `code` VARCHAR(50) DEFAULT NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,241 @@
<?php
class Upgrade30 extends UpgradeNew
{
public function checkRightfulness_1()
{
return findModule('products_collections') && $this->checkTableExists('products_collections');
}
/** New module 'collections' -> products_collections table */
public function makeChanges_1()
{
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('products_collections').' (
`id_product` INT(11) NOT NULL,
`id_product_related` INT(11) NOT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE '.getTableName('products_collections').'
ADD PRIMARY KEY (`id_product`,`id_product_related`), ADD KEY `id_product_related` (`id_product_related`)');
sqlQuery('ALTER TABLE '.getTableName('products_collections').'
ADD CONSTRAINT `products_collections_ibfk_2` FOREIGN KEY (`id_product_related`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `products_collections_ibfk_1` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_2()
{
return $this->checkColumnType('products', 'show_in_feed', "enum('Y','N')");
}
/** Convert product.show_in_feed from BOOL to Y/N */
public function makeChanges_2()
{
sqlQuery('ALTER TABLE '.getTableName('products')." CHANGE `show_in_feed` `show_in_feed` ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
sqlQuery('UPDATE '.getTableName('products')." SET `show_in_feed`='N' WHERE `show_in_feed`=''");
$this->upgradeOK();
}
public function checkRightfulness_3()
{
return $this->checkConstraintExists('orders', 'order_no');
}
/** Add unique to order_no */
public function makeChanges_3()
{
sqlQuery('ALTER TABLE '.getTableName('orders').' ADD UNIQUE(`order_no`)');
$this->upgradeOK();
}
public function checkRightfulness_4()
{
return findModule('stock_in') && $this->checkColumnExists('suppliers', 'import_settings');
}
/** Add import_settings to suppliers */
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('suppliers').' ADD `import_settings` TEXT');
$this->upgradeOK();
}
public function checkRightfulness_5()
{
return findModule('stock_in') && $this->checkColumnExists('products_of_suppliers', 'import_multiplier');
}
/** Add import_multiplier to products_of_suppliers */
public function makeChanges_5()
{
sqlQuery('ALTER TABLE '.getTableName('products_of_suppliers').' ADD `import_multiplier` INT DEFAULT 1');
$this->upgradeOK();
}
public function checkRightfulness_6()
{
return false;
}
public function checkRightfulness_7()
{
return Settings::getDefault()->user_rights_version == 0;
}
/** Update user rights: ORDER_ADD|ORDER_ERASE|ORDER_EDIT **/
public function makeChanges_7()
{
$settings = Settings::getDefault();
sqlQuery('UPDATE '.getTableName('admins')."
SET privilege = TRIM(BOTH '|' FROM REPLACE(CONCAT('|', privilege, '|'), '|ORDER|', '|ORDER_ADD|ORDER_ERASE|ORDER_EDIT|'))");
$this->commitDataMigration(1);
$this->upgradeOK();
}
public function checkRightfulness_8()
{
return findModule('order_edit') && $this->checkColumnIsNull('order_edit', 'id_item', true);
}
/** Make order_edit.id_item null **/
public function makeChanges_8()
{
sqlQuery('ALTER TABLE '.getTableName('order_edit').' CHANGE `id_item` `id_item` INT(10) UNSIGNED NULL DEFAULT NULL');
sqlQuery('ALTER TABLE '.getTableName('order_edit').' DROP FOREIGN KEY `order_edit_ibfk_4`');
sqlQuery('ALTER TABLE '.getTableName('order_edit').' ADD CONSTRAINT `order_edit_ibfk_4` FOREIGN KEY (`id_item`) REFERENCES `order_items`(`id`) ON DELETE SET NULL ON UPDATE SET NULL');
$this->upgradeOK();
}
public function checkRightfulness_10()
{
return findModule('stock_in') && $this->checkColumnExists('stock_in', 'multiplier');
}
/** Add 'multiplier' to 'stock_in' **/
public function makeChanges_10()
{
sqlQuery('ALTER TABLE '.getTableName('stock_in')." ADD `multiplier` DECIMAL(5,2) NOT NULL DEFAULT '1'");
$this->upgradeOK();
}
public function checkRightfulness_11()
{
return findModule('orders_of_suppliers') && $this->checkTableExists('orders_of_suppliers');
}
/** Create table 'orders_of_suppliers' **/
public function makeChanges_11()
{
sqlQuery('CREATE TABLE IF NOT EXISTS '.getTableName('orders_of_suppliers').' (
`id` INT(11) NOT NULL,
`id_supplier` INT(11) NOT NULL,
`id_product` INT(11) NOT NULL,
`id_variation` INT(11) DEFAULT NULL,
`pieces` INT(11) NOT NULL,
`date_create` DATETIME NOT NULL
) ENGINE=InnoDB ');
sqlQuery('ALTER TABLE '.getTableName('orders_of_suppliers').'
ADD PRIMARY KEY (`id`), ADD KEY `id_supplier` (`id_supplier`), ADD KEY `id_variation` (`id_variation`), ADD KEY `id_product` (`id_product`)');
sqlQuery('ALTER TABLE '.getTableName('orders_of_suppliers').'
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT');
sqlQuery('ALTER TABLE '.getTableName('orders_of_suppliers').'
ADD CONSTRAINT `orders_of_suppliers_ibfk_1` FOREIGN KEY (`id_supplier`) REFERENCES `suppliers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `orders_of_suppliers_ibfk_2` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `orders_of_suppliers_ibfk_3` FOREIGN KEY (`id_variation`) REFERENCES `products_variations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_12()
{
return findModule('stock_in') && $this->checkColumnIsNull('stock_in', 'number', true);
}
/** Make stock_in.number and stock_in.code null **/
public function makeChanges_12()
{
sqlQuery('ALTER TABLE '.getTableName('stock_in').' CHANGE `number` `number` INT(11) NULL, CHANGE `code` `code` BIGINT(20) NULL');
$this->upgradeOK();
}
public function checkRightfulness_13()
{
return findModule('eshop_delivery') && $this->checkColumnExists('delivery_type', 'figure');
}
/** Add Figure to delivery_type - show/hide delivery types **/
public function makeChanges_13()
{
sqlQuery('ALTER TABLE '.getTableName('delivery_type')." ADD `figure` ENUM('Y','N','','') NOT NULL DEFAULT 'Y'");
$this->upgradeOK();
}
public function checkRightfulness_14()
{
global $cfg;
return !empty($cfg['Modules']['eshop_delivery']['images']) && $this->checkColumnExists('delivery_type', 'delivery_photo');
}
/** Add photos to delivery_type **/
public function makeChanges_14()
{
sqlQuery('ALTER TABLE '.getTableName('delivery_type').'
ADD `delivery_photo` VARCHAR(50),
ADD `payment_photo` VARCHAR(50)');
$this->upgradeOK();
}
public function checkRightfulness_15()
{
return $this->checkColumnType('users', 'email', 'VARCHAR(100)');
}
/** Make email NULLable and 100 chars long **/
public function makeChanges_15()
{
sqlQuery('ALTER TABLE `users` CHANGE `email` `email` VARCHAR(100) NOT NULL DEFAULT ""');
$this->upgradeOK();
}
public function checkRightfulness_16()
{
return findModule('stock_in') && $this->checkColumnExists('stock_in_items', 'vat');
}
/** Add vat to stock_in_items. Update name and vats **/
public function makeChanges_16()
{
sqlQuery('ALTER TABLE '.getTableName('stock_in_items').' ADD `vat` INT NOT NULL DEFAULT 0');
sqlQuery('UPDATE '.getTableName('stock_in_items').' sii
LEFT JOIN '.getTableName('products').' p ON sii.id_product=p.id
LEFT JOIN '.getTableName('vats').' v ON p.vat=v.id
SET sii.name=p.title, sii.vat=v.vat
WHERE sii.id_product IS NOT NULL');
foreach (sqlQuery('SELECT * FROM '.getTableName('stock_in_items').' WHERE id_variation IS NOT NULL') as $row) {
$this->updateSQL('stock_in_items', ['name' => Variations::fillInProductTitle($row['id_variation'], $row['name'])], ['id' => $row['id']]);
}
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,303 @@
<?php
class Upgrade31 extends UpgradeNew
{
public function checkRightfulness_1()
{
return findModule('templates') && $this->checkTableExists('templates');
}
/** New module 'templates' */
public function makeChanges_1()
{
sqlQuery('
CREATE TABLE IF NOT EXISTS `templates` (
`id` INT(11) NOT NULL,
`id_category` INT(11) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`text` TEXT NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=12 ;
CREATE TABLE IF NOT EXISTS `templates_categories` (
`id` INT(11) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`position` INT(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `templates_products` (
`id_template` INT(11) NOT NULL,
`id_product` INT(11) NOT NULL
) ENGINE=InnoDB;
ALTER TABLE `templates`
ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `name` (`name`), ADD KEY `id_template_category` (`id_category`);
ALTER TABLE `templates_categories`
ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `name` (`name`);
ALTER TABLE `templates_products`
ADD PRIMARY KEY (`id_template`,`id_product`), ADD KEY `id_product` (`id_product`);
ALTER TABLE `templates`
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=12;
ALTER TABLE `templates_categories`
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;
ALTER TABLE `templates`
ADD CONSTRAINT `templates_ibfk_1` FOREIGN KEY (`id_category`) REFERENCES `templates_categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `templates_products`
ADD CONSTRAINT `templates_products_ibfk_2` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `templates_products_ibfk_1` FOREIGN KEY (`id_template`) REFERENCES `templates` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
');
$this->upgradeOK();
}
public function checkRightfulness_6()
{
return $this->checkConstraintExists('users', 'email');
}
/** Users - add unique to email */
public function makeChanges_6()
{
// make email case insensitive
sqlQuery('ALTER TABLE `users` CHANGE `email` `email` VARCHAR(100) NOT NULL DEFAULT ""');
// Merge users with identical email
$duplicates = sqlQuery('SELECT GROUP_CONCAT(id ORDER BY id DESC) AS ids FROM users GROUP BY email HAVING COUNT(*) > 1');
foreach ($duplicates as $duplicate) {
$ids = explode(',', $duplicate['ids']);
$master_id = array_shift($ids);
sqlQuery('UPDATE orders SET id_user = :new_id WHERE id_user IN (:old_ids)',
['old_ids' => $ids, 'new_id' => $master_id], ['old_ids' => \Doctrine\DBAL\Connection::PARAM_INT_ARRAY]);
sqlQuery('DELETE FROM users WHERE id IN (:old_ids)',
['old_ids' => $ids], ['old_ids' => \Doctrine\DBAL\Connection::PARAM_INT_ARRAY]);
}
sqlQuery('ALTER TABLE users ADD UNIQUE(`email`)');
$this->upgradeOK();
}
public function checkRightfulness_7()
{
return findModule('order_payment') && $this->checkForeignKeyExists('order_payments', 'id_order');
}
/** Order Payments - add missing constraint */
public function makeChanges_7()
{
var_dump(sqlFetchAssoc(sqlQuery('SELECT COUNT(*) FROM '.getTableName('order_payments').' op LEFT JOIN '.getTableName('orders').' o ON o.id=op.id_order WHERE o.id IS NULL')));
sqlQuery('DELETE op FROM '.getTableName('order_payments').' op LEFT JOIN '.getTableName('orders').' o ON o.id=op.id_order WHERE o.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('order_payments').' ADD FOREIGN KEY (`id_order`) REFERENCES `orders`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_8()
{
return findModule('price_levels') && $this->checkColumnExists('price_levels', 'combine');
}
/** Price Levels - add 'discount_discount' and 'combine' */
public function makeChanges_8()
{
sqlQuery('ALTER TABLE '.getTableName('price_levels').' ADD `discount_discount` FLOAT NULL DEFAULT NULL AFTER `discount`');
sqlQuery('ALTER TABLE '.getTableName('price_levels').' ADD `combine` ENUM("Y","N") NOT NULL DEFAULT "Y"');
$this->upgradeOK();
}
public function checkRightfulness_10()
{
return findModule('products_favorites') && $this->checkForeignKeyExists('products_favorites', 'id_user');
}
/** Products Favorites - add missing constraint */
public function makeChanges_10()
{
sqlQuery('DELETE pf FROM '.getTableName('products_favorites').' pf
LEFT JOIN '.getTableName('users').' u ON u.id=pf.id_user
LEFT JOIN '.getTableName('products').' p ON p.id=pf.id_product
WHERE u.id IS NULL OR p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('products_favorites').' ENGINE = InnoDB');
sqlQuery('ALTER TABLE '.getTableName('products_favorites').' CHANGE `id_user` `id_user` INT(11) UNSIGNED NOT NULL DEFAULT "0"');
sqlQuery('ALTER TABLE '.getTableName('products_favorites').' ADD FOREIGN KEY (`id_user`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE '.getTableName('products_favorites').' ADD FOREIGN KEY (`id_product`) REFERENCES `products`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_11()
{
return findModule(\Modules::ORDER_PAYMENT) && $this->checkColumnExists('order_payments', 'admin');
}
/** POS payments - add missing columns */
public function makeChanges_11()
{
sqlQuery('ALTER TABLE '.getTableName('order_payments').' ADD `admin` INT NULL');
sqlQuery('ALTER TABLE '.getTableName('order_payments').' ADD `method` INT NOT NULL');
sqlQuery('ALTER TABLE '.getTableName('order_payments').' CHANGE `id_order` `id_order` INT(11) UNSIGNED NULL');
sqlQuery('ALTER TABLE '.getTableName('order_payments').' CHANGE `date` `date` DATETIME NOT NULL;');
sqlQuery('ALTER TABLE '.getTableName('order_payments').' ADD FOREIGN KEY (`admin`) REFERENCES `admins`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
sqlQuery('UPDATE '.getTableName('admins')." SET privilege=REPLACE(privilege, 'ORDER_PAYMENT', 'POS_ADD|POS_EDIT|POS_ERASE')");
$this->upgradeOK();
}
public function checkRightfulness_12()
{
return $this->checkColumnExists('producers', 'position');
}
/** Producers position - for sorting producers*/
public function makeChanges_12()
{
sqlQuery('ALTER TABLE '.getTableName('producers').' ADD `position` INT(11) NULL');
$this->upgradeOK();
}
public function checkRightfulness_13()
{
return findModule('abra') && $this->checkTableExists('abra_settings');
}
/** Abra sync - add abra sync tables */
public function makeChanges_13()
{
sqlQuery('CREATE TABLE '.getTableName('abra_products').' (
`id_abra` VARCHAR(30) NOT NULL,
`id_product` INT(11) NOT NULL
) ENGINE=InnoDB');
sqlQuery('CREATE TABLE `abra_sections` (
`id_abra` VARCHAR(30) NOT NULL,
`id_section` INT(11) NOT NULL
) ENGINE=InnoDB');
sqlQuery('CREATE TABLE `abra_settings` (
`name` VARCHAR(20) NOT NULL,
`value` VARCHAR(100) NOT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE `abra_products`
ADD KEY `id_abra` (`id_abra`), ADD KEY `id_product` (`id_product`)');
sqlQuery('ALTER TABLE `abra_sections`
ADD KEY `id_abra` (`id_abra`), ADD KEY `id_section` (`id_section`)');
sqlQuery('ALTER TABLE `abra_settings`
ADD KEY `name` (`name`)');
sqlQuery('ALTER TABLE `abra_products`
ADD CONSTRAINT `abra_products_ibfk_1` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `abra_sections`
ADD CONSTRAINT `abra_sections_ibfk_1` FOREIGN KEY (`id_section`) REFERENCES `sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_14()
{
return findModule('abra') && $this->checkTableExists('abra_orders');
}
/** Abra sync - add abra order sync tables */
public function makeChanges_14()
{
sqlQuery('CREATE TABLE '.getTableName('abra_orders').' (
`id_abra` VARCHAR(30) NOT NULL,
`id_order` INT(10) UNSIGNED NOT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE `abra_orders`
ADD KEY `id_abra` (`id_abra`), ADD KEY `id_order` (`id_order`)');
sqlQuery('ALTER TABLE `abra_orders`
ADD CONSTRAINT `abra_orders_ibfk_1` FOREIGN KEY (`id_order`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
}
public function checkRightfulness_15()
{
return !$this->checkFulltextConstraintExists('articles', 'lead_in');
}
/** Articles - innodb */
public function makeChanges_15()
{
sqlQuery('ALTER TABLE '.getTableName('articles').' DROP KEY `lead_in`');
sqlQuery('ALTER TABLE '.getTableName('articles').' ENGINE = InnoDB');
$this->upgradeOK();
}
public function checkRightfulness_16()
{
return $this->checkForeignKeyExists('photos_articles_relation', 'id_art');
}
/** Articles - add FK */
public function makeChanges_16()
{
if ($this->verbose) {
var_dump(sqlFetchAll(sqlQuery('SELECT * FROM photos_articles_relation par LEFT JOIN photos ph ON ph.id=par.id_photo WHERE ph.id IS NULL')));
var_dump(sqlFetchAll(sqlQuery('SELECT * FROM photos_articles_relation par LEFT JOIN articles a ON a.id=par.id_art WHERE a.id IS NULL')));
}
sqlQuery('DELETE par FROM photos_articles_relation par LEFT JOIN photos ph ON ph.id=par.id_photo WHERE ph.id IS NULL');
sqlQuery('DELETE par FROM photos_articles_relation par LEFT JOIN articles a ON a.id=par.id_art WHERE a.id IS NULL');
if ($this->checkForeignKeyExists('photos_articles_relation', 'id_photo')) {
sqlQuery('ALTER TABLE `photos_articles_relation`
ADD CONSTRAINT `photos_articles_relation_ibfk_1` FOREIGN KEY (`id_photo`) REFERENCES `photos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
}
sqlQuery("ALTER TABLE `photos_articles_relation` CHANGE `id_art` `id_art` INT(11) NOT NULL DEFAULT '0'");
sqlQuery('ALTER TABLE `photos_articles_relation`
ADD CONSTRAINT `photos_articles_relation_ibfk_2` FOREIGN KEY (`id_art`) REFERENCES `articles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_abraDelayedUpdates()
{
return findModule('abra') && $this->checkTableExists('abra_delayed_update');
}
/** Create abra_delayed_update table */
public function upgrade_abraDelayedUpdates()
{
sqlQuery('CREATE TABLE IF NOT EXISTS abra_delayed_update (
related_id INT NOT NULL,
type VARCHAR(25) NOT NULL,
CONSTRAINT delayed_update UNIQUE (related_id, type)
)');
$this->upgradeOK();
}
public function check_abraDelayedUpdatesStringId()
{
return findModule('abra') && $this->checkColumnType('abra_delayed_update', 'related_id', 'VARCHAR(50)');
}
/** Change abra_delayed_update.related_id to varchar */
public function upgrade_abraDelayedUpdatesStringId()
{
sqlQuery('ALTER TABLE abra_delayed_update MODIFY related_id VARCHAR(50) NOT NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,461 @@
<?php
class Upgrade32 extends UpgradeNew
{
public function checkRightfulness_1()
{
return findModule('eshop_delivery') && $this->checkTableExists('delivery_type_delivery');
}
/** Split delivery_types to delivery and payment */
public function makeChanges_1()
{
sqlQuery("
CREATE TABLE `delivery_type_delivery` (
`id` INT(11) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`price` FLOAT NOT NULL DEFAULT '0',
`photo` VARCHAR(50) DEFAULT NULL
) ENGINE=InnoDB;
-- --------------------------------------------------------
--
-- Table structure for table `delivery_type_payment`
--
CREATE TABLE `delivery_type_payment` (
`id` INT(11) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`price` FLOAT NOT NULL DEFAULT '0',
`class` VARCHAR(20) DEFAULT NULL,
`photo` VARCHAR(50) DEFAULT NULL
) ENGINE=InnoDB;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `delivery_type_delivery`
--
ALTER TABLE `delivery_type_delivery`
ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `name` (`name`);
--
-- Indexes for table `delivery_type_payment`
--
ALTER TABLE `delivery_type_payment`
ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `name` (`name`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `delivery_type_delivery`
--
ALTER TABLE `delivery_type_delivery`
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `delivery_type_payment`
--
ALTER TABLE `delivery_type_payment`
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT;SET FOREIGN_KEY_CHECKS=1;
");
$this->upgradeOK();
}
public function checkRightfulness_2()
{
return findModule('eshop_delivery') && $this->checkColumnExists('delivery_type', 'id_delivery');
}
/** Create relations */
public function makeChanges_2()
{
sqlQuery('ALTER TABLE `delivery_type` ADD `id_delivery` INT NULL AFTER `id`, ADD `id_payment` INT NULL AFTER `id_delivery`');
sqlQuery('ALTER TABLE `delivery_type` ADD INDEX(`id_delivery`)');
sqlQuery('ALTER TABLE `delivery_type` ADD INDEX(`id_payment`)');
sqlQuery('ALTER TABLE `delivery_type` ADD FOREIGN KEY (`id_delivery`) REFERENCES `delivery_type_delivery`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `delivery_type` ADD FOREIGN KEY (`id_payment`) REFERENCES `delivery_type_payment`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_3()
{
return findModule('eshop_delivery') && !$this->checkColumnExists('delivery_type', 'delivery');
}
/** Migrate existing deliveries */
public function makeChanges_3()
{
$image = 'NULL';
if (findModule('eshop_delivery', 'images')) {
$image = 'delivery_photo';
}
sqlQuery('DELETE FROM `delivery_type_delivery`');
sqlQuery("INSERT INTO `delivery_type_delivery`(`id`, `name`, `price`, `photo`)
SELECT NULL, delivery, 0, {$image} FROM `delivery_type` WHERE delivery != '' GROUP BY delivery");
if (findModule('eshop_delivery', 'images')) {
$image = 'payment_photo';
}
$class = 'NULL';
if (findModule('payments')) {
$class = 'payment_class';
}
sqlQuery('DELETE FROM `delivery_type_payment`');
sqlQuery("INSERT INTO `delivery_type_payment`(`id`, `name`, `price`, `class`, `photo`)
SELECT NULL, payment, 0, {$class}, {$image} FROM `delivery_type` WHERE payment != '' GROUP BY payment");
sqlQuery('UPDATE `delivery_type` dt SET `id_delivery`=(SELECT id FROM delivery_type_delivery dtd WHERE dtd.name=dt.delivery)');
sqlQuery('UPDATE `delivery_type` dt SET `id_payment`=(SELECT id FROM delivery_type_payment dtp WHERE dtp.name=dt.payment)');
sqlQuery('ALTER TABLE `delivery_type` CHANGE `price` `price` FLOAT NULL DEFAULT NULL');
sqlQuery('ALTER TABLE `delivery_type` CHANGE `price_dont_countin_from` `price_dont_countin_from` FLOAT NULL DEFAULT NULL');
// Update price_dont_countin_from - set to NULL where was 0
sqlQuery('UPDATE `delivery_type` SET `price_dont_countin_from`=NULL WHERE `price_dont_countin_from` = 0');
if (findModule('payments')) {
sqlQuery('ALTER TABLE `delivery_type` DROP `payment_class`');
}
sqlQuery('ALTER TABLE `delivery_type` DROP `payment`, DROP `delivery`');
$this->upgradeOK();
}
public function checkRightfulness_4()
{
return $this->checkColumnExists('photos_products_relation', 'position');
}
/** Add position column for photo ordering */
public function makeChanges_4()
{
sqlQuery('ALTER TABLE '.getTableName('photos_products_relation').' ADD `position` INT(11) NULL ');
sqlQuery('UPDATE '.getTableName('photos_products_relation')." SET `position`='1' WHERE `show_in_lead`='N' ");
sqlQuery('UPDATE '.getTableName('photos_products_relation')." SET `position`='0' WHERE `show_in_lead`='Y' ");
$this->upgradeOK();
}
public function checkRightfulness_5()
{
return findModule('price_levels') && $this->checkForeignKeyExists('price_levels_products', 'id_product');
}
/** Price Levels Products - add missing constraint */
public function makeChanges_5()
{
sqlQuery('ALTER TABLE '.getTableName('price_levels_products').' CHANGE `id_product` `id_product` INT(11) NOT NULL');
sqlQuery('DELETE plp FROM '.getTableName('price_levels_products').' plp
LEFT JOIN '.getTableName('price_levels').' pl ON pl.id=plp.id_price_level
LEFT JOIN '.getTableName('products').' p ON p.id=plp.id_product
WHERE pl.id IS NULL OR p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('price_levels_products').' ADD FOREIGN KEY (`id_price_level`) REFERENCES `price_levels`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE '.getTableName('price_levels_products').' ADD FOREIGN KEY (`id_product`) REFERENCES `products`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_6()
{
return findModule('price_levels') && $this->checkForeignKeyExists('price_levels_sections', 'id_section');
}
/** Price Levels Sections - add missing constraint */
public function makeChanges_6()
{
sqlQuery('ALTER TABLE '.getTableName('price_levels_sections').' CHANGE `id_section` `id_section` INT(11) NOT NULL');
sqlQuery('DELETE plp FROM '.getTableName('price_levels_sections').' plp
LEFT JOIN '.getTableName('price_levels').' pl ON pl.id=plp.id_price_level
LEFT JOIN '.getTableName('sections').' p ON p.id=plp.id_section
WHERE pl.id IS NULL OR p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('price_levels_sections').' ADD FOREIGN KEY (`id_price_level`) REFERENCES `price_levels`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE '.getTableName('price_levels_sections').' ADD FOREIGN KEY (`id_section`) REFERENCES `sections`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_7()
{
return findModule('price_levels') && $this->checkForeignKeyExists('price_levels_producers', 'id_producer');
}
/** Price Levels Producers - add missing constraint */
public function makeChanges_7()
{
sqlQuery('ALTER TABLE '.getTableName('price_levels_producers').' CHANGE `id_producer` `id_producer` INT(10) UNSIGNED NOT NULL');
sqlQuery('DELETE plp FROM '.getTableName('price_levels_producers').' plp
LEFT JOIN '.getTableName('price_levels').' pl ON pl.id=plp.id_price_level
LEFT JOIN '.getTableName('producers').' p ON p.id=plp.id_producer
WHERE pl.id IS NULL OR p.id IS NULL');
sqlQuery('ALTER TABLE '.getTableName('price_levels_producers').' ADD FOREIGN KEY (`id_price_level`) REFERENCES `price_levels`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE '.getTableName('price_levels_producers').' ADD FOREIGN KEY (`id_producer`) REFERENCES `producers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_8()
{
return findModule('price_levels') && $this->checkForeignKeyExists('price_levels_producers', 'id_producer');
}
/** Price Levels Producers - add missing constraint */
public function makeChanges_8()
{
sqlQuery('ALTER TABLE '.getTableName('sections').' CHANGE `lead_figure` `lead_figure` ENUM("Y","N") NOT NULL DEFAULT "N"');
sqlQuery('ALTER TABLE '.getTableName('sections').' CHANGE `behaviour` `behaviour` ENUM("1","2") NOT NULL DEFAULT "2"');
$this->upgradeOK();
}
public function checkRightfulness_9()
{
return findModule('deliveries') && $this->checkColumnExists('delivery_type_delivery', 'class');
}
/** Delivery Type Delivery - class */
public function makeChanges_9()
{
sqlQuery('ALTER TABLE '.getTableName('delivery_type_delivery').' ADD `class` VARCHAR(50) NULL DEFAULT NULL');
$this->upgradeOK();
}
//
// function checkRightfulness_10()
// {
// return findModule('eshop_delivery') && $this->checkColumnExists('delivery_type_delivery', 'in_person');
// }
//
// /** Delivery Type Delivery - in_person */
// function makeChanges_10()
// {
// sqlQuery("ALTER TABLE ".getTableName('delivery_type_delivery')." ADD `in_person` ENUM('Y','N') DEFAULT 'N'");
//
// $this->upgradeOK();
// }
public function checkRightfulness_11()
{
return findModule('eshop_delivery') && $this->checkColumnExists('delivery_type_delivery', 'time_days');
}
/** Delivery Type Delivery - delivery days and delivery hour */
public function makeChanges_11()
{
sqlQuery('ALTER TABLE '.getTableName('delivery_type_delivery').' ADD `time_days` INT NULL DEFAULT NULL , ADD `time_hours` TIME NULL DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_12()
{
return $this->checkEnumExists('products', 'figure', 'O');
}
/** Old products - product.figure ENUM add 'O' */
public function makeChanges_12()
{
$this->checkEnumExists('products', 'figure', 'O', $figures);
$figures = str_replace(')', ",'O')", $figures);
sqlQuery('ALTER TABLE '.getTableName('products')." CHANGE `figure` `figure` {$figures} DEFAULT 'Y'");
$this->upgradeOK();
}
public function checkRightfulness_13()
{
return $this->checkColumnExists('producers', 'meta_title');
}
/** Producers - add SEO columns */
public function makeChanges_13()
{
$SQL = sqlQuery('ALTER TABLE '.getTableName('producers').' ADD
(`meta_title` VARCHAR(70) NULL DEFAULT NULL,
`meta_description` VARCHAR(250) NULL DEFAULT NULL,
`meta_keywords` VARCHAR(100) NULL DEFAULT NULL)');
$this->upgradeOK();
}
public function checkRightfulness_14()
{
return findModule('sliders') && $this->checkColumnExists('sliders_images', 'date_from');
}
/** Sliders images - add dates columns */
public function makeChanges_14()
{
sqlQuery('ALTER TABLE '.getTableName('sliders_images').' ADD `date_from` DATETIME NULL');
sqlQuery('ALTER TABLE '.getTableName('sliders_images').' ADD `date_to` DATETIME NULL');
$this->upgradeOK();
}
public function checkRightfulness_15()
{
return findModule('sliders') && $this->checkColumnExists('sliders', 'size');
}
/** Sliders - add size */
public function makeChanges_15()
{
sqlQuery('ALTER TABLE '.getTableName('sliders').' ADD `size` VARCHAR(20) NULL DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_16()
{
return $this->checkColumnExists('parameters', 'position');
}
/** Add position column for parameters */
public function makeChanges_16()
{
sqlQuery('ALTER TABLE '.getTableName('parameters').' ADD `position` INT(11) NULL ');
$this->upgradeOK();
}
public function checkRightfulness_17()
{
return $this->checkColumnExists('producers', 'orderby');
}
/** Add ordering columns for producers */
public function makeChanges_17()
{
sqlQuery('ALTER TABLE '.getTableName('producers')." ADD `orderby` ENUM('date','title','price','store') NOT NULL DEFAULT 'title' ");
sqlQuery('ALTER TABLE '.getTableName('producers')." ADD `orderdir` ENUM('ASC','DESC') NOT NULL DEFAULT 'ASC' ");
$this->upgradeOK();
}
public function checkRightfulness_18()
{
return findModule('eshop_users') && $this->checkTableExists('users_groups');
}
/** Create Users Groups and relations table*/
public function makeChanges_18()
{
sqlQuery('CREATE TABLE IF NOT EXISTS `users_groups` (
`id` INT(11) NOT NULL,
`name` VARCHAR(50) NOT NULL,
`descr` TEXT
) ENGINE=InnoDB;
ALTER TABLE `users_groups` ADD PRIMARY KEY (`id`);
ALTER TABLE `users_groups`
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
ALTER TABLE `users_groups` ADD UNIQUE(`name`);
CREATE TABLE IF NOT EXISTS `users_groups_relations` (
`id_group` INT(11) NOT NULL,
`id_user` INT(11) UNSIGNED NOT NULL
) ENGINE=InnoDB;
ALTER TABLE `users_groups_relations` ADD PRIMARY KEY (`id_group`,`id_user`), ADD KEY `users_groups_relations_ibfk_2` (`id_user`);
ALTER TABLE `users_groups_relations`
ADD CONSTRAINT `users_groups_relations_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `users_groups_relations_ibfk_1` FOREIGN KEY (`id_group`) REFERENCES `users_groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `users_groups` ADD UNIQUE(`name`);
');
$this->upgradeOK();
}
public function checkRightfulness_19()
{
return $this->checkColumnExists('products_in_sections', 'position');
}
public function checkRightfulness_20()
{
return !$this->checkColumnExists('settings', 'key_name') && Settings::getDefault()->user_rights_version == 1;
}
/** Move analytics from config to settings */
public function makeChanges_20()
{
global $dbcfg, $cfg;
$settings = Settings::createFromDB();
if (empty($dbcfg['analytics']['google_analytics']['ID']) && !empty($cfg['Modules']['google_analytics']['ID'])) {
$settings->analytics['google_analytics']['ID'] = $cfg['Modules']['google_analytics']['ID'];
}
if (empty($dbcfg['analytics']['google_conversion']['ID']) && !empty($cfg['Modules']['google_conversion']['ID'])) {
$settings->analytics['google_conversion']['ID'] = $cfg['Modules']['google_conversion']['ID'];
}
if (empty($dbcfg['analytics']['google_conversion']['label']) && !empty($cfg['Modules']['google_conversion']['label'])) {
$settings->analytics['google_conversion']['label'] = $cfg['Modules']['google_conversion']['label'];
}
if (empty($dbcfg['analytics']['heureka_overeno']['ID']) && !empty($cfg['Heureka']['id'])) {
$settings->analytics['heureka_overeno']['ID'] = $cfg['Heureka']['id'];
}
if (empty($dbcfg['analytics']['heureka_overeno']['ID']) && !empty($cfg['Modules']['heureka_overeno']['id'])) {
$settings->analytics['heureka_overeno']['ID'] = $cfg['Modules']['heureka_overeno']['id'];
}
if (empty($dbcfg['analytics']['heureka_conversion']['ID']) && !empty($cfg['Modules']['heureka_conversion']['ID'])) {
$settings->analytics['heureka_conversion']['ID'] = $cfg['Modules']['heureka_conversion']['ID'];
}
if (empty($dbcfg['analytics']['zbozi_cz_feedback']['chsum']) && !empty($cfg['Modules']['zbozi_cz_feedback']['chsum'])) {
$settings->analytics['zbozi_cz_feedback']['chsum'] = $cfg['Modules']['zbozi_cz_feedback']['chsum'];
}
if (empty($dbcfg['analytics']['sklik_conversion']['ID']) && !empty($cfg['Modules']['sklik_conversion']['ID'])) {
$settings->analytics['sklik_conversion']['ID'] = $cfg['Modules']['sklik_conversion']['ID'];
}
if (empty($dbcfg['analytics']['seznam_rtg']['ID']) && !empty($cfg['Modules']['seznam_rtg']['ID'])) {
$settings->analytics['seznam_rtg']['ID'] = $cfg['Modules']['seznam_rtg']['ID'];
}
$this->commitDataMigration(2);
$this->upgradeOK();
}
public function checkRightfulness_22()
{
return !$this->checkColumnExists('settings', 'settings') && $this->checkColumnCollation('settings', 'settings', 'utf8mb4_bin');
}
/** Change settings to UTF-8 */
public function makeChanges_22()
{
sqlQuery('ALTER TABLE `settings` CHANGE `settings` `settings` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL;');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,459 @@
<?php
class Upgrade33 extends UpgradeNew
{
public function checkRightfulness_1()
{
return $this->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}' => [</br>'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]}],</br>], </br>";
} else {
$addToTypes .= "[{$values}],</br>], </br>";
}
$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,
], </br>";
$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}],
], </br>";
$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}],
], </br>";
$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}],
], </br>";
$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('<h2>Chybi v configu:</h2>'.$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('<h2>Chybi v configu: $cfg[\'Modules\'][\'products_related\'] = true;</h2>');
}
if (!$this->checkTableIsEmpty('attachments') && !findModule('attachments')) {
exit('<h2>Chybi v configu: $cfg[\'Modules\'][\'attachments\'] = true;</h2>');
}
if (!$this->checkTableIsEmpty('links') && !findModule('links')) {
exit('<h2>Chybi v configu: $cfg[\'Modules\'][\'links\'] = true;</h2>');
}
if (!$this->checkTableIsEmpty('products_collections') && !findModule('products_collections')) {
exit('<h2>Chybi v configu: $cfg[\'Modules\'][\'products_collections\'] = true;</h2>');
}
if (!$this->checkColumnIsEmpty('products', 'price_common') && findModule('products', 'price_common') === null) {
exit('<h2>Chybi v configu: $cfg[\'Modules\'][\'products\'] = [\'price_common\' => true];</h2>');
}
}
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();
}
}

View File

@@ -0,0 +1,309 @@
<?php
class Upgrade34 extends UpgradeNew
{
public function checkRightfulness_1()
{
return findModule('abra') && $this->checkTableExists('abra_users');
}
/** Abra sync - add abra deliveries and payments sync tables */
public function makeChanges_1()
{
sqlQuery('CREATE TABLE abra_users (
`id_abra` VARCHAR(30) NOT NULL,
`id_user` INT UNSIGNED NOT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE `abra_users`
ADD KEY `id_abra` (`id_abra`)');
sqlQuery('ALTER TABLE `abra_users`
ADD CONSTRAINT `abra_users_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_2()
{
return findModule('watchdog') && $this->checkTableExists('products_watchdog');
}
/** Watchdog */
public function makeChanges_2()
{
sqlQuery('CREATE TABLE products_watchdog (
`id_user` INT UNSIGNED NOT NULL,
`id_product` INT NOT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE `products_watchdog`
ADD CONSTRAINT `watchdog_ibfk_2` FOREIGN KEY (`id_product`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE `products_watchdog`
ADD CONSTRAINT `watchdog_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_3()
{
return findModule('eshop_users') && $this->checkColumnExists('users', 'figure');
}
/** Disabled user account */
public function makeChanges_3()
{
sqlQuery('ALTER TABLE users
ADD COLUMN `figure` ENUM(\'Y\',\'N\') DEFAULT \'Y\' AFTER user_key');
$this->upgradeOK();
}
public function checkRightfulness_4()
{
return findModule('currencies') && $this->checkColumnExists('users', 'currency');
}
/** Add 'currencies' enum [CZK / EUR] for users */
public function makeChanges_4()
{
sqlQuery('ALTER TABLE users ADD COLUMN `currency` VARCHAR(3) DEFAULT \'CZK\' AFTER country');
$this->upgradeOK();
}
public function checkRightfulness_5()
{
return findModule('currencies') && $this->checkColumnExists('orders', 'currency');
}
/** Add 'currencies' enum [CZK / EUR] for orders */
public function makeChanges_5()
{
sqlQuery('ALTER TABLE orders ADD COLUMN `currency` VARCHAR(3) DEFAULT \'CZK\' AFTER order_no');
$this->upgradeOK();
}
protected $decimal_precision = '15,4';
public function checkRightfulness_6()
{
return $this->checkColumnType('products', 'price', 'DECIMAL('.$this->decimal_precision.')');
}
/** Change type of price, price_common, discount to DECIMAL */
public function makeChanges_6()
{
sqlQuery('ALTER TABLE `products` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `products` CHANGE `price_common` `price_common` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `products` CHANGE `discount` `discount` DECIMAL(12,8) UNSIGNED NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `orders` CHANGE `total_price` `total_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `order_items` CHANGE `total_price` `total_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `order_items` CHANGE `piece_price` `piece_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
if (findModule('eshop_delivery')) {
sqlQuery('ALTER TABLE `delivery_type` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') NULL');
sqlQuery('ALTER TABLE `delivery_type` CHANGE `price_dont_countin_from` `price_dont_countin_from` DECIMAL('.$this->decimal_precision.') NULL');
sqlQuery('ALTER TABLE `delivery_type_delivery` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `delivery_type_payment` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
}
$this->upgradeOK();
}
public function checkRightfulness_7()
{
return $this->checkColumnExists('orders', 'currency_rate');
}
/** Add 'currency_rate' to orders */
public function makeChanges_7()
{
sqlQuery('ALTER TABLE orders ADD COLUMN `currency_rate` DECIMAL(15,8) DEFAULT \'1\' AFTER order_no');
$this->upgradeOK();
}
public function checkRightfulness_8()
{
return findModule('price_levels') && $this->checkForeignKeyExists('users_dealer_price_level', 'id_user');
}
/** Users Price Levels - add missing constraints */
public function makeChanges_8()
{
sqlQuery('DELETE udpl FROM users_dealer_price_level udpl
LEFT JOIN price_levels pl ON pl.id=udpl.id_price_level
LEFT JOIN users u ON u.id=udpl.id_user
WHERE pl.id IS NULL OR u.id IS NULL');
sqlQuery('ALTER TABLE users_dealer_price_level ADD FOREIGN KEY (`id_price_level`) REFERENCES `price_levels`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
sqlQuery('ALTER TABLE users_dealer_price_level ADD FOREIGN KEY (`id_user`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_UsersDealerPricelevelUnique()
{
return findModule('price_levels') && $this->checkConstraintExists('users_dealer_price_level', 'id_user');
}
/** Add UNIQUE on users_dealer_price_level (id_user) */
public function upgrade_UsersDealerPricelevelUnique()
{
sqlQuery('ALTER TABLE users_dealer_price_level ADD UNIQUE (id_user)');
$this->upgradeOK();
}
public function checkRightfulness_9()
{
return findModule('eshop_users') && $this->checkColumnExists('users', 'date_logged');
}
/** Users.date_logged - add date of last login */
public function makeChanges_9()
{
sqlQuery('ALTER TABLE users ADD COLUMN date_logged DATETIME NULL DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_10()
{
return findModule('eshop_users') && $this->checkColumnCollation('users', 'name', 'cp1250_general_ci') && $this->checkColumnCollation('users', 'name', 'utf8mb4_general_ci');
}
/** Users - make fields case insensitive */
public function makeChanges_10()
{
sqlQuery('ALTER TABLE `users` CHANGE `name` `name` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `surname` `surname` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `firm` `firm` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `street` `street` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `city` `city` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `zip` `zip` VARCHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `country` `country` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `ico` `ico` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `dic` `dic` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `delivery_name` `delivery_name` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `delivery_surname` `delivery_surname` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `delivery_firm` `delivery_firm` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `delivery_street` `delivery_street` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `delivery_city` `delivery_city` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\',
CHANGE `delivery_country` `delivery_country` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT \'\'');
$this->upgradeOK();
}
public function checkRightfulness_11()
{
return findModule('eshop_users') && !$this->checkColumnExists('users', 'login');
}
/** Users - remove login field and set unactive when login is empty */
public function makeChanges_11()
{
sqlQuery("UPDATE users SET figure='N' WHERE login IS NULL");
sqlQuery('ALTER TABLE users DROP COLUMN login');
$this->upgradeOK();
}
public function checkRightfulness_12()
{
return findModule('eshop_delivery') && findModule('currencies') && $this->checkColumnExists('delivery_type_delivery', 'currencies');
}
/** Delivery - limit to only some currencies */
public function makeChanges_12()
{
sqlQuery('ALTER TABLE `delivery_type_delivery`
ADD `currencies` VARCHAR(200) NULL DEFAULT NULL');
}
public function checkRightfulness_13()
{
return $this->checkColumnType('order_edit', 'total_price', 'DECIMAL('.$this->decimal_precision.')') && findModule('order_edit');
}
/** Change decimal type - order_edit */
public function makeChanges_13()
{
sqlQuery('ALTER TABLE `order_edit` CHANGE `total_price` `total_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `order_edit` CHANGE `piece_price` `piece_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
$this->upgradeOK();
}
public function checkRightfulness_14()
{
return findModule('order_payment') && $this->checkColumnType('order_payments', 'price', 'DECIMAL('.$this->decimal_precision.')');
}
/** Change decimal type - order_payments */
public function makeChanges_14()
{
sqlQuery('ALTER TABLE `order_payments` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') NOT NULL');
$this->upgradeOK();
}
public function checkRightfulness_15()
{
return findModule('products_of_suppliers') && $this->checkColumnType('products_of_suppliers', 'price_buy', 'DECIMAL('.$this->decimal_precision.')');
}
/** Change decimal type - products_of_suppliers */
public function makeChanges_15()
{
sqlQuery('ALTER TABLE `products_of_suppliers` CHANGE `price_buy` `price_buy` DECIMAL('.$this->decimal_precision.') DEFAULT NULL');
sqlQuery('ALTER TABLE `products_of_suppliers` CHANGE `price_sell` `price_sell` DECIMAL('.$this->decimal_precision.') DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_productsOfSuppliersNote()
{
return (findModule(Modules::PRODUCTS_SUPPLIERS) || findModule(Modules::STOCK_IN)) && $this->checkColumnExists('products_of_suppliers', 'note');
}
/** Add column note into table products_of_suppliers */
public function makeChanges_productsOfSuppliersNote()
{
sqlQuery('ALTER TABLE products_of_suppliers ADD COLUMN note MEDIUMTEXT DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_16()
{
return findModule('products_variations') && $this->checkColumnType('products_variations', 'price', 'DECIMAL('.$this->decimal_precision.')');
}
/** Change decimal type - products_variations */
public function makeChanges_16()
{
sqlQuery('ALTER TABLE `products_variations` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') DEFAULT NULL');
$this->upgradeOK();
}
public function checkRightfulness_17()
{
return findModule('stock_in') && $this->checkColumnType('stock_in', 'total_price', 'DECIMAL('.$this->decimal_precision.')');
}
/** Change decimal type - stock_in */
public function makeChanges_17()
{
sqlQuery('ALTER TABLE `stock_in` CHANGE `total_price` `total_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `stock_in` CHANGE `transport_price` `transport_price` DECIMAL('.$this->decimal_precision.') NOT NULL DEFAULT \'0\'');
sqlQuery('ALTER TABLE `stock_in_items` CHANGE `price` `price` DECIMAL('.$this->decimal_precision.') NOT NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,395 @@
<?php
class Upgrade35 extends UpgradeNew
{
public function checkRightfulness_1()
{
return isDevelopment() && findModule('eshop_users') && !defined('TEST_SUITE')
&& returnSQLResult('SELECT id FROM users WHERE email=:email', ['email' => 'wpj@wpj.cz']) == false;
}
/** Development - make sure wpj@wpj.cz user exists */
public function makeChanges_1()
{
sqlQuery(
'INSERT IGNORE INTO users (email, passw, `name`, surname)
VALUES (:email, :passwd, :name, :surname)
ON DUPLICATE KEY UPDATE email=VALUES(email), passw=VALUES(passw), `name`=VALUES(`name`), surname=VALUES(surname)',
[
'email' => 'wpj@wpj.cz',
'passwd' => password_hash('wpj', PASSWORD_DEFAULT),
'name' => 'Wpj',
'surname' => 'Wpj',
]
);
$this->upgradeOK();
}
public function checkRightfulness_2()
{
return findModule('abra') && $this->checkTableExists('abra_producers');
}
/** Abra sync - add abra producers sync tables */
public function makeChanges_2()
{
sqlQuery('CREATE TABLE abra_producers (
`id_abra` VARCHAR(30) NOT NULL,
`id_producer` INT UNSIGNED NOT NULL
) ENGINE=InnoDB');
sqlQuery('ALTER TABLE `abra_producers`
ADD KEY `id_abra` (`id_abra`)');
sqlQuery('ALTER TABLE `abra_producers`
ADD CONSTRAINT `abra_producers_ibfk_1` FOREIGN KEY (`id_producer`) REFERENCES `producers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function checkRightfulness_3()
{
return findModule('products_variations') && $this->checkColumnIsNull('products_variations', 'in_store', false);
}
/** Product Variations - make in_store not null */
public function makeChanges_3()
{
sqlQuery("ALTER TABLE `products_variations` CHANGE `in_store` `in_store` INT(10) NOT NULL DEFAULT '0'");
$this->upgradeOK();
}
public function checkRightfulness_4()
{
return findModule('products_sections') && $this->checkColumnExists('sections', 'name_short');
}
/** Add sections.name_short column */
public function makeChanges_4()
{
sqlQuery('ALTER TABLE `sections` ADD COLUMN `name_short` VARCHAR(50) DEFAULT NULL AFTER name');
$this->upgradeOK();
}
public function checkRightfulness_5()
{
return findModule('order_payment') && $this->checkColumnType('order_payments', 'payment_data', 'TEXT');
}
/** Order_payments - change type INT to TEXT */
public function makeChanges_5()
{
sqlQuery('ALTER TABLE order_payments CHANGE payment_data payment_data TEXT');
$this->upgradeOK();
}
public function checkRightfulness_6()
{
return findModule('products_variations') && $this->checkColumnExists('sections', 'list_variations');
}
/** Add section.list_variations column */
public function makeChanges_6()
{
sqlQuery("ALTER TABLE sections ADD COLUMN list_variations ENUM('Y','N') NOT NULL DEFAULT 'N' AFTER `date`");
$this->upgradeOK();
}
public function check_makeZIPLarger()
{
return findModule('eshop_users') && $this->checkColumnType('users', 'zip', 'VARCHAR(50)');
}
/** Make ZIP fields 50 chars long */
public function upgrade_makeZIPLarger()
{
sqlQuery("ALTER TABLE `users` CHANGE `delivery_zip` `delivery_zip` VARCHAR( 50 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT ''");
sqlQuery("ALTER TABLE `users` CHANGE `zip` `zip` VARCHAR( 50 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT ''");
$this->upgradeOK();
}
public function check_kindOfPhotos()
{
global $cfg;
if (!isset($cfg['Photo']['kind'])) {
return false;
}
return $this->checkColumnType('photos_products_relation', 'show_in_lead', "enum('".join("','", array_keys($cfg['Photo']['kind']))."')");
}
/** Dynamic change enum of photos_products_relation */
public function upgrade_kindOfPhotos()
{
global $cfg;
sqlQuery("ALTER TABLE photos_products_relation CHANGE show_in_lead show_in_lead ENUM('".join("','", array_keys($cfg['Photo']['kind']))."') NOT NULL DEFAULT 'N'");
$this->upgradeOK();
}
public function check_variationFigure()
{
return $this->checkColumnExists('products_variations', 'figure');
}
/** Products Variation - add figure field to hide variations */
public function upgrade_variationFigure()
{
sqlQuery("ALTER TABLE products_variations ADD figure ENUM('Y','N') NOT NULL DEFAULT 'Y'");
sqlQuery('UPDATE products_variations SET figure="Y"');
$this->upgradeOK();
}
public function check_API()
{
return findModule('eshop_users') && findModule('api') && $this->checkColumnExists('users', 'api');
}
/** API - add api fields into users */
public function upgrade_API()
{
sqlQuery("ALTER TABLE users ADD api ENUM('Y','N') NOT NULL DEFAULT 'N'");
sqlQuery('ALTER TABLE users ADD api_password VARCHAR(60) DEFAULT NULL');
$this->upgradeOK();
}
public function check_SectionsFlags()
{
return $this->checkColumnExists('sections', 'flags');
}
/** Add flags column into sections */
public function upgrade_SectionsFlags()
{
sqlQuery('ALTER TABLE sections ADD COLUMN `flags` SET(\'\') NOT NULL');
$this->upgradeOK();
}
// overi, jestli je opravnene provest upgrade
public function check_SectionsFlagsUpdate()
{
global $cfg;
if (isset($cfg['Sections']['Flags'])) {
$type = '';
$this->checkEnumExists('sections', 'flags', 'bžet', $type);
foreach ($cfg['Sections']['Flags'] as $name => $flag) {
if (strstr($type, "'{$name}'") === false) {
return true;
}
}
}
return false;
}
/** Update sections flags */
public function upgrade_SectionsFlagsUpdate()
{
global $cfg;
$type = '';
$this->checkEnumExists('sections', 'flags', 'bžet', $type);
foreach ($cfg['Sections']['Flags'] as $name => $flag) {
if (strstr($type, "'{$name}'") === false) {
$type = str_replace(')', ",'{$name}')", $type);
}
}
sqlQuery("ALTER TABLE sections CHANGE `flags` `flags` {$type} NOT NULL");
$this->upgradeOK();
}
public function check_watchdog_last_in_store()
{
return findModule('watchdog') && $this->checkColumnExists('products_watchdog', 'last_in_store');
}
public function upgrade_watchdog_last_in_store()
{
sqlQuery('ALTER TABLE products_watchdog ADD COLUMN `last_in_store` INT');
$this->upgradeOK();
}
// public function check_ModuleSectionsLead()
// {
// $count = returnSQLResult("SELECT COUNT(*) FROM sections WHERE lead_figure='Y'");
//
// return !findModule('sections_lead') && $count;
// }
//
// /** Check if modul sections_lead is added */
// public function upgrade_ModuleSectionsLead()
// {
// die('<h2>Chybi v configu modul: $cfg[\'Modules\'][\'sections_lead\'] = true;</h2>');
// }
public function check_IncreaseAdminLogin()
{
return $this->checkColumnType('admins', 'login', 'VARCHAR(50)');
}
/** Change `login` from varchar(20) to varchar(50) */
public function upgrade_IncreaseAdminLogin()
{
sqlQuery("ALTER TABLE admins CHANGE COLUMN `login` `login` VARCHAR(50) NOT NULL DEFAULT ''");
$this->upgradeOK();
}
public function check_AddSectionsSeznamFeed()
{
return $this->checkColumnExists('sections', 'feed_seznam');
}
/** Add feed_seznam field to sections */
public function upgrade_AddSectionsSeznamFeed()
{
/*
CREATE TABLE kupshop_shared.feed_seznam (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL,
`category_text` varchar(250) COLLATE utf8mb4_general_ci NOT NULL
)
*/
sqlQuery('ALTER TABLE sections ADD COLUMN `feed_seznam` INT(11) DEFAULT NULL');
$this->upgradeOK();
}
public function check_watchdog_supports_variations()
{
return findmodule('watchdog') && $this->checkColumnExists('products_watchdog', 'id_variation');
}
/** Add `id_variation` column to `products_watchdog` table */
public function upgrade_watchdog_supports_variations()
{
sqlQuery('ALTER TABLE products_watchdog ADD COLUMN id_variation INT DEFAULT NULL AFTER id_product');
sqlQuery('ALTER TABLE products_watchdog ADD CONSTRAINT FOREIGN KEY (id_variation) REFERENCES products_variations(id) ON DELETE CASCADE ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_ProductsInArticles()
{
return findmodule(\Modules::ARTICLES) && $this->checkTableExists('products_in_articles');
}
/** Add products to articles */
public function upgrade_ProductsInArticles()
{
sqlQuery('CREATE TABLE products_in_articles (
`id_product` INT(11),
`id_article` INT(11)
) ENGINE=InnoDB;
ALTER TABLE products_in_articles ADD CONSTRAINT `abra_products_in_articles_ibfk_1` FOREIGN KEY (id_product) REFERENCES products(id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE products_in_articles ADD CONSTRAINT `abra_products_in_articles_ibfk_2` FOREIGN KEY (id_article) REFERENCES articles(id) ON DELETE CASCADE ON UPDATE CASCADE;
');
$this->upgradeOK();
}
public function check_Reviews()
{
return findmodule('reviews') && $this->checkTableExists('reviews');
}
/** Add reviews */
public function upgrade_Reviews()
{
sqlQuery('CREATE TABLE reviews (
`id` INT(11) UNSIGNED NOT NULL,
`id_product` INT(11) NOT NULL,
`id_product_variation` INT(11) NOT NULL,
`date` DATETIME NOT NULL,
`rating` FLOAT(2,1),
`recommends` TINYINT(1),
`pros` TEXT,
`cons` TEXT,
`summary` TEXT,
`name` VARCHAR(30),
PRIMARY KEY (id),
CONSTRAINT `reviews_products_fk` FOREIGN KEY (id_product) REFERENCES products(id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `reviews_products_variations_fk` FOREIGN KEY (id_product_variation) REFERENCES products_variations(id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
CREATE INDEX reviews_date ON reviews (date);
CREATE INDEX reviews_rating ON reviews (rating);
');
$this->upgradeOK();
}
public function check_ReviewsLangs()
{
return findmodule('reviews') && findModule(Modules::TRANSLATIONS) && $this->checkColumnExists('reviews', 'id_language');
}
/** Add languages to table reviews */
public function upgrade_ReviewsLangs()
{
$langContext = \KupShop\KupShopBundle\Util\Compat\ServiceContainer::getService(\KupShop\KupShopBundle\Context\LanguageContext::class);
sqlQuery("ALTER TABLE reviews ADD COLUMN id_language varchar(2) not null DEFAULT '{$langContext->getDefaultId()}'");
$this->upgradeOK();
}
public function check_AddProductsFigureIndex()
{
return $this->checkIndexNameExists('products', 'figure');
}
/** Add index to products.figure and products_variations.figure */
public function upgrade_AddProductsFigureIndex()
{
sqlQuery('ALTER TABLE products ADD INDEX figure (figure)');
sqlQuery('ALTER TABLE products_variations ADD INDEX figure (figure)');
$this->upgradeOK();
}
public function check_AddPhotosFigureIndex()
{
return $this->checkIndexNameExists('photos_articles_relation', 'show_in_lead');
}
/** Add index to photos_????_relation.figure */
public function upgrade_AddPhotosFigureIndex()
{
// sqlQuery('ALTER TABLE photos_products_relation ADD INDEX show_in_lead (show_in_lead)');
sqlQuery('ALTER TABLE photos_articles_relation ADD INDEX show_in_lead (show_in_lead)');
// sqlQuery('ALTER TABLE photos_pages_relation ADD INDEX show_in_lead (show_in_lead)');
$this->upgradeOK();
}
public function check_AddProductPriceIndex()
{
return $this->checkIndexNameExists('products', 'price');
}
/** Add index to product.price and product_variations.price */
public function upgrade_AddProductPriceIndex()
{
sqlQuery('ALTER TABLE products ADD INDEX price (price)');
sqlQuery('ALTER TABLE products_variations ADD INDEX price (price)');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,183 @@
<?php
class Upgrade36 extends UpgradeNew
{
public function check_RemoveInPersonColumn()
{
if (!findModule('eshop_delivery') || $this->checkColumnExists('delivery_type_delivery', 'in_person')) {
return false;
}
$hasInPerson = returnSQLResult("SELECT COUNT(*) FROM delivery_type_delivery WHERE in_person='Y'");
if ($hasInPerson && !findModule('deliveries')) {
exit("<h2>Nekde je aktivovany osobni odber a neni modul 'deliveries'!: \$cfg['Modules']['deliveries'] = true;</h2>");
}
return true;
}
/** remove delivery_type_delivery in_person column */
public function upgrade_RemoveInPersonColumn()
{
if (findModule('deliveries')) {
sqlQuery('UPDATE delivery_type_delivery SET class="OsobniOdber" WHERE in_person="Y" AND class IS NULL');
}
sqlQuery('ALTER TABLE delivery_type_delivery DROP COLUMN in_person');
$this->upgradeOK();
}
public function check_AddDiscountTypeProduct()
{
return findModule('purchase_discounts') && $this->checkEnumExists('discounts', 'condition_type', 'product');
}
/** add condition_type product to enum */
public function upgrade_AddDiscountTypeProduct()
{
sqlQuery("ALTER TABLE discounts MODIFY COLUMN condition_type ENUM('price','pieces','date','coupon','order','product');");
$this->upgradeOK();
}
public function check_MoreSpaceForSliderSize()
{
return findModule('sliders') && $this->checkColumnType('sliders', 'size', 'VARCHAR(100)');
}
/** Make slider.size larger */
public function upgrade_MoreSpaceForSliderSize()
{
sqlQuery('ALTER TABLE sliders CHANGE size size VARCHAR(100)');
$this->upgradeOK();
}
public function check_IncreaseFirmField()
{
return findModule('eshop_users') && $this->checkColumnType('users', 'firm', 'VARCHAR(100)');
}
/** Change users firm from varchar(50) to varchar(100) */
public function upgrade_IncreaseFirmField()
{
sqlQuery("ALTER TABLE users CHANGE COLUMN `firm` `firm` VARCHAR(100) NOT NULL DEFAULT ''");
sqlQuery("ALTER TABLE users CHANGE COLUMN `delivery_firm` `delivery_firm` VARCHAR(100) NOT NULL DEFAULT ''");
$this->upgradeOK();
}
public function check_IncreaseOrdersFirmField()
{
return findModule('orders') && $this->checkColumnType('orders', 'invoice_firm', 'VARCHAR(100)');
}
/** Change users orders firm from varchar(50) to varchar(100) */
public function upgrade_IncreaseOrdersFirmField()
{
sqlQuery("ALTER TABLE orders CHANGE COLUMN `invoice_firm` `invoice_firm` VARCHAR(100) NOT NULL DEFAULT ''");
sqlQuery("ALTER TABLE orders CHANGE COLUMN `delivery_firm` `delivery_firm` VARCHAR(100) NOT NULL DEFAULT ''");
$this->upgradeOK();
}
public function check_MorePrecisionForProductDiscount()
{
return $this->checkColumnType('products', 'discount', 'decimal(12,8) unsigned');
}
/** Make product discount more precise */
public function upgrade_MorePrecisionForProductDiscount()
{
sqlQuery('ALTER TABLE `products` CHANGE `discount` `discount` DECIMAL(12,8) UNSIGNED NOT NULL DEFAULT \'0\'');
$this->upgradeOK();
}
public function check_PriceLvlsProductsUnit()
{
return findModule('price_levels') && $this->checkColumnType('price_levels_products', 'unit', "enum('perc','price','final_price')");
}
/** Add final_price to price_levels_products unit enum */
public function upgrade_PriceLvlsProductsUnit()
{
sqlQuery("ALTER TABLE price_levels_products CHANGE unit unit ENUM('perc','price','final_price') NOT NULL DEFAULT 'perc'");
$this->upgradeOK();
}
public function check_ReviewOrderId()
{
return findModule('reviews') && $this->checkColumnExists('reviews', 'id_order');
}
/** Add order_id to review */
public function upgrade_ReviewOrderId()
{
sqlQuery('ALTER TABLE reviews ADD id_order INT(10) UNSIGNED NULL DEFAULT NULL');
sqlQuery('ALTER TABLE reviews ADD CONSTRAINT `reviews_order_fk` FOREIGN KEY (id_order) REFERENCES orders(id) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_ReviewNullableVariation()
{
return findModule('reviews') && $this->checkColumnIsNull('reviews', 'id_product_variation', true);
}
/** Allow review variation to be null*/
public function upgrade_ReviewNullableVariation()
{
sqlQuery('ALTER TABLE reviews CHANGE id_product_variation id_product_variation INT(11) NULL DEFAULT NULL');
$this->upgradeOK();
}
public function check_AddUserToReviews()
{
return findModule('reviews') && $this->checkColumnExists('reviews', 'id_user');
}
/** Add ref to id_user, figure into reviews*/
public function upgrade_AddUserToReviews()
{
sqlQuery('ALTER TABLE reviews ADD COLUMN id_user INT(11) UNSIGNED DEFAULT NULL');
sqlQuery('ALTER TABLE reviews ADD COLUMN figure TINYINT(1) NOT NULL DEFAULT 1');
sqlQuery('ALTER TABLE `reviews` ADD CONSTRAINT `reviews_user_ibfk1` FOREIGN KEY (`id_user`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_AddProductsWeight()
{
return findModule(\Modules::PRODUCTS, \Modules::SUB_WEIGHT) && $this->checkColumnExists('products', 'weight');
}
/** Add weight to products and variations*/
public function upgrade_AddProductsWeight()
{
sqlQuery('ALTER TABLE products ADD COLUMN weight DECIMAL(15,4) DEFAULT NULL');
sqlQuery('ALTER TABLE products_variations ADD COLUMN weight DECIMAL(15,4) DEFAULT NULL');
$this->upgradeOK();
}
public function check_DeliveryDescription()
{
return findModule('eshop_delivery') && $this->checkColumnExists('delivery_type', 'description');
}
/** Add description to delivery_types/deliveries/payments */
public function upgrade_DeliveryDescription()
{
sqlQuery('ALTER TABLE delivery_type ADD COLUMN description TEXT DEFAULT NULL');
sqlQuery('ALTER TABLE delivery_type_delivery ADD COLUMN description TEXT DEFAULT NULL');
sqlQuery('ALTER TABLE delivery_type_payment ADD COLUMN description TEXT DEFAULT NULL');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,193 @@
<?php
class Upgrade37 extends UpgradeNew
{
public function getDataPath($folder)
{
return $this->getShopDir().'data/'.$folder;
}
private $folders = [
'',
'backup',
'files',
'images',
'photos',
'photos/sliders',
'section',
'producer',
'delivery',
'payment',
'tmp',
];
public function check_DataFolders()
{
foreach ($this->folders as $folder) {
if (!file_exists($this->getDataPath($folder))) {
return true;
}
}
return false;
}
/** Create ./data folders */
public function upgrade_DataFolders()
{
foreach ($this->folders as $folder) {
$path = $this->getDataPath($folder);
if (!file_exists($path)) {
mkdir($path);
chmod($path, 0777);
}
}
$this->upgradeOK();
}
public function check_SectionsPhotos()
{
return $this->checkTableExists('photos_sections_relation');
}
/** Create sections photos*/
public function upgrade_SectionsPhotos()
{
sqlQuery("
CREATE TABLE IF NOT EXISTS `photos_sections_relation` (
`id_photo` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`id_section` INT(11) NOT NULL DEFAULT '0',
`show_in_lead` ENUM('Y','N') NOT NULL DEFAULT 'N',
`active` ENUM('Y','N') NOT NULL DEFAULT 'Y',
`date_added` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`position` INT(11) DEFAULT NULL
) ENGINE=InnoDB COMMENT='fotky k sekci';
ALTER TABLE `photos_sections_relation`
ADD PRIMARY KEY (`id_photo`,`id_section`),
ADD KEY `photos_sections_relation_ibfk_1` (`id_section`),
ADD KEY `show_in_lead` (`show_in_lead`);
ALTER TABLE `photos_sections_relation`
ADD CONSTRAINT `photos_sections_relation_ibfk_1` FOREIGN KEY (`id_photo`) REFERENCES `photos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `photos_sections_relation_ibfk_2` FOREIGN KEY (`id_section`) REFERENCES `sections` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
");
$this->upgradeOK();
}
public function check_ParametersConfigurations()
{
return findModule(\Modules::PRODUCTS_PARAMETERS, \Modules::SUB_CONFIGURATIONS) && $this->checkTableExists('parameters_configurations');
}
/** Create Parameters Configurations table */
public function upgrade_ParametersConfigurations()
{
sqlQuery('
CREATE TABLE `parameters_configurations` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_parameter` INT(10) UNSIGNED NOT NULL,
`id_product` INT(11) NOT NULL,
FOREIGN KEY `id_parameter_fk` (id_parameter) REFERENCES parameters (id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY `id_product_fk` (id_product) REFERENCES products (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
');
$this->upgradeOK();
}
public function check_ParametersConfigurationsPrice()
{
return findModule('products_parameters', 'configurations') && $this->checkColumnExists('parameters_products', 'configuration_price');
}
/** Add configuration price to products parameters */
public function upgrade_ParametersConfigurationsPrice()
{
sqlQuery('
ALTER TABLE `parameters_products` ADD COLUMN `configuration_price` DECIMAL NULL DEFAULT NULL
');
$this->upgradeOK();
}
public function check_SectionAnnotation()
{
return findModule(\Modules::PRODUCTS_SECTIONS, \Modules::SUB_ANNOTATION) && $this->checkColumnExists('sections', 'annotation');
}
/** Add annotation to sections */
public function upgrade_SectionAnnotation()
{
sqlQuery('
ALTER TABLE `sections` ADD COLUMN `annotation` TEXT NULL DEFAULT NULL
');
$this->upgradeOK();
}
public function check_productPriceBuy()
{
return findModule(\Modules::PRODUCTS, \Modules::SUB_PRICE_BUY) && $this->checkColumnExists('products', 'price_buy');
}
/** Add price_buy to products */
public function upgrade_productPriceBuy()
{
sqlQuery('ALTER TABLE `products` ADD COLUMN `price_buy` DECIMAL(15, 4) NULL DEFAULT NULL');
sqlQuery('ALTER TABLE `products_variations` ADD COLUMN `price_buy` DECIMAL(15, 4) NULL DEFAULT NULL');
$this->upgradeOK();
}
public function check_PriceRoundOrder()
{
return is_null(Settings::getDefault()->price_round_order);
}
/** Add order price rounding to settings */
public function upgrade_PriceRoundOrder()
{
$cfg = Settings::getDefault();
$cfg->saveValue('price_round_order', $cfg->price_round);
$this->upgradeOK();
}
public function check_OrderDueDate()
{
return findModule(\Modules::ORDERS) && $this->checkColumnExists('orders', 'date_due');
}
/** Add due date to order*/
public function upgrade_OrderDueDate()
{
sqlQuery('
ALTER TABLE `orders` ADD COLUMN `date_due` DATETIME NULL DEFAULT NULL AFTER date_updated
');
$this->upgradeOK();
}
public function check_POSFakeProduct()
{
$id_product = returnSQLResult('SELECT id FROM products WHERE id=0');
return findModule(\Modules::POS) && $id_product === false;
}
/** Create POS fake product - neprodukt */
public function upgrade_POSFakeProduct()
{
sqlQuery("INSERT INTO products (id, title, code, figure, show_in_feed, short_descr, long_descr, parameters, vat, campaign) VALUES (0, 'NEPRODUKT - POKLADNA - NEMAZAT', '0', 'Y', 'N', 'NEPRODUKT - POKLADNA - NEMAZAT', 'NEPRODUKT - POKLADNA - NEMAZAT', 'NEPRODUKT - POKLADNA - NEMAZAT', 1, '');");
$id = sqlInsertId();
$this->updateSQL('products', ['id' => 0], ['id' => $id]);
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,453 @@
<?php
class Upgrade38 extends UpgradeNew
{
public function check_DatesOnProductsVariations()
{
return $this->checkColumnExists('products_variations', 'updated');
}
/** Create add date to products variations */
public function upgrade_DatesOnProductsVariations()
{
sqlQuery("ALTER TABLE products_variations ADD `updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
ALTER TABLE products_variations ADD `date_added` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
$this->upgradeOK();
}
public function check_utfToDatabase()
{
return $this->checkDatabaseEncoding('utf8mb4');
}
/** Set UTF to database */
public function upgrade_utfToDatabase()
{
sqlQuery("ALTER DATABASE `{$GLOBALS['cfg']['Connection']['database']}` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci");
$this->upgradeOK();
}
public function check_utfToAllTables()
{
return $this->checkColumnCollation('products', 'title', 'utf8mb4_general_ci');
}
/** Set UTF to all tables */
public function upgrade_utfToAllTables()
{
sqlQuery('SET FOREIGN_KEY_CHECKS=0;');
$platform = sqlGetConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
foreach (sqlGetConnection()->getSchemaManager()->listTables() as $table) {
try {
sqlQuery("ALTER TABLE {$table->getName()} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci");
} catch (Exception $e) {
echo $e->getMessage();
}
}
$this->upgradeOK();
}
public function check_AddFeedTokenField()
{
return findModule(\Modules::XML_FEEDS_B2B, \Modules::SUB_SECURE) && $this->checkColumnExists('users', 'feed_token');
}
/** Add feeds token field into users */
public function upgrade_AddFeedTokenField()
{
sqlQuery('ALTER TABLE users ADD `feed_token` varchar(60) DEFAULT NULL;');
sqlQuery('ALTER TABLE users ADD `feed_in_store` INT(1) DEFAULT 1;');
$this->upgradeOK();
}
public function check_OrderItemsDatetime()
{
return $this->checkColumnType('order_items', 'date', 'TIMESTAMP');
}
/** Order items change date to datetime */
public function upgrade_OrderItemsDatetime()
{
sqlQuery('ALTER TABLE order_items MODIFY COLUMN `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;');
$this->upgradeOK();
}
public function check_RemoveDuplicatePhotosRelation()
{
$id_variation = sqlNumRows(sqlQuery("SHOW FIELDS FROM photos_products_relation WHERE Field = 'id_variation'"));
if (findModule(\Modules::PRODUCTS_VARIATIONS_PHOTOS) || $id_variation) {
return sqlNumRows(sqlQuery('SELECT id_photo, id_product, COUNT(*) AS cnt
FROM photos_products_relation
WHERE id_variation IS NULL
GROUP BY id_product, id_photo
HAVING COUNT(*) > 1;')) > 0;
}
return false;
}
/** Remove duplicate photos_products_relation */
public function upgrade_RemoveDuplicatePhotosRelation()
{
$duplicates = sqlQuery('SELECT id_photo, id_product, COUNT(*) as cnt
FROM photos_products_relation
WHERE id_variation IS NULL
GROUP BY id_product, id_photo
HAVING COUNT(*) > 1
ORDER BY position');
foreach ($duplicates as $row) {
sqlQuery('DELETE FROM photos_products_relation
WHERE id_variation IS NULL AND id_photo=:id_photo AND id_product=:id_product
ORDER BY position
LIMIT '.($row['cnt'] - 1), $row);
}
$this->upgradeOK();
}
public function check_OrdersAdmin()
{
return $this->checkColumnExists('orders', 'admin');
}
/** Add admin column to order */
public function upgrade_OrdersAdmin()
{
sqlQuery('ALTER TABLE orders ADD `admin` INT DEFAULT NULL');
sqlQuery('ALTER TABLE orders ADD FOREIGN KEY (`admin`) REFERENCES `admins`(`id`) ON DELETE SET NULL ON UPDATE CASCADE');
$this->upgradeOK();
}
public function check_OrdersPOS()
{
return (findModule(Modules::POS) || findModule(Modules::NEW_POS)) && $this->checkColumnExists('orders', 'pos');
}
/** Add pos column to order */
public function upgrade_OrdersPOS()
{
sqlQuery('ALTER TABLE orders ADD `pos` INT NOT NULL DEFAULT 0');
$this->upgradeOK();
}
public function check_DiscountToOrderItems()
{
return $this->checkColumnExists('order_items', 'discount');
}
/** Order items add discount field*/
public function upgrade_DiscountToOrderItems()
{
sqlQuery('ALTER TABLE order_items ADD COLUMN `discount` DECIMAL(15,4) NOT NULL DEFAULT 0');
$this->upgradeOK();
}
public function check_DiscountToOrderItemsEdit()
{
return findModule(Modules::ORDER_EDIT) && $this->checkColumnExists('order_edit', 'discount');
}
/** order_edit add discount field*/
public function upgrade_DiscountToOrderItemsEdit()
{
sqlQuery('ALTER TABLE order_edit ADD COLUMN `discount` DECIMAL(15,4) NOT NULL DEFAULT 0');
$this->upgradeOK();
}
private $pos_delivery_id;
private $pos_payment_cash;
private $pos_payment_card;
private $pos_payment_transfer;
// public function check_PosDeliveryTypeClass()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $this->pos_delivery_id = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type_delivery')
// ->where('name=:name')
// ->setParameter('name', 'Osobní Odběr')
// ->execute()
// ->fetchColumn();
//
// return !$this->pos_delivery_id;
// }
//
// /** Add class OsobniOdber to delivery type osobni odber */
// public function upgrade_PosDeliveryTypeClass()
// {
// sqlQueryBuilder()
// ->update('delivery_type_delivery')
// ->values([
// 'name' => ':name',
// 'class' => ':class',
// ])->where('name=Osobní odběr')
// ->setParameters([
// 'name' => 'Osobní odběr',
// 'class' => 'OsobniOdber',
// ])
// ->execute();
//
// $this->pos_delivery_id = sqlInsertId();
//
// $this->upgradeOK();
// }
//
// public function check_PosDeliveryTypes()
// {
// if (!findModule(Modules::POS) || $this->pos_delivery_id) {
// return false;
// }
// $this->pos_delivery_id = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type_delivery')
// ->where('class=:class')
// ->setParameter('class', 'OsobniOdber')
// ->execute()
// ->fetchColumn();
//
// return !$this->pos_delivery_id;
// }
//
// /** Create missing delivery required in POS */
// public function upgrade_PosDeliveryTypes()
// {
// sqlQueryBuilder()
// ->insert('delivery_type_delivery')
// ->values([
// 'name' => ':name',
// 'class' => ':class',
// ])
// ->setParameters([
// 'name' => 'Osobní odběr',
// 'class' => 'OsobniOdber',
// ])
// ->execute();
//
// $this->pos_delivery_id = sqlInsertId();
//
// $this->upgradeOK();
// }
//
// public function check_PosPaymentCash()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $this->pos_payment_cash = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type_payment')
// ->where('class=:class')
// ->setParameter('class', 'Hotovost')
// ->execute()
// ->fetchColumn();
//
// return !$this->pos_payment_cash;
// }
//
// /** Create missing payment required in POS - cash*/
// public function upgrade_PosPaymentCash()
// {
// sqlQueryBuilder()
// ->insert('delivery_type_payment')
// ->values([
// 'name' => ':name',
// 'class' => ':class',
// ])
// ->setParameters([
// 'name' => 'Hotově',
// 'class' => 'Hotovost',
// ])
// ->execute();
//
// $this->pos_payment_cash = sqlInsertId();
//
// $this->upgradeOK();
// }
//
// public function check_PosPaymentCard()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $this->pos_payment_card = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type_payment')
// ->where('class=:class')
// ->setParameter('class', 'PlatebniKarta')
// ->execute()
// ->fetchColumn();
//
// return !$this->pos_payment_card;
// }
//
// /** Create missing payment required in POS - card*/
// public function upgrade_PosPaymentCard()
// {
// sqlQueryBuilder()
// ->insert('delivery_type_payment')
// ->values([
// 'name' => ':name',
// 'class' => ':class',
// ])
// ->setParameters([
// 'name' => 'Platební kartou',
// 'class' => 'PlatebniKarta',
// ])
// ->execute();
//
// $this->pos_payment_card = sqlInsertId();
//
// $this->upgradeOK();
// }
//
// public function check_PosPaymentTranfer()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $this->pos_payment_transfer = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type_payment')
// ->where('class=:class')
// ->setParameter('class', 'Prevodem')
// ->execute()
// ->fetchColumn();
//
// return !$this->pos_payment_transfer;
// }
//
// /** Create missing payment required in POS - transfer*/
// public function upgrade_PosPaymentTranfer()
// {
// sqlQueryBuilder()
// ->insert('delivery_type_payment')
// ->values([
// 'name' => ':name',
// 'class' => ':class',
// ])
// ->setParameters([
// 'name' => 'Převodem',
// 'class' => 'Prevodem',
// ])
// ->execute();
//
// $this->pos_payment_transfer = sqlInsertId();
//
// $this->upgradeOK();
// }
//
// public function check_PosDeliveryTypesCash()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $cash = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type')
// ->where('id_delivery=:id_delivery AND id_payment=:id_payment')
// ->setParameters(['id_payment' => $this->pos_payment_cash, 'id_delivery' => $this->pos_delivery_id])
// ->execute()
// ->fetchColumn();
//
// return !$cash;
// }
//
// /** Create missing delivery types required in POS - CASH */
// public function upgrade_PosDeliveryTypesCash()
// {
// $pos = returnSQLResult('SELECT MAX(list_order) FROM delivery_type');
// sqlQueryBuilder()
// ->insert('delivery_type')
// ->values([
// 'id_delivery' => $this->pos_delivery_id,
// 'id_payment' => $this->pos_payment_cash,
// 'figure' => '"N"',
// 'list_order' => $pos,
// ])
// ->execute();
//
// $this->upgradeOK();
// }
//
// public function check_PosDeliveryTypesCard()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $card = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type')
// ->where('id_delivery=:id_delivery AND id_payment=:id_payment')
// ->setParameters(['id_payment' => $this->pos_payment_card, 'id_delivery' => $this->pos_delivery_id])
// ->execute()
// ->fetchColumn();
//
// return !$card;
// }
//
// /** Create missing delivery types required in POS - card */
// public function upgrade_PosDeliveryTypesCard()
// {
// $pos = returnSQLResult('SELECT MAX(list_order) FROM delivery_type');
// sqlQueryBuilder()
// ->insert('delivery_type')
// ->values([
// 'id_delivery' => $this->pos_delivery_id,
// 'id_payment' => $this->pos_payment_card,
// 'figure' => '"N"',
// 'list_order' => $pos,
// ])
// ->execute();
//
// $this->upgradeOK();
// }
//
// public function check_PosDeliveryTypesTransfer()
// {
// if (!findModule(Modules::POS)) {
// return false;
// }
// $card = sqlQueryBuilder()
// ->select('id')
// ->from('delivery_type')
// ->where('id_delivery=:id_delivery AND id_payment=:id_payment')
// ->setParameters(['id_payment' => $this->pos_payment_transfer, 'id_delivery' => $this->pos_delivery_id])
// ->execute()
// ->fetchColumn();
//
// return !$card;
// }
//
// /** Create missing delivery types required in POS - transfer */
// public function upgrade_PosDeliveryTypesTransfer()
// {
// $pos = returnSQLResult('SELECT MAX(list_order) FROM delivery_type');
// sqlQueryBuilder()
// ->insert('delivery_type')
// ->values([
// 'id_delivery' => $this->pos_delivery_id,
// 'id_payment' => $this->pos_payment_transfer,
// 'figure' => '"N"',
// 'list_order' => $pos,
// ])
// ->execute();
//
// $this->upgradeOK();
// }
}

View File

@@ -0,0 +1,57 @@
<?php
class Upgrade39 extends UpgradeNew
{
public function checkRightfulness_blocksForSections()
{
return $this->checkColumnExists('sections', 'id_block');
}
/** Add id_block to sections and move content from sections.descr to blocks */
public function makeChanges_blocksForSections()
{
sqlQuery('
ALTER TABLE sections
ADD COLUMN `id_block` int(11) UNSIGNED DEFAULT NULL AFTER id,
ADD CONSTRAINT `fk_sections_blocks` FOREIGN KEY (id_block) REFERENCES blocks(id)
ON DELETE SET NULL ON UPDATE CASCADE;
');
$sections = sqlQueryBuilder()->select('*')->from('sections')->execute();
foreach ($sections as $section) {
// crate root block and assign it to sections.id_block
$this->insertSQL('blocks', []);
$rootBlockID = sqlInsertId();
$this->updateSQL('sections', ['id_block' => $rootBlockID], ['id' => $section['id']]);
$this->insertSQL('blocks', [
'id_root' => $rootBlockID,
'id_parent' => $rootBlockID,
'position' => 1,
'name' => $section['name'],
'content' => $section['descr'],
]);
}
sqlQuery('ALTER TABLE sections
DROP COLUMN `descr`;');
$this->upgradeOK();
}
public function checkRightfulness_largerAndUniqueParameterName()
{
return $this->checkColumnType('parameters', 'name', 'varchar(100)');
}
/** Make parameters.name larger and unique */
public function makeChanges_largerAndUniqueParameterName()
{
sqlQuery("
ALTER TABLE parameters
MODIFY COLUMN `name` varchar(100) default '' not null;
CREATE UNIQUE INDEX parameters_name_uindex ON parameters (name);
");
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,381 @@
<?php
class Upgrade40 extends UpgradeNew
{
public function check_PriceLevelsRanges()
{
return findModule(\Modules::PRICE_LEVELS) && $this->checkTableExists('price_levels_ranges');
}
/** Create table for price_level ranges*/
public function upgrade_PriceLevelsRanges()
{
sqlQuery(" CREATE TABLE IF NOT EXISTS price_levels_ranges (
id_price_level INT(10) UNSIGNED NOT NULL,
range_from INT(11) NOT NULL,
range_to INT(11) NOT NULL,
discount float default '0' not null,
unit enum('perc', 'price', 'final_price') default 'perc' not null
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE price_levels_ranges ADD FOREIGN KEY (`id_price_level`) REFERENCES `price_levels`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
");
$this->upgradeOK();
}
public function check_InnoDBMargins()
{
return findModule(\Modules::PRICE_LEVELS) && $this->checkIsInnoDB('price_levels_ranges');
}
/** Fix innodb instead myisam*/
public function upgrade_InnoDBMargins()
{
sqlQuery('ALTER TABLE price_levels_ranges ENGINE = InnoDB;');
}
public function check_EmailsTable()
{
return $this->checkTableExists('emails');
}
/** Create table emails*/
public function upgrade_EmailsTable()
{
sqlQuery(' CREATE TABLE IF NOT EXISTS emails (
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_status INT(11) DEFAULT NULL,
type VARCHAR(250) NOT NULL,
position INT(11) DEFAULT NULL,
body TEXT NOT NULL,
subject VARCHAR(250) DEFAULT NULL,
name VARCHAR(250) DEFAULT NULL,
email VARCHAR(250),
sms TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
');
$settings = Settings::createFromDB();
if ($settings->getOrderMessages()) {
foreach ($settings->getOrderMessages() as $name => &$message) {
$this->insertSQL('emails', [
'order_status' => (empty($message['status'])) ? null : $message['status'],
'subject' => $message['subject'],
'name' => $name,
'body' => $message['text'],
'type' => \KupShop\KupShopBundle\Email\OrderMessageEmail::getType(),
]);
}
}
$this->insertSQL('emails', [
'subject' => $settings->getOrderReceivedSubject(),
'body' => $settings->getOrderReceivedText(),
'type' => \KupShop\KupShopBundle\Email\OrderCreateEmail::getType(),
]);
$this->insertSQL('emails', [
'email' => $settings->order_from_mail,
'subject' => 'Šablona emailu',
'body' => $settings->getOrderTemplateText(),
'type' => \KupShop\KupShopBundle\Email\BaseEmail::getType(),
]);
$this->insertSQL('emails', [
'subject' => $settings->getOrderStatusSubject(),
'body' => $settings->getOrderStatusText(),
'type' => \KupShop\KupShopBundle\Email\OrderChangeEmail::getType(),
]);
$this->upgradeOK();
}
public function check_DefaultOrdering()
{
return $this->checkColumnDefault('sections', 'orderby', 'title');
}
/** Set producer/section default ordering to 'title' */
public function upgrade_DefaultOrdering()
{
sqlQuery("ALTER TABLE sections ALTER COLUMN orderby SET DEFAULT 'title'");
sqlQuery("ALTER TABLE producers ALTER COLUMN orderby SET DEFAULT 'title'");
}
public function check_SectionGoogleFeed()
{
if (Settings::getDefault()->user_rights_version == 3) {
$this->commitDataMigration(4);
}
return false;
}
/** Fix Google feed*/
public function upgrade_SectionGoogleFeed()
{
sqlGetConnection()->transactional(function () {
sqlQuery('UPDATE sections s LEFT JOIN kupshop_shared.feed_google f ON f.id_old = s.feed_google SET s.feed_google = f.id');
$query = sqlQuery('SELECT id,name FROM sections s WHERE s.feed_google = 0');
$zero = sqlNumRows($query);
if ($zero != 0) {
sqlQuery('UPDATE sections SET feed_google = NULL WHERE feed_google = 0');
var_dump($query->fetchAll());
}
$this->commitDataMigration(4);
$this->upgradeOK();
});
}
public function check_Settings__table()
{
return !$this->checkTableExists('settings__');
}
/** Remove settings__ table */
public function upgrade_Settings__table()
{
sqlQuery('DROP TABLE settings__');
$this->upgradeOK();
}
public function check_AddRemoveFromSet()
{
return $this->checkFunctionExists('ADD_TO_SET');
}
/** Add ADD_TO_SET and REMOVE_FROM_SET database functions */
public function upgrade_AddRemoveFromSet()
{
sqlQuery("CREATE FUNCTION IF NOT EXISTS ADD_TO_SET(`member` VARCHAR(64), `set` VARCHAR(4096))
RETURNS VARCHAR(4096)
COMMENT 'ADD_TO_SET(member, set)\nAdds member to a SET string'
DETERMINISTIC NO SQL
RETURN CONCAT_WS(',', IF(`set` = '', NULL, `set`), `member`)");
sqlQuery("CREATE FUNCTION IF NOT EXISTS REMOVE_FROM_SET(`member` VARCHAR(64), `set` VARCHAR(4096))
RETURNS VARCHAR(4096)
COMMENT 'REMOVE_FROM_SET(member, set)\nRemoves member from a SET string'
DETERMINISTIC NO SQL
RETURN TRIM(BOTH ',' FROM
REPLACE(CONCAT(',', `set`, ','), CONCAT(',', `member`, ','), ',')
)");
$this->upgradeOK();
}
public function check_AddIdToSectionProducer()
{
return $this->checkColumnExists('section_producer', 'id');
}
/** Add id column to section producer */
public function upgrade_AddIdToSectionProducer()
{
sqlQuery('alter table section_producer add unique key `id_section_producer_uk` (`id_section`, `id_producer`);
ALTER TABLE section_producer DROP PRIMARY KEY;
ALTER TABLE section_producer ADD id INT(11) PRIMARY KEY AUTO_INCREMENT FIRST;
');
$this->upgradeOK();
}
public function check_addTablePhotosProducers()
{
return $this->checkTableExists('photos_producers_relation');
}
/** Add photos to producer */
public function upgrade_addTablePhotosProducers()
{
sqlQuery("create table photos_producers_relation
(
id_photo int default '0' not null,
id_producer int(11) UNSIGNED default '0' not null,
show_in_lead enum('Y', 'N') default 'N' not null,
active enum('Y', 'N') default 'Y' not null,
date_added datetime default '0000-00-00 00:00:00' not null,
position int null,
primary key (id_photo, id_producer),
constraint photos_producers_relation_ibfk_1
foreign key (id_producer) references producers (id)
on update cascade on delete cascade
);
create index photos_producers_relation_ibfk_2
on photos_producers_relation (id_producer)
;
create index photos_producers_relation_ibfk_1
on photos_producers_relation (show_in_lead)
;
");
$this->upgradeOK();
}
public function check_addTableDeliveryZasilkovna()
{
return $this->checkTableExists('delivery_zasilkovna', 'kupshop_shared');
}
/** Add table delivery_zasilkovna */
public function upgrade_addTableDeliveryZasilkovna()
{
sqlQuery('create table kupshop_shared.delivery_zasilkovna
(
id int primary key,
zip int(5) ZEROFILL null,
data text null,
hours text null,
street varchar(100) null,
country varchar(50) null,
city varchar(50) null,
name varchar(50) null,
place varchar(50) null,
labelRouting varchar(50) null,
url varchar(250) null,
directions text null
);
');
$this->upgradeOK();
}
public function check_addTableDeliveryUrgentCargus()
{
return $this->checkTableExists('delivery_ro_regions', 'kupshop_shared');
}
/** Add table delivery_ro_regions */
public function upgrade_addTableDeliveryUrgentCargus()
{
sqlQuery('create table kupshop_shared.delivery_ro_regions
(
id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
county VARCHAR(60) NOT NULL,
city VARCHAR(60) NOT NULL
);
');
$this->upgradeOK();
}
public function check_InnoDBDiscounts()
{
return findModule('purchase_discounts') && $this->checkIsInnoDB('discounts');
}
/** Discounts: Fix innodb instead myisam */
public function upgrade_InnoDBDiscounts()
{
sqlQuery('ALTER TABLE discounts ENGINE = InnoDB;');
$this->upgradeOK();
}
public function check_PhotosSyncIdField()
{
return $this->checkColumnExists('photos', 'sync_id');
}
/** Add Photos sync_id field, remove author, image_1 */
public function upgrade_PhotosSyncIdField()
{
sqlQuery('ALTER TABLE photos ADD COLUMN sync_id TEXT');
sqlQuery('UPDATE photos SET sync_id=descr');
sqlQuery('ALTER TABLE photos DROP COLUMN author, DROP COLUMN image_1');
$this->upgradeOK();
}
public function check_utfAbraComplementModel()
{
return findModule('abra') && $this->checkColumnCollation('abra_complement_models', 'name', 'utf8mb4_general_ci') && !$this->checkTableExists('abra_complement_models');
}
/** abra_complement_models COLLATION to utf8mb4_general_ci */
public function upgrade_utfAbraComplementModel()
{
sqlQuery('ALTER TABLE abra_complement_models MODIFY name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
$this->upgradeOK();
}
public function check_utfAbraSeries()
{
return findModule('abra') && !$this->checkTableExists('abra_series') && $this->checkColumnCollation('abra_series', 'name', 'utf8mb4_general_ci');
}
/** abra_series COLLATION to utf8mb4_general_ci */
public function upgrade_utfAbraSeries()
{
sqlQuery('ALTER TABLE abra_series MODIFY name VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
sqlQuery('ALTER TABLE abra_series MODIFY descr LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
$this->upgradeOK();
}
public function check_strip_tags()
{
return $this->checkFunctionExists('STRIP_TAGS');
}
/** Add STRIP_TAGS database function */
public function upgrade_strip_tags()
{
sqlQuery("CREATE FUNCTION IF NOT EXISTS STRIP_TAGS(str text) RETURNS text
DETERMINISTIC NO SQL
BEGIN
DECLARE start, end INT DEFAULT 1;
LOOP
SET start = LOCATE('<', str, start);
IF (!start) THEN RETURN str; END IF;
SET end = LOCATE('>', str, start);
IF (!end) THEN SET end = start; END IF;
SET str = INSERT(str, start, end - start + 1, '');
END LOOP;
END;");
$this->upgradeOK();
}
public function check_GreetingName()
{
return $this->checkIndexNameExists('kupshop_shared.greeting_name', 'greeting_name__index');
}
/** Change kupshop_shared.greeting_name INDEX */
public function upgrade_GreetingName()
{
if (!$this->checkIndexNameExists('kupshop_shared.greeting_name', 'PRIMARY')) {
sqlQuery('ALTER TABLE kupshop_shared.greeting_name DROP PRIMARY KEY');
}
sqlQuery('ALTER TABLE kupshop_shared.greeting_name MODIFY original VARCHAR(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
sqlQuery('CREATE INDEX greeting_name__index ON kupshop_shared.greeting_name (original, sex);');
$this->upgradeOK();
}
public function check_GreetingSurname()
{
return $this->checkIndexNameExists('kupshop_shared.greeting_surname', 'greeting_surname__index');
}
/** Change kupshop_shared.greeting_surname INDEX */
public function upgrade_GreetingSurname()
{
if (!$this->checkIndexNameExists('kupshop_shared.greeting_surname', 'PRIMARY')) {
sqlQuery('ALTER TABLE kupshop_shared.greeting_surname DROP PRIMARY KEY');
}
sqlQuery('ALTER TABLE kupshop_shared.greeting_surname MODIFY original VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
sqlQuery('CREATE INDEX greeting_surname__index ON kupshop_shared.greeting_surname (original, sex);');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,96 @@
<?php
class Upgrade41 extends UpgradeNew
{
public function check_delivery_zip_codes()
{
return $this->checkTableExists('delivery_zip_codes', 'kupshop_shared');
}
/** Create column for delivery_balik_na_postu*/
public function upgrade_delivery_zip_codes()
{
sqlQuery('CREATE TABLE kupshop_shared.delivery_zip_codes
(
zip INT(5) PRIMARY KEY,
time_zone TINYINT(1),
country VARCHAR(10)
);'
);
$this->upgradeOK();
}
public function check_EanToProductOfSuppliers()
{
return (findModule(Modules::PRODUCTS_SUPPLIERS)
|| findModule(Modules::SUPPLIERS)
|| findModule(Modules::STOCK_IN)
|| findModule('automatic_import'))
&& $this->checkColumnExists('products_of_suppliers', 'ean');
}
/** Add ean to products of suppliers */
public function upgrade_EanToProductOfSuppliers()
{
sqlQuery('ALTER TABLE products_of_suppliers ADD COLUMN ean bigint null AFTER code;');
}
public function check_ImportMultiplierProductsOfSuppliers()
{
return findModule(Modules::PRODUCTS_SUPPLIERS) && findModule(Modules::STOCK_IN)
&& ($this->checkColumnType('products_of_suppliers', 'import_multiplier', 'float')
|| $this->checkColumnDefault('products_of_suppliers', 'import_multiplier', '1'));
}
/** Change column import_multiplier from integer to float */
public function upgrade_ImportMultiplierProductsOfSuppliers()
{
sqlQuery('ALTER TABLE products_of_suppliers CHANGE import_multiplier import_multiplier FLOAT DEFAULT 1');
$this->upgradeOK();
}
/** Increase orders zip length to 50 */
public function check_zipField()
{
$row = sqlFetch(sqlQuery("SELECT COLUMN_TYPE
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA='".$GLOBALS['cfg']['Connection']['database']."'
AND TABLE_NAME='orders'
AND COLUMN_NAME='invoice_zip'
LIMIT 1"));
return $row['COLUMN_TYPE'] === 'varchar(5)';
}
public function upgrade_zipField()
{
sqlQuery("ALTER TABLE orders MODIFY COLUMN invoice_zip VARCHAR(50) DEFAULT '' NOT NULL;");
sqlQuery("ALTER TABLE orders MODIFY COLUMN delivery_zip VARCHAR(50) DEFAULT '' NOT NULL;");
}
public function check_stockInCodeAndData()
{
return findModule(Modules::STOCK_IN) && $this->checkColumnExists('stock_in', 'data');
}
public function upgrade_stockInCodeAndData()
{
sqlQuery('ALTER TABLE stock_in MODIFY COLUMN code VARCHAR(50);
ALTER TABLE stock_in ADD COLUMN data TEXT;');
}
public function check_stockInFlags()
{
return findModule(Modules::STOCK_IN) && $this->checkColumnExists('stock_in', 'flags');
}
/** Add column 'flags' to 'stock_in' table */
public function upgrade_stockInFlags()
{
sqlQuery('ALTER TABLE stock_in ADD COLUMN flags SET(\'O\') DEFAULT NULL AFTER closed');
$this->upgradeOK();
}
}

View File

@@ -0,0 +1,429 @@
<?php
class Upgrade42 extends UpgradeNew
{
public function check_productsOfSuppliersCoreLength()
{
return findModule(Modules::PRODUCTS_SUPPLIERS) && $this->checkColumnType('products_of_suppliers', 'code', 'VARCHAR(100)');
}
/** products_of_suppliers: make 'code' 100 chars long */
public function upgrade_productsOfSuppliersCoreLength()
{
sqlQuery('ALTER TABLE products_of_suppliers MODIFY COLUMN code VARCHAR(100);');
}
public function check_photos_products_relation_id_photo_index()
{
return !findModule(Modules::PRODUCTS_VARIATIONS_PHOTOS) && !$this->checkConstraintWithColumnExists('photos_products_relation', 'id_photo', 'id_variation');
}
/** photos_products_relation: remove `id_variation` column from UNIQUE KEY `id_photo` */
public function upgrade_photos_products_relation_id_photo_index()
{
sqlQuery('SET FOREIGN_KEY_CHECKS = 0');
sqlQuery('ALTER TABLE `photos_products_relation` DROP INDEX `id_photo`');
sqlQuery('ALTER TABLE `photos_products_relation` ADD UNIQUE KEY `id_photo` (`id_photo`,`id_product`)');
sqlQuery('SET FOREIGN_KEY_CHECKS = 1');
$this->upgradeOK();
}
public function check_photos_products_relation_id_photo_index2()
{
return findModule(Modules::PRODUCTS_VARIATIONS_PHOTOS) && $this->checkConstraintWithColumnExists('photos_products_relation', 'id_photo', 'id_variation');
}
/** photos_products_relation: add `id_variation` column to UNIQUE KEY `id_photo` (module PRODUCTS_VARIATIONS_PHOTOS) */
public function upgrade_photos_products_relation_id_photo_index2()
{
sqlQuery('SET FOREIGN_KEY_CHECKS = 0');
sqlQuery('ALTER TABLE `photos_products_relation` ADD INDEX `id_photo_tmp` (`id_photo`)');
sqlQuery('ALTER TABLE `photos_products_relation` DROP INDEX `id_photo`');
sqlQuery('ALTER TABLE `photos_products_relation` ADD UNIQUE KEY `id_photo` (`id_photo`,`id_product`,`id_variation`)');
sqlQuery('ALTER TABLE `photos_products_relation` DROP INDEX `id_photo_tmp`');
sqlQuery('SET FOREIGN_KEY_CHECKS = 1');
$this->upgradeOK();
}
public function check_ProductsRelatedTypes()
{
return findModule(Modules::PRODUCTS_RELATED, Modules::SUB_TYPES) && $this->checkTableExists('products_related_types');
}
/** add types to products_related */
public function upgrade_ProductsRelatedTypes()
{
sqlQuery('
CREATE TABLE products_related_types (
`id` int auto_increment PRIMARY KEY ,
`name` VARCHAR(50) NOT NULL
);
');
$this->insertSQL('products_related_types', ['name' => 'Související']);
$this->upgradeOK();
}
/** Add products related type */
public function check_ProductsRelatedType()
{
return findModule(Modules::PRODUCTS_RELATED, Modules::SUB_TYPES) && $this->checkColumnExists('products_related', 'type');
}
public function upgrade_ProductsRelatedType()
{
sqlQuery('ALTER TABLE products_related ADD COLUMN `type` INT DEFAULT NULL');
sqlQuery('ALTER TABLE products_related ADD FOREIGN KEY (`type`) REFERENCES `products_related_types`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;');
$this->upgradeOK();
}
public function check_ProductsRelatedTypesPrimaryKey()
{
return findModule(Modules::PRODUCTS_RELATED, Modules::SUB_TYPES)
&& $this->checkColumnIsNull('products_related', 'type', false);
}
/** products_related: update primary key to be able have multiple types of products_related */
public function upgrade_ProductsRelatedTypesPrimaryKey()
{
// pokud neexistuje zadnej type, tak ho pridam
if (!($typeId = sqlQuery('SELECT id FROM products_related_types ORDER BY id ASC')->fetchColumn())) {
$this->insertSQL('products_related_types', ['name' => 'Související']);
$typeId = sqlInsertId();
}
// nastavit vsem co maji NULL type
sqlQuery('UPDATE products_related SET type = :type WHERE type IS NULL', ['type' => $typeId]);
sqlQuery('ALTER TABLE products_related DROP FOREIGN KEY products_related_ibfk_3');
sqlQuery('ALTER TABLE products_related CHANGE type type INT NOT NULL;');
// znovu vytvorit foreign key - kvuli zmene na ON DELETE CASCADE
sqlQuery('ALTER TABLE products_related ADD FOREIGN KEY (`type`) REFERENCES `products_related_types`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;');
// dropnout a pridat primary key i s typem
sqlQuery('ALTER TABLE products_related DROP PRIMARY KEY, ADD PRIMARY KEY (id_top_product, id_rel_product, type);');
$this->upgradeOK();
}
public function check_AddDataColumn()
{
return $this->checkColumnExists('delivery_type_delivery', 'data');
}
/** Add field data to delivery_type_delivery */
public function upgrade_AddDataColumn()
{
sqlQuery('alter table delivery_type_delivery
add data text null;');
$this->upgradeOK();
}
public function check_AddCustomDataColumn()
{
return $this->checkColumnExists('delivery_type', 'data');
}
/** Add field data to delivery_type */
public function upgrade_AddCustomDataColumn()
{
sqlQuery('alter table delivery_type
add data text null;');
$this->upgradeOK();
}
public function check_AddRegDeliveryDontCountinFrom()
{
return $this->checkColumnExists('delivery_type', 'price_dont_countin_from_reg');
}
/** Add price_dont_countin_from_reg to delivery_type */
public function upgrade_AddRegDeliveryDontCountinFrom()
{
sqlQuery('ALTER TABLE delivery_type ADD COLUMN `price_dont_countin_from_reg` DECIMAL(15,4) NULL;');
$this->upgradeOK();
}
public function check_pr_id_sec_pos_id_producer()
{
return $this->checkColumnExists('products_in_sections_positions', 'id_producer');
}
/** Add field id_producer into products_in_sections_positions */
public function upgrade_pr_id_sec_pos_id_producer()
{
try {
sqlQuery('alter table products_in_sections_positions drop foreign key products_in_sections_positions_ibfk_1');
} catch (Doctrine\DBAL\Exception\DriverException $e) {
}
try {
sqlQuery('alter table products_in_sections_positions drop foreign key products_in_sections_positions_products_id_fk');
} catch (Doctrine\DBAL\Exception\DriverException $e) {
}
sqlQuery('alter table products_in_sections_positions drop foreign key products_in_sections_positions_ibfk_2');
sqlQuery('alter table products_in_sections_positions drop primary key');
sqlQuery('
alter table products_in_sections_positions modify id_section int(11) null;
alter table products_in_sections_positions
add id_producer int(11) unsigned null;
alter table products_in_sections_positions
add constraint products_in_sections_positions_pk
unique (id_product, id_section, id_producer);
ALTER TABLE products_in_sections_positions ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
alter table products_in_sections_positions
add constraint products_in_sections_positions_producers_id_fk
foreign key (id_producer) references producers (id);
alter table products_in_sections_positions
add constraint products_in_sections_positions_ibfk_1
foreign key (id_product) references products (id);
alter table products_in_sections_positions
add constraint products_in_sections_positions_ibfk_2
foreign key (id_section) references sections (id);
');
$this->upgradeOK();
}
public function check_ImportMultiplierProductsOfSuppliers()
{
if ($this->checkColumnExists('products_of_suppliers', 'import_multiplier')) {
// table or field doesn't exist
return false;
}
return $this->checkColumnDefault('products_of_suppliers', 'import_multiplier', '1');
}
/** Change column import_multiplier from float to float not null default 1 */
public function upgrade_ImportMultiplierProductsOfSuppliers()
{
sqlQuery('UPDATE products_of_suppliers SET import_multiplier=1 WHERE import_multiplier IS NULL');
sqlQuery('ALTER TABLE products_of_suppliers CHANGE import_multiplier import_multiplier FLOAT NOT NULL DEFAULT 1');
$this->upgradeOK();
}
public function check_FixParametersConfigurationsPrice()
{
return findModule('products_parameters', 'configurations') && $this->checkColumnType('parameters_products', 'configuration_price', 'DECIMAL(15,4)');
}
/** Modify price of conf products parameters */
public function upgrade_FixParametersConfigurationsPrice()
{
sqlQuery('
ALTER TABLE `parameters_products` MODIFY COLUMN `configuration_price` DECIMAL(15,4) NULL DEFAULT NULL
');
$this->upgradeOK();
}
public function check_orderEmailLength()
{
return $this->checkColumnType('orders', 'invoice_email', 'VARCHAR(100)');
}
/** increase email length to 100 */
public function upgrade_orderEmailLength()
{
sqlQuery('
ALTER TABLE `orders` MODIFY COLUMN `invoice_email` varchar(100) default \'\' not null
');
$this->upgradeOK();
}
public function check_templatesNameLength()
{
return findModule(\Modules::TEMPLATES) && $this->checkColumnType('templates', 'name', 'VARCHAR(100)');
}
/** increase template name length to 100 */
public function upgrade_templatesNameLength()
{
sqlQuery('
ALTER TABLE `templates` MODIFY COLUMN `name` varchar(100) not null;
');
$this->upgradeOK();
}
public function check_AddAdminsDataColumn()
{
return $this->checkColumnExists('admins', 'data');
}
/** Add field data to admins */
public function upgrade_AddAdminsDataColumn()
{
sqlQuery('ALTER TABLE admins ADD data TEXT NULL;');
$this->upgradeOK();
}
public function check_SupplierDataColumn()
{
return $this->checkColumnExists('suppliers', 'data');
}
/** Add 'data' column into table 'suppliers' */
public function upgrade_SupplierDataColumn()
{
sqlQuery('ALTER TABLE suppliers ADD COLUMN data MEDIUMTEXT DEFAULT NULL');
$this->upgradeOK();
}
public function check_SupplierEmailColumnLength()
{
return $this->checkColumnType('suppliers', 'email', 'VARCHAR(50)');
}
/** increase length of 'email' column in 'suppliers' table */
public function upgrade_SupplierEmailColumnLength()
{
sqlQuery('ALTER TABLE suppliers CHANGE COLUMN email email VARCHAR(50) DEFAULT NULL');
$this->upgradeOK();
}
public function check_SupplierAddressLength()
{
return $this->checkColumnType('suppliers', 'address', 'MEDIUMTEXT');
}
/** Change 'address' column in 'suppliers' table to mediumtext */
public function upgrade_SupplierAddressLength()
{
sqlQuery('ALTER TABLE suppliers CHANGE COLUMN address address MEDIUMTEXT DEFAULT NULL');
$this->upgradeOK();
}
public function check_ProductsNoteLength()
{
return findModule(\Modules::PRODUCTS, Modules::SUB_NOTE) && $this->checkColumnType('products', 'note', 'VARCHAR(255)');
}
/** increase products/variations note to 255 */
public function upgrade_ProductsNoteLength()
{
sqlQuery('
ALTER TABLE `products` MODIFY COLUMN `note` varchar(255) null;
ALTER TABLE `products_variations` MODIFY COLUMN `note` varchar(255) null;
');
$this->upgradeOK();
}
public function check_POSOrdersFlag()
{
return findModule(Modules::POS) && Settings::getDefault()->user_rights_version == 11;
}
/** Add POS flag to orders created by POS */
public function upgrade_POSOrdersFlag()
{
$settings = \Settings::getDefault();
sqlQuery('UPDATE orders SET flags = ADD_TO_SET("POS", flags) WHERE pos = 1');
$this->commitDataMigration(12);
$this->upgradeOK();
}
public function check_ProducersDescr()
{
return !$this->checkColumnExists('producers', 'descr');
}
/** Delete description from producers */
public function upgrade_ProducersDescr()
{
sqlQuery('ALTER TABLE producers DROP COLUMN descr');
$this->upgradeOK();
}
public function check_TemplatesText()
{
return !$this->checkColumnExists('templates', 'text');
}
/** Delete text from templates */
public function upgrade_TemplatesText()
{
sqlQuery('ALTER TABLE templates DROP COLUMN text');
$this->upgradeOK();
}
public function check_DataDeliveryTypePayment()
{
return $this->checkColumnExists('delivery_type_payment', 'data');
}
/** Add 'data' column to table 'delivery_type_payment' */
public function upgrade_DataDeliveryTypePayment()
{
sqlQuery('ALTER TABLE delivery_type_payment ADD COLUMN data MEDIUMTEXT DEFAULT NULL');
$this->upgradeOK();
}
public function check_cartTableForeignKeyForUser()
{
return $this->checkConstraintRule('cart', 'cart_ibfk_3');
}
/** Add 'cart_ibfk_3' foreign key to table 'cart' and update id_user to null where id_user = 0*/
public function upgrade_cartTableForeignKeyForUser()
{
sqlQuery('ALTER TABLE cart MODIFY COLUMN id_user INT UNSIGNED NULL');
sqlQuery('UPDATE cart SET id_user = NULL WHERE id_user = 0');
sqlQuery('
DELETE c FROM cart c
LEFT JOIN users u on u.id = c.id_user
WHERE c.id_user IS NOT NULL AND u.id IS NULL
');
sqlQuery('ALTER TABLE cart ADD CONSTRAINT cart_ibfk_3 FOREIGN KEY (id_user) REFERENCES users(id) ON DELETE CASCADE');
$this->upgradeOK();
}
public function check_templatesCategoriesPositions(): bool
{
return !$this->checkTableExists('templates_categories') && $this->checkColumnExists('templates_categories', 'product_detail_position');
}
/** Add `product_detail_position` column to template_categories */
public function upgrade_templatesCategoriesPositions(): void
{
sqlQuery("ALTER TABLE `templates_categories` ADD COLUMN `product_detail_position` VARCHAR(63) NOT NULL DEFAULT '';");
$this->upgradeOK();
}
public function check_addOrderPaymentsIndexOnDate(): bool
{
return $this->checkIndexNameExists('order_payments', 'order_payments_date_index');
}
/** Add `order_payments_date_index` index to order_payments on date */
public function upgrade_addOrderPaymentsIndexOnDate(): void
{
sqlQuery('create index order_payments_date_index on order_payments (date)');
$this->upgradeOK();
}
}