1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Console; |
6
|
|
|
|
7
|
|
|
use Illuminate\Database\Console\DbCommand as IlluminateDbCommand; |
8
|
|
|
use Symfony\Component\Process\Process; |
9
|
|
|
|
10
|
|
|
class DbCommand extends IlluminateDbCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Execute the console command. |
14
|
|
|
* |
15
|
|
|
* @return int |
16
|
|
|
* |
17
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter") |
18
|
|
|
*/ |
19
|
|
|
public function handle() |
20
|
|
|
{ |
21
|
|
|
$connection = $this->getConnection(); |
22
|
|
|
|
23
|
|
|
if ((! isset($connection['host']) && ! isset($connection['endpoint'])) && $connection['driver'] !== 'sqlite') { |
24
|
|
|
$this->components->error('No host specified for this database connection.'); |
25
|
|
|
$this->line(' Use the <options=bold>[--read]</> and <options=bold>[--write]</> options to specify a read or write connection.'); |
26
|
|
|
$this->newLine(); |
27
|
|
|
|
28
|
|
|
return IlluminateDbCommand::FAILURE; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
(new Process( |
32
|
|
|
array_merge([$this->getCommand($connection)], $this->commandArguments($connection)), |
33
|
|
|
null, |
34
|
|
|
$this->commandEnvironment($connection), |
35
|
|
|
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) { |
36
|
|
|
$this->output->write($buffer); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
return 0; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get the database client command to run. |
44
|
|
|
* |
45
|
|
|
* @param array<mixed> $connection |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getCommand(array $connection) |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
'mysql' => 'mysql', |
52
|
|
|
'pgsql' => 'psql', |
53
|
|
|
'sqlite' => 'sqlite3', |
54
|
|
|
'sqlsrv' => 'sqlcmd', |
55
|
|
|
'arangodb' => 'arangosh', |
56
|
|
|
][$connection['driver']]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the arguments for the ArangoDB CLI (Arangosh). |
61
|
|
|
* |
62
|
|
|
* @param array<mixed> $connection |
63
|
|
|
* @return array<mixed> |
64
|
|
|
*/ |
65
|
|
|
protected function getArangodbArguments(array $connection) |
66
|
|
|
{ |
67
|
|
|
return array_merge([ |
68
|
|
|
'--server.endpoint=' . $connection['endpoint'], |
69
|
|
|
'--server.database=' . $connection['database'], |
70
|
|
|
'--server.username=' . $connection['username'], |
71
|
|
|
], $this->getOptionalArguments([ |
72
|
|
|
'password' => '--server.password=' . $connection['password'], |
73
|
|
|
], $connection)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|