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

ActivateModuleCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
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