Skip to content

Commit b520a36

Browse files
committed
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.
1 parent 6c73477 commit b520a36

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
"Surfnet_": "library/"
110110
},
111111
"psr-4": {
112-
"OpenConext\\": "src/OpenConext"
112+
"OpenConext\\": "src/OpenConext",
113+
"OpenConext\\EngineBlock\\Doctrine\\Migrations\\": "migrations/DoctrineMigrations"
113114
},
114115
"classmap": [
115116
"src/Kernel.php"

library/EngineBlock/ApplicationSingleton.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OpenConext\EngineBlockBundle\Exception\Art;
2424
use Psr\Log\LoggerInterface;
2525
use Symfony\Component\DependencyInjection\ContainerInterface;
26+
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
2627

2728
define('ENGINEBLOCK_FOLDER_ROOT' , realpath(__DIR__ . '/../../') . '/');
2829
define('ENGINEBLOCK_FOLDER_LIBRARY' , ENGINEBLOCK_FOLDER_ROOT . 'library/');
@@ -235,8 +236,11 @@ public function reportError(Throwable $exception, $messageSuffix = '')
235236
$log->log($severity, $message, $logContext);
236237

237238
// Store some valuable debug info in session so it can be displayed on feedback pages
238-
@session_start();
239-
$this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception));
239+
if($this->hasSession()) {
240+
// In CLI context, the session is not available
241+
@session_start();
242+
$this->getSession()->set('feedbackInfo', $this->collectFeedbackInfo($exception));
243+
}
240244

241245
// flush all messages in queue, something went wrong!
242246
$this->flushLog('An error was caught');
@@ -420,6 +424,16 @@ public function getSession()
420424
return $this->getDiContainer()->getSession();
421425
}
422426

427+
public function hasSession(): bool
428+
{
429+
try {
430+
$this->getSession();
431+
return true;
432+
} catch (SessionNotFoundException) {
433+
return false;
434+
}
435+
}
436+
423437
/**
424438
* @return \EngineBlock_Application_DiContainer
425439
*/

migrations/DoctrineMigrations/Version20260224000000.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
namespace OpenConext\EngineBlock\Doctrine\Migrations;
2222

23+
use Doctrine\DBAL\Schema\Index;
24+
use Doctrine\DBAL\Schema\Name\Identifier;
25+
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
26+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
27+
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
2328
use Doctrine\DBAL\Schema\Schema;
2429

2530
/**
@@ -39,9 +44,17 @@ public function preUp(Schema $schema): void
3944
{
4045
parent::preUp($schema);
4146

42-
$indexes = $this->connection->createSchemaManager()->listTableIndexes('consent');
47+
$indexes = $this->connection->createSchemaManager()->introspectTableIndexes(new OptionallyQualifiedName(Identifier::unquoted('consent'), null));
48+
$deletedAtIndex = array_filter(
49+
$indexes,
50+
static fn(Index $index) => $index->getObjectName()->equals(
51+
UnqualifiedName::unquoted('deleted_at'),
52+
UnquotedIdentifierFolding::NONE
53+
)
54+
);
55+
4356
$this->skipIf(
44-
!isset($indexes['deleted_at']),
57+
count($deletedAtIndex) === 0,
4558
'Index deleted_at on consent table does not exist. Skipping.'
4659
);
4760
}

0 commit comments

Comments
 (0)