This commit is contained in:
2025-04-01 00:38:54 +02:00
parent d4d4c0c09d
commit 87da06293a
22351 changed files with 5168854 additions and 7538 deletions

View File

@@ -0,0 +1,91 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Block;
use PrestaShop\Module\AutoUpgrade\ChannelInfo;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use Twig\Environment;
class ChannelInfoBlock
{
/**
* @var UpgradeConfiguration
*/
private $config;
/**
* @var ChannelInfo
*/
private $channelInfo;
/**
* @var Environment
*/
private $twig;
/**
* ChannelInfoBlock constructor.
*
* @param UpgradeConfiguration $config
* @param ChannelInfo $channelInfo
* @param Environment $twig
*/
public function __construct(UpgradeConfiguration $config, ChannelInfo $channelInfo, $twig)
{
$this->config = $config;
$this->channelInfo = $channelInfo;
$this->twig = $twig;
}
/**
* @return array<string, mixed>
*/
public function getTemplateVars(): array
{
$channel = $this->channelInfo->getChannel();
$upgradeInfo = $this->channelInfo->getInfo();
if ($channel == 'private') {
$upgradeInfo['link'] = $this->config->get('private_release_link');
$upgradeInfo['md5'] = $this->config->get('private_release_md5');
}
return [
'psBaseUri' => __PS_BASE_URI__,
'upgradeInfo' => $upgradeInfo,
];
}
/**
* @return string HTML
*/
public function render(): string
{
return $this->twig->render('@ModuleAutoUpgrade/block/channelInfo.html.twig', $this->getTemplateVars());
}
}

View File

@@ -0,0 +1,68 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Block;
use PrestaShop\Module\AutoUpgrade\BackupFinder;
use Twig\Environment;
class RollbackForm
{
/**
* @var Environment
*/
private $twig;
/**
* @var BackupFinder
*/
private $backupFinder;
/**
* @param Environment $twig
*/
public function __construct($twig, BackupFinder $backupFinder)
{
$this->twig = $twig;
$this->backupFinder = $backupFinder;
}
/**
* @return array<string, mixed>
*/
public function getTemplateVars(): array
{
return [
'availableBackups' => $this->backupFinder->getAvailableBackups(),
];
}
public function render(): string
{
return $this->twig->render('@ModuleAutoUpgrade/block/rollbackForm.html.twig', $this->getTemplateVars());
}
}

View File

@@ -0,0 +1,223 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Block;
use Configuration;
use PrestaShop\Module\AutoUpgrade\ChannelInfo;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Task\AbstractTask;
use PrestaShop\Module\AutoUpgrade\Upgrader;
use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
use Twig\Environment;
class UpgradeButtonBlock
{
/**
* @var Environment
*/
private $twig;
/**
* @var Translator
*/
private $translator;
/**
* @var Upgrader
*/
private $upgrader;
/**
* @var UpgradeConfiguration
*/
private $config;
/**
* @var UpgradeSelfCheck
*/
private $selfCheck;
/**
* @var string
*/
private $downloadPath;
/**
* @var string
*/
private $token;
/**
* @param Environment $twig
*/
public function __construct(
$twig,
Translator $translator,
UpgradeConfiguration $config,
Upgrader $upgrader,
UpgradeSelfCheck $selfCheck,
string $downloadPath,
string $token
) {
$this->twig = $twig;
$this->translator = $translator;
$this->upgrader = $upgrader;
$this->config = $config;
$this->selfCheck = $selfCheck;
$this->downloadPath = $downloadPath;
$this->token = $token;
}
/**
* @return array<string, mixed>
*/
public function getTemplateVars(): array
{
$translator = $this->translator;
$versionCompare = $this->upgrader->version_num !== null
? version_compare(_PS_VERSION_, $this->upgrader->version_num)
: 0
;
$channel = $this->config->get('channel');
if (!in_array($channel, ['archive', 'directory']) && !empty($this->upgrader->version_num)) {
$latestVersion = "{$this->upgrader->version_name} - ({$this->upgrader->version_num})";
} else {
$latestVersion = $translator->trans('N/A');
}
$showUpgradeButton = false;
$showUpgradeLink = false;
$upgradeLink = '';
$changelogLink = '';
$skipActions = [];
// decide to display "Start Upgrade" or not
if ($this->selfCheck->isOkForUpgrade() && $versionCompare < 0) {
$showUpgradeButton = true;
if (!in_array($channel, ['archive', 'directory'])) {
if ($channel == 'private') {
$this->upgrader->link = $this->config->get('private_release_link');
}
$showUpgradeLink = true;
$upgradeLink = $this->upgrader->link;
$changelogLink = $this->upgrader->changelog;
}
// if skipActions property is used, we will handle that in the display :)
$skipActions = AbstractTask::$skipAction;
}
if (empty($channel)) {
$channel = Upgrader::DEFAULT_CHANNEL;
}
$dir = glob($this->downloadPath . DIRECTORY_SEPARATOR . '*.zip');
$xml = glob($this->downloadPath . DIRECTORY_SEPARATOR . '*.xml');
$templateVars = [
'versionCompare' => $versionCompare,
'currentPsVersion' => _PS_VERSION_,
'latestChannelVersion' => $latestVersion,
'channel' => $channel,
'showUpgradeButton' => $showUpgradeButton,
'upgradeLink' => $upgradeLink,
'showUpgradeLink' => $showUpgradeLink,
'changelogLink' => $changelogLink,
'skipActions' => $skipActions,
'lastVersionCheck' => Configuration::get('PS_LAST_VERSION_CHECK'),
'token' => $this->token,
'channelOptions' => $this->getOptChannels(),
'privateChannel' => [
'releaseLink' => $this->config->get('private_release_link'),
'releaseMd5' => $this->config->get('private_release_md5'),
'allowMajor' => $this->config->get('private_allow_major'),
],
'archiveFiles' => $dir,
'xmlFiles' => $xml,
'archiveFileName' => $this->config->get('archive.filename'),
'xmlFileName' => $this->config->get('archive.xml'),
'archiveVersionNumber' => $this->config->get('archive.version_num'),
'downloadPath' => $this->downloadPath . DIRECTORY_SEPARATOR,
'directoryVersionNumber' => $this->config->get('directory.version_num'),
'phpVersion' => PHP_VERSION,
];
return array_merge($templateVars, $this->buildChannelInfoBlockVars($channel));
}
/**
* display the summary current version / target version + "Upgrade Now" button with a "more options" button.
*
* @return string HTML
*/
public function render(): string
{
return $this->twig->render('@ModuleAutoUpgrade/block/upgradeButtonBlock.html.twig', $this->getTemplateVars());
}
/**
* @return array<int, array<string>>
*/
private function getOptChannels(): array
{
$translator = $this->translator;
return [
['useMajor', 'major', $translator->trans('Major release')],
['useMinor', 'minor', $translator->trans('Minor release (recommended)')],
['useRC', 'rc', $translator->trans('Release candidates')],
['useBeta', 'beta', $translator->trans('Beta releases')],
['useAlpha', 'alpha', $translator->trans('Alpha releases')],
['usePrivate', 'private', $translator->trans('Private release (require link and MD5 hash)')],
['useArchive', 'archive', $translator->trans('Local archive')],
['useDirectory', 'directory', $translator->trans('Local directory')],
];
}
private function getInfoForChannel(string $channel): ChannelInfo
{
return new ChannelInfo($this->upgrader, $this->config, $channel);
}
/**
* @param string $channel
*
* @return array<string, mixed>
*/
private function buildChannelInfoBlockVars(string $channel): array
{
$channelInfo = $this->getInfoForChannel($channel);
return (new ChannelInfoBlock($this->config, $channelInfo, $this->twig))
->getTemplateVars();
}
}

View File

@@ -0,0 +1,128 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Block;
use Context;
use PrestaShop\Module\AutoUpgrade\Tools14;
use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck;
use Twig\Environment;
/**
* Builds the upgrade checklist block.
*/
class UpgradeChecklist
{
/**
* @var Environment
*/
private $twig;
/**
* @var UpgradeSelfCheck
*/
private $selfCheck;
/**
* @var string
*/
private $currentIndex;
/**
* @var string
*/
private $token;
/**
* UpgradeChecklistBlock constructor.
*
* @param Environment $twig
* @param UpgradeSelfCheck $upgradeSelfCheck
* @param string $currentIndex
* @param string $token
*/
public function __construct(
$twig,
UpgradeSelfCheck $upgradeSelfCheck,
string $currentIndex,
string $token
) {
$this->twig = $twig;
$this->selfCheck = $upgradeSelfCheck;
$this->currentIndex = $currentIndex;
$this->token = $token;
}
/**
* @return array<string, mixed>
*/
public function getTemplateVars(): array
{
return [
'showErrorMessage' => !$this->selfCheck->isOkForUpgrade(),
'moduleVersion' => $this->selfCheck->getModuleVersion(),
'moduleIsUpToDate' => $this->selfCheck->isModuleVersionLatest(),
'moduleUpdateLink' => Context::getContext()->link->getAdminLink('AdminModulesUpdates'),
'isShopVersionMatchingVersionInDatabase' => $this->selfCheck->isShopVersionMatchingVersionInDatabase(),
'adminToken' => Tools14::getAdminTokenLite('AdminModules'),
'informationsLink' => Context::getContext()->link->getAdminLink('AdminInformation'),
'maintenanceLink' => Context::getContext()->link->getAdminLink('AdminMaintenance'),
'rootDirectoryIsWritable' => $this->selfCheck->isRootDirectoryWritable(),
'rootDirectory' => _PS_ROOT_DIR_,
'adminDirectoryIsWritable' => $this->selfCheck->isAdminAutoUpgradeDirectoryWritable(),
'adminDirectoryWritableReport' => $this->selfCheck->getAdminAutoUpgradeDirectoryWritableReport(),
'safeModeIsDisabled' => $this->selfCheck->isSafeModeDisabled(),
'allowUrlFopenOrCurlIsEnabled' => $this->selfCheck->isFOpenOrCurlEnabled(),
'zipIsEnabled' => $this->selfCheck->isZipEnabled(),
'storeIsInMaintenance' => $this->selfCheck->isShopDeactivated(),
'isLocalEnvironment' => $this->selfCheck->isLocalEnvironment(),
'currentIndex' => $this->currentIndex,
'token' => $this->token,
'cachingIsDisabled' => $this->selfCheck->isCacheDisabled(),
'maxExecutionTime' => $this->selfCheck->getMaxExecutionTime(),
'phpRequirementsState' => $this->selfCheck->getPhpRequirementsState(PHP_VERSION_ID),
'phpCompatibilityRange' => $this->selfCheck->getPhpCompatibilityRange(),
'checkApacheModRewrite' => $this->selfCheck->isApacheModRewriteEnabled(),
'notLoadedPhpExtensions' => $this->selfCheck->getNotLoadedPhpExtensions(),
'checkKeyGeneration' => $this->selfCheck->checkKeyGeneration(),
'checkMemoryLimit' => $this->selfCheck->isMemoryLimitValid(),
'checkFileUploads' => $this->selfCheck->isPhpFileUploadsConfigurationEnabled(),
'notExistsPhpFunctions' => $this->selfCheck->getNotExistsPhpFunctions(),
'checkPhpSessions' => $this->selfCheck->isPhpSessionsValid(),
'missingFiles' => $this->selfCheck->getMissingFiles(),
'notWritingDirectories' => $this->selfCheck->getNotWritingDirectories(),
];
}
/**
* Returns the block's HTML.
*/
public function render(): string
{
return $this->twig->render('@ModuleAutoUpgrade/block/checklist.html.twig', $this->getTemplateVars());
}
}

View File

@@ -0,0 +1,34 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,88 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Form;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
class BackupOptionsForm
{
/**
* @var array<string, array<string>>
*/
private $fields;
/**
* @var Translator
*/
private $translator;
/**
* @var FormRenderer
*/
private $formRenderer;
public function __construct(Translator $translator, FormRenderer $formRenderer)
{
$this->translator = $translator;
$this->formRenderer = $formRenderer;
$this->fields = [
'PS_AUTOUP_BACKUP' => [
'title' => $this->translator->trans('Back up my files and database'),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '1',
'type' => 'bool',
'desc' => $this->translator->trans(
'Automatically back up your database and files in order to restore your shop if needed. This is experimental: you should still perform your own manual backup for safety.'
),
],
'PS_AUTOUP_KEEP_IMAGES' => [
'title' => $this->translator->trans(
'Back up my images'
),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '1',
'type' => 'bool',
'desc' => $this->translator->trans(
'To save time, you can decide not to back your images up. In any case, always make sure you did back them up manually.'
),
],
];
}
public function render(): string
{
return $this->formRenderer->render(
'backupOptions',
$this->fields,
$this->translator->trans('Backup Options')
);
}
}

View File

@@ -0,0 +1,261 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Form;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
use Twig\Environment;
class FormRenderer
{
/**
* @var UpgradeConfiguration
*/
private $config;
/**
* @var Translator
*/
private $translator;
/**
* @var Environment
*/
private $twig;
/**
* @param Environment $twig
*/
public function __construct(
UpgradeConfiguration $configuration,
$twig,
Translator $translator
) {
$this->config = $configuration;
$this->twig = $twig;
$this->translator = $translator;
}
/**
* @param array<string, array<string, string|array<string>>> $fields
*/
public function render(string $name, array $fields, string $tabname): string
{
$formFields = [];
foreach ($fields as $key => $field) {
$html = '';
$required = !empty($field['required']);
$disabled = !empty($field['disabled']);
if ($key === 'PS_DISABLE_OVERRIDES') {
// values fetched from configuration in database
$val = UpgradeConfiguration::isOverrideAllowed();
} else {
// other conf values are fetched from config file
$val = $this->config->get($key);
}
if ($val === null) {
$val = isset($field['defaultValue']) ? $field['defaultValue'] : false;
}
if (!in_array($field['type'], ['image', 'radio', 'select', 'container', 'bool', 'container_end']) || isset($field['show'])) {
$html .= '<div style="clear: both; padding-top:15px">'
. ($field['title'] ? '<label >' . $field['title'] . '</label>' : '')
. '<div class="margin-form" style="padding-top:5px">';
}
// Display the appropriate input type for each field
switch ($field['type']) {
case 'disabled':
$html .= $field['disabled'];
break;
case 'bool':
$html .= $this->renderBool($field, $key, $val);
break;
case 'radio':
$html .= $this->renderRadio($field, $key, $val, $disabled);
break;
case 'select':
$html .= $this->renderSelect($field, $key, $val);
break;
case 'textarea':
$html .= $this->renderTextarea($field, $key, $val, $disabled);
break;
case 'container':
$html .= '<div id="' . $key . '">';
break;
case 'container_end':
$html .= (isset($field['content']) ? $field['content'] : '') . '</div>';
break;
case 'text':
default:
$html .= $this->renderTextField($field, $key, $val, $disabled);
}
if ($required && !in_array($field['type'], ['image', 'radio'])) {
$html .= ' <sup>*</sup>';
}
if (isset($field['desc']) && !in_array($field['type'], ['bool', 'select'])) {
$html .= '<p style="clear:both">';
if (!empty($field['thumb']) && $field['thumb']['pos'] == 'after') {
$html .= $this->renderThumb($field);
}
$html .= $field['desc'] . '</p>';
}
if (!in_array($field['type'], ['image', 'radio', 'select', 'container', 'bool', 'container_end']) || isset($field['show'])) {
$html .= '</div></div>';
}
$formFields[] = $html;
}
return $this->twig->render(
'@ModuleAutoUpgrade/form.html.twig',
[
'name' => $name,
'tabName' => $tabname,
'fields' => $formFields,
]
);
}
/**
* @param array<string, string|array<string>> $field
*/
private function renderBool(array $field, string $key, bool $val): string
{
return '<div class="form-group">
<label class="col-lg-3 control-label">' . $field['title'] . '</label>
<div class="col-lg-9">
<span class="switch prestashop-switch fixed-width-lg">
<input type="radio" name="' . $key . '" id="' . $key . '_on" value="1" ' . ($val ? ' checked="checked"' : '') . (isset($field['js']['on']) ? $field['js']['on'] : '') . ' />
<label for="' . $key . '_on" class="radioCheck">
<i class="color_success"></i> '
. $this->translator->trans('Yes') . '
</label>
<input type="radio" name="' . $key . '" id="' . $key . '_off" value="0" ' . (!$val ? 'checked="checked"' : '') . (isset($field['js']['off']) ? $field['js']['off'] : '') . '/>
<label for="' . $key . '_off" class="radioCheck">
<i class="color_danger"></i> ' . $this->translator->trans('No') . '
</label>
<a class="slide-button btn"></a>
</span>
<div class="help-block">' . $field['desc'] . '</div>
</div>
</div>';
}
/**
* @param array<string, string|array<string>> $field
*/
private function renderRadio(array $field, string $key, string $val, bool $disabled): string
{
$html = '';
foreach ($field['choices'] as $cValue => $cKey) {
$html .= '<input ' . ($disabled ? 'disabled="disabled"' : '') . ' type="radio" name="' . $key . '" id="' . $key . $cValue . '_on" value="' . (int) ($cValue) . '"' . (($cValue == $val) ? ' checked="checked"' : '') . (isset($field['js'][$cValue]) ? ' ' . $field['js'][$cValue] : '') . ' /><label class="t" for="' . $key . $cValue . '_on"> ' . $cKey . '</label><br />';
}
$html .= '<br />';
return $html;
}
/**
* @param array<string, string|array<string>> $field
*/
private function renderSelect(array $field, string $key, string $val): string
{
$html = '<div class="form-group">
<label class="col-lg-3 control-label">' . $field['title'] . '</label>
<div class="col-lg-9">
<select name="' . $key . '">';
foreach ($field['choices'] as $cValue => $cKey) {
$html .= '<option value="' . (int) $cValue . '"'
. (($cValue == $val) ? ' selected' : '')
. '>'
. $cKey
. '</option>';
}
$html .= '</select>
<div class="help-block">' . $field['desc'] . '</div>
</div>
</div>';
return $html;
}
/**
* @param array<string, string|array<string>> $field
*/
private function renderTextarea(array $field, string $key, string $val, bool $disabled): string
{
return '<textarea '
. ($disabled ? 'disabled="disabled"' : '')
. ' name="' . $key
. '" cols="' . $field['cols']
. '" rows="' . $field['rows']
. '">'
. htmlentities($val, ENT_COMPAT, 'UTF-8')
. '</textarea>';
}
/**
* @param array<string, string|array<string>> $field
*/
private function renderTextField(array $field, string $key, string $val, bool $disabled): string
{
return '<input '
. ($disabled ? 'disabled="disabled"' : '')
. ' type="' . $field['type'] . '"'
. (isset($field['id']) ? ' id="' . $field['id'] . '"' : '')
. ' size="' . (isset($field['size']) ? (int) ($field['size']) : 5)
. '" name="' . $key
. '" value="' . ($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8'))
. '" />'
. (isset($field['next']) ? '&nbsp;' . $field['next'] : '');
}
/**
* @param array<string, string|array<string>> $field
*/
private function renderThumb(array $field): string
{
return "<img src=\"{$field['thumb']['file']}\" alt=\"{$field['title']}\" title=\"{$field['title']}\" style=\"float:left;\">";
}
}

View File

@@ -0,0 +1,140 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig\Form;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
class UpgradeOptionsForm
{
/**
* @var array<string, array<string, string>>
*/
private $fields;
/**
* @var Translator
*/
private $translator;
/**
* @var FormRenderer
*/
private $formRenderer;
public function __construct(Translator $translator, FormRenderer $formRenderer)
{
$this->translator = $translator;
$this->formRenderer = $formRenderer;
$this->fields = [
'PS_AUTOUP_PERFORMANCE' => [
'title' => $translator->trans(
'Server performance'
),
'cast' => 'intval',
'validation' => 'isInt',
'defaultValue' => '1',
'type' => 'select', 'desc' => $translator->trans(
'Unless you are using a dedicated server, select "Low".'
) . '<br />' .
$translator->trans(
'A high value can cause the upgrade to fail if your server is not powerful enough to process the upgrade tasks in a short amount of time.'
),
'choices' => [
1 => $translator->trans('Low (recommended)'),
2 => $translator->trans('Medium'),
3 => $translator->trans('High'),
],
],
'PS_AUTOUP_CUSTOM_MOD_DESACT' => [
'title' => $translator->trans('Disable non-native modules'),
'cast' => 'intval',
'validation' => 'isBool',
'type' => 'bool',
'desc' => $translator->trans(
'As non-native modules can experience some compatibility issues, we recommend to disable them by default.') . '<br />' .
$translator->trans('Keeping them enabled might prevent you from loading the "Modules" page properly after the upgrade.'),
],
'PS_DISABLE_OVERRIDES' => [
'title' => $translator->trans('Disable all overrides'),
'cast' => 'intval',
'validation' => 'isBool',
'type' => 'bool',
'desc' => $translator->trans('Enable or disable all classes and controllers overrides.'),
],
'PS_AUTOUP_UPDATE_DEFAULT_THEME' => [
'title' => $translator->trans('Upgrade the default theme'),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '1',
'type' => 'bool',
'desc' => $translator->trans(
'If you customized the default PrestaShop theme in its folder (folder name "classic" in 1.7), enabling this option will lose your modifications.') . '<br />'
. $translator->trans(
'If you are using your own theme, enabling this option will simply update the default theme files, and your own theme will be safe.'),
],
'PS_AUTOUP_CHANGE_DEFAULT_THEME' => [
'title' => $translator->trans('Switch to the default theme'),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '0',
'type' => 'bool',
'desc' => $translator->trans('This will change your theme: your shop will then use the default theme of the version of PrestaShop you are upgrading to.'),
],
'PS_AUTOUP_UPDATE_RTL_FILES' => [
'title' => $translator->trans('Regenerate RTL stylesheet'),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '1',
'type' => 'bool',
'desc' => $translator->trans(
'If enabled, any RTL-specific files that you might have added to all your themes might be deleted by the created stylesheet.'),
],
'PS_AUTOUP_KEEP_MAILS' => [
'title' => $translator->trans('Keep the customized email templates'),
'cast' => 'intval',
'validation' => 'isBool',
'type' => 'bool',
'desc' => $translator->trans('This will not upgrade the default PrestaShop e-mails.') . '<br />'
. $translator->trans('If you customized the default PrestaShop e-mail templates, enabling this option will keep your modifications.'),
],
];
}
public function render(): string
{
return $this->formRenderer->render(
'upgradeOptions',
$this->fields,
$this->translator->trans('Upgrade Options')
);
}
}

View File

@@ -0,0 +1,34 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,63 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
use Twig_Extension;
use Twig_SimpleFilter;
/**
* Filter (Support for Twig 1)
*/
class TransFilterExtension extends Twig_Extension
{
/**
* @var Translator
*/
private $translator;
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
public function getFilters(): array
{
return [
new Twig_SimpleFilter('trans', [$this, 'trans']),
];
}
/**
* @param array<int|string, int|string> $params
*/
public function trans(string $string, array $params = []): string
{
return $this->translator->trans($string, $params);
}
}

View File

@@ -0,0 +1,66 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
namespace PrestaShop\Module\AutoUpgrade\Twig;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
/**
* Filter (Support for Twig 3)
*/
class TransFilterExtension3 extends AbstractExtension
{
/**
* @var Translator
*/
private $translator;
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
/**
* @return TwigFilter[]
*/
public function getFilters(): array
{
return [
new TwigFilter('trans', [$this, 'trans']),
];
}
/**
* @param array<int|string, string> $params
*/
public function trans(string $string, $params = []): string
{
return $this->translator->trans($string, $params);
}
}

View File

@@ -0,0 +1,34 @@
<?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 Academic Free License 3.0 (AFL-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/AFL-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/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;