Skip to content

Commit

Permalink
Do not initialize in tasks the Core by default, only when requested
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Feb 5, 2025
1 parent 45aed49 commit e8192e3
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 37 deletions.
22 changes: 1 addition & 21 deletions classes/Task/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,7 @@ public function setErrorFlag(): void
}
}

/**
* @throws Exception
*/
public function init(): void
{
$this->container->initPrestaShopCore();
$this->setupEnvironment();
}

/**
* @throws Exception
*/
protected function setupEnvironment(): void
{
$updateConfiguration = $this->container->getUpdateConfiguration();

if ($this::TASK_TYPE === TaskType::TASK_TYPE_UPDATE && $updateConfiguration->isChannelLocal()) {
$archiveXml = $updateConfiguration->getLocalChannelXml();
$this->container->getFileLoader()->addXmlMd5File($this->container->getUpgrader()->getDestinationVersion(), $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $archiveXml);
}
}
public function init(): void {}

abstract public function run(): int;
}
8 changes: 8 additions & 0 deletions classes/Task/Backup/BackupDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class BackupDatabase extends AbstractTask

const MAX_SIZE_PER_INSERT_STMT = 950000;

/**
* @throws Exception
*/
public function init(): void
{
$this->container->initPrestaShopCore();
}

/**
* @throws Exception
*/
Expand Down
5 changes: 0 additions & 5 deletions classes/Task/Restore/RestoreFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,4 @@ public function run(): int

return ExitCode::SUCCESS;
}

public function init(): void
{
// Do nothing
}
}
5 changes: 0 additions & 5 deletions classes/Task/Restore/RestoreInitialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,4 @@ public function run(): int

return ExitCode::SUCCESS;
}

public function init(): void
{
// Do nothing
}
}
9 changes: 9 additions & 0 deletions classes/Task/Update/CleanDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace PrestaShop\Module\AutoUpgrade\Task\Update;

use Exception;
use PrestaShop\Module\AutoUpgrade\Task\AbstractTask;
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
use PrestaShop\Module\AutoUpgrade\Task\TaskName;
Expand Down Expand Up @@ -53,4 +54,12 @@ public function run(): int

return ExitCode::SUCCESS;
}

/**
* @throws Exception
*/
public function init(): void
{
$this->container->initPrestaShopCore();
}
}
8 changes: 8 additions & 0 deletions classes/Task/Update/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class Download extends AbstractTask
{
const TASK_TYPE = TaskType::TASK_TYPE_UPDATE;

/**
* @throws Exception
*/
public function init(): void
{
$this->container->initPrestaShopCore();
}

/**
* @throws Exception
*/
Expand Down
8 changes: 8 additions & 0 deletions classes/Task/Update/Unzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class Unzip extends AbstractTask
{
const TASK_TYPE = TaskType::TASK_TYPE_UPDATE;

/**
* @throws Exception
*/
public function init(): void
{
$this->container->initPrestaShopCore();
}

/**
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Update/UpdateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function init(): void

// Migrating settings file
$this->container->initPrestaShopAutoloader();
parent::init();
$this->container->initPrestaShopCore();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions classes/Task/Update/UpdateFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ protected function warmUp(): int
$this->container->getCompletionCalculator()->getBasePercentageOfTask(self::class)
);

$archiveXml = $this->container->getUpdateConfiguration()->getLocalChannelXml();
$this->container->getFileLoader()->addXmlMd5File(
$this->container->getUpgrader()->getDestinationVersion(),
$this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $archiveXml
);

// Get path to the folder with release we will use to upgrade and check if it's valid
$newReleasePath = $this->container->getProperty(UpgradeContainer::LATEST_PATH);
if (!$this->container->getFilesystemAdapter()->isReleaseValid($newReleasePath)) {
Expand Down Expand Up @@ -274,9 +280,4 @@ protected function warmUp(): int

return ExitCode::SUCCESS;
}

public function init(): void
{
$this->setupEnvironment();
}
}
8 changes: 8 additions & 0 deletions classes/Task/Update/UpdateModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ public function warmUp(): int
return ExitCode::SUCCESS;
}

/**
* @throws Exception
*/
public function init(): void
{
$this->container->initPrestaShopCore();
}

private function handleException(UpgradeException $e): void
{
if ($e->getSeverity() === UpgradeException::SEVERITY_ERROR) {
Expand Down

0 comments on commit e8192e3

Please sign in to comment.