Files
lulandia.pl/modules/phstickers/classes/StickerUpdate.php
2025-04-01 00:38:54 +02:00

204 lines
9.1 KiB
PHP

<?php
class StickerUpdate
{
public $update = false;
public $updateList = array();
public function __construct()
{
}
public function checkUpdate()
{
$this->updateVersion102();
$this->updateVersion103();
$this->updateVersion104();
$this->updateVersion105();
$this->updateVersion106();
}
private function updateVersion102()
{
$update102_sql1 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "price_min"');
if (empty($update102_sql1)) {
$this->update = true;
$this->updateList[0] = 'price_min';
}
$update102_sql2 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "price_max"');
if (empty($update102_sql2)) {
$this->update = true;
$this->updateList[1] = 'price_max';
}
}
private function updateVersion103()
{
$update103_sql1 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers_product` WHERE `Field` = "inherit"');
if (empty($update103_sql1)) {
$this->update = true;
$this->updateList[2] = 'inherit';
}
}
private function updateVersion104()
{
$update104_sql1 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "qty_min"');
if (empty($update104_sql1)) {
$this->update = true;
$this->updateList[3] = 'qty_min';
}
$update104_sql2 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "qty_max"');
if (empty($update104_sql2)) {
$this->update = true;
$this->updateList[4] = 'qty_max';
}
$update104_sql3 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "price_on"');
if (empty($update104_sql3)) {
$this->update = true;
$this->updateList[5] = 'price_on';
}
$update104_sql4 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "qty_on"');
if (empty($update104_sql4)) {
$this->update = true;
$this->updateList[6] = 'qty_on';
}
$update104_sql5 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "manu_on"');
if (empty($update104_sql5)) {
$this->update = true;
$this->updateList[7] = 'manu_on';
}
$update104_sql6 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "id_manufacturer"');
if (empty($update104_sql6)) {
$this->update = true;
$this->updateList[8] = 'id_manufacturer';
}
}
private function updateVersion105()
{
$update105_sql1 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "position_price"');
if (empty($update105_sql1)) {
$this->update = true;
$this->updateList[9] = 'position_price';
}
$update105_sql2 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "position_qty"');
if (empty($update105_sql2)) {
$this->update = true;
$this->updateList[10] = 'position_qty';
}
$update105_sql3 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "position_manu"');
if (empty($update105_sql3)) {
$this->update = true;
$this->updateList[11] = 'position_manu';
}
$update105_sql4 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'phstickers_lang` WHERE `file_name` = "100proc.png"');
if (empty($update105_sql4)) {
$this->update = true;
$this->updateList[12][0] = '100proc.png';
}
$update105_sql5 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'phstickers_lang` WHERE `file_name` = "polecany.png"');
if (empty($update105_sql5)) {
$this->update = true;
$this->updateList[12][1] = 'polecany.png';
}
}
private function updateVersion106()
{
$update106_sql1 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "position_new"');
if (empty($update106_sql1)) {
$this->update = true;
$this->updateList[13] = 'position_new';
}
$update106_sql2 = Db::getInstance()->executeS('SHOW COLUMNS FROM `'._DB_PREFIX_.'phstickers` WHERE `Field` = "show_new"');
if (empty($update106_sql2)) {
$this->update = true;
$this->updateList[14] = 'show_new';
}
}
public function processUpdate($adminLink)
{
if (Tools::getIsset('addPriceMinProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `price_min` DOUBLE(20, 6) NOT NULL AFTER `id_sticker`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addPriceMaxProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `price_max` DOUBLE(20, 6) NOT NULL AFTER `price_min`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addInheritProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers_product` ADD `inherit` int(11) NOT NULL');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addQtyMinProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `qty_min` int(11) NOT NULL AFTER `price_max`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addQtyMaxProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `qty_max` int(11) NOT NULL AFTER `qty_min`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addPriceOnProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `price_on` int(11) NOT NULL AFTER `id_sticker`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addQtyOnProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `qty_on` int(11) NOT NULL AFTER `price_max`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addManuOnProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `manu_on` int(11) NOT NULL AFTER `qty_max`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addIdManuProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `id_manufacturer` int(11) NOT NULL AFTER `manu_on`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addPosPriceProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `position_price` int(11) NOT NULL AFTER `price_max`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addPosQtyProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `position_qty` int(11) NOT NULL AFTER `qty_max`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addPosManuProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `position_manu` int(11) NOT NULL AFTER `id_manufacturer`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addImage105Process')) {
$naklejki = Tools::getValue('manyImage');
$naklejkiExp = explode('|', $naklejki);
if (!empty($naklejkiExp)) {
foreach ($naklejkiExp as $item) {
if (!empty($item)) {
Db::getInstance()->insert('phstickers', array(
'date_add' => date('Y-m-d H:i:s')
));
$id = Db::getInstance()->Insert_ID();
Db::getInstance()->insert('phstickers_lang', array(
'id_sticker' => (int)$id,
'file_name' => $item,
'id_lang' => Context::getContext()->cookie->id_lang
));
}
}
}
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addPosNewProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `position_new` int(11) NOT NULL AFTER `position_manu`');
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('addShowNewProcess')) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'phstickers` ADD `show_new` int(11) NOT NULL AFTER `position_new`');
Tools::redirect($adminLink.'&conf=4');
}
}
}