diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index fa23d27..cf29019 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -51,7 +51,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { $lock->block(61); - EntityFacade::saveMetadataToFederationFolder($this->entity->id,$folderName); + EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName); //TODO write custom function to run special MDA script (ask about this) diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php new file mode 100644 index 0000000..866148a --- /dev/null +++ b/app/Jobs/EduGainDeleteEntity.php @@ -0,0 +1,69 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $diskName = config('storageCfg.name'); + $folderName = config('storageCfg.edu2edugain'); + try { + if (! Storage::disk($diskName)->exists($folderName)) { + throw new Exception("No $folderName in $diskName"); + } + } catch (Exception $e) { + $this->fail($e); + } + $pathToDirectory = Storage::disk($diskName)->path($folderName); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + try { + $lock->block(61); + EntityFacade::deleteEntityMetadataFromFolder($this->entity->file,$folderName); + + //TODO write custom function to run special MDA script (ask about this) + + // RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + } +} diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index e3c6731..b7af833 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -55,7 +55,7 @@ public function handle(): void $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; $lock = Cache::lock($lockKey, 61); try { - $lock->block(120); + $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); NotificationService::sendEntityNotification($entity,EntityStateChanged::class); diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index 379842b..45043f1 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -3,6 +3,7 @@ namespace App\Listeners; use App\Events\CreateEntity; +use App\Jobs\EduGainAddEntity; use App\Jobs\FolderAddEntity; class SendCreatedEntityToSaveJob @@ -23,6 +24,11 @@ public function handle(CreateEntity $event): void if ($event->entity->approved == 1) { FolderAddEntity::dispatch($event->entity); + + if($event->entity->edugain == 1){ + EduGainAddEntity::dispatch($event->entity); + } + } } } diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index 8d2d9a2..10e4d53 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -3,9 +3,9 @@ namespace App\Listeners; use App\Events\DeleteEntity; -use App\Facades\EntityFacade; +use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderDeleteEntity; -use Illuminate\Support\Facades\Log; + class SendDeletedEntityToDeleteJob { @@ -22,6 +22,12 @@ public function __construct() */ public function handle(DeleteEntity $event): void { - FolderDeleteEntity::dispatch($event->entity); + FolderDeleteEntity::dispatch($event->entity); + + if($event->entity->edugain == 1){ + EduGainDeleteEntity::dispatch($event->entity); + } + + } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index a330716..1123e7c 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -3,6 +3,8 @@ namespace App\Listeners; use App\Events\UpdateEntity; +use App\Jobs\EduGainAddEntity; +use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; use App\Models\User; use App\Notifications\EntityUpdated; @@ -27,17 +29,26 @@ public function handle(UpdateEntity $event): void $entity = $event->entity; - - if ($entity->wasChanged('xml_file') || ($entity->wasChanged('approved') && $entity->approved == 1) ) { FolderAddEntity::dispatch($event->entity); } - elseif ($entity->approved == 1) + elseif ($entity->approved == 1 && !$entity->wasChanged('edugain')) { NotificationService::sendEntityNotification($entity,EntityUpdated::class); } + if($entity->wasChanged('edugain')) + { + if($entity->edugain == 1) { + EduGainAddEntity::dispatch($entity); + } else { + EduGainDeleteEntity::dispatch($entity); + } + } + + + } }