This commit is contained in:
Bozhidar Slaveykov 2024-04-05 18:14:33 +03:00
parent d961b69500
commit 492289b36f
4 changed files with 72 additions and 72 deletions

View file

@ -0,0 +1,67 @@
<?php
namespace App\Listeners;
use App\Actions\ApacheWebsiteCreate;
use App\Events\ModelWebsiteCreated;
use App\Models\Customer;
use App\Models\HostingPackage;
use App\Models\HostingPlan;
use App\Models\HostingSubscription;
use Cassandra\Custom;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Str;
use function Symfony\Component\String\u;
class ModelDomainCreatedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(ModelDomainCreated $event): void
{
$findDomain = \App\Models\Domain::where('id', $event->model->id)->first();
if (!$findDomain) {
return;
}
$findHostingSubscription = HostingSubscription::where('id', $findDomain->hosting_subscription_id)->first();
if (!$findHostingSubscription) {
return;
}
$findHostingPlan = HostingPlan::where('id', $findHostingSubscription->hosting_plan_id)->first();
if (!$findHostingPlan) {
return;
}
$newApacheWebsite = new ApacheWebsiteCreate();
$newApacheWebsite->setDomain($findDomain->domain);
$newApacheWebsite->setUser($findHostingSubscription->system_username);
$newApacheWebsite->setAdditionalServices($findHostingPlan->additional_services);
$newApacheWebsite->setFeatures($findHostingPlan->features);
$create = $newApacheWebsite->handle();
dd($create);
if (!empty($create)) {
$findDomain->home_root = $create['homeRoot'];
$findDomain->domain_root = $create['domainRoot'];
$findDomain->domain_public = $create['domainPublic'];
$findDomain->save();
event(new \App\Events\DomainIsCreated($findDomain));
}
}
}

View file

@ -8,7 +8,7 @@ use App\ShellApi;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class ModelWebsiteDeletingListener
class ModelDomainDeletingListener
{
/**
* Create the event listener.

View file

@ -1,67 +0,0 @@
<?php
namespace App\Listeners;
use App\Actions\ApacheWebsiteCreate;
use App\Events\ModelWebsiteCreated;
use App\Models\Customer;
use App\Models\HostingPackage;
use App\Models\HostingPlan;
use Cassandra\Custom;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Str;
use function Symfony\Component\String\u;
class ModelWebsiteCreatedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(ModelWebsiteCreated $event): void
{
$findWebsite = \App\Models\Domain::where('id', $event->model->id)->first();
if (!$findWebsite) {
return;
}
$findCustomer = Customer::where('id', $findWebsite->customer_id)->first();
if (!$findCustomer) {
return;
}
$findHostingPlan = HostingPlan::where('id', $findWebsite->hosting_plan_id)->first();
if (!$findHostingPlan) {
return;
}
$newApacheWebsite = new ApacheWebsiteCreate();
$newApacheWebsite->setDomain($findWebsite->domain);
$newApacheWebsite->setUser($findCustomer->username);
$newApacheWebsite->setEmail($findCustomer->email);
$newApacheWebsite->setPassword(Str::random(16));
$newApacheWebsite->setAdditionalServices($findHostingPlan->additional_services);
$newApacheWebsite->setFeatures($findHostingPlan->features);
$create = $newApacheWebsite->handle();
if (!empty($create)) {
$findWebsite->domain_username = $findCustomer->username;
$findWebsite->home_root = $create['homeRoot'];
$findWebsite->domain_root = $create['domainRoot'];
$findWebsite->domain_public = $create['domainPublic'];
$findWebsite->save();
event(new \App\Events\HostingAccountIsCreated($findWebsite));
}
}
}

View file

@ -11,8 +11,8 @@ use App\Listeners\ModelHostingSubscriptionDeletingListener;
use App\Events\ModelWebsiteCreated;
use App\Events\ModelWebsiteDeleting;
use App\Listeners\ModelWebsiteCreatedListener;
use App\Listeners\ModelWebsiteDeletingListener;
use App\Listeners\ModelDomainCreatedListener;
use App\Listeners\ModelDomainDeletingListener;
use App\Policies\CustomerPolicy;
use Filament\Facades\Filament;
@ -49,8 +49,8 @@ class AppServiceProvider extends ServiceProvider
Gate::define('delete-customer', [CustomerPolicy::class, 'delete']);
Event::listen(ModelWebsiteCreated::class,ModelWebsiteCreatedListener::class);
Event::listen(ModelWebsiteDeleting::class,ModelWebsiteDeletingListener::class);
Event::listen(ModelWebsiteCreated::class,ModelDomainCreatedListener::class);
Event::listen(ModelWebsiteDeleting::class,ModelDomainDeletingListener::class);
Event::listen(ModelHostingSubscriptionCreated::class,ModelHostingSubscriptionCreatedListener::class);
Event::listen(ModelHostingSubscriptionDeleting::class,ModelHostingSubscriptionDeletingListener::class);