Skip to content

Commit

Permalink
Add various types
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Jun 19, 2024
1 parent 7ac6fee commit fb77d6b
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 50 deletions.
1 change: 1 addition & 0 deletions classes/Services/DistributionApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DistributionApiService

/**
* @throws DistributionApiException
* @return array<string, string>
*/
public function getPhpVersionRequirements(string $targetVersion): array
{
Expand Down
76 changes: 50 additions & 26 deletions classes/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,61 @@
*/
class State
{
/**
* @var string
*/
private $install_version; // Destination version of PrestaShop
/**
* @var string
*/
private $backupName;
/**
* @var string
*/
private $backupFilesFilename;
/**
* @var string
*/
private $backupDbFilename;
/**
* @var string
*/
private $restoreName;
/**
* @var string
*/
private $restoreFilesFilename;
/**
* @var string[]
*/
private $restoreDbFilenames = [];

// STEP BackupDb
/**
* @var string[]
*/
private $backup_lines;
/**
* @var int
*/
private $backup_loop_limit;
/**
* @var string
*/
private $backup_table;

/**
* Int during BackupDb, allowing the script to increent the number of different file names
* String during step RestoreDb, which contains the file to process (Data coming from toRestoreQueryList).
*
* @var string|int Contains the SQL progress
* @var int Contains the SQL progress
*/
private $dbStep = 0;

/**
* Data filled in upgrade warmup, to avoid risky tasks during the process.
*
* @var array|null File containing sample files to be deleted
*/
private $removeList;
/**
* installedLanguagesIso is an array of iso_code of each installed languages.
*
* @var array
* @var string[]
*/
private $installedLanguagesIso = [];
/**
Expand All @@ -84,7 +108,7 @@ class State
private $warning_exists = false;

/**
* @param array $savedState from another request
* @param array<string, mixed> $savedState from another request
*/
public function importFromArray(array $savedState): State
{
Expand All @@ -108,7 +132,7 @@ public function importFromEncodedData(string $encodedData): State
}

/**
* @return array of class properties for export
* @return array<string, mixed> of class properties for export
*/
public function export(): array
{
Expand Down Expand Up @@ -172,6 +196,9 @@ public function getBackupDbFilename(): string
return $this->backupDbFilename;
}

/**
* @return string[]|null
*/
public function getBackupLines(): ?array
{
return $this->backup_lines;
Expand All @@ -187,16 +214,11 @@ public function getBackupTable(): ?string
return $this->backup_table;
}

public function getDbStep()
public function getDbStep(): int
{
return $this->dbStep;
}

public function getRemoveList(): ?array
{
return $this->removeList;
}

public function getRestoreName(): string
{
return $this->restoreName;
Expand All @@ -207,6 +229,9 @@ public function getRestoreFilesFilename(): ?string
return $this->restoreFilesFilename;
}

/**
* @return string[]
*/
public function getRestoreDbFilenames(): array
{
return $this->restoreDbFilenames;
Expand Down Expand Up @@ -268,6 +293,9 @@ public function setBackupDbFilename(string $backupDbFilename): State
return $this;
}

/**
* @param string[]|null $backup_lines
*/
public function setBackupLines(?array $backup_lines): State
{
$this->backup_lines = $backup_lines;
Expand All @@ -289,21 +317,14 @@ public function setBackupTable(?string $backup_table): State
return $this;
}

public function setDbStep($dbStep): State
public function setDbStep(int $dbStep): State
{
$this->dbStep = $dbStep;

return $this;
}

public function setRemoveList(?array $removeList): State
{
$this->removeList = $removeList;

return $this;
}

public function setRestoreName($restoreName): State
public function setRestoreName(string $restoreName): State
{
$this->restoreName = $restoreName;

Expand All @@ -317,6 +338,9 @@ public function setRestoreFilesFilename(string $restoreFilesFilename): State
return $this;
}

/**
* @param string[] $restoreDbFilenames
*/
public function setRestoreDbFilenames(array $restoreDbFilenames): State
{
$this->restoreDbFilenames = $restoreDbFilenames;
Expand All @@ -335,7 +359,7 @@ public function setInstalledLanguagesIso(array $installedLanguagesIso): State
}

/**
* @param array<string, string> $module_addons Key is the module ID on Addons
* @param array<string, string> $modules_addons Key is the module ID on Addons
*/
public function setModulesAddons(array $modules_addons): State
{
Expand Down
26 changes: 22 additions & 4 deletions classes/TaskRunner/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@

abstract class AbstractTask
{
/* usage : key = the step you want to skip
* value = the next step you want instead
* example : public static $skipAction = array();
/**
* usage : key = the step you want to skip
* value = the next step you want instead
* example : public static $skipAction = array();
*
* @var array<string, string>
*/
public static $skipAction = [];

Expand All @@ -56,10 +59,25 @@ abstract class AbstractTask
protected $container;

// Task progress details
/**
* @var bool
*/
protected $stepDone;
/**
* @var string
*/
protected $status;
/**
* @var bool
*/
protected $error;
/**
* @var array<string, string|array<string>>
*/
protected $nextParams = [];
/**
* @var string
*/
protected $next;

/**
Expand Down Expand Up @@ -105,7 +123,7 @@ public function getResponse(): AjaxResponse
->setUpgradeConfiguration($this->container->getUpgradeConfiguration());
}

private function checkTaskMayRun()
private function checkTaskMayRun(): void
{
// PrestaShop demo mode
if (defined('_PS_MODE_DEMO_') && _PS_MODE_DEMO_ == true) {
Expand Down
7 changes: 5 additions & 2 deletions classes/TaskRunner/ChainedTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
*/
abstract class ChainedTasks extends AbstractTask
{
/**
* @var string
*/
protected $step;

/**
Expand Down Expand Up @@ -67,9 +70,9 @@ public function run(): int
/**
* Customize the execution context with several options.
*
* @param array $options
* @param array<string, string> $options
*/
abstract public function setOptions(array $options);
abstract public function setOptions(array $options): void;

/**
* Tell the while loop if it can continue.
Expand Down
4 changes: 1 addition & 3 deletions classes/TaskRunner/Miscellaneous/CheckFilesVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function run(): int
}

foreach (['core', 'translation', 'mail'] as $type) {
if (!isset($changedFileList[$type])) {
$changedFileList[$type] = [];
}
$changedFileList[$type] = [];
}

if ($checksumCompare->isAuthenticPrestashopVersion($currentPrestaShopVersion)) {
Expand Down
22 changes: 17 additions & 5 deletions classes/TaskRunner/Miscellaneous/UpdateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UpdateConfig extends AbstractTask
/**
* Data being passed by CLI entry point
*
* @var array
* @var array<string, mixed>
*/
protected $cliParameters;

Expand Down Expand Up @@ -128,12 +128,18 @@ public function run(): int
return ExitCode::SUCCESS;
}

public function inputCliParameters($parameters)
/**
* @param array<string, mixed> $parameters
*/
public function inputCliParameters($parameters): void
{
$this->cliParameters = $parameters;
}

protected function getConfigurationData()
/**
* @return array<string, mixed>
*/
protected function getConfigurationData(): array
{
if (null !== $this->cliParameters) {
return $this->getCLIParams();
Expand All @@ -142,6 +148,9 @@ protected function getConfigurationData()
return $this->getRequestParams();
}

/**
* @return array<string, mixed>
*/
protected function getCLIParams(): array
{
if (empty($this->cliParameters)) {
Expand All @@ -151,15 +160,18 @@ protected function getCLIParams(): array
return $this->cliParameters;
}

protected function getRequestParams()
/**
* @return array<string, mixed>
*/
protected function getRequestParams(): array
{
return empty($_REQUEST['params']) ? [] : $_REQUEST['params'];
}

/**
* update module configuration (saved in file UpgradeFiles::configFilename) with $new_config.
*
* @param array $config
* @param array<string, mixed> $config
*
* @return bool true if success
*
Expand Down
5 changes: 4 additions & 1 deletion classes/TaskRunner/Rollback/AllRollbackTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class AllRollbackTasks extends ChainedTasks
{
const initialTask = 'rollback';

/**
* @var string
*/
protected $step = self::initialTask;

/**
Expand All @@ -44,7 +47,7 @@ class AllRollbackTasks extends ChainedTasks
* > channel: Makes a specific upgrade (minor, major etc.)
* > data: Loads an encoded array of data coming from another request.
*
* @param array $options
* @param array<string, string> $options
*/
public function setOptions(array $options): void
{
Expand Down
2 changes: 1 addition & 1 deletion classes/TaskRunner/Rollback/RestoreDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function run(): int

return ExitCode::FAIL;
}
$this->container->getState()->setDbStep($match[1]);
$this->container->getState()->setDbStep((int) $match[1]);
$backupdb_path = $this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getState()->getRestoreName();

$dot_pos = strrpos($currentDbFilename, '.');
Expand Down
2 changes: 1 addition & 1 deletion classes/TaskRunner/Upgrade/BackupDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function run(): int
fclose($fp);
}
$backupfile = $this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getState()->getBackupName() . DIRECTORY_SEPARATOR . $this->container->getState()->getBackupDbFilename();
$backupfile = preg_replace('#_XXXXXX_#', '_' . str_pad($this->container->getState()->getDbStep(), 6, '0', STR_PAD_LEFT) . '_', $backupfile);
$backupfile = preg_replace('#_XXXXXX_#', '_' . str_pad(strval($this->container->getState()->getDbStep()), 6, '0', STR_PAD_LEFT) . '_', $backupfile);

// start init file
// Figure out what compression is available and open the file
Expand Down
2 changes: 0 additions & 2 deletions classes/TaskRunner/Upgrade/Unzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public function run(): int
}
}

// Unsetting to force listing
$this->container->getState()->setRemoveList(null);
$this->next = 'backupFiles';
$this->logger->info($this->translator->trans('File extraction complete. Now backing up files...'));

Expand Down
2 changes: 1 addition & 1 deletion classes/UpgradeSelfCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class UpgradeSelfCheck
private $maxExecutionTime;

/**
* @var array
* @var array<string, string>
*/
private $phpCompatibilityRange;

Expand Down
Loading

0 comments on commit fb77d6b

Please sign in to comment.