237 lines
7.3 KiB
PHP
237 lines
7.3 KiB
PHP
<?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();
|
|
}
|
|
}
|