Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Apr 22, 2024
1 parent ad5fc1b commit c6ab9e5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
57 changes: 57 additions & 0 deletions upgrade/php/remove_duplicates_from_authorization_role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

function remove_duplicates_from_authorization_role()
{
$duplicates = Db::getInstance()->executeS(
'SELECT MIN(id_authorization_role) AS keep_ID, slug FROM ' . _DB_PREFIX_ . 'authorization_role GROUP BY slug HAVING COUNT(*) > 1'
);

if (empty($duplicates)) {
return;
}

foreach ($duplicates as $duplicate) {

$elementsToRemoves = Db::getInstance()->getValue(
"SELECT id_authorization_role FROM " . _DB_PREFIX_ . "authorization_role WHERE slug = '" . $duplicate['slug'] . "' AND id_authorization_role != " . $duplicate['keep_ID']
);

foreach ($elementsToRemoves as $elementToRemove) {
Db::getInstance()->executeS(
"UPDATE " . _DB_PREFIX_ . "access SET id_authorization_role = '" . $duplicate['keep_ID'] . "' WHERE id_authorization_role = " . $elementsToRemoves['keep_ID']
);
}

Db::getInstance()->executeS(
"DELETE FROM" . _DB_PREFIX_ . "authorization_role WHERE id_authorization_role = " . $duplicate['id_authorization_role']
);
}

Db::getInstance()->executeS(
"ALTER TABLE " . _DB_PREFIX_ . "authorization_role ADD UNIQUE KEY slug (slug)"
);
}
8 changes: 6 additions & 2 deletions upgrade/sql/1.7.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ ALTER TABLE `PREFIX_product_shop` CHANGE `redirect_type` `redirect_type`
ENUM('','404','301-product','302-product','301-category','302-category')
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';

ALTER TABLE `PREFIX_product` CHANGE `id_product_redirected` `id_type_redirected` INT(10) NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product_shop` CHANGE `id_product_redirected` `id_type_redirected` INT(10) NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product` CHANGE `id_product_redirected` `id_type_redirected` INT(10) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `PREFIX_product_shop` CHANGE `id_product_redirected` `id_type_redirected` INT(10) UNSIGNED NOT NULL DEFAULT '0';

INSERT INTO `PREFIX_hook` (`id_hook`, `name`, `title`, `description`, `position`) VALUES
(NULL, 'filterCmsContent', 'Filter the content page', 'This hook is called just before fetching content page', '1'),
Expand Down Expand Up @@ -107,3 +107,7 @@ ALTER TABLE `PREFIX_tab` CHANGE `id_tab` `id_tab` INT(11) NOT NULL AUTO_INCREMEN

ALTER TABLE `PREFIX_tab_lang` CHANGE `id_tab` `id_tab` INT(11) NOT NULL;
ALTER TABLE `PREFIX_tab_lang` CHANGE `id_lang` `id_lang` INT(11) NOT NULL;

/* PHP:remove_duplicates_from_authorization_role(); */;

ALTER TABLE `PREFIX_authorization_role` ADD UNIQUE KEY `slug` (`slug`);
5 changes: 5 additions & 0 deletions upgrade/sql/1.7.2.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ ALTER TABLE `PREFIX_supply_order_detail` CHANGE `isbn` `isbn` VARCHAR(32) NULL D
ALTER TABLE `PREFIX_stock_available` ADD `physical_quantity` INT NOT NULL DEFAULT '0' AFTER `quantity`;
ALTER TABLE `PREFIX_stock_available` ADD `reserved_quantity` INT NOT NULL DEFAULT '0' AFTER `physical_quantity`;
ALTER TABLE `PREFIX_stock_mvt` CHANGE `id_stock` `id_stock` INT(11) UNSIGNED NOT NULL COMMENT 'since ps 1.7 corresponding to id_stock_available';
ALTER TABLE `PREFIX_stock_mvt` CHANGE `employee_lastname` `employee_lastname` varchar(32) DEFAULT NULL;
ALTER TABLE `PREFIX_stock_mvt` CHANGE `employee_firstname` `employee_firstname` varchar(32) DEFAULT NULL;
ALTER TABLE `PREFIX_stock_mvt` CHANGE `sign` `sign` smallint(6) NOT NULL DEFAULT '1';

UPDATE `PREFIX_configuration` SET `value` = 0 WHERE `name` = "PS_ADVANCED_STOCK_MANAGEMENT";
/* PHP:add_new_status_stock(); */;

ALTER TABLE `PREFIX_carrier_lang` CHANGE `delay` `delay` varchar(512) DEFAULT NULL;

0 comments on commit c6ab9e5

Please sign in to comment.