has_submodules = true; $parentModule->save(); } // insert module into database $module = Module::create([ 'name' => $name, 'description' => $description, 'handler' => $handler, 'manages_content' => $managesContent, 'support_categories' => $supportCategories, 'alias' => $alias, 'module_settings' => json_encode($settings), 'parent_id' => $parentModuleId ? $parentModuleId : null, 'enabled' => 1, 'is_template' => $isTemplate ]); // install something module-specific if ($handler) { call_user_func([$handler, 'install']); } return $module; } /** * Delete module from database and uninstall its dependencies * * @throws \ErrorException */ 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 if ($this->is_template) { $this->deleteDirectory(resource_path('views/visitor')); $this->deleteDirectory(resource_path('views/modules')); $this->deleteDirectory(public_path('assets')); // delete all template paths TemplatePath::getQuery()->delete(); } if ($this->handler && is_callable([$this->handler, 'uninstall'])) { call_user_func([$this->handler, 'uninstall'], $this); } $this->delete(); } /** * Delete directory when uninstalling module. * * @param $directory * * @throws \ErrorException */ private function deleteDirectory($directory) { if (!is_dir($directory)) return; $success = \File::deleteDirectory($directory, true); if (!$success) { throw new \ErrorException('Cannot delete ' . $directory); } } }