Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
refs #32779 : rework upgrade file 2.4.1 and 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Afayadas committed Dec 27, 2021
1 parent 4164e44 commit 006fc5d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 80 deletions.
14 changes: 0 additions & 14 deletions upgrade/Upgrade-2.4.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,8 @@ function upgrade_module_2_4_0($module)

return true;
} catch (PrestaShopDatabaseException $e) {
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::logError(
$e->getMessage(),
null,
null,
'Upgrade 2.4.0'
);
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::closeLogger();
return false;
} catch (PrestaShopException $e) {
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::logError(
$e->getMessage(),
null,
null,
'Upgrade 2.4.0'
);
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::closeLogger();
return false;
}
}
67 changes: 1 addition & 66 deletions upgrade/Upgrade-2.4.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,79 +35,14 @@ function upgrade_module_2_4_1($module)
try {
$installer = new Stripe_officialClasslib\Install\ModuleInstaller($module);

if (!$installer->install()) {
if (!$installer->installExtension(Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerExtension::class)) {
return false;
}

$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
'SELECT os.id_order_state FROM `' . _DB_PREFIX_ . 'order_state` os
INNER JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.id_order_state = osl.id_order_state)
WHERE osl.name LIKE "%stripe%" AND os.color = "#FFDD99" GROUP BY os.id_order_state;');

if (!empty($result)) {
$order_state_to_delete = array_column($result, 'id_order_state');

foreach ($order_state_to_delete as $id) {
$order_state = new OrderState((int) $id);
$order_state->delete();
}
}

if (Configuration::get(Stripe_official::OXXO_WAITING) == Configuration::get(Stripe_official::SEPA_DISPUTE)) {
$stripe_order_states = [
['sofort', '#4169E1', stripe_official::OS_SOFORT_WAITING],
['stripe', '#03befc', stripe_official::CAPTURE_WAITING],
['sepa', '#fcba03', stripe_official::SEPA_WAITING],
['sepa', '#e3e1dc', stripe_official::SEPA_DISPUTE],
['oxxo', '#C23416', stripe_official::OXXO_WAITING],
];

foreach ($stripe_order_states as list($name, $color, $config)) {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
'SELECT os.id_order_state FROM `' . _DB_PREFIX_ . 'order_state` os
INNER JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.id_order_state = osl.id_order_state)
WHERE osl.name LIKE "%' . pSQL($name) . '%" AND os.color = "' . pSQL($color) . '" GROUP BY os.id_order_state ORDER BY os.id_order_state DESC;');

if (empty($result)) {
break;
}

$order_state_ids = array_column($result, 'id_order_state');

foreach ($order_state_ids as $key => $order_state_id) {
$order_state = new OrderState((int) $order_state_id);

if ($key > 0) {
$order_state->delete();
} else {
$order_state->unremovable = true;
$order_state->module_name = 'stripe_official';
$order_state->save();

Configuration::updateValue($config, $order_state->id);
}
}
}
}

return true;
} catch (PrestaShopDatabaseException $e) {
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::logError(
$e->getMessage(),
null,
null,
'Upgrade 2.4.1'
);
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::closeLogger();
return false;
} catch (PrestaShopException $e) {
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::logError(
$e->getMessage(),
null,
null,
'Upgrade 2.4.1'
);
Stripe_officialClasslib\Extensions\ProcessLogger\ProcessLoggerHandler::closeLogger();
return false;
}
}

0 comments on commit 006fc5d

Please sign in to comment.