1
|
|
|
<?php |
2
|
|
|
namespace CodexShaper\DBM\Commands; |
3
|
|
|
|
4
|
|
|
use CodexShaper\DBM\Facades\Manager; |
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
class DatabaseAdmin extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'dbm:admin {email} {action=create} {--c|column=email}'; |
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Make Database Admin'; |
23
|
|
|
/** |
24
|
|
|
* Get Option |
25
|
|
|
* |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
|
|
protected function getOptions() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null], |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the composer command for the environment. |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
protected function findComposer() |
41
|
|
|
{ |
42
|
|
|
if (file_exists(getcwd() . '/composer.phar')) { |
43
|
|
|
return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar'; |
44
|
|
|
} |
45
|
|
|
return 'composer'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Execute the console command. |
50
|
|
|
* |
51
|
|
|
* @param \Illuminate\Filesystem\Filesystem $filesystem |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
public function handle(Filesystem $filesystem) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$email = $this->argument('email'); |
58
|
|
|
$column = $this->option('column'); |
59
|
|
|
$permissions = Manager::Permission()->all(); |
60
|
|
|
$successMessage = "Admin Created successfully"; |
61
|
|
|
|
62
|
|
|
if ($this->argument('action') == 'drop') { |
63
|
|
|
$permissions = []; |
64
|
|
|
$successMessage = "Admin Deleted successfully"; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$userModel = config('dbm.user.model'); |
68
|
|
|
$userTable = config('dbm.user.table'); |
69
|
|
|
$localObject = Manager::model($userModel, $userTable) |
70
|
|
|
->where($column, $email) |
71
|
|
|
->first(); |
72
|
|
|
Manager::Object() |
73
|
|
|
->setManyToManyRelation( |
74
|
|
|
$localObject, |
75
|
|
|
Manager::Permission(), |
76
|
|
|
'dbm_user_permissions', |
77
|
|
|
'user_id', |
78
|
|
|
'dbm_permission_id' |
79
|
|
|
) |
80
|
|
|
->belongs_to_many() |
81
|
|
|
->sync($permissions); |
82
|
|
|
$this->info($successMessage); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.