diff --git a/composer.json b/composer.json index a7d39427d..082080c31 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 807dd93c3..8eca5e7ff 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,10 @@ 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 + $this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception)); + } // flush all messages in queue, something went wrong! $this->flushLog('An error was caught'); @@ -420,6 +423,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 ac69de8a1..e85a85b6e 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.' ); }