1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Builder; |
4
|
|
|
|
5
|
|
|
use ByJG\Config\Exception\ConfigNotFoundException; |
6
|
|
|
use ByJG\Config\Exception\EnvironmentException; |
7
|
|
|
use ByJG\Config\Exception\KeyNotFoundException; |
8
|
|
|
use ByJG\DbMigration\Database\MySqlDatabase; |
9
|
|
|
use ByJG\DbMigration\Exception\InvalidMigrationFile; |
10
|
|
|
use ByJG\DbMigration\Migration; |
11
|
|
|
use ByJG\Util\Uri; |
12
|
|
|
use Composer\Script\Event; |
13
|
|
|
use Exception; |
14
|
|
|
use Psr\SimpleCache\InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
class Scripts extends _Lib |
17
|
|
|
{ |
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
parent::__construct(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Event $event |
|
|
|
|
25
|
|
|
* @throws ConfigNotFoundException |
26
|
|
|
* @throws EnvironmentException |
27
|
|
|
* @throws KeyNotFoundException |
28
|
|
|
* @throws InvalidMigrationFile |
29
|
|
|
* @throws InvalidArgumentException |
30
|
|
|
*/ |
31
|
|
|
public static function migrate(Event $event) |
32
|
|
|
{ |
33
|
|
|
$migrate = new Scripts(); |
34
|
|
|
$migrate->runMigrate($event->getArguments()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws ConfigNotFoundException |
39
|
|
|
* @throws EnvironmentException |
40
|
|
|
* @throws KeyNotFoundException |
41
|
|
|
* @throws InvalidArgumentException |
42
|
|
|
*/ |
43
|
|
|
public static function genRestDocs() |
44
|
|
|
{ |
45
|
|
|
$build = new Scripts(); |
46
|
|
|
$build->runGenRestDocs(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param $arguments |
51
|
|
|
* @throws ConfigNotFoundException |
52
|
|
|
* @throws EnvironmentException |
53
|
|
|
* @throws KeyNotFoundException |
54
|
|
|
* @throws InvalidMigrationFile |
55
|
|
|
* @throws InvalidArgumentException |
56
|
|
|
*/ |
57
|
|
|
public function runMigrate($arguments) |
58
|
|
|
{ |
59
|
|
|
$dbConnection = Psr11::container()->get('DBDRIVER_CONNECTION'); |
60
|
|
|
|
61
|
|
|
$migration = new Migration(new Uri($dbConnection), $this->workdir . "/db"); |
62
|
|
|
$migration->registerDatabase("mysql", MySqlDatabase::class); |
63
|
|
|
$migration->addCallbackProgress(function ($cmd, $version) { |
64
|
|
|
echo "Doing $cmd, $version\n"; |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
$argumentList = $this->extractArguments($arguments); |
68
|
|
|
|
69
|
|
|
$exec['reset'] = function () use ($migration, $argumentList) { |
|
|
|
|
70
|
|
|
if (!$argumentList["--yes"]) { |
71
|
|
|
throw new Exception("Reset require the argument --yes"); |
72
|
|
|
} |
73
|
|
|
$migration->prepareEnvironment(); |
74
|
|
|
$migration->reset(); |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
$exec["update"] = function () use ($migration, $argumentList) { |
79
|
|
|
$migration->update($argumentList["--up-to"], $argumentList["--force"]); |
80
|
|
|
}; |
81
|
|
|
|
82
|
|
|
if (isset($exec[$argumentList['command']])) { |
|
|
|
|
83
|
|
|
$exec[$argumentList['command']](); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param $arguments |
89
|
|
|
* @param bool $hasCmd |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
protected function extractArguments($arguments, $hasCmd = true) { |
93
|
|
|
$ret = [ |
94
|
|
|
'--up-to' => null, |
95
|
|
|
'--yes' => null, |
96
|
|
|
'--force' => false, |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$start = 0; |
100
|
|
|
if ($hasCmd) { |
101
|
|
|
$ret['command'] = isset($arguments[0]) ? $arguments[0] : null; |
102
|
|
|
$start = 1; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
for ($i=$start; $i < count($arguments); $i++) { |
|
|
|
|
106
|
|
|
$args = explode("=", $arguments[$i]); |
107
|
|
|
$ret[$args[0]] = isset($args[1]) ? $args[1] : true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $ret; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @throws ConfigNotFoundException |
115
|
|
|
* @throws EnvironmentException |
116
|
|
|
* @throws KeyNotFoundException |
117
|
|
|
* @throws InvalidArgumentException |
118
|
|
|
*/ |
119
|
|
|
public function runGenRestDocs() |
120
|
|
|
{ |
121
|
|
|
$docPath = $this->workdir . '/web/docs/'; |
122
|
|
|
chdir($this->workdir); |
123
|
|
|
$this->liveExecuteCommand( |
124
|
|
|
$this->fixDir("vendor/bin/swagger") |
125
|
|
|
. " --output \"$docPath\" " |
126
|
|
|
. "--exclude vendor " |
127
|
|
|
. "--exclude docker " |
128
|
|
|
. "--exclude fw " |
129
|
|
|
. "--processor OperationId" |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$docs = file_get_contents("$docPath/swagger.json"); |
133
|
|
|
$docs = str_replace('__HOSTNAME__', Psr11::container()->get('API_SERVER'), $docs); |
134
|
|
|
file_put_contents("$docPath/swagger.json", $docs); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths