Skip to content

Commit

Permalink
Update tmp paths
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Feb 4, 2025
1 parent 94f3197 commit 084c4d6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
18 changes: 9 additions & 9 deletions classes/Task/Update/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Download extends AbstractTask
public function run(): int
{
if (!\ConfigurationTest::test_fopen() && !\ConfigurationTest::test_curl()) {
$this->logger->error($this->translator->trans('You need allow_url_fopen or cURL enabled for automatic download to work. You can also manually upload it in filepath %s.', [$this->container->getFilePath()]));
$this->logger->error($this->translator->trans('You need allow_url_fopen or cURL enabled for automatic download to work. You can also manually upload it in filepath %s.', [$this->container->getArchiveFilePath()]));
$this->next = TaskName::TASK_ERROR;

return ExitCode::FAIL;
Expand All @@ -60,25 +60,25 @@ public function run(): int
);

$this->logger->debug($this->translator->trans('Downloading from %s', [$this->container->getUpgrader()->getOnlineDestinationRelease()->getZipDownloadUrl()]));
$this->logger->debug($this->translator->trans('File will be saved in %s', [$this->container->getFilePath()]));
$this->logger->debug($this->translator->trans('File will be saved in %s', [$this->container->getArchiveFilePath()]));

$downloadPath = $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH);
$releasesDir = $this->container->getProperty(UpgradeContainer::TMP_RELEASES_DIR);

if ($this->container->getFileSystem()->exists($downloadPath)) {
foreach (scandir($downloadPath) as $item) {
if ($this->container->getFileSystem()->exists($releasesDir)) {
foreach (scandir($releasesDir) as $item) {
if ($item !== '.' && $item !== '..') {
$path = $downloadPath . DIRECTORY_SEPARATOR . $item;
$path = $releasesDir . DIRECTORY_SEPARATOR . $item;
$this->container->getFileSystem()->remove($path);
}
}
$this->logger->debug($this->translator->trans('Download directory has been emptied'));
}
$report = '';
$relative_download_path = str_replace(_PS_ROOT_DIR_, '', $downloadPath);
$relative_download_path = str_replace(_PS_ROOT_DIR_, '', $releasesDir);
if (\ConfigurationTest::test_dir($relative_download_path, false, $report)) {
$this->downloadArchive();
} else {
$this->logger->error($this->translator->trans('Download directory %s is not writable.', [$this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH)]));
$this->logger->error($this->translator->trans('Download directory %s is not writable.', [$this->container->getProperty(UpgradeContainer::TMP_RELEASES_DIR)]));
$this->next = TaskName::TASK_ERROR;
}

Expand All @@ -92,7 +92,7 @@ public function run(): int
*/
public function downloadArchive(): void
{
$destPath = realpath($this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH)) . DIRECTORY_SEPARATOR . $this->container->getProperty(UpgradeContainer::ARCHIVE_FILENAME);
$destPath = realpath($this->container->getProperty(UpgradeContainer::TMP_RELEASES_DIR)) . DIRECTORY_SEPARATOR . $this->container->getProperty(UpgradeContainer::ARCHIVE_FILENAME);
$archiveUrl = $this->container->getUpgrader()->getOnlineDestinationRelease()->getZipDownloadUrl();

try {
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Update/Unzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Unzip extends AbstractTask
*/
public function run(): int
{
$filepath = $this->container->getFilePath();
$filepath = $this->container->getArchiveFilePath();
$destExtract = $this->container->getProperty(UpgradeContainer::LATEST_PATH);

$this->container->getUpdateState()->setProgressPercentage(
Expand Down
13 changes: 12 additions & 1 deletion classes/Task/Update/UpdateComplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function run(): int
$this->next = TaskName::TASK_COMPLETE;

$filesystem = $this->container->getFileSystem();
$filePath = $this->container->getFilePath();
$filePath = $this->container->getArchiveFilePath();
$latestPath = $this->container->getProperty(UpgradeContainer::LATEST_PATH);

if ($filesystem->exists($filePath)) {
Expand All @@ -79,6 +79,17 @@ public function run(): int
}

// removing temporary files
$tmpModulePath = $this->container->getProperty(UpgradeContainer::TMP_MODULES_PATH);
if ($this->container->getFileSystem()->exists($tmpModulePath)) {
foreach (scandir($tmpModulePath) as $item) {
if ($item !== '.' && $item !== '..' && $item !== 'index.php') {
$path = $tmpModulePath . DIRECTORY_SEPARATOR . $item;
$this->container->getFileSystem()->remove($path);
}
}
$this->logger->debug($this->translator->trans('The temporary directory of modules has been emptied'));
}

$this->container->getFileStorage()->cleanAllUpdateFiles();
$this->container->getAnalytics()->track('Upgrade Succeeded', Analytics::WITH_UPDATE_PROPERTIES);

Expand Down
4 changes: 2 additions & 2 deletions classes/Task/Update/UpdateModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function run(): int
$modulesPath = $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR;

$moduleSourceList = new ModuleSourceAggregate($this->container->getModuleSourceProviders());
$moduleDownloader = new ModuleDownloader($this->container->getDownloadService(), $this->translator, $this->logger, $this->container->getProperty(UpgradeContainer::TMP_PATH));
$moduleDownloader = new ModuleDownloader($this->container->getDownloadService(), $this->translator, $this->logger, $this->container->getProperty(UpgradeContainer::TMP_MODULES_DIR));
$moduleUnzipper = new ModuleUnzipper($this->translator, $this->container->getZipAction(), $modulesPath);
$moduleMigration = new ModuleMigration($this->container->getFileSystem(), $this->translator, $this->logger, $this->container->getProperty(UpgradeContainer::TMP_PATH));
$moduleMigration = new ModuleMigration($this->container->getFileSystem(), $this->translator, $this->logger, $this->container->getProperty(UpgradeContainer::TMP_MODULES_DIR));

if ($listModules->getRemainingTotal()) {
$moduleInfos = $listModules->getNext();
Expand Down
51 changes: 33 additions & 18 deletions classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@
*/
class UpgradeContainer
{
const WORKSPACE_PATH = 'workspace'; // AdminSelfUpgrade::$autoupgradePath
const WORKSPACE_PATH = 'workspace';
const BACKUP_PATH = 'backup';
const DOWNLOAD_PATH = 'download';
const LATEST_PATH = 'latest'; // AdminSelfUpgrade::$latestRootDir
const LATEST_PATH = 'latest';
const LATEST_DIR = 'latest/';
const LOGS_PATH = 'logs';
const TMP_PATH = 'tmp';
const TMP_MODULES_PATH = 'modules';
const TMP_MODULES_DIR = 'modules/';
const TMP_RELEASES_DIR = 'releases/';
const PS_ADMIN_PATH = 'ps_admin';
const PS_ADMIN_SUBDIR = 'ps_admin_subdir';
const PS_ROOT_PATH = 'ps_root'; // AdminSelfUpgrade::$prodRootDir
const PS_ROOT_PATH = 'ps_root';
const ARCHIVE_FILENAME = 'destDownloadFilename';
const ARCHIVE_FILEPATH = 'destDownloadFilepath';
const PS_VERSION = 'version';
Expand Down Expand Up @@ -275,25 +278,45 @@ public function getProperty(string $property): ?string
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'backup';
case self::DOWNLOAD_PATH:
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'download';
case self::LATEST_PATH:
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'latest';
case self::LATEST_DIR:
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'latest' . DIRECTORY_SEPARATOR;
case self::TMP_PATH:
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'tmp';
case self::TMP_MODULES_PATH:
return $this->getProperty(self::TMP_PATH) . DIRECTORY_SEPARATOR . 'modules';
case self::TMP_MODULES_DIR:
return $this->getProperty(self::TMP_MODULES_PATH) . DIRECTORY_SEPARATOR;
case self::TMP_RELEASES_DIR:
return $this->getProperty(self::TMP_PATH) . DIRECTORY_SEPARATOR . 'releases' . DIRECTORY_SEPARATOR;
case self::LATEST_PATH:
return $this->getProperty(self::TMP_PATH) . DIRECTORY_SEPARATOR . 'latest';
case self::LATEST_DIR:
return $this->getProperty(self::LATEST_PATH) . DIRECTORY_SEPARATOR;
case self::LOGS_PATH:
return $this->autoupgradeWorkDir . DIRECTORY_SEPARATOR . 'logs';
case self::ARCHIVE_FILENAME:
return $this->getUpdateConfiguration()->getChannelZip();
case self::ARCHIVE_FILEPATH:
return $this->getProperty(self::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $this->getProperty(self::ARCHIVE_FILENAME);
return $this->getArchiveFilePath();
case self::PS_VERSION:
return $this->getPrestaShopConfiguration()->getPrestaShopVersion();
default:
return '';
}
}

/**
* @throws Exception
*/
public function getArchiveFilePath(): ?string
{
$fileName = $this->getProperty(self::ARCHIVE_FILENAME);

if ($this->getUpdateConfiguration()->isChannelLocal()) {
return $this->getProperty(self::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $fileName;
}

return $this->getProperty(self::TMP_RELEASES_DIR) . $fileName;
}

public function getAnalytics(): Analytics
{
if (null === $this->analytics) {
Expand Down Expand Up @@ -395,16 +418,6 @@ public function getDb(): \Db
return \Db::getInstance();
}

/**
* Return the path to the zipfile containing prestashop.
*
* @throws Exception
*/
public function getFilePath(): string
{
return $this->getProperty(self::ARCHIVE_FILEPATH);
}

public function getFileStorage(): FileStorage
{
if (null === $this->fileStorage) {
Expand Down Expand Up @@ -807,6 +820,8 @@ public function getWorkspace(): Workspace
self::LATEST_PATH,
self::LOGS_PATH,
self::TMP_PATH,
self::TMP_MODULES_DIR,
self::TMP_RELEASES_DIR,
];

foreach ($properties as $property) {
Expand Down

0 comments on commit 084c4d6

Please sign in to comment.