-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move progress related code to a dedicated class
- Loading branch information
1 parent
da6f226
commit c96da96
Showing
21 changed files
with
176 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?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; | ||
|
||
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; | ||
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreDb; | ||
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreFiles; | ||
use PrestaShop\Module\AutoUpgrade\Task\Rollback\Rollback; | ||
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RollbackComplete; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\BackupDb; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\BackupFiles; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\CleanDatabase; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\Download; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\Unzip; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeComplete; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeDb; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeFiles; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeModules; | ||
use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeNow; | ||
|
||
class CompletionCalculator | ||
{ | ||
/** @var UpgradeConfiguration */ | ||
private $upgradeConfiguration; | ||
|
||
public function __construct(UpgradeConfiguration $upgradeConfiguration) | ||
{ | ||
$this->upgradeConfiguration = $upgradeConfiguration; | ||
} | ||
|
||
/** | ||
* The key baseWithoutBackup exists while the backup and upgrade are on the same workflow | ||
* | ||
* @return array<string, array{base:int, baseWithoutBackup:int|null}> | ||
*/ | ||
private static function getPercentages(): array | ||
{ | ||
return [ | ||
// Upgrade (+ backup) | ||
UpgradeNow::class => ['base' => 0], | ||
Download::class => ['base' => 5, 'baseWithoutBackup' => 10], | ||
Unzip::class => ['base' => 10, 'baseWithoutBackup' => 20], | ||
BackupFiles::class => ['base' => 20], | ||
BackupDb::class => ['base' => 40], | ||
UpgradeFiles::class => ['base' => 50, 'baseWithoutBackup' => 40], | ||
UpgradeDb::class => ['base' => 70, 'baseWithoutBackup' => 60], | ||
UpgradeModules::class => ['base' => 90, 'baseWithoutBackup' => 80], | ||
CleanDatabase::class => ['base' => 100], | ||
UpgradeComplete::class => ['base' => 100], | ||
|
||
// Restore | ||
Rollback::class => ['base' => 0], | ||
RestoreFiles::class => ['base' => 33], | ||
RestoreDb::class => ['base' => 66], | ||
RollbackComplete::class => ['base' => 100], | ||
]; | ||
} | ||
|
||
/** | ||
* @return int<0, 100> | ||
*/ | ||
public function getBasePercentageOfTask(string $taskName): int | ||
{ | ||
$withoutBackup = !$this->upgradeConfiguration->shouldBackupFiles(); | ||
$percentages = self::getPercentages()[$taskName]; | ||
|
||
if ($withoutBackup && $percentages['baseWithoutBackup'] !== null) { | ||
return $percentages['baseWithoutBackup']; | ||
} | ||
|
||
return $percentages['base']; | ||
} | ||
|
||
/** | ||
* @return int<0, 100> | ||
*/ | ||
public function computePercentage(Backlog $backlog, string $currentTaskClass, string $nextTaskClass): int | ||
{ | ||
$currentBaseProgress = $this->getBasePercentageOfTask($currentTaskClass); | ||
$nextBaseProgress = $this->getBasePercentageOfTask($nextTaskClass); | ||
|
||
return $currentBaseProgress + (($nextBaseProgress - $currentBaseProgress) * ($backlog->getInitialTotal() - $backlog->getRemainingTotal()) / $backlog->getInitialTotal()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.