From 27c1ea4a501f8b9417cc40ff0d0d60a12b3a192a Mon Sep 17 00:00:00 2001 From: Lukas Staab Date: Fri, 23 Feb 2024 15:22:50 +0100 Subject: [PATCH] adding daily schedule for syncing db and ldap minor code fixes --- app/Console/Commands/LegacyImport/ImportRoles.php | 3 +-- app/Console/Commands/LegacyImport/ImportUserFromLegacy.php | 4 +++- app/Console/Kernel.php | 1 + .../migrations/2023_09_20_175722_password_reset_table.php | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/LegacyImport/ImportRoles.php b/app/Console/Commands/LegacyImport/ImportRoles.php index 375992b..0892c91 100644 --- a/app/Console/Commands/LegacyImport/ImportRoles.php +++ b/app/Console/Commands/LegacyImport/ImportRoles.php @@ -48,7 +48,7 @@ public function handle() if(!isset($realms[$role->realm_uid])){ $realms[$role->realm_uid] = Community::findByUid($role->realm_uid); } - $this->comment('Importing Com ' . $role->name . ' to Realm ' . $role->realm_uid . ' ...'); + $this->comment('Importing Com-Role ' . $role->name . ' to Realm ' . $role->realm_uid . ' ...'); $c = Committee::findByName($role->realm_uid, $role->gshort); $r = $c?->roles()->where('cn', $role->rshort); @@ -77,7 +77,6 @@ public function handle() 'from' => $assertion->from, 'until' => $assertion->until, ]); - } } } diff --git a/app/Console/Commands/LegacyImport/ImportUserFromLegacy.php b/app/Console/Commands/LegacyImport/ImportUserFromLegacy.php index ab276f0..4a419c6 100644 --- a/app/Console/Commands/LegacyImport/ImportUserFromLegacy.php +++ b/app/Console/Commands/LegacyImport/ImportUserFromLegacy.php @@ -55,7 +55,9 @@ public function handle() $ldapUser->setDn('uid=' . $user->username . ',ou=People,dc=open-administration,dc=de'); $ldapUser->save(); } - $realms[$user->realm_uid]->membersGroup()->members()->attach($ldapUser); + if(!$realms[$user->realm_uid]->membersGroup()->members()->exists($ldapUser)){ + $realms[$user->realm_uid]->membersGroup()->members()->attach($ldapUser); + } } } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index d8bc1d2..9e2936f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { // $schedule->command('inspire')->hourly(); + $schedule->command('ldap:sync-roles')->dailyAt("00:01"); } /** diff --git a/database/migrations/2023_09_20_175722_password_reset_table.php b/database/migrations/2023_09_20_175722_password_reset_table.php index 81a7229..3e00580 100644 --- a/database/migrations/2023_09_20_175722_password_reset_table.php +++ b/database/migrations/2023_09_20_175722_password_reset_table.php @@ -11,7 +11,7 @@ */ public function up(): void { - Schema::create('password_reset_tokens', function (Blueprint $table) { + Schema::create('password_reset_tokens', static function (Blueprint $table) { $table->string('email')->primary(); $table->string('token'); $table->timestamp('created_at')->nullable();