Skip to content

Commit

Permalink
make delete with observer (no test)
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 23, 2024
1 parent a002d72 commit 6cb3e98
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 62 deletions.
23 changes: 0 additions & 23 deletions app/Events/AddMembership.php

This file was deleted.

6 changes: 6 additions & 0 deletions app/Jobs/FolderDeleteMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 0 additions & 29 deletions app/Listeners/SendNewMemberToSaveJob.php

This file was deleted.

5 changes: 0 additions & 5 deletions app/Models/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Models;

use App\Events\AddMembership;
use Illuminate\Database\Eloquent\Relations\Pivot;

class Membership extends Pivot
Expand Down Expand Up @@ -32,8 +31,4 @@ public function approver()
{
return $this->belongsTo('App\Models\User', 'approved_by');
}

protected $dispatchesEvents = [
'updated' => AddMembership::class,
];
}
57 changes: 57 additions & 0 deletions app/Observers/MembershipObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Observers;

use App\Jobs\FolderAddMembership;
use App\Jobs\FolderDeleteMembership;
use App\Models\Membership;
use Illuminate\Support\Facades\Log;

class MembershipObserver
{
/**
* Handle the Membership "created" event.
*/
public function created(Membership $membership): void
{
//
}

/**
* Handle the Membership "updated" event.
*/
public function updated(Membership $membership): void
{
if ($membership->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
{
//
}
}
8 changes: 3 additions & 5 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,9 +27,6 @@ class EventServiceProvider extends ServiceProvider
FederationApprove::class => [
CreateFederationFolder::class,
],
AddMembership::class => [
SendNewMemberToSaveJob::class,
],

];

Expand All @@ -41,5 +38,6 @@ class EventServiceProvider extends ServiceProvider
public function boot()
{
Entity::observe(EntityObserver::class);
Membership::observe(MembershipObserver::class);
}
}

0 comments on commit 6cb3e98

Please sign in to comment.