From ff6062a0b8ffe458bc739873d380bb194b1cd523 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 17 Jul 2024 13:48:12 +0200 Subject: [PATCH] make better seeder run pint and fix FolderAddEntity --- app/Jobs/FolderAddEntity.php | 10 ++--- app/Listeners/SendUpdatedEntityToSaveJob.php | 5 --- app/Services/NotificationService.php | 39 ++++++++++++-------- database/seeders/DatabaseSeeder.php | 14 +++++++ 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 1162efe..11b30c9 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -68,12 +68,10 @@ public function handle(): void if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); - } else - { - if($this->entity->wasChanged('approved') && $this->entity->approved == 1) { - NotificationService::sendEntityNotification($this->entity,); - } - else { + } else { + if ($this->entity->wasChanged('approved') && $this->entity->approved == 1) { + NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); + } else { NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 25860cc..333c102 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -6,11 +6,6 @@ use App\Jobs\EduGainAddEntity; use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; -use App\Notifications\EntityAddedToHfd; -use App\Notifications\EntityAddedToRs; -use App\Notifications\EntityDeletedFromHfd; -use App\Notifications\EntityDeletedFromRs; -use App\Notifications\EntityUpdated; use App\Services\NotificationService; class SendUpdatedEntityToSaveJob diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 66820d3..6c429b0 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -15,6 +15,10 @@ class NotificationService { public static function sendEntityNotification(Entity $entity, $notification): void { + if ($notification == null) { + return; + } + $admins = User::activeAdmins()->select('id', 'email')->get(); $operators = $entity->operators->pluck('id')->toArray(); @@ -29,39 +33,42 @@ public static function sendEntityNotification(Entity $entity, $notification): vo private static function sendRsNotification(Entity $entity): bool { - if($entity->wasChanged('rs')) { + if ($entity->wasChanged('rs')) { - if($entity->rs == 1) { - self::sendEntityNotification($entity,EntityAddedToRs::class); + if ($entity->rs == 1) { + self::sendEntityNotification($entity, EntityAddedToRs::class); } else { - self::sendEntityNotification($entity,EntityDeletedFromRs::class); + self::sendEntityNotification($entity, EntityDeletedFromRs::class); } + return true; } + return false; } - private static function sendHfDNotification(Entity $entity): bool + + private static function sendHfDNotification(Entity $entity): bool { if ($entity->wasChanged('hfd')) { - if($entity->hfd) { - self::sendEntityNotification($entity,EntityAddedToHfd::class); - } else { - self::sendEntityNotification($entity,EntityDeletedFromHfd::class); - } - return true; + if ($entity->hfd) { + self::sendEntityNotification($entity, EntityAddedToHfd::class); + } else { + self::sendEntityNotification($entity, EntityDeletedFromHfd::class); } + + return true; + } + return false; } - - public static function sendUpdateNotification(Entity $entity): void + public static function sendUpdateNotification(Entity $entity): void { - if( !self::sendRsNotification($entity) && !self::sendHfDNotification($entity)){ - self::sendEntityNotification($entity,EntityUpdated::class); + if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) { + self::sendEntityNotification($entity, EntityUpdated::class); } } - } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index f6d7ff9..0ee88e5 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -7,10 +7,14 @@ use App\Models\Federation; use App\Models\Group; use App\Models\User; +use App\Traits\FederationTrait; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Storage; class DatabaseSeeder extends Seeder { + use FederationTrait; + /** * Seed the application's database. * @@ -18,11 +22,21 @@ class DatabaseSeeder extends Seeder */ public function run() { + $diskName = config('storageCfg.name'); + + if (Storage::disk($diskName)->exists('')) { + Storage::disk($diskName)->deleteDirectory(''); + } + User::factory()->create(['active' => true, 'admin' => true]); User::factory()->create(['active' => true, 'admin' => true]); User::factory()->create(['active' => false, 'admin' => true]); User::factory()->create(['active' => true]); User::factory(96)->create(); + + $edu2edugain = config('storageCfg.edu2edugain'); + $this->createFederationFolder($edu2edugain); + /* Federation::factory(20)->create(); Entity::factory(100)->create();*/ /* Category::factory(20)->create();