Skip to content

Commit 2de18e1

Browse files
committed
Merge branch 'release/v0.0.2' into main
2 parents e89b089 + ea70519 commit 2de18e1

File tree

1 file changed

+137
-2
lines changed

1 file changed

+137
-2
lines changed

Helpers/VaahArtisan.php

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,151 @@
33

44
class VaahArtisan{
55

6+
public $params;
7+
68
public function __construct()
79
{
810

911

1012

1113
}
1214

13-
public function test()
15+
//-------------------------------------------------
16+
public function validateMigrateCommand($command)
17+
{
18+
//acceptable commands
19+
$commands = [
20+
"migrate",
21+
"migrate:fresh",
22+
"migrate:install",
23+
"migrate:refresh",
24+
"migrate:reset",
25+
"migrate:rollback",
26+
"migrate:status",
27+
"db:seed",
28+
"db:wipe",
29+
];
30+
31+
32+
if(!in_array($command, $commands))
33+
{
34+
$response['status'] = 'failed';
35+
$response['errors'][] = 'Invalid command';
36+
if(env('APP_DEBUG'))
37+
{
38+
$response['hint']['acceptable_commands'] = $commands;
39+
}
40+
return $response;
41+
42+
}
43+
44+
$response['status'] = 'success';
45+
$response['data'][] = '';
46+
return $response;
47+
}
48+
//-------------------------------------------------
49+
public function migrate($command, $db_connection_name=null, $path=null )
50+
{
51+
52+
$is_valid = $this->validateMigrateCommand($command);
53+
54+
if($is_valid['status'] == 'failed')
55+
{
56+
return $is_valid;
57+
}
58+
59+
if($path)
60+
{
61+
$this->params['--path'] = $path;
62+
}
63+
64+
if($path)
65+
{
66+
$this->params['--database'] = $db_connection_name;
67+
}
68+
69+
$response = [
70+
'status' => 'success'
71+
];
72+
73+
try{
74+
\Artisan::call($command, $this->params);
75+
$response['status'] = 'success';
76+
$response['data'] = [];
77+
$response['messages'][] = 'Migrate command "'.$command.'" successfully executed';
78+
79+
}catch(\Exception $e)
80+
{
81+
$response['status'] = 'failed';
82+
$response['errors'][] = $e->getMessage();
83+
}
84+
return $response;
85+
86+
}
87+
//-------------------------------------------------
88+
public function validateSeedCommand($command)
89+
{
90+
//acceptable commands
91+
$commands = [
92+
"db:seed",
93+
"db:wipe",
94+
];
95+
96+
97+
if(!in_array($command, $commands))
98+
{
99+
$response['status'] = 'failed';
100+
$response['errors'][] = 'Invalid command';
101+
if(env('APP_DEBUG'))
102+
{
103+
$response['hint']['acceptable_commands'] = $commands;
104+
}
105+
return $response;
106+
107+
}
108+
109+
$response['status'] = 'success';
110+
$response['data'][] = '';
111+
return $response;
112+
}
113+
//-------------------------------------------------
114+
public function seed($command, $db_connection_name=null, $class=null)
14115
{
15-
die("<hr/>line number=abc");
116+
$is_valid = $this->validateSeedCommand($command);
117+
118+
if($is_valid['status'] == 'failed')
119+
{
120+
return $is_valid;
121+
}
122+
123+
if($class)
124+
{
125+
$this->params['--class'] = $class;
126+
}
127+
128+
if($db_connection_name)
129+
{
130+
$this->params['--database'] = $db_connection_name;
131+
}
132+
133+
$response = [
134+
'status' => 'success'
135+
];
136+
137+
try{
138+
\Artisan::call($command, $this->params);
139+
$response['status'] = 'success';
140+
$response['data'] = [];
141+
$response['messages'][] = 'Database has been seeded successfully';
142+
143+
}catch(\Exception $e)
144+
{
145+
$response['status'] = 'failed';
146+
$response['errors'][] = $e->getMessage();
147+
}
148+
return $response;
149+
16150
}
151+
//-------------------------------------------------
17152

18153
}

0 commit comments

Comments
 (0)