From b520a365e037807a1f863bf6c13095f310fc2453 Mon Sep 17 00:00:00 2001 From: Johan Kromhout Date: Wed, 18 Mar 2026 08:43:35 +0100 Subject: [PATCH 1/2] Fix error reporting / session / migration issues Prior to this change, the error reporter would always try to write feedback info to the session, even if there was no session because the script is running from a CLI context. This change skips that step if no session is available. Prior to this change, the migrations would fail because a class hierarchy was introduced, which required the namespace to be registered in the autoloader. This change updates the autoloader and repairs the migrations without changing the migration namespace so migrations are not executed again on existing environments. Prior to this change, a migration relied on a deprecated DBAL method to check if an index existed. This change rewrites the check using only non-deprecated checks. --- composer.json | 3 ++- library/EngineBlock/ApplicationSingleton.php | 18 ++++++++++++++++-- .../Version20260224000000.php | 17 +++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a7d39427de..082080c314 100644 --- a/composer.json +++ b/composer.json @@ -109,7 +109,8 @@ "Surfnet_": "library/" }, "psr-4": { - "OpenConext\\": "src/OpenConext" + "OpenConext\\": "src/OpenConext", + "OpenConext\\EngineBlock\\Doctrine\\Migrations\\": "migrations/DoctrineMigrations" }, "classmap": [ "src/Kernel.php" diff --git a/library/EngineBlock/ApplicationSingleton.php b/library/EngineBlock/ApplicationSingleton.php index 807dd93c31..f292fc550e 100644 --- a/library/EngineBlock/ApplicationSingleton.php +++ b/library/EngineBlock/ApplicationSingleton.php @@ -23,6 +23,7 @@ use OpenConext\EngineBlockBundle\Exception\Art; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; define('ENGINEBLOCK_FOLDER_ROOT' , realpath(__DIR__ . '/../../') . '/'); define('ENGINEBLOCK_FOLDER_LIBRARY' , ENGINEBLOCK_FOLDER_ROOT . 'library/'); @@ -235,8 +236,11 @@ public function reportError(Throwable $exception, $messageSuffix = '') $log->log($severity, $message, $logContext); // Store some valuable debug info in session so it can be displayed on feedback pages - @session_start(); - $this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception)); + if($this->hasSession()) { + // In CLI context, the session is not available + @session_start(); + $this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception)); + } // flush all messages in queue, something went wrong! $this->flushLog('An error was caught'); @@ -420,6 +424,16 @@ public function getSession() return $this->getDiContainer()->getSession(); } + public function hasSession(): bool + { + try { + $this->getSession(); + return true; + } catch (SessionNotFoundException) { + return false; + } + } + /** * @return \EngineBlock_Application_DiContainer */ diff --git a/migrations/DoctrineMigrations/Version20260224000000.php b/migrations/DoctrineMigrations/Version20260224000000.php index ac69de8a10..e85a85b6ed 100644 --- a/migrations/DoctrineMigrations/Version20260224000000.php +++ b/migrations/DoctrineMigrations/Version20260224000000.php @@ -20,6 +20,11 @@ namespace OpenConext\EngineBlock\Doctrine\Migrations; +use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\Name\Identifier; +use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName; +use Doctrine\DBAL\Schema\Name\UnqualifiedName; +use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding; use Doctrine\DBAL\Schema\Schema; /** @@ -39,9 +44,17 @@ public function preUp(Schema $schema): void { parent::preUp($schema); - $indexes = $this->connection->createSchemaManager()->listTableIndexes('consent'); + $indexes = $this->connection->createSchemaManager()->introspectTableIndexes(new OptionallyQualifiedName(Identifier::unquoted('consent'), null)); + $deletedAtIndex = array_filter( + $indexes, + static fn(Index $index) => $index->getObjectName()->equals( + UnqualifiedName::unquoted('deleted_at'), + UnquotedIdentifierFolding::NONE + ) + ); + $this->skipIf( - !isset($indexes['deleted_at']), + count($deletedAtIndex) === 0, 'Index deleted_at on consent table does not exist. Skipping.' ); } From 072660d0626550cc02227065442ecddd1ef858a9 Mon Sep 17 00:00:00 2001 From: Johan Kromhout Date: Wed, 18 Mar 2026 09:13:41 +0100 Subject: [PATCH 2/2] Remove extra session_start() Prior to this change, the hasSession() would already trigger a session_start from within Symfony Framework. The session_start left in there was not needed and confusing. This change leaves session handling to the framework and does not try to start the session again manually. --- library/EngineBlock/ApplicationSingleton.php | 1 - 1 file changed, 1 deletion(-) diff --git a/library/EngineBlock/ApplicationSingleton.php b/library/EngineBlock/ApplicationSingleton.php index f292fc550e..8eca5e7ff1 100644 --- a/library/EngineBlock/ApplicationSingleton.php +++ b/library/EngineBlock/ApplicationSingleton.php @@ -238,7 +238,6 @@ public function reportError(Throwable $exception, $messageSuffix = '') // Store some valuable debug info in session so it can be displayed on feedback pages if($this->hasSession()) { // In CLI context, the session is not available - @session_start(); $this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception)); }