Skip to content

Commit

Permalink
Merge pull request #865 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Prepare release of v6.1.0 of autoupgrade module
  • Loading branch information
Quetzacoalt91 authored Sep 3, 2024
2 parents 7c7c84d + 6b3ed43 commit 1d55a5a
Show file tree
Hide file tree
Showing 113 changed files with 7,234 additions and 6,418 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
CAMPAIGN: 'autoupgrade'
jobs:
ui_test_matrix:
if: github.event.pull_request.draft == false
name: UI Tests (Matrix)
runs-on: ubuntu-latest
env:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ concurrency:
cancel-in-progress: true
jobs:
upgrade:
if: github.event.pull_request.draft == false
strategy:
matrix:
from: ['1.7.0.6', '1.7.6.9', '1.7.6.1', '1.7.7.0', '8.0.0', '8.1.0']
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('vendor');
->exclude('vendor')
->exclude('node_modules');

return $config;
7 changes: 5 additions & 2 deletions autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
$this->name = 'autoupgrade';
$this->tab = 'administration';
$this->author = 'PrestaShop';
$this->version = '6.0.0';
$this->version = '6.1.0';
$this->need_instance = 1;
$this->module_key = '926bc3e16738b7b834f37fc63d59dcf8';

Expand Down Expand Up @@ -184,7 +184,10 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
{
require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/classes/UpgradeTools/Translator.php';

$translator = new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator();
$translator = new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator(
_PS_ROOT_DIR_ . 'modules' . DIRECTORY_SEPARATOR . 'autoupgrade' . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR,
\Context::getContext()->language->iso_code
);

return $translator->trans($id, $parameters);
}
Expand Down
5 changes: 2 additions & 3 deletions classes/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function track($event, $propertiesType = self::WITH_COMMON_PROPERTIES)
}

\Segment::track(array_merge(
['event' => $event],
['event' => '[SUE] ' . $event],
$this->getProperties($propertiesType)
));
\Segment::flush();
Expand All @@ -116,8 +116,7 @@ public function getProperties($type)
'from_ps_version' => $this->state->getOriginVersion(),
'to_ps_version' => $this->state->getInstallVersion(),
'upgrade_channel' => $this->upgradeConfiguration->getChannel(),
'backup_files_and_databases' => $this->upgradeConfiguration->get('PS_AUTOUP_BACKUP')
|| !$this->upgradeConfiguration->get('skip_backup'),
'backup_files_and_databases' => $this->upgradeConfiguration->shouldBackupFilesAndDatabase(),
'backup_images' => $this->upgradeConfiguration->shouldBackupImages(),
'server_performance' => $this->upgradeConfiguration->getPerformanceLevel(),
'disable_non_native_modules' => $this->upgradeConfiguration->shouldDeactivateCustomModules(),
Expand Down
64 changes: 58 additions & 6 deletions classes/Parameters/UpgradeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

namespace PrestaShop\Module\AutoUpgrade\Parameters;

use Configuration;
use Doctrine\Common\Collections\ArrayCollection;
use Shop;

/**
* Contains the module configuration (form params).
Expand All @@ -36,12 +38,35 @@
*/
class UpgradeConfiguration extends ArrayCollection
{
const UPGRADE_CONST_KEYS = [
'PS_AUTOUP_PERFORMANCE',
'PS_AUTOUP_CUSTOM_MOD_DESACT',
'PS_AUTOUP_UPDATE_DEFAULT_THEME',
'PS_AUTOUP_CHANGE_DEFAULT_THEME',
'PS_AUTOUP_UPDATE_RTL_FILES',
'PS_AUTOUP_KEEP_MAILS',
'PS_AUTOUP_BACKUP',
'PS_AUTOUP_KEEP_IMAGES',
'PS_DISABLE_OVERRIDES',
];

const PS_CONST_DEFAULT_VALUE = [
'PS_AUTOUP_PERFORMANCE' => 1,
'PS_AUTOUP_CUSTOM_MOD_DESACT' => 1,
'PS_AUTOUP_UPDATE_DEFAULT_THEME' => 1,
'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 0,
'PS_AUTOUP_UPDATE_RTL_FILES' => 1,
'PS_AUTOUP_KEEP_MAILS' => 0,
'PS_AUTOUP_BACKUP' => 1,
'PS_AUTOUP_KEEP_IMAGES' => 1,
];

/**
* Performance settings, if your server has a low memory size, lower these values.
*
* @var array<string, int[]>
*/
protected $performanceValues = [
private const PERFORMANCE_VALUES = [
'loopFiles' => [400, 800, 1600], // files
'loopTime' => [6, 12, 25], // seconds
'maxBackupFileSize' => [15728640, 31457280, 62914560], // bytes
Expand Down Expand Up @@ -77,31 +102,31 @@ public function getChannel(): string
*/
public function getNumberOfFilesPerCall(): int
{
return $this->performanceValues['loopFiles'][$this->getPerformanceLevel()];
return $this::PERFORMANCE_VALUES['loopFiles'][$this->getPerformanceLevel()];
}

/**
* @return int Number of seconds allowed before having to make another request
*/
public function getTimePerCall(): int
{
return $this->performanceValues['loopTime'][$this->getPerformanceLevel()];
return $this::PERFORMANCE_VALUES['loopTime'][$this->getPerformanceLevel()];
}

/**
* @return int Kind of reference for SQL file creation, giving a file size before another request is needed
*/
public function getMaxSizeToWritePerCall(): int
{
return $this->performanceValues['maxWrittenAllowed'][$this->getPerformanceLevel()];
return $this::PERFORMANCE_VALUES['maxWrittenAllowed'][$this->getPerformanceLevel()];
}

/**
* @return int Max file size allowed in backup
*/
public function getMaxFileToBackup(): int
{
return $this->performanceValues['maxBackupFileSize'][$this->getPerformanceLevel()];
return $this::PERFORMANCE_VALUES['maxBackupFileSize'][$this->getPerformanceLevel()];
}

/**
Expand All @@ -112,8 +137,13 @@ public function getPerformanceLevel(): int
return $this->get('PS_AUTOUP_PERFORMANCE') - 1;
}

public function shouldBackupFilesAndDatabase(): bool
{
return (bool) $this->get('PS_AUTOUP_BACKUP');
}

/**
* @return bool True if the autoupgrade module should backup the images as well
* @return bool True if the autoupgrade module backup should include the images
*/
public function shouldBackupImages(): bool
{
Expand Down Expand Up @@ -160,6 +190,28 @@ public function shouldUpdateRTLFiles(): bool
return (bool) $this->get('PS_AUTOUP_UPDATE_RTL_FILES');
}

public static function isOverrideAllowed(): bool
{
return (bool) Configuration::get('PS_DISABLE_OVERRIDES');
}

public static function updateDisabledOverride(bool $value, ?int $shopId = null): void
{
if ($shopId) {
Configuration::updateValue('PS_DISABLE_OVERRIDES', $value, false, null, (int) $shopId);
} else {
Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', $value);
}
}

public static function updatePSDisableOverrides(bool $value): void
{
foreach (Shop::getCompleteListOfShopsID() as $id_shop) {
self::updateDisabledOverride($value, $id_shop);
}
self::updateDisabledOverride($value);
}

/**
* @param array<string, mixed> $array
*
Expand Down
14 changes: 3 additions & 11 deletions classes/Parameters/UpgradeConfigurationStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function load(string $fileName = ''): UpgradeConfiguration
}

/**
* @param \PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration $config
* @param UpgradeConfiguration $config
* @param string $fileName Destination path of the config file
*/
public function save($config, string $fileName): bool
Expand All @@ -59,17 +59,9 @@ public function save($config, string $fileName): bool
*/
public function getDefaultData(): array
{
return [
'PS_AUTOUP_PERFORMANCE' => 1,
'PS_AUTOUP_CUSTOM_MOD_DESACT' => 1,
'PS_AUTOUP_UPDATE_DEFAULT_THEME' => 1,
'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 0,
'PS_AUTOUP_UPDATE_RTL_FILES' => 1,
'PS_AUTOUP_KEEP_MAILS' => 0,
'PS_AUTOUP_BACKUP' => 1,
'PS_AUTOUP_KEEP_IMAGES' => 1,
return array_merge(UpgradeConfiguration::PS_CONST_DEFAULT_VALUE, [
'channel' => Upgrader::DEFAULT_CHANNEL,
'archive.filename' => Upgrader::DEFAULT_FILENAME,
];
]);
}
}
91 changes: 91 additions & 0 deletions classes/Progress/Backlog.php
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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 <[email protected]>
* @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\Progress;

class Backlog
{
/**
* Number of elements in backlog at the beginning
*
* @var int
*/
private $initialTotal;

/**
* Remaining backlog of elements
*
* @var mixed[]
*/
private $backlog;

/**
* @param mixed[] $backlog
*/
public function __construct(array $backlog, int $initialTotal)
{
$this->backlog = $backlog;
$this->initialTotal = $initialTotal;
}

/**
* @param array{'backlog':mixed[],'initialTotal':int} $contents
*/
public static function fromContents($contents): self
{
return new self($contents['backlog'], $contents['initialTotal']);
}

/**
* @return array{'backlog':mixed[],'initialTotal':int}
*/
public function dump(): array
{
return [
'backlog' => $this->backlog,
'initialTotal' => $this->initialTotal,
];
}

/**
* @return mixed
*/
public function getNext()
{
return array_pop($this->backlog);
}

public function getRemainingTotal(): int
{
return count($this->backlog);
}

public function getInitialTotal(): int
{
return $this->initialTotal;
}
}
Loading

0 comments on commit 1d55a5a

Please sign in to comment.