diff --git a/app/Events/AddMembership.php b/app/Events/AddMembership.php deleted file mode 100644 index 59e3aee..0000000 --- a/app/Events/AddMembership.php +++ /dev/null @@ -1,23 +0,0 @@ -membership = $membership; - } -} diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 4b5d0f5..7c936bf 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; +use function PHPUnit\Framework\isNull; class FolderDeleteMembership implements ShouldQueue { @@ -48,6 +49,11 @@ public function handle(): void if (! Storage::disk($diskName)->exists($federation->name)) { $this->fail(); } + $pathToFile = $federation->name.'/'.$entity->file; + if(! Storage::disk($diskName)->exists($pathToFile)) { + return; + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; $lock = Cache::lock($lockKey, 61); diff --git a/app/Listeners/SendNewMemberToSaveJob.php b/app/Listeners/SendNewMemberToSaveJob.php deleted file mode 100644 index 4137276..0000000 --- a/app/Listeners/SendNewMemberToSaveJob.php +++ /dev/null @@ -1,29 +0,0 @@ -membership->approved == 1) { - FolderAddMembership::dispatch($event->membership); - } - - } -} diff --git a/app/Models/Membership.php b/app/Models/Membership.php index 358125d..9585666 100644 --- a/app/Models/Membership.php +++ b/app/Models/Membership.php @@ -2,7 +2,6 @@ namespace App\Models; -use App\Events\AddMembership; use Illuminate\Database\Eloquent\Relations\Pivot; class Membership extends Pivot @@ -32,8 +31,4 @@ public function approver() { return $this->belongsTo('App\Models\User', 'approved_by'); } - - protected $dispatchesEvents = [ - 'updated' => AddMembership::class, - ]; } diff --git a/app/Observers/MembershipObserver.php b/app/Observers/MembershipObserver.php new file mode 100644 index 0000000..3b0b1e4 --- /dev/null +++ b/app/Observers/MembershipObserver.php @@ -0,0 +1,57 @@ +approved == 1) { + FolderAddMembership::dispatch($membership); + } + } + + /** + * Handle the Membership "deleted" event. + */ + public function deleted(Membership $membership): void + { + $entity = $membership->entity; + $federation = $membership->federation; + FolderDeleteMembership::dispatch($entity, $federation); + + + } + + /** + * Handle the Membership "restored" event. + */ + public function restored(Membership $membership): void + { + // + } + + /** + * Handle the Membership "force deleted" event. + */ + public function forceDeleted(Membership $membership): void + { + // + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 252198c..675c0ff 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,12 +2,12 @@ namespace App\Providers; -use App\Events\AddMembership; use App\Events\FederationApprove; use App\Listeners\CreateFederationFolder; -use App\Listeners\SendNewMemberToSaveJob; use App\Models\Entity; +use App\Models\Membership; use App\Observers\EntityObserver; +use App\Observers\MembershipObserver; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -27,9 +27,6 @@ class EventServiceProvider extends ServiceProvider FederationApprove::class => [ CreateFederationFolder::class, ], - AddMembership::class => [ - SendNewMemberToSaveJob::class, - ], ]; @@ -41,5 +38,6 @@ class EventServiceProvider extends ServiceProvider public function boot() { Entity::observe(EntityObserver::class); + Membership::observe(MembershipObserver::class); } }