Skip to content

Commit

Permalink
Make SessionConfig an http listener instead of just legacy provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Dec 20, 2024
1 parent 5ed9f50 commit 2cd8fad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 0 additions & 1 deletion dependency_injection/legacyConfigProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
*/

$services->set(LegacyConfigurators\CleanPHPSelfParam::class)->tag($tagName, ['priority' => 150]);
$services->set(LegacyConfigurators\SessionConfig::class)->tag($tagName, ['priority' => 130]);

// FIXME: This class MUST stay at the end until the entire config is revamped.
$services->set(LegacyConfigurators\ConfigRest::class)->tag($tagName, ['priority' => 10]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,52 @@
* ---------------------------------------------------------------------
*/

namespace Glpi\Config\LegacyConfigurators;
namespace Glpi\Http\Listener;

use Glpi\Config\ConfigProviderHasRequestTrait;
use Glpi\Config\ConfigProviderWithRequestInterface;
use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Kernel\ListenersPriority;
use Glpi\Toolbox\URL;
use Session;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

final class SessionConfig implements LegacyConfigProviderInterface, ConfigProviderWithRequestInterface
final class SessionConfig implements EventSubscriberInterface
{
use ConfigProviderHasRequestTrait;
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => ['onKernelRequest', ListenersPriority::REQUEST_LISTENERS_PRIORITIES[self::class]],
];
}

public function execute(): void
public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}

if (!isset($_SESSION["MESSAGE_AFTER_REDIRECT"])) {
$_SESSION["MESSAGE_AFTER_REDIRECT"] = [];
}

$request = $this->getRequest();
$request = $event->getRequest();

// Manage force tab
if ($request->query->has('forcetab')) {
$itemtype = URL::extractItemtypeFromUrlPath($request->getPathInfo());
if ($itemtype !== null) {
Session::setActiveTab($itemtype, $_REQUEST['forcetab']);
Session::setActiveTab($itemtype, $event->getRequest()->get('forcetab'));
}
}

// Manage tabs
if (isset($_REQUEST['glpi_tab']) && isset($_REQUEST['itemtype'])) {
Session::setActiveTab($_REQUEST['itemtype'], $_REQUEST['glpi_tab']);
if ($event->getRequest()->get('glpi_tab') && $event->getRequest()->get('itemtype')) {
Session::setActiveTab($event->getRequest()->get('itemtype'), $event->getRequest()->get('glpi_tab'));
}

// Override list-limit if choosen
if (isset($_REQUEST['glpilist_limit'])) {
$_SESSION['glpilist_limit'] = $_REQUEST['glpilist_limit'];
if ($event->getRequest()->get('glpilist_limit')) {
$_SESSION['glpilist_limit'] = $event->getRequest()->get('glpilist_limit');
}
}
}
2 changes: 2 additions & 0 deletions src/Glpi/Kernel/ListenersPriority.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ final class ListenersPriority
// Must also be executed before other controllers, since it defines its own controller.
HttpListener\CheckIfUpdateNeededListener::class => 440,

HttpListener\SessionConfig::class => 430,

HttpListener\CheckMaintenanceListener::class => 425,

// Legacy config providers.
Expand Down

0 comments on commit 2cd8fad

Please sign in to comment.