Skip to content

Commit

Permalink
Update admin controller
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Jan 21, 2025
1 parent 509f07e commit 1e18979
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
2 changes: 2 additions & 0 deletions classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
use PrestaShop\Module\AutoUpgrade\Xml\ChecksumCompare;
use PrestaShop\Module\AutoUpgrade\Xml\FileLoader;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Filesystem\Filesystem;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Loader\FilesystemLoader;
Expand Down Expand Up @@ -862,6 +863,7 @@ public function getWorkspace(): Workspace

$this->workspace = new Workspace(
$this->getTranslator(),
new Filesystem(),
$paths
);
}
Expand Down
37 changes: 18 additions & 19 deletions classes/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,28 @@

use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;

class Workspace
{
/**
* @var Translator
*/
/** @var Translator */
private $translator;

/**
* @var string[] List of paths used by autoupgrade
*/
private $paths;

/** @var Filesystem */
private $filesystem;

/**
* @param string[] $paths
*/
public function __construct(Translator $translator, array $paths)
public function __construct(Translator $translator, Filesystem $filesystem, array $paths)
{
$this->translator = $translator;
$this->filesystem = $filesystem;
$this->paths = $paths;
}

Expand All @@ -71,10 +74,8 @@ public function createFolders(): void
public function createPhpIndex(string $directoryPath): void
{
$filePath = $directoryPath . DIRECTORY_SEPARATOR . 'index.php';
if (!file_exists($filePath)) {
if (!copy(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'index.php', $filePath)) {
throw new IOException($this->translator->trans('Unable to create file %s', [$filePath]));
}
if (!$this->filesystem->exists($filePath)) {
$this->filesystem->copy(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'index.php', $filePath);
}
}

Expand All @@ -84,29 +85,27 @@ public function createPhpIndex(string $directoryPath): void
public function createHtAccess(string $modulePath): void
{
$filePath = $modulePath . DIRECTORY_SEPARATOR . '.htaccess';
$content = <<<HTACCESS

if (!$this->filesystem->exists($filePath)) {
$content = <<<HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine On
# Si on accède au dossier "log", on autorise l'accès
RewriteCond %{REQUEST_URI} ^/log/ [NC]
RewriteRule ^ - [L]
# Sinon, on interdit l'accès
RewriteCond %{REQUEST_URI} ^.*/autoupgrade/logs/ [NC]
RewriteCond %{REQUEST_URI} !\.txt$ [NC]
RewriteRule ^ - [F]
RewriteRule ^ - [L]
</IfModule>
HTACCESS;
if (!file_exists($filePath)) {
if (!file_put_contents($filePath, $content)) {
throw new IOException($this->translator->trans('Unable to create file %s', [$filePath]));
}
$this->filesystem->dumpFile($filePath, $content);
}
}

/**
* @throws IOException
*/
public function init($modulePath): void
public function init(string $modulePath): void
{
$this->createFolders();
$this->createHtAccess($modulePath);
Expand Down
16 changes: 2 additions & 14 deletions controllers/admin/AdminSelfUpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,6 @@ public function init()
$this->upgradeContainer->getFileStorage()->cleanAllBackupFiles();
$this->upgradeContainer->getFileStorage()->cleanAllRestoreFiles();

// TODO: Can be removed when the old UI is not needed anymore
if (!$this->upgradeContainer->getUpdateState()->isInitialized()) {
$this->upgradeContainer->getPrestaShopConfiguration()->fillInUpdateConfiguration(
$this->upgradeContainer->getUpdateConfiguration()
);
$this->upgradeContainer->getUpdateState()->initDefault(
$this->upgradeContainer->getProperty(UpgradeContainer::PS_VERSION),
$this->upgradeContainer->getUpgrader(),
$this->upgradeContainer->getUpdateConfiguration()
);
}

// If you have defined this somewhere, you know what you do
// load options from configuration if we're not in ajax mode
if (!$this->ajax) {
Expand Down Expand Up @@ -313,7 +301,7 @@ public function initContent()
'autoupgrade_variables' => $this->getScriptsVariables(),
]);
$request = Request::createFromGlobals();
$this->addNewUIAssets($request);
$this->addUIAssets($request);

$response = (new Router($this->upgradeContainer))->handle($request);

Expand Down Expand Up @@ -349,7 +337,7 @@ private function getScriptsVariables()
*
* @return void
*/
private function addNewUIAssets(Request $request)
private function addUIAssets(Request $request)
{
$assetsEnvironment = $this->upgradeContainer->getAssetsEnvironment();
$assetsBaseUrl = $assetsEnvironment->getAssetsBaseUrl($request);
Expand Down

0 comments on commit 1e18979

Please sign in to comment.