Passed
Push — main ( 52a9ba...b89683 )
by PRATIK
04:37 queued 14s
created

AdmineticWebsiteInstallCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 35
dl 0
loc 76
rs 10
c 3
b 0
f 1
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 29 5
A addBelongsToCategory() 0 14 3
1
<?php
2
3
namespace Adminetic\Website\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Artisan;
7
8
class AdmineticWebsiteInstallCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'install:adminetic-website';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Command to install adminetic website module.';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return int
38
     */
39
    public function handle()
40
    {
41
        if ($this->confirm('Do you wish to seed module permission?')) {
42
            Artisan::call('adminetic:website-permission');
43
        }
44
        if ($this->confirm('Do you wish to publish migration file?')) {
45
            Artisan::call('vendor:publish', ['--tag' => 'website-migrations']);
46
        } else {
47
            $this->info('Please turn off publish_migrations option in config/website');
48
            $this->info('Then run 1: (composer dump-autoload) 2: (php artisan migrate)');
49
        }
50
        $this->info('Adminetic website permission seeded ... ✅');
51
        Artisan::call('vendor:publish', [
52
            '--tag' => ['website-config'],
53
        ]);
54
        if ($this->confirm('Do you wish to publish view table?')) {
55
            Artisan::call('vendor:publish', ['--provider' => 'CyrildeWit\EloquentViewable\EloquentViewableServiceProvider', '--tag' => 'migrations']);
56
        }
57
        Artisan::call('vendor:publish', ['--provider' => 'Spatie\Analytics\AnalyticsServiceProvider']);
58
        $this->info('Adminetic website config file published ... ✅');
59
        $this->addBelongsToCategory();
60
        $this->info('Adminetic category installed ... ✅');
61
        if ($this->confirm('Do you wish to run website table migration?')) {
62
            Artisan::call('migrate');
63
            Artisan::call('migrate:adminetic-website');
64
        }
65
        $this->info('Adminetic website module migration complete ... ✅');
66
        $this->info('Adminetic Website Installed.');
67
        $this->info('Star to the admenictic repo would be appreciated.');
68
    }
69
70
    private function addBelongsToCategory()
71
    {
72
        $traitTemplate = file_get_contents(__DIR__ . '/../../Console/Stubs/CategoryMorphedByMany.stub');
73
74
        if (!file_exists($path = app_path('Traits'))) {
75
            mkdir($path, 0777, true);
76
        }
77
78
        $file = app_path('Traits/CategoryMorphedByMany.php');
79
        file_put_contents($file, $traitTemplate);
80
        if (file_exists($file)) {
81
            $this->info('CategoryMorphedByMany  trait created successfully ... ✅');
82
        } else {
83
            $this->error('Failed to create CategoryMorphedByMany  trait ...');
84
        }
85
    }
86
}
87