This commit is contained in:
Bozhidar 2024-10-17 11:48:23 +03:00
parent 1441eaa6e4
commit f2f7dc815e
6 changed files with 82 additions and 32 deletions

View file

@ -0,0 +1,38 @@
<?php
namespace Modules\Microweber\App\Providers;
use App\Events\DomainIsChanged;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Modules\Microweber\Listeners\DomainIsChangedListener;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
DomainIsChanged::class => [
DomainIsChangedListener::class,
],
];
/**
* Register any events for your application.
*/
public function boot(): void
{
//
}
/**
* Determine if events and listeners should be automatically discovered.
*/
public function shouldDiscoverEvents(): bool
{
return false;
}
}

View file

@ -47,6 +47,7 @@ class MicroweberServiceProvider extends ServiceProvider
}); });
$this->app->register(RouteServiceProvider::class); $this->app->register(RouteServiceProvider::class);
$this->app->register(EventServiceProvider::class);
app()->backupManager->registerConfig(MicroweberBackupConfig::class, $this->moduleNameLower); app()->backupManager->registerConfig(MicroweberBackupConfig::class, $this->moduleNameLower);
app()->virtualHostManager->registerConfig(MicroweberApacheVirtualHostConfig::class, $this->moduleNameLower); app()->virtualHostManager->registerConfig(MicroweberApacheVirtualHostConfig::class, $this->moduleNameLower);

View file

@ -0,0 +1,38 @@
<?php
namespace Modules\Microweber\Listeners;
use App\Events\DomainIsChanged;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Modules\Microweber\App\Models\MicroweberInstallation;
class DomainIsChangedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
}
/**
* Handle the event.
*/
public function handle(DomainIsChanged $event): void
{
if (!isset($event->domain->id)) {
return;
}
$findMicroweberInstallation = MicroweberInstallation::where('domain_id', $event->domain->id)->first();
if (!$findMicroweberInstallation) {
return;
}
shell_exec('php '. $findMicroweberInstallation->installation_path . '/artisan cache:clear');
}
}

View file

@ -14,12 +14,14 @@ class DomainIsChanged
{ {
use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
public $domain;
/** /**
* Create a new event instance. * Create a new event instance.
*/ */
public function __construct() public function __construct($domain)
{ {
// $this->domain = $domain;
} }
/** /**

View file

@ -1,26 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\DomainIsChanged;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class DomainIsChangedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(DomainIsChanged $event): void
{
//
}
}

View file

@ -34,10 +34,7 @@ class EventServiceProvider extends ServiceProvider
], ],
ModelPhyreServerCreated::class => [ ModelPhyreServerCreated::class => [
ModelPhyreServerCreatedListener::class, ModelPhyreServerCreatedListener::class,
], ]
DomainIsChanged::class => [
DomainIsChangedListener::class,
],
]; ];
/** /**