FEATURE #1753: remove pingpong/modules and use custom solution
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace App\ModuleManager;
|
||||
|
||||
use App\Models\Module;
|
||||
use App\Models\Templates\TemplatePath;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class Uninstaller {
|
||||
/**
|
||||
* Delete module from database and uninstall its dependencies
|
||||
*
|
||||
* @param Module $module
|
||||
*
|
||||
* @throws \ErrorException
|
||||
*/
|
||||
public static function uninstall(Module $module)
|
||||
{
|
||||
// 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 ($module->is_template) {
|
||||
self::deleteDirectory(resource_path('views/visitor'));
|
||||
self::deleteDirectory(resource_path('views/modules'));
|
||||
self::deleteDirectory(public_path('assets'));
|
||||
|
||||
// delete all template paths
|
||||
TemplatePath::getQuery()
|
||||
->delete();
|
||||
}
|
||||
|
||||
if ($module->handler && is_callable([$module->handler, 'uninstall'])) {
|
||||
call_user_func([$module->handler, 'uninstall'], $module);
|
||||
}
|
||||
|
||||
$module->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete directory when uninstalling module.
|
||||
*
|
||||
* @param $directory
|
||||
*
|
||||
* @throws \ErrorException
|
||||
*/
|
||||
private static function deleteDirectory($directory)
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$success = \File::deleteDirectory($directory, true);
|
||||
|
||||
if (!$success) {
|
||||
throw new \ErrorException('Cannot delete ' . $directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user