|
40 | 40 | Client::VERSION
|
41 | 41 | );
|
42 | 42 |
|
43 |
| -printf ("Backup Endpoints and Namespaces in /src\n"); |
| 43 | +printf ("Backup Endpoints and Namespaces in:\n%s\n", $backupFileName); |
44 | 44 | backup($backupFileName);
|
45 | 45 |
|
46 |
| -cleanFolders(); |
47 |
| - |
48 | 46 | $start = microtime(true);
|
49 | 47 | printf ("Generating endpoints for Elasticsearch\n");
|
50 | 48 |
|
|
61 | 59 | ]
|
62 | 60 | );
|
63 | 61 | $files = explode("\n", $result);
|
64 |
| -$outputDir = __DIR__ . "/../src/Elasticsearch/"; |
| 62 | + |
| 63 | +$outputDir = __DIR__ . "/output"; |
| 64 | +if (!file_exists($outputDir)) { |
| 65 | + mkdir($outputDir); |
| 66 | +} |
65 | 67 |
|
66 | 68 | $endpointDir = "$outputDir/Endpoints/";
|
| 69 | +if (!file_exists($endpointDir)) { |
| 70 | + mkdir($endpointDir); |
| 71 | +} |
67 | 72 |
|
68 | 73 | $countEndpoint = 0;
|
69 | 74 | $namespaces = [];
|
|
88 | 93 | );
|
89 | 94 | if (!isValidPhpSyntax($outputFile)) {
|
90 | 95 | printf("Error: syntax error in %s\n", $outputFile);
|
91 |
| - $success = false; |
92 |
| - break; |
| 96 | + exit(1); |
93 | 97 | }
|
94 | 98 |
|
95 | 99 | printf("done\n");
|
|
98 | 102 | $countEndpoint++;
|
99 | 103 | }
|
100 | 104 |
|
101 |
| -if (!$success) { |
102 |
| - printf ("Roll back to the previous Endpoints and Namespace (ver. %s)\n", Client::VERSION); |
103 |
| - cleanFolders(); |
104 |
| - restore($backupFileName); |
105 |
| - exit(1); |
106 |
| -} |
107 |
| - |
108 | 105 | // Generate namespaces
|
109 | 106 | $namespaceDir = "$outputDir/Namespaces/";
|
| 107 | +if (!file_exists($namespaceDir)) { |
| 108 | + mkdir($namespaceDir); |
| 109 | +} |
| 110 | + |
110 | 111 | $countNamespace = 0;
|
111 | 112 | $clientFile = "$outputDir/Client.php";
|
112 | 113 |
|
|
122 | 123 | );
|
123 | 124 | if (!isValidPhpSyntax($clientFile)) {
|
124 | 125 | printf("Error: syntax error in %s\n", $clientFile);
|
125 |
| - $success = false; |
126 |
| - break; |
| 126 | + exit(1); |
127 | 127 | }
|
128 | 128 | $countNamespace++;
|
129 | 129 | continue;
|
|
139 | 139 | );
|
140 | 140 | if (!isValidPhpSyntax($namespaceFile)) {
|
141 | 141 | printf("Error: syntax error in %s\n", $namespaceFile);
|
142 |
| - $success = false; |
143 |
| - break; |
| 142 | + exit(1); |
144 | 143 | }
|
145 | 144 | $countNamespace++;
|
146 | 145 | }
|
147 | 146 |
|
| 147 | +$destDir = __DIR__ . "/../src/Elasticsearch"; |
| 148 | + |
| 149 | +printf("Copying the generated files to %s\n", $destDir); |
| 150 | +cleanFolders(); |
| 151 | +moveSubFolder($outputDir . "/Endpoints", $destDir . "/Endpoints"); |
| 152 | +moveSubFolder($outputDir . "/Namespaces", $destDir . "/Namespaces"); |
| 153 | +rename($outputDir . "/Client.php", $destDir . "/Client.php"); |
| 154 | + |
148 | 155 | $end = microtime(true);
|
149 |
| -if ($success) { |
150 |
| - printf("\nGenerated %d endpoints and %d namespaces in %.3f seconds\n.", $countEndpoint, $countNamespace, $end - $start); |
151 |
| -} else { |
152 |
| - printf ("Roll back to the previous Endpoints and Namespace (ver. %s)\n", Client::VERSION); |
153 |
| - cleanFolders(); |
154 |
| - restore($backupFileName); |
155 |
| -} |
| 156 | +printf("\nGenerated %d endpoints and %d namespaces in %.3f seconds\n", $countEndpoint, $countNamespace, $end - $start); |
| 157 | + |
| 158 | +removeDirectory($outputDir); |
156 | 159 |
|
157 | 160 | /**
|
158 |
| - * FUNCTIONS |
| 161 | + * ---------------------------------- FUNCTIONS ---------------------------------- |
159 | 162 | */
|
160 | 163 |
|
161 | 164 | /**
|
162 | 165 | * Remove a directory recursively
|
163 | 166 | */
|
164 |
| - function removeDirectory($directory, array $omit = []) |
| 167 | +function removeDirectory($directory, array $omit = []) |
165 | 168 | {
|
166 | 169 | foreach(glob("{$directory}/*") as $file)
|
167 | 170 | {
|
@@ -196,6 +199,16 @@ function cleanFolders()
|
196 | 199 | @unlink(__DIR__ . '/../src/Elasticsearch/Client.php');
|
197 | 200 | }
|
198 | 201 |
|
| 202 | +/** |
| 203 | + * Move subfolder |
| 204 | + */ |
| 205 | +function moveSubFolder(string $origin, string $destination) |
| 206 | +{ |
| 207 | + foreach (glob("{$origin}/*") as $file) { |
| 208 | + rename($file, $destination . "/" . basename($file)); |
| 209 | + } |
| 210 | +} |
| 211 | + |
199 | 212 | /**
|
200 | 213 | * Backup Endpoints, Namespaces and Client in src/Elasticsearch
|
201 | 214 | */
|
|
0 commit comments