Passed
Push — dev6 ( 273503...6464e0 )
by Ron
20:01
created

ActivateModuleCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 21
c 2
b 0
f 0
dl 0
loc 56
rs 10
ccs 0
cts 8
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkForConfig() 0 3 1
A handle() 0 33 3
A __construct() 0 3 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Artisan;
7
use Nwidart\Modules\Facades\Module;
8
9
class ActivateModuleCommand extends Command
10
{
11
    protected $signature   = 'tb_module:activate {module}';
12
    protected $description = 'Activate a new Tech Bench Add On Module';
13
14
    protected $module;
15
16
    /**
17
     * Create a new command instance
18
     */
19
    public function __construct()
20
    {
21
        parent::__construct();
22
    }
23
24
    /**
25
     * Execute the console command
26
     */
27
    public function handle()
28
    {
29
        $this->module = Module::find($this->argument('module'));
30
31
        //  Verify Module exists
32
        if(!$this->module)
33
        {
34
            $this->error('Unable to find module');
35
            return 1;
36
        }
37
38
        //  Verify module has config file
39
        $this->line('Activating Module '.$this->module);
40
        if(!$this->checkForConfig())
41
        {
42
            $this->error('Config file is missing');
43
            return 1;
44
        }
45
46
        //  Enable the module
47
        Artisan::call('module:enable '.$this->module->getStudlyName());
48
49
        //  Run any migrations
50
        $this->line('Setting up database');
51
        Artisan::call('migrate');
52
53
        //  Combine the new Javascript files
54
        $this->line('Creating Javascript files (this may take some time)');
55
        shell_exec('cd '.base_path().DIRECTORY_SEPARATOR.' && npm run production');
56
57
        $this->info('Module has been activated');
58
59
        return Command::SUCCESS;
60
    }
61
62
    protected function checkForConfig()
63
    {
64
        return file_exists($this->module->getPath().DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'config.php');
65
    }
66
}
67