@@ -212,6 +212,84 @@ public function theCliUpdaterIsRun() {
212212 $ this ->CLIReturnCode = $ returnCode ;
213213 }
214214
215+ /**
216+ * @Given the archive for version :version is available locally
217+ */
218+ public function theArchiveForVersionIsAvailableLocally (string $ version ): void {
219+ if ($ this ->skipIt ) {
220+ return ;
221+ }
222+
223+ $ filename = 'nextcloud- ' . $ version . '.zip ' ;
224+ if (!file_exists ($ this ->tmpDownloadDir . $ filename )) {
225+ $ fp = fopen ($ this ->tmpDownloadDir . $ filename , 'w+ ' );
226+ $ url = $ this ->downloadURL . $ filename ;
227+ $ ch = curl_init ($ url );
228+ curl_setopt ($ ch , CURLOPT_FILE , $ fp );
229+ curl_setopt ($ ch , CURLOPT_USERAGENT , 'Nextcloud Updater ' );
230+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , 1 );
231+ if (curl_exec ($ ch ) === false ) {
232+ throw new \Exception ('Curl error: ' . curl_error ($ ch ));
233+ }
234+ $ httpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
235+ if ($ httpCode !== 200 ) {
236+ throw new \Exception ('Download failed for ' . $ url . ' - HTTP code: ' . $ httpCode );
237+ }
238+ curl_close ($ ch );
239+ fclose ($ fp );
240+ }
241+ }
242+
243+ /**
244+ * @When the CLI updater is run with local file URL for version :version and --no-verify successfully
245+ */
246+ public function theCliUpdaterIsRunWithLocalFileUrlAndNoVerifySuccessfully (string $ version ): void {
247+ if ($ this ->skipIt ) {
248+ return ;
249+ }
250+
251+ $ this ->runUpdaterWithLocalFileUrl ($ version , noVerify: true );
252+
253+ if ($ this ->CLIReturnCode !== 0 ) {
254+ throw new Exception ('updater failed ' . PHP_EOL . implode (PHP_EOL , $ this ->CLIOutput ));
255+ }
256+ }
257+
258+ /**
259+ * @When the CLI updater is run with local file URL for version :version
260+ */
261+ public function theCliUpdaterIsRunWithLocalFileUrl (string $ version ): void {
262+ if ($ this ->skipIt ) {
263+ return ;
264+ }
265+
266+ $ this ->runUpdaterWithLocalFileUrl ($ version , noVerify: false );
267+ }
268+
269+ private function runUpdaterWithLocalFileUrl (string $ version , bool $ noVerify ): void {
270+ $ filename = 'nextcloud- ' . $ version . '.zip ' ;
271+ $ fileUrl = 'file:// ' . $ this ->tmpDownloadDir . $ filename ;
272+
273+ if (!file_exists ($ this ->buildDir . 'updater.phar ' )) {
274+ throw new Exception ('updater.phar not available - please build it in advance via "box build -c box.json" ' );
275+ }
276+
277+ copy ($ this ->buildDir . 'updater.phar ' , $ this ->serverDir . 'nextcloud/updater/updater ' );
278+ chdir ($ this ->serverDir . 'nextcloud/updater ' );
279+ chmod ($ this ->serverDir . 'nextcloud/updater/updater ' , 0755 );
280+
281+ $ args = '-n --url ' . escapeshellarg ($ fileUrl );
282+ if ($ noVerify ) {
283+ $ args .= ' --no-verify ' ;
284+ }
285+ exec ('./updater ' . $ args . ' 2>&1 ' , $ output , $ returnCode );
286+
287+ // sleep to let the opcache do it's work and invalidate the status.php
288+ sleep (5 );
289+ $ this ->CLIOutput = $ output ;
290+ $ this ->CLIReturnCode = $ returnCode ;
291+ }
292+
215293 /**
216294 * @param $version
217295 */
0 commit comments