Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SessionConfig an http listener instead of just legacy provider #18588

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading