19
19
use Elasticsearch \Util \ClientEndpoint ;
20
20
use Elasticsearch \Util \Endpoint ;
21
21
use Elasticsearch \Util \NamespaceEndpoint ;
22
+ use Elasticsearch \Tests \Utility ;
22
23
23
24
require_once dirname (__DIR__ ) . '/vendor/autoload.php ' ;
24
25
26
+
27
+
28
+ removeDirectory (__DIR__ . '/../src/Elasticsearch/Endpoints ' , [
29
+ __DIR__ . '/../src/Elasticsearch/Endpoints/AbstractEndpoint.php ' ,
30
+ ]);
31
+ removeDirectory (__DIR__ . '/../src/Elasticsearch/Namespaces ' , [
32
+ __DIR__ . '/../src/Elasticsearch/Namespaces/AbstractNamespace.php ' ,
33
+ __DIR__ . '/../src/Elasticsearch/Namespaces/BooleanRequestWrapper.php ' ,
34
+ __DIR__ . '/../src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php '
35
+ ]);
36
+
37
+ die ();
38
+ printf ("Generating endpoints for Elasticsearch \n" );
39
+ printf ("--- \n" );
40
+
25
41
$ start = microtime (true );
26
- if (!isset ($ argv [1 ])) {
27
- print_usage_msg ();
28
- exit (1 );
29
- }
30
- if ($ argv [1 ] < '7.3.0 ' ) {
31
- printf ("Error: the version must be >= 7.4.0 \n" );
42
+
43
+ $ client = Utility::getClient ();
44
+
45
+ $ serverInfo = $ client ->info ();
46
+ $ version = $ serverInfo ['version ' ]['number ' ];
47
+ $ buildHash = $ serverInfo ['version ' ]['build_hash ' ];
48
+
49
+ if (version_compare ($ version , '7.4.0 ' , '< ' )) {
50
+ printf ("Error: the ES version must be >= 7.4.0 \n" );
32
51
exit (1 );
33
52
}
34
53
35
- $ ver = $ argv [1 ];
36
- $ version = 'v ' . $ ver ;
37
-
38
54
$ gitWrapper = new GitWrapper ();
39
55
$ git = $ gitWrapper ->workingCopy (dirname (__DIR__ ) . '/util/elasticsearch ' );
40
56
41
- $ git ->run ('fetch ' , ['--all ' ]);
42
- $ tags = explode ("\n" , $ git ->run ('tag ' ));
43
- if (!in_array ($ version , $ tags )) {
44
- $ branches = explode ("\n" , $ git ->run ('branch ' , ['-r ' ]));
45
- array_walk ($ branches , function (&$ value , &$ key ) {
46
- $ value = trim ($ value );
47
- });
48
- $ version = "origin/ $ ver " ;
49
- if (!in_array ($ version , $ branches )) {
50
- printf ("Error: the version %s specified doesnot exist \n" , $ version );
51
- exit (1 );
52
- }
53
- }
54
-
55
- $ git ->run ('checkout ' , [$ version ]);
57
+ $ git ->run ('checkout ' , [$ buildHash ]);
56
58
$ result = $ git ->run (
57
59
'ls-files ' ,
58
60
[
61
63
]
62
64
);
63
65
$ files = explode ("\n" , $ result );
64
- $ outputDir = __DIR__ . "/output/ $ ver " ;
66
+ $ outputDir = __DIR__ . "/output/ $ version " ;
65
67
66
68
// Remove the output directory
67
69
printf ("Removing %s folder \n" , $ outputDir );
82
84
}
83
85
printf ("Generation %s... " , basename ($ file ));
84
86
85
- $ endpoint = new Endpoint ($ file , $ git ->run ('show ' , [': ' . trim ($ file )]), $ ver );
87
+ $ endpoint = new Endpoint ($ file , $ git ->run ('show ' , [': ' . trim ($ file )]), $ version );
86
88
87
89
$ dir = $ endpointDir . NamespaceEndpoint::normalizeName ($ endpoint ->namespace );
88
90
if (!file_exists ($ dir )) {
109
111
110
112
foreach ($ namespaces as $ name => $ endpoints ) {
111
113
if (empty ($ name )) {
112
- $ clientEndpoint = new ClientEndpoint (array_keys ($ namespaces ), $ ver );
114
+ $ clientEndpoint = new ClientEndpoint (array_keys ($ namespaces ), $ version );
113
115
foreach ($ endpoints as $ ep ) {
114
116
$ clientEndpoint ->addEndpoint ($ ep );
115
117
}
120
122
$ countNamespace ++;
121
123
continue ;
122
124
}
123
- $ namespace = new NamespaceEndpoint ($ name , $ ver );
125
+ $ namespace = new NamespaceEndpoint ($ name , $ version );
124
126
foreach ($ endpoints as $ ep ) {
125
127
$ namespace ->addEndpoint ($ ep );
126
128
}
131
133
$ countNamespace ++;
132
134
}
133
135
136
+ # Clean
134
137
$ end = microtime (true );
135
138
printf ("\nGenerated %d endpoints and %d namespaces in %.3f seconds \n. " , $ countEndpoint , $ countNamespace , $ end - $ start );
139
+ printf ("--- \n" );
140
+
141
+ printf ("Backup Endpoints and Namespaces in /src " );
136
142
143
+ $ file = Client::Version;
144
+
145
+ $ zip = new ZipArchive ();
146
+ $ ret = $ zip ->open ('application.zip ' , ZipArchive::CREATE | ZipArchive::OVERWRITE );
147
+ if ($ ret !== TRUE ) {
148
+ printf ('Failed with code %d ' , $ ret );
149
+ } else {
150
+ $ options = array ('add_path ' => 'sources/ ' , 'remove_all_path ' => TRUE );
151
+ $ zip ->addGlob ('*.{php,txt} ' , GLOB_BRACE , $ options );
152
+ $ zip ->close ();
153
+ }
137
154
// End
138
155
139
156
function print_usage_msg (): void
@@ -143,17 +160,41 @@ function print_usage_msg(): void
143
160
}
144
161
145
162
// Remove directory recursively
146
- function removeDirectory ($ directory )
163
+ function removeDirectory ($ directory, array $ omit = [] )
147
164
{
148
165
foreach (glob ("{$ directory }/* " ) as $ file )
149
166
{
150
167
if (is_dir ($ file )) {
151
- removeDirectory ($ file );
168
+ if (!in_array ($ file , $ omit )) {
169
+ //removeDirectory($file);
170
+ printf ("Elimino directory %s \n" , $ file );
171
+ }
152
172
} else {
153
- unlink ($ file );
173
+ if (!in_array ($ file , $ omit )) {
174
+ //unlink($file);
175
+ printf ("Elimino file %s \n" , $ file );
176
+ }
154
177
}
155
178
}
156
- if (is_dir ($ directory )) {
157
- rmdir ($ directory );
179
+ if (is_dir ($ directory ) && empty ($ omit )) {
180
+ //rmdir($directory);
181
+ printf ("Elimino directory %s \n" , $ directory );
158
182
}
159
- }
183
+ }
184
+
185
+ # Copy files and directory recursively
186
+ function copyAll (string $ src , string $ dst ) {
187
+ $ dir = opendir ($ src );
188
+ @mkdir ($ dst );
189
+ while (false !== ( $ file = readdir ($ dir )) ) {
190
+ if (( $ file != '. ' ) && ( $ file != '.. ' )) {
191
+ if ( is_dir ($ src . '/ ' . $ file ) ) {
192
+ copyAll ($ src . '/ ' . $ file , $ dst . '/ ' . $ file );
193
+ }
194
+ else {
195
+ copy ($ src . '/ ' . $ file , $ dst . '/ ' . $ file );
196
+ }
197
+ }
198
+ }
199
+ closedir ($ dir );
200
+ }
0 commit comments