module = $module; $this->installer = $installer; $this->db = $db; } public function upgrade(): bool { CacheClearer::getInstance()->clear(); $this->installer->install($this->module); return $this->updateGuiConfiguration() && $this->removeStaleAssets(self::STALE_ASSETS) && $this->removeClasses(self::CLASSES_TO_REMOVE) && $this->removeFiles(self::FILES_TO_REMOVE); } private function updateGuiConfiguration(): bool { $result = true; foreach ($this->getConfigurableBindingPlaces() as $bindingPlace) { $result &= $this->updateStylesConfig($bindingPlace); } return (bool) $result; } /** * Method may not exist if the previous version of the file was already included (e.g., during recompilation of the container) * before unpacking a new version of the module. */ private function getConfigurableBindingPlaces(): array { if (method_exists(GuiConfiguration::class, 'getConfigurableBindingPlaces')) { return GuiConfiguration::getConfigurableBindingPlaces(); } return [ BindingPlace::BasketSummary(), BindingPlace::ProductCard(), BindingPlace::LoginPage(), BindingPlace::RegisterFormPage(), BindingPlace::CheckoutPage(), BindingPlace::MiniCartPage(), BindingPlace::OrderCreate(), ]; } private function updateStylesConfig(BindingPlace $bindingPlace): bool { $data = $this->getConfigDataByKeys([ $widgetConfigKey = self::getWidgetConfigKey($bindingPlace), $stylesConfigKey = self::getHtmlStylesConfigKey($bindingPlace), ]); if ([] === $data) { return true; } $dataByShopGroup = $this->groupConfigValuesByShop($data); $newWidgetConfigs = []; $newStyles = []; foreach ($dataByShopGroup as $shopGroupId => $dataByShop) { foreach ($dataByShop as $shopId => $data) { if (null === $widgetConfig = $data[$widgetConfigKey] ?? null) { continue; } $widgetConfig = json_decode($widgetConfig, true); if (!is_array($widgetConfig) || !isset($widgetConfig['alignment'])) { continue; } if (isset($data[$stylesConfigKey])) { $stylesConfig = json_decode($data[$stylesConfigKey], true) ?? []; } else { $stylesConfig = []; } $stylesConfig['justifyContent'] = HtmlStyles::getJustifyContentStyleByAlignment($widgetConfig['alignment']); unset($widgetConfig['alignment'], $widgetConfig['basket'], $widgetConfig['minWidthPx']); $newStyles[$shopGroupId][$shopId] = $stylesConfig; $newWidgetConfigs[$shopGroupId][$shopId] = $widgetConfig; } } return $this->setJsonConfigValues($widgetConfigKey, $newWidgetConfigs) && $this->setJsonConfigValues($stylesConfigKey, $newStyles); } private static function getWidgetConfigKey(BindingPlace $bindingPlace): string { if (BindingPlace::BasketSummary() === $bindingPlace) { return 'INPOST_PAY_CART_WIDGET_CONFIG'; } return 'INPOST_PAY_' . $bindingPlace->value . '_WIDGET_CONFIG'; } private static function getHtmlStylesConfigKey(BindingPlace $bindingPlace): string { if (BindingPlace::BasketSummary() === $bindingPlace) { return 'INPOST_PAY_CART_HTML_STYLES'; } if (BindingPlace::ProductCard() === $bindingPlace) { return 'INPOST_PAY_PRODUCT_HTML_STYLES'; } return 'INPOST_PAY_' . $bindingPlace->value . '_HTML_STYLES'; } } /** * @param InPostIzi $module */ function upgrade_module_2_0_0(Module $module): bool { if (Tools::version_compare(_PS_VERSION_, '1.7.1')) { try { $module->uninstall(); } finally { return false; } } $db = Db::getInstance(); $dbInstaller = new DatabaseInstaller(new Configuration($db), [ new Version_2_0_0(new Connection($db)), ]); return (new InPostIziUpdater_2_0_0($module, $dbInstaller, $db))->upgrade(); }