Passed
Push — master ( 1cc110...8d0399 )
by Reza
03:22
created

Uninstall   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 20
c 4
b 0
f 1
dl 0
loc 40
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteFiles() 0 10 1
A dropTables() 0 4 1
A handle() 0 16 3
1
<?php
2
3
namespace EasyPanel\Commands\Actions;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\File;
7
use Illuminate\Support\Facades\Schema;
8
use EasyPanel\Services\LangManager;
9
10
class Uninstall extends Command
11
{
12
13
    protected $signature = 'panel:uninstall {--f|force : Force mode}';
14
    protected $description = 'Uninstall the panel';
15
16
    public function handle()
17
    {
18
        $status = $this->option('force') ? true : $this->confirm("Do you really want to uninstall the panel ? (All files and components will be deleted)", true);
19
20
        if (!$status) {
21
            $this->info("The process was canceled");
22
            return;
23
        }
24
25
        // Delete folders and files which EasyPanel published
26
        $this->deleteFiles();
27
28
        // Drop tables which has been created by EasyPanel
29
        $this->dropTables();
30
31
        $this->info("All files and components was deleted!");
32
    }
33
34
    private function dropTables()
35
    {
36
        Schema::dropIfExists('cruds');
37
        Schema::dropIfExists('panel_admins');
38
    }
39
40
    private function deleteFiles()
41
    {
42
        File::deleteDirectory(app_path('Http/Livewire/Admin'));
43
        File::deleteDirectory(app_path('CRUD'));
44
        File::deleteDirectory(resource_path('views/livewire/admin'));
45
        File::deleteDirectory(resource_path('views/vendor/admin'));
46
        File::deleteDirectory(resource_path('cruds'));
47
        File::deleteDirectory(public_path('assets/admin'));
48
        File::delete(config_path('easy_panel.php'));
49
        File::delete(LangManager::getFiles());
50
    }
51
52
53
}
54