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