Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ public function hookDisplayBackOfficeHeader()
return '';
}

return (new \PrestaShop\Module\AutoUpgrade\Hooks\DisplayBackOfficeHeader($this->getUpgradeContainer()))->renderUpdateNotification();
return (new \PrestaShop\Module\AutoUpgrade\Hooks\DisplayBackOfficeHeader(
$this->getUpgradeContainer(),
$this->getCurrentRequest()
))->renderUpdateNotification();
}

/**
Expand Down Expand Up @@ -268,4 +271,26 @@ public function getUpgradeContainer()

return $this->container;
}

/**
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getCurrentRequest()
{
// When possible, retrieve an existing instance of Request to avoid issues on pages with uploaded files.
// We are compatible with PS 1.7.0 BUT:
// - Module::get() exists since PS 1.7.3.
// - Service "request_stack" is found from PS 8.
if (version_compare(_PS_VERSION_, '8.0.0', '>=')) {
/** @var \Symfony\Component\HttpFoundation\RequestStack $requestStack */
$requestStack = $this->get('request_stack');
$request = $requestStack->getCurrentRequest();

if ($request) {
return $request;
}
}

return \Symfony\Component\HttpFoundation\Request::createFromGlobals();
}
}
11 changes: 8 additions & 3 deletions classes/Hooks/DisplayBackOfficeHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class DisplayBackOfficeHeader
*/
private $container;

/**
* @var Request
*/
private $request;

/**
* @var Upgrader
*/
Expand Down Expand Up @@ -93,9 +98,10 @@ class DisplayBackOfficeHeader
/**
* @throws Exception
*/
public function __construct(UpgradeContainer $container)
public function __construct(UpgradeContainer $container, Request $request)
{
$this->container = $container;
$this->request = $request;
$this->upgrader = $this->container->getUpgrader();
$this->updateNotificationService = $this->container->getUpdateNotificationService();
$this->updateNotificationConfiguration = $this->updateNotificationService->getUpdateNotificationConfiguration();
Expand Down Expand Up @@ -129,8 +135,7 @@ public function renderUpdateNotification(): string

$this->addScriptsVariables();

$request = Request::createFromGlobals();
$this->addUIAssets($request);
$this->addUIAssets($this->request);

if (!$this->isEmployeeDefaultController()) {
return $this->content;
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminSelfUpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function initContent()
$this->content = $this->upgradeContainer->getTwig()->render('@ModuleAutoUpgrade/module-script-variables.html.twig', [
'autoupgrade_variables' => $this->getScriptsVariables(),
]);
$request = Request::createFromGlobals();
$request = $this->module->getCurrentRequest();
$this->addUIAssets($request);

$response = (new Router($this->upgradeContainer))->handle($request);
Expand Down
4 changes: 4 additions & 0 deletions tests/phpstan/phpstan-1.7.2.5.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ parameters:
- "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(int\\)\\: mixed\\)\\|null, 'add_quotes' given\\.$#"
- '#Parameter \$params of method Autoupgrade::hookDisplayBackOfficeEmployeeMenu\(\) has invalid type PrestaShop\\PrestaShop\\Core\\Action\\ActionsBarButtonsCollection.#'
- '#Parameter \#1 \$kernel of class Symfony\\Bundle\\FrameworkBundle\\Console\\Application constructor expects Symfony\\Component\\HttpKernel\\KernelInterface, AdminKernel\|AppKernel given.$#'
-
message: '#Call to an undefined method Autoupgrade::get\(\)\.#'
path: ./../../autoupgrade.php
count: 1
-
identifier: booleanAnd.rightAlwaysTrue
path: ./../../classes/UpgradeSelfCheck.php
Expand Down