Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packetery/libs/ApiCarrier/ApiCarrierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function save(array $carriers, Packetery $module)

public function getCreateTableSql()
{
return 'CREATE TABLE `' . $this->getPrefixedTableName() . '` (
return 'CREATE TABLE IF NOT EXISTS `' . $this->getPrefixedTableName() . '` (
`id` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`is_pickup_points` boolean NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion packetery/libs/Log/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getDropTableSql()
*/
public function getCreateTableSql()
{
return 'CREATE TABLE ' . $this->getPrefixedTableName() . ' (
return 'CREATE TABLE IF NOT EXISTS ' . $this->getPrefixedTableName() . ' (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(10) NULL,
`params` text NOT NULL,
Expand Down
36 changes: 26 additions & 10 deletions packetery/libs/Module/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ private function createMultiLangField($translationKey)
private function installDatabase()
{
$sql = [];
// DB migrations do not work with PACKETERY_REMOVE_ALL_DATA set to false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co ten komentář znamená? Pokud je nastavena konstanta, tak to přece neovlivní spuštění skriptů ze složky upgrade, ne?
Pokud jde o situaci, že si eshopista odinstaluje starší verzi a nainstaluje novější, tak tu musí sám vyřešit. Mazání tabulek by neodpovídalo nastavení konstanty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade soubory se nepoužijí při čerstvé instalaci. Původní řešení to řešilo dropováním tabulek.

$dropTables = !defined('PACKETERY_REMOVE_ALL_DATA') || PACKETERY_REMOVE_ALL_DATA;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neodpovídá zadání - pokud není konstanta definována, nemají se tabulky odstraňovat. I když v tomto případě by se to tak mohlo řešit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Měnit dosavadní výchozí chování je blbost. Připravte se na to, že to fungovat nebude.


$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_order`';
$sql[] = 'CREATE TABLE `' . _DB_PREFIX_ . 'packetery_order` (
if ($dropTables) {
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_order`';
}
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'packetery_order` (
`id_order` int,
`id_cart` int,
`id_branch` int NULL,
Expand Down Expand Up @@ -173,14 +177,18 @@ private function installDatabase()
UNIQUE(`id_cart`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';

$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_payment`';
$sql[] = 'CREATE TABLE `' . _DB_PREFIX_ . 'packetery_payment` (
if ($dropTables) {
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_payment`';
}
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'packetery_payment` (
`module_name` varchar(255) NOT NULL PRIMARY KEY,
`is_cod` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT charset=utf8;';

$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_address_delivery`';
$sql[] = 'CREATE TABLE `' . _DB_PREFIX_ . 'packetery_address_delivery` (
if ($dropTables) {
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_address_delivery`';
}
$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'packetery_address_delivery` (
`id_carrier` int NOT NULL PRIMARY KEY,
`id_branch` varchar(255) NOT NULL,
`name_branch` varchar(255) NULL,
Expand All @@ -192,19 +200,27 @@ private function installDatabase()
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';

$productAttributeRepository = $this->module->diContainer->get(ProductAttributeRepository::class);
$sql[] = $productAttributeRepository->getDropTableSql();
if ($dropTables) {
$sql[] = $productAttributeRepository->getDropTableSql();
}
$sql[] = $productAttributeRepository->getCreateTableSql();

$apiCarrierRepository = $this->module->diContainer->get(ApiCarrierRepository::class);
$sql[] = $apiCarrierRepository->getDropTableSql();
if ($dropTables) {
$sql[] = $apiCarrierRepository->getDropTableSql();
}
$sql[] = $apiCarrierRepository->getCreateTableSql();

$logRepository = $this->module->diContainer->get(LogRepository::class);
$sql[] = $logRepository->getDropTableSql();
if ($dropTables) {
$sql[] = $logRepository->getDropTableSql();
}
$sql[] = $logRepository->getCreateTableSql();

$packetTrackingRepository = $this->module->diContainer->get(PacketTrackingRepository::class);
$sql[] = $packetTrackingRepository->getDropTableSql();
if ($dropTables) {
$sql[] = $packetTrackingRepository->getDropTableSql();
}
$sql[] = $packetTrackingRepository->getCreateTableSql();

if (!$this->dbTools->executeQueries($sql, $this->getExceptionRaisedText(), true)) {
Expand Down
8 changes: 8 additions & 0 deletions packetery/libs/Module/Uninstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function deleteTab($className)
*/
private function uninstallDatabase()
{
if (defined('PACKETERY_REMOVE_ALL_DATA') && !PACKETERY_REMOVE_ALL_DATA) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neodpovídá zadání - pokud není konstanta definována, nemají se tabulky odstraňovat.

return true;
}

$sql = [];
// remove tables with payment and carrier settings, and with carriers
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'packetery_payment`';
Expand Down Expand Up @@ -140,6 +144,10 @@ private function unregisterHooks()
*/
private function deleteConfiguration()
{
if (defined('PACKETERY_REMOVE_ALL_DATA') && !PACKETERY_REMOVE_ALL_DATA) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neodpovídá zadání - pokud není konstanta definována, nemá se nastavení odstraňovat.

return true;
}

return (
Configuration::deleteByName('PACKETERY_APIPASS') &&
Configuration::deleteByName('PACKETERY_ESHOP_ID') &&
Expand Down
2 changes: 1 addition & 1 deletion packetery/libs/PacketTracking/PacketTrackingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getDropTableSql()
*/
public function getCreateTableSql()
{
return 'CREATE TABLE `' . $this->getPrefixedTableName() . '` (
return 'CREATE TABLE IF NOT EXISTS `' . $this->getPrefixedTableName() . '` (
`id` int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_order` int unsigned NOT NULL,
`packet_id` varchar(15) NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion packetery/libs/Product/ProductAttributeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getDropTableSql()
*/
public function getCreateTableSql()
{
return 'CREATE TABLE `' . $this->getPrefixedTableName() . '` (
return 'CREATE TABLE IF NOT EXISTS `' . $this->getPrefixedTableName() . '` (
`id_product` int(11) NOT NULL PRIMARY KEY,
`is_adult` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
Expand Down