FEATURE: delete all template paths from template_path table on template uninstall

This commit is contained in:
Michal Kváček
2016-09-20 14:54:43 +02:00
parent e8b91db6f2
commit 39279a1633
+13 -8
View File
@@ -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);
}
}
}