Skip to content

Commit

Permalink
rewrite existed event to Observer
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 25, 2024
1 parent 9dd81a9 commit 360b59f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 67 deletions.
23 changes: 0 additions & 23 deletions app/Events/FederationApprove.php

This file was deleted.

34 changes: 0 additions & 34 deletions app/Listeners/CreateFederationFolder.php

This file was deleted.

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

namespace App\Models;

use App\Events\FederationApprove;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand Down Expand Up @@ -61,8 +60,4 @@ public function scopeSearch($query, ?string $search = null)
->orWhere('xml_id', 'like', "%$search%")
->orWhere('xml_name', 'like', "%$search%");
}

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

namespace App\Observers;

use App\Models\Federation;
use App\Services\FederationService;
use Illuminate\Support\Facades\Storage;

class FederationObserver
{
/**
* Handle the Federation "created" event.
*/
public function created(Federation $federation): void
{
//
}

/**
* Handle the Federation "updated" event.
*/
public function updated(Federation $federation): void
{
$diskName = config('storageCfg.name');
if ($federation->approved && $federation->wasChanged('approved')) {
if (! Storage::disk($diskName)->exists($federation->name)) {
FederationService::createFederationFolder($federation->name);
}
}
}

/**
* Handle the Federation "deleted" event.
*/
public function deleted(Federation $federation): void
{
//
}

/**
* Handle the Federation "restored" event.
*/
public function restored(Federation $federation): void
{
//
}

/**
* Handle the Federation "force deleted" event.
*/
public function forceDeleted(Federation $federation): void
{
//
}
}
8 changes: 3 additions & 5 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Providers;

use App\Events\FederationApprove;
use App\Listeners\CreateFederationFolder;
use App\Models\Entity;
use App\Models\Federation;
use App\Models\Membership;
use App\Observers\EntityObserver;
use App\Observers\FederationObserver;
use App\Observers\MembershipObserver;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
Expand All @@ -24,9 +24,6 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [
SendEmailVerificationNotification::class,
],
FederationApprove::class => [
CreateFederationFolder::class,
],

];

Expand All @@ -39,5 +36,6 @@ public function boot()
{
Entity::observe(EntityObserver::class);
Membership::observe(MembershipObserver::class);
Federation::observe(FederationObserver::class);
}
}

0 comments on commit 360b59f

Please sign in to comment.