This commit is contained in:
Bozhidar Slaveykov 2024-04-02 18:51:50 +03:00
parent d5a82c528a
commit f8ae6c0153
2 changed files with 44 additions and 1 deletions

View file

@ -0,0 +1,33 @@
<?php
namespace App\Actions;
use App\ShellApi;
class ApacheWebsiteDelete
{
public $domain;
public function setDomain($domain)
{
$this->domain = $domain;
}
public function handle()
{
$apacheConf = '/etc/apache2/sites-available/'.$this->domain.'.conf';
ShellApi::exec('rm -rf ' . $apacheConf);
$apacheConfEnabled = '/etc/apache2/sites-enabled/'.$this->domain.'.conf';
ShellApi::exec('rm -rf ' . $apacheConfEnabled);
// SSL
$apacheSSLConf = '/etc/apache2/sites-available/'.$this->domain.'-ssl.conf';
ShellApi::exec('rm -rf ' . $apacheSSLConf);
$apacheSSLConfEnabled = '/etc/apache2/sites-enabled/'.$this->domain.'-ssl.conf';
ShellApi::exec('rm -rf ' . $apacheSSLConfEnabled);
}
}

View file

@ -2,7 +2,9 @@
namespace App\Listeners;
use App\Actions\ApacheWebsiteDelete;
use App\Events\ModelWebsiteDeleting;
use App\ShellApi;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
@ -21,6 +23,14 @@ class ModelWebsiteDeletingListener
*/
public function handle(ModelWebsiteDeleting $event): void
{
// dd($event);
$domainRoot = '/home/'.$event->model->domain_username.'/domains/'.$event->model->domain;
ShellApi::exec('rm -rf ' . $domainRoot);
$deleteApacheWebsite = new ApacheWebsiteDelete();
$deleteApacheWebsite->setDomain($event->model->domain);
$deleteApacheWebsite->handle();
}
}