3939$ version = $ serverInfo ['version ' ]['number ' ];
4040
4141$ artifactFile = sprintf ("rest-resources-zip-%s.zip " , $ version );
42- $ tempFilePath = sprintf ("%s/%s.zip " , sys_get_temp_dir (), $ serverInfo ['version ' ]['build_hash ' ]);
42+ $ buildHash = $ serverInfo ['version ' ]['build_hash ' ];
43+ $ tempFilePath = sprintf ("%s/%s.zip " , sys_get_temp_dir (), $ buildHash );
4344
4445if (!file_exists ($ tempFilePath )) {
4546 // Download of Elasticsearch rest-api artifacts
4950 exit (1 );
5051 }
5152 $ content = json_decode ($ json , true );
53+ $ found = false ;
5254 foreach ($ content ['version ' ]['builds ' ] as $ builds ) {
53- if ($ builds ['projects ' ]['elasticsearch ' ]['commit_hash ' ] === $ serverInfo [ ' version ' ][ ' build_hash ' ] ) {
55+ if ($ builds ['projects ' ]['elasticsearch ' ]['commit_hash ' ] === $ buildHash ) {
5456 // Download the artifact ZIP file (rest-resources-zip-$version.zip)
5557 printf ("Download %s \n" , $ builds ['projects ' ]['elasticsearch ' ]['packages ' ][$ artifactFile ]['url ' ]);
5658 if (!copy ($ builds ['projects ' ]['elasticsearch ' ]['packages ' ][$ artifactFile ]['url ' ], $ tempFilePath )) {
5759 printf ("ERROR: failed to download %s \n" , $ artifactFile );
5860 }
61+ $ found = true ;
5962 break ;
6063 }
6164 }
65+ if (!$ found ) {
66+ $ build = $ content ['version ' ]['builds ' ][0 ]; // pick the most recent
67+ $ resource = $ build ["projects " ]["elasticsearch " ]["packages " ][sprintf ("rest-resources-zip-%s.zip " , $ version )]['url ' ];
68+ if (!copy ($ resource , $ tempFilePath )) {
69+ printf ("ERROR: failed to download %s \n" , $ resource );
70+ }
71+ }
6272} else {
6373 printf ("The file %s already exists \n" , $ tempFilePath );
6474}
6575
6676if (!file_exists ($ tempFilePath )) {
67- printf ("ERROR: the commit_hash %s has not been found \n" , $ serverInfo [ ' version ' ][ ' build_hash ' ] );
77+ printf ("ERROR: I cannot download file %s \n" , $ tempFilePath );
6878 exit (1 );
6979}
7080$ zip = new ZipArchive ();
7181$ zip ->open ($ tempFilePath );
72- printf ("Extracting %s \ninto %s/rest-spec/%s \n" , $ tempFilePath , __DIR__ , $ serverInfo [ ' version ' ][ ' build_hash ' ] );
73- $ zip ->extractTo (sprintf ("%s/rest-spec/%s " , __DIR__ , $ serverInfo [ ' version ' ][ ' build_hash ' ] ));
82+ printf ("Extracting %s \ninto %s/rest-spec/%s \n" , $ tempFilePath , __DIR__ , $ buildHash );
83+ $ zip ->extractTo (sprintf ("%s/rest-spec/%s " , __DIR__ , $ buildHash ));
7484$ zip ->close ();
7585
7686printf ("Rest-spec API installed successfully! \n\n" );
0 commit comments