44
55namespace SimpleSAML \Module \oidc \Controller ;
66
7+ use SimpleSAML \Locale \Translate ;
78use SimpleSAML \Module \oidc \Admin \Authorization ;
89use SimpleSAML \Module \oidc \Codebooks \RoutesEnum ;
910use SimpleSAML \Module \oidc \Factories \TemplateFactory ;
1011use SimpleSAML \Module \oidc \ModuleConfig ;
12+ use SimpleSAML \Module \oidc \Services \DatabaseMigration ;
13+ use SimpleSAML \Module \oidc \Services \SessionMessagesService ;
14+ use Symfony \Component \HttpFoundation \RedirectResponse ;
1115use Symfony \Component \HttpFoundation \Response ;
1216
1317class AdminController
@@ -16,6 +20,8 @@ public function __construct(
1620 protected readonly ModuleConfig $ moduleConfig ,
1721 protected readonly TemplateFactory $ templateFactory ,
1822 protected readonly Authorization $ authorization ,
23+ protected readonly DatabaseMigration $ databaseMigration ,
24+ protected readonly SessionMessagesService $ sessionMessagesService ,
1925 ) {
2026 $ this ->authorization ->requireSspAdmin (true );
2127 }
@@ -24,8 +30,26 @@ public function configOverview(): Response
2430 {
2531 return $ this ->templateFactory ->build (
2632 'oidc:config/overview.twig ' ,
27- ['moduleConfig ' => $ this ->moduleConfig ],
33+ [
34+ 'moduleConfig ' => $ this ->moduleConfig ,
35+ 'databaseMigration ' => $ this ->databaseMigration ,
36+ ],
2837 RoutesEnum::AdminConfigOverview->value ,
2938 );
3039 }
40+
41+ public function runMigrations (): Response
42+ {
43+ if ($ this ->databaseMigration ->isMigrated ()) {
44+ $ message = Translate::noop ('Database is already migrated. ' );
45+ $ this ->sessionMessagesService ->addMessage ($ message );
46+ return new RedirectResponse ($ this ->moduleConfig ->getModuleUrl (RoutesEnum::AdminConfigOverview->value ));
47+ }
48+
49+ $ this ->databaseMigration ->migrate ();
50+ $ message = Translate::noop ('Database migrated successfully. ' );
51+ $ this ->sessionMessagesService ->addMessage ($ message );
52+
53+ return new RedirectResponse ($ this ->moduleConfig ->getModuleUrl (RoutesEnum::AdminConfigOverview->value ));
54+ }
3155}
0 commit comments