Skip to content

Commit

Permalink
when Federation was approved then create folder in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 1, 2024
1 parent bf5f8d2 commit 31567cd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/Events/FederationApprove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Events;

use App\Models\Federation;
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;

class FederationApprove
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public Federation $federation;

/**
* Create a new event instance.
*/
public function __construct(Federation $federation)
{
$this->federation = $federation;
}

}
38 changes: 38 additions & 0 deletions app/Listeners/CreateFederationFolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Listeners;

use App\Events\FederationApprove;
use App\Traits\FederationTrait;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Storage;

class CreateFederationFolder
{
use FederationTrait;

/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(FederationApprove $event): void
{

$federation = $event->federation;
if($federation->approved)
{
if(!Storage::disk('metadata')->exists($federation->name)){
$this->createFederationFolder($federation->name);
}
}

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

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 @@ -60,4 +61,9 @@ public function scopeSearch($query, string $search = null)
->orWhere('xml_id', 'like', "%$search%")
->orWhere('xml_name', 'like', "%$search%");
}

protected $dispatchesEvents = [
'updated' => FederationApprove::class,
];

}
6 changes: 6 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Providers;

use App\Events\FederationApprove;
use App\Listeners\CreateFederationFolder;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
Expand All @@ -18,6 +20,10 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [
SendEmailVerificationNotification::class,
],
FederationApprove::class =>
[
CreateFederationFolder::class,
]
];

/**
Expand Down

0 comments on commit 31567cd

Please sign in to comment.