Skip to content

Commit

Permalink
Merge pull request #1160 from Quetzacoalt91/remove-default-initializa…
Browse files Browse the repository at this point in the history
…tion-of-core

Do not initialize in tasks the Core by default, only when requested
  • Loading branch information
Quetzacoalt91 authored Feb 20, 2025
2 parents e7fc2c8 + 1c7ee5d commit f7791dd
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 34 deletions.
18 changes: 0 additions & 18 deletions classes/Task/AbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,8 @@ 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);
}
}

abstract public function run(): int;
Expand Down
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)
);

$updateConfiguration = $this->container->getUpdateConfiguration();
if ($updateConfiguration->isChannelLocal()) {
$archiveXml = $updateConfiguration->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 f7791dd

Please sign in to comment.