39
39
$ version = $ serverInfo ['version ' ]['number ' ];
40
40
41
41
$ 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 );
43
44
44
45
if (!file_exists ($ tempFilePath )) {
45
46
// Download of Elasticsearch rest-api artifacts
49
50
exit (1 );
50
51
}
51
52
$ content = json_decode ($ json , true );
53
+ $ found = false ;
52
54
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 ) {
54
56
// Download the artifact ZIP file (rest-resources-zip-$version.zip)
55
57
printf ("Download %s \n" , $ builds ['projects ' ]['elasticsearch ' ]['packages ' ][$ artifactFile ]['url ' ]);
56
58
if (!copy ($ builds ['projects ' ]['elasticsearch ' ]['packages ' ][$ artifactFile ]['url ' ], $ tempFilePath )) {
57
59
printf ("ERROR: failed to download %s \n" , $ artifactFile );
58
60
}
61
+ $ found = true ;
59
62
break ;
60
63
}
61
64
}
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
+ }
62
72
} else {
63
73
printf ("The file %s already exists \n" , $ tempFilePath );
64
74
}
65
75
66
76
if (!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 );
68
78
exit (1 );
69
79
}
70
80
$ zip = new ZipArchive ();
71
81
$ 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 ));
74
84
$ zip ->close ();
75
85
76
86
printf ("Rest-spec API installed successfully! \n\n" );
0 commit comments