Bozhidar Slaveykov 1 år sedan
förälder
incheckning
f8ae6c0153

+ 33 - 0
web/app/Actions/ApacheWebsiteDelete.php

@@ -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);
+
+    }
+}

+ 11 - 1
web/app/Listeners/ModelWebsiteDeletingListener.php

@@ -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();
+
     }
 }