diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 6326591..60f23e4 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -474,15 +474,15 @@ function () use ($entity) { $color = $entity->rs ? 'green' : 'red'; // TODO notification -/* if ($entity->rs) { - GitAddToRs::dispatch($entity, Auth::user()); - Notification::send($entity->operators, new EntityAddedToRs($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity)); - } else { - GitDeleteFromRs::dispatch($entity, Auth::user()); - Notification::send($entity->operators, new EntityDeletedFromRs($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity)); - }*/ + /* if ($entity->rs) { + GitAddToRs::dispatch($entity, Auth::user()); + Notification::send($entity->operators, new EntityAddedToRs($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity)); + } else { + GitDeleteFromRs::dispatch($entity, Auth::user()); + Notification::send($entity->operators, new EntityDeletedFromRs($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity)); + }*/ return redirect() ->back() @@ -543,16 +543,16 @@ function () use ($entity, $category) { $color = $entity->hfd ? 'red' : 'green'; //TODO change HfD status -/* if ($entity->hfd) { - GitAddToHfd::dispatch($entity, Auth::user()); - Notification::send($entity->operators, new EntityAddedToHfd($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); - } else { - GitDeleteFromHfd::dispatch($entity, Auth::user()); - Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity)); - Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); - }*/ + /* if ($entity->hfd) { + GitAddToHfd::dispatch($entity, Auth::user()); + Notification::send($entity->operators, new EntityAddedToHfd($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); + } else { + GitDeleteFromHfd::dispatch($entity, Auth::user()); + Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity)); + Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); + }*/ return redirect() ->route('entities.show', $entity) diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index 1818f65..57b5c24 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -4,9 +4,6 @@ use App\Facades\EntityFacade; use App\Models\Entity; -use App\Notifications\EntityStateChanged; -use App\Notifications\EntityUpdated; -use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Exception; use Illuminate\Bus\Queueable; @@ -22,6 +19,7 @@ class EduGainAddEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use HandlesJobsFailuresTrait; + public Entity $entity; /** @@ -41,7 +39,7 @@ public function handle(): void $folderName = config('storageCfg.edu2edugain'); try { if (! Storage::disk($diskName)->exists($folderName)) { - throw new Exception("No $folderName in $diskName"); + throw new Exception("No $folderName in $diskName"); } } catch (Exception $e) { $this->fail($e); @@ -51,7 +49,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { $lock->block(61); - EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName); + EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName); //TODO write custom function to run special MDA script (ask about this) EduGainRunMdaScript::dispatch($lock->owner()); @@ -64,7 +62,5 @@ public function handle(): void } } - - } } diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 6152ea5..0b951b4 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -43,7 +43,7 @@ public function handle(): void $folderName = config('storageCfg.edu2edugain'); try { if (! Storage::disk($diskName)->exists($folderName)) { - throw new Exception("No $folderName in $diskName"); + throw new Exception("No $folderName in $diskName"); } } catch (Exception $e) { $this->fail($e); @@ -53,7 +53,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { $lock->block(61); - EntityFacade::deleteEntityMetadataFromFolder($this->entity->file,$folderName); + EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); //TODO write custom function to run special MDA script (ask about this) diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php index b7e9514..c4f906e 100644 --- a/app/Jobs/EduGainRunMdaScript.php +++ b/app/Jobs/EduGainRunMdaScript.php @@ -54,8 +54,5 @@ public function handle(): void } - - - } } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index d56af97..beda436 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -3,13 +3,11 @@ namespace App\Jobs; use App\Facades\EntityFacade; -use App\Mail\ExceptionOccured; use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; use App\Notifications\EntityStateChanged; use App\Notifications\EntityUpdated; -use App\Services\EntityService; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; @@ -20,10 +18,8 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; use Mockery\Exception; -use Throwable; class FolderAddEntity implements ShouldQueue { @@ -34,7 +30,6 @@ class FolderAddEntity implements ShouldQueue */ use HandlesJobsFailuresTrait; - public Entity $entity; /** @@ -71,11 +66,10 @@ public function handle(): void $lock->block(61); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); - if ($this->entity->wasRecentlyCreated) { - NotificationService::sendEntityNotification($this->entity,EntityUpdated::class); + NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); } elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { - NotificationService::sendEntityNotification($this->entity,EntityStateChanged::class); + NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); } RunMdaScript::dispatch($federation, $lock->owner()); @@ -99,5 +93,4 @@ public function middleware(): array { return [(new WithoutOverlapping($this->entity->id))->dontRelease()]; } - } diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index b7af833..490faee 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -6,7 +6,6 @@ use App\Models\Entity; use App\Notifications\EntityDeletedFromHfd; use App\Notifications\EntityStateChanged; -use App\Services\EntityService; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; @@ -58,12 +57,11 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - NotificationService::sendEntityNotification($entity,EntityStateChanged::class); + NotificationService::sendEntityNotification($entity, EntityStateChanged::class); if ($entity->hfd) { - NotificationService::sendEntityNotification($entity,EntityDeletedFromHfd::class); + NotificationService::sendEntityNotification($entity, EntityDeletedFromHfd::class); } - RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php index 9e02d5c..43318e2 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -45,7 +45,6 @@ public function handle(): void $filterArray = explode(', ', $this->federation->filters); $scriptPath = config('storageCfg.mdaScript'); - $realScriptPath = realpath($scriptPath); try { @@ -77,11 +76,11 @@ public function middleware(): array { $diskName = config('storageCfg.name'); $pathToDirectory = Storage::disk($diskName)->path($this->federation->name); - $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; return [ new RateLimited('mda-run-limit'), - (new WithoutOverlapping($lockKey))->dontRelease() + (new WithoutOverlapping($lockKey))->dontRelease(), ]; } diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index 45043f1..be43a24 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -25,7 +25,7 @@ public function handle(CreateEntity $event): void if ($event->entity->approved == 1) { FolderAddEntity::dispatch($event->entity); - if($event->entity->edugain == 1){ + if ($event->entity->edugain == 1) { EduGainAddEntity::dispatch($event->entity); } diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index 10e4d53..c8763ce 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -6,7 +6,6 @@ use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderDeleteEntity; - class SendDeletedEntityToDeleteJob { /** @@ -24,10 +23,9 @@ public function handle(DeleteEntity $event): void { FolderDeleteEntity::dispatch($event->entity); - if($event->entity->edugain == 1){ + if ($event->entity->edugain == 1) { EduGainDeleteEntity::dispatch($event->entity); } - } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 1123e7c..b6ef3cf 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -6,10 +6,8 @@ use App\Jobs\EduGainAddEntity; use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; -use App\Models\User; use App\Notifications\EntityUpdated; use App\Services\NotificationService; -use Illuminate\Support\Facades\Notification; class SendUpdatedEntityToSaveJob { @@ -31,24 +29,18 @@ public function handle(UpdateEntity $event): void if ($entity->wasChanged('xml_file') || ($entity->wasChanged('approved') && $entity->approved == 1) - ) - { + ) { FolderAddEntity::dispatch($event->entity); + } elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) { + NotificationService::sendEntityNotification($entity, EntityUpdated::class); } - elseif ($entity->approved == 1 && !$entity->wasChanged('edugain')) - { - NotificationService::sendEntityNotification($entity,EntityUpdated::class); - } - if($entity->wasChanged('edugain')) - { - if($entity->edugain == 1) { + if ($entity->wasChanged('edugain')) { + if ($entity->edugain == 1) { EduGainAddEntity::dispatch($entity); } else { EduGainDeleteEntity::dispatch($entity); } } - - } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 58e39d6..c206604 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -33,13 +33,13 @@ public function boot() // Mail::alwaysTo('foo@example.org'); Model::preventLazyLoading(); } -//TODO comment this for testing part -/* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { - $diskName = config('storageCfg.name'); - $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); - $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - return Limit::perMinute(1)->by($lockKey); - });*/ + //TODO comment this for testing part + /* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { + $diskName = config('storageCfg.name'); + $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + return Limit::perMinute(1)->by($lockKey); + });*/ } } diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index cf82a1b..61097c0 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -1,23 +1,24 @@ select('id', 'email')->get(); $operators = $entity->operators->pluck('id')->toArray(); $filteredAdmins = $admins->filter(function ($admin) use ($operators) { - return !in_array($admin->id, $operators); + return ! in_array($admin->id, $operators); }); Notification::sendNow($entity->operators, new $notification($entity)); Notification::sendNow($filteredAdmins, new $notification($entity)); } - } diff --git a/app/Traits/HandlesJobsFailuresTrait.php b/app/Traits/HandlesJobsFailuresTrait.php index 732823c..7c10aa9 100644 --- a/app/Traits/HandlesJobsFailuresTrait.php +++ b/app/Traits/HandlesJobsFailuresTrait.php @@ -1,8 +1,10 @@ 'metadata', 'mdaConfigFolder' => env('MDA_CONFIG_FOLDER'), 'mdaScript' => env('MDA_SCRIPT'), - 'edu2edugain' =>env('EDU_TO_EDUGAIN_FOLDER'), + 'edu2edugain' => env('EDU_TO_EDUGAIN_FOLDER'), ];