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,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();
}
}