Skip to content

Commit

Permalink
Merge pull request #813 from ga-devfront/enchancement/add-throw-error
Browse files Browse the repository at this point in the history
enchancement: Change the logger to throw exception and silent mkdir
  • Loading branch information
Quetzacoalt91 authored Aug 5, 2024
2 parents a28b828 + caa8b52 commit d275474
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ public function getWorkspace(): Workspace
}

$this->workspace = new Workspace(
$this->getLogger(),
$this->getTranslator(),
$paths
);
Expand Down
16 changes: 5 additions & 11 deletions classes/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@

namespace PrestaShop\Module\AutoUpgrade;

use PrestaShop\Module\AutoUpgrade\Log\LoggerInterface;
use Exception;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;

class Workspace
{
/**
* @var LoggerInterface
*/
private $logger;

/**
* @var Translator
*/
Expand All @@ -50,21 +45,20 @@ class Workspace
/**
* @param string[] $paths
*/
public function __construct(LoggerInterface $logger, Translator $translator, array $paths)
public function __construct(Translator $translator, array $paths)
{
$this->logger = $logger;
$this->translator = $translator;
$this->paths = $paths;
}

public function createFolders(): void
{
foreach ($this->paths as $path) {
if (!file_exists($path) && !mkdir($path)) {
$this->logger->error($this->translator->trans('Unable to create directory %s', [$path]));
if (!file_exists($path) && !@mkdir($path)) {
throw new Exception($this->translator->trans('Unable to create directory %s', [$path]));
}
if (!is_writable($path)) {
$this->logger->error($this->translator->trans('Unable to write in the directory "%s"', [$path]));
throw new Exception($this->translator->trans('Cannot write to the directory. Please ensure you have the necessary write permissions on "%s".', [$path]));
}
}
}
Expand Down

0 comments on commit d275474

Please sign in to comment.