Skip to content

Commit

Permalink
fix: feedback from review
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-devfront committed Feb 25, 2025
1 parent de64e54 commit b396980
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
33 changes: 31 additions & 2 deletions autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Autoupgrade extends Module
*/
public $multishop_context;

/**
* @var \PrestaShop\Module\AutoUpgrade\UpgradeContainer
*/
protected $container;

public function __construct()
{
$this->name = 'autoupgrade';
Expand Down Expand Up @@ -219,17 +224,41 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
* @throws \Twig\Error\SyntaxError
*/
public function hookDisplayBackOfficeHeader()
{
if (!$this->initAutoloaderIfCompliant()) {
return '';
}

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

/**
* @return bool
*/
public function initAutoloaderIfCompliant()
{
require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/classes/VersionUtils.php';
if (!\PrestaShop\Module\AutoUpgrade\VersionUtils::isActualPHPVersionCompatible()) {
return '';
return false;
}

$autoloadPath = __DIR__ . '/vendor/autoload.php';
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
}

return (new \PrestaShop\Module\AutoUpgrade\Hooks\DisplayBackOfficeHeader())->renderUpdateNotification();
return true;
}

/**
* @return \PrestaShop\Module\AutoUpgrade\UpgradeContainer
*/
public function getUpgradeContainer()
{
if (null === $this->container) {
$this->container = new \PrestaShop\Module\AutoUpgrade\UpgradeContainer(_PS_ROOT_DIR_, realpath(_PS_ADMIN_DIR_));
}

return $this->container;
}
}
4 changes: 2 additions & 2 deletions classes/Hooks/DisplayBackOfficeHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class DisplayBackOfficeHeader
/**
* @throws Exception
*/
public function __construct()
public function __construct(UpgradeContainer $container)
{
$this->container = new UpgradeContainer(_PS_ROOT_DIR_, realpath(_PS_ADMIN_DIR_));
$this->container = $container;
$this->upgrader = $this->container->getUpgrader();
$this->updateNotificationService = $this->container->getUpdateNotificationService();
$this->updateNotificationConfiguration = $this->updateNotificationService->getUpdateNotificationConfiguration();
Expand Down
20 changes: 12 additions & 8 deletions controllers/admin/AdminAutoupgradeAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,33 @@

use PrestaShop\Module\AutoUpgrade\Hooks\DisplayBackOfficeHeader;
use PrestaShop\Module\AutoUpgrade\Router\Routes;
use PrestaShop\Module\AutoUpgrade\Services\UpdateNotificationService;
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
use Symfony\Component\HttpFoundation\JsonResponse;

class AdminAutoupgradeAjaxController extends ModuleAdminController
{
/** @var Autoupgrade */
public $module;

/** @var bool */
private $isActualPHPVersionCompatible = true;

/**
* @var UpgradeContainer
*/
private $upgradeContainer;

public function __construct()
{
parent::__construct();
require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/classes/VersionUtils.php';

if (!\PrestaShop\Module\AutoUpgrade\VersionUtils::isActualPHPVersionCompatible()) {
if (!$this->module->initAutoloaderIfCompliant()) {
$this->isActualPHPVersionCompatible = false;

return;
}

$autoloadPath = __DIR__ . '/../../vendor/autoload.php';
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
}
$this->upgradeContainer = $this->module->getUpgradeContainer();
}

public function postProcess()
Expand All @@ -54,7 +58,7 @@ public function postProcess()
$action = Tools::getValue('action');
$currentEmployeeId = \Context::getContext()->employee->id;

$updateNotificationService = new UpdateNotificationService();
$updateNotificationService = $this->upgradeContainer->getUpdateNotificationService();
$updateNotificationConfiguration = $updateNotificationService->getUpdateNotificationConfiguration();
$updateNotificationConfiguration->addEmployee($currentEmployeeId, time() + DisplayBackOfficeHeader::INTERVAL_CHECK_TIME_IN_SECONDS);

Expand Down
9 changes: 1 addition & 8 deletions controllers/admin/AdminSelfUpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,12 @@ public function __construct()
{
$this->bootstrap = true;
parent::__construct();
require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/classes/VersionUtils.php';

if (!\PrestaShop\Module\AutoUpgrade\VersionUtils::isActualPHPVersionCompatible()) {
if (!$this->module->initAutoloaderIfCompliant()) {
$this->isActualPHPVersionCompatible = false;

return;
}

$autoloadPath = __DIR__ . '/../../vendor/autoload.php';
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
}

@set_time_limit(0);
@ini_set('max_execution_time', '0');
@ini_set('magic_quotes_runtime', '0');
Expand Down

0 comments on commit b396980

Please sign in to comment.