Uninstall::handle()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
c 5
b 0
f 1
nc 4
nop 0
dl 0
loc 18
rs 10
1
<?php
2
3
namespace EasyPanel\Commands\Actions;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Support\Facades\File;
8
use Illuminate\Support\Facades\Schema;
9
use EasyPanel\Support\Contract\LangManager;
10
11
class Uninstall extends Command
12
{
13
14
    protected $signature = 'panel:uninstall {--f|force : Force mode}';
15
    protected $description = 'Uninstall the panel';
16
17
    public function handle()
18
    {
19
        $status = $this->option('force') ? true : $this->confirm("Do you really want to uninstall the panel ? (All files and components will be deleted)", true);
20
21
        if (!$status) {
22
            $this->info("The process was canceled");
23
            return;
24
        }
25
26
        // Delete folders and files which EasyPanel published
27
        $this->deleteFiles();
28
29
        // Drop tables which has been created by EasyPanel
30
        $this->dropTables();
31
32
        $this->deleteMigrations();
33
34
        $this->info("All files and components was deleted!");
35
    }
36
37
    private function dropTables()
38
    {
39
        Schema::dropIfExists('cruds');
40
        Schema::dropIfExists('panel_admins');
41
        Schema::dropIfExists('role_user');
42
        Schema::dropIfExists('roles');
43
    }
44
45
    private function deleteFiles()
46
    {
47
        File::deleteDirectory(app_path('Http/Livewire/Admin'));
48
        File::deleteDirectory(app_path('CRUD'));
49
        File::deleteDirectory(resource_path('views/livewire/admin'));
50
        File::deleteDirectory(resource_path('views/vendor/admin'));
51
        File::deleteDirectory(resource_path('cruds'));
52
        File::deleteDirectory(public_path('assets/admin'));
53
        File::delete(config_path('easy_panel.php'));
54
        File::delete(config_path('dynamicACL.php'));
55
        File::delete(LangManager::getFiles());
56
    }
57
58
    private function deleteMigrations()
59
    {
60
        $migrationFiles = File::glob(database_path('migrations/*999999*.php'));
61
62
        File::delete($migrationFiles);
63
64
        DB::table('migrations')
65
            ->where('migration', 'like', '%999999%')
66
            ->delete();
67
    }
68
}
69