diff --git a/app/Events/AddMembership.php b/app/Events/AddMembership.php index 13dab23..59e3aee 100644 --- a/app/Events/AddMembership.php +++ b/app/Events/AddMembership.php @@ -3,11 +3,7 @@ namespace App\Events; use App\Models\Membership; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; @@ -17,7 +13,6 @@ class AddMembership public Membership $membership; - /** * Create a new event instance. */ @@ -25,5 +20,4 @@ public function __construct(Membership $membership) { $this->membership = $membership; } - } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index ab3a7e2..2a7686f 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -17,7 +17,6 @@ use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; @@ -50,7 +49,6 @@ public function handle(): void ->where('approved', 1) ->get(); - $diskName = config('storageCfg.name'); foreach ($federationMembershipId as $fedId) { @@ -80,7 +78,7 @@ public function handle(): void RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { - Log::error($e->getMessage()); + $this->fail($e); } finally { if ($lock->isOwnedByCurrentProcess()) { $lock->release(); diff --git a/app/Jobs/FolderAddMembership.php b/app/Jobs/FolderAddMembership.php new file mode 100644 index 0000000..7a6b1e0 --- /dev/null +++ b/app/Jobs/FolderAddMembership.php @@ -0,0 +1,64 @@ +membership = $membership; + } + + /** + * Execute the job. + */ + public function handle(): void + { + Log::info('MEMBERSHIP START'); + $federation = Federation::find($this->membership->federation_id); + $entity = Entity::find($this->membership->entity_id); + $diskName = config('storageCfg.name'); + if (! Storage::disk($diskName)->exists($federation->name)) { + $this->fail(); + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + + try { + $lock->block(61); + EntityFacade::saveMetadataToFederationFolder($entity->id, $federation->id); + RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + $this->fail($e); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + } +} diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php new file mode 100644 index 0000000..6864b8b --- /dev/null +++ b/app/Jobs/FolderDeleteMembership.php @@ -0,0 +1,30 @@ +membership->entity_id; - $entity = Entity::find($entityId); - - if ($entity->approved == 1 && $event->membership->approved == 1 ) { - Log::info(" dispatch FolderAddEntity from Listener SendNewMemberToSaveJob"); + if ($event->membership->approved == 1) { + FolderAddMembership::dispatch($event->membership); } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 333c102..139028f 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -7,6 +7,7 @@ use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; use App\Services\NotificationService; +use Illuminate\Support\Facades\Log; class SendUpdatedEntityToSaveJob { @@ -26,11 +27,11 @@ public function handle(UpdateEntity $event): void $entity = $event->entity; - if ($entity->wasChanged('xml_file') || - ($entity->wasChanged('approved') && $entity->approved == 1) + if ($entity->wasChanged('xml_file') ) { FolderAddEntity::dispatch($event->entity); } elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) { + Log::info('update some entity in SendUpdatedEntityToSaveJob'); NotificationService::sendUpdateNotification($entity); } if ($entity->wasChanged('edugain')) { diff --git a/app/Models/Membership.php b/app/Models/Membership.php index f8cfed8..abedeab 100644 --- a/app/Models/Membership.php +++ b/app/Models/Membership.php @@ -35,8 +35,7 @@ public function approver() protected $dispatchesEvents = [ 'updated' => AddMembership::class, - // 'deleted' => DeleteEntity::class, + // 'deleted' => DeleteEntity::class, ]; - }