diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index 57b5c24..b43d768 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -4,6 +4,7 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Traits\EdugainTrait; use App\Traits\HandlesJobsFailuresTrait; use Exception; use Illuminate\Bus\Queueable; @@ -18,7 +19,7 @@ class EduGainAddEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - use HandlesJobsFailuresTrait; + use HandlesJobsFailuresTrait,EdugainTrait; public Entity $entity; @@ -37,6 +38,10 @@ public function handle(): void { $diskName = config('storageCfg.name'); $folderName = config('storageCfg.edu2edugain'); + if (! Storage::disk($diskName)->exists($folderName)) { + $this->makeEdu2Edugain(); + } + try { if (! Storage::disk($diskName)->exists($folderName)) { throw new Exception("No $folderName in $diskName"); @@ -51,7 +56,6 @@ public function handle(): void $lock->block(61); EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName); - //TODO write custom function to run special MDA script (ask about this) EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 0b951b4..e31cdf1 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -4,6 +4,7 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Traits\EdugainTrait; use App\Traits\HandlesJobsFailuresTrait; use Exception; use Illuminate\Bus\Queueable; @@ -22,7 +23,7 @@ class EduGainDeleteEntity implements ShouldQueue /** * trait with failure function */ - use HandlesJobsFailuresTrait; + use HandlesJobsFailuresTrait,EdugainTrait; public Entity $entity; @@ -41,6 +42,11 @@ public function handle(): void { $diskName = config('storageCfg.name'); $folderName = config('storageCfg.edu2edugain'); + + if (! Storage::disk($diskName)->exists($folderName)) { + $this->makeEdu2Edugain(); + } + try { if (! Storage::disk($diskName)->exists($folderName)) { throw new Exception("No $folderName in $diskName"); @@ -55,7 +61,6 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); - //TODO write custom function to run special MDA script (ask about this) EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index c8763ce..04420d1 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -21,11 +21,17 @@ public function __construct() */ public function handle(DeleteEntity $event): void { - FolderDeleteEntity::dispatch($event->entity); + $entity = $event->entity; - if ($event->entity->edugain == 1) { - EduGainDeleteEntity::dispatch($event->entity); + if(!$entity->isForceDeleting()) + { + FolderDeleteEntity::dispatch($event->entity); + + if ($event->entity->edugain == 1) { + EduGainDeleteEntity::dispatch($event->entity); + } } + } }