diff --git a/app/Models/Module.php b/app/Models/Module.php index 27787299..95afd209 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -83,20 +83,24 @@ class Module extends Model * * @throws \ErrorException */ - public function uninstall() { + public function uninstall() + { // check if user does not want to install module in runtime if (!App::runningInConsole()) { throw new \ErrorException('Modules can be uninstalled only via Artisan!'); } // delete everything in /resources/views/visitor - $this->deleteDirectory(resource_path('views/visitor')); - $this->deleteDirectory(public_path('assets')); + if ($this->is_template) { + $this->deleteDirectory(resource_path('views/visitor')); + $this->deleteDirectory(public_path('assets')); - $handler = $this->handler; + // delete all template paths + TemplatePath::getQuery()->delete(); + } - if ($handler && is_callable([$handler, 'uninstall'])) { - call_user_func([$handler, 'uninstall'], $this); + if ($this->handler && is_callable([$this->handler, 'uninstall'])) { + call_user_func([$this->handler, 'uninstall'], $this); } $this->delete(); @@ -109,11 +113,12 @@ class Module extends Model * * @throws \ErrorException */ - private function deleteDirectory($directory) { + private function deleteDirectory($directory) + { $success = \File::deleteDirectory($directory, true); if (!$success) { - throw new \ErrorException('Cannot delete '.$directory); + throw new \ErrorException('Cannot delete ' . $directory); } } } \ No newline at end of file