]> BookStack Code Mirror - system-cli/commitdiff
Download Vendor: Added packages to cleanup files
authorDan Brown <redacted>
Wed, 14 May 2025 11:44:25 +0000 (12:44 +0100)
committerDan Brown <redacted>
Wed, 14 May 2025 11:44:25 +0000 (12:44 +0100)
src/Commands/DownloadVendorCommand.php
tests/Commands/DownloadVendorCommandTest.php

index 7c18fed653aed596befc15389256897fbd2afe9f..d3b0501d6efa47167a4084f429132ab8e62a0585 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
 
 namespace Cli\Commands;
 
@@ -65,12 +65,22 @@ class DownloadVendorCommand extends Command
 
     protected function cleanupAppServices(string $appDir): bool
     {
-        $servicesFile = implode(DIRECTORY_SEPARATOR, [$appDir, 'bootstrap', 'cache', 'services.php']);
-        if (file_exists($servicesFile)) {
-            return @unlink($servicesFile);
+        $filesToClear = [
+            implode(DIRECTORY_SEPARATOR, [$appDir, 'bootstrap', 'cache', 'services.php']),
+            implode(DIRECTORY_SEPARATOR, [$appDir, 'bootstrap', 'cache', 'packages.php']),
+        ];
+
+        $status = true;
+
+        foreach ($filesToClear as $file) {
+            if (file_exists($file)) {
+                if (@unlink($file) === false) {
+                    $status = false;
+                }
+            }
         }
 
-        return true;
+        return $status;
     }
 
     protected function extractZip(string $zipPath, string $appDir): void
index 8fc2e55ab6e38068e78881a4176c58ecc2b5fbf1..e96d5dc88528c071b1b99a08822f197ab38fdb5d 100644 (file)
@@ -11,6 +11,8 @@ class DownloadVendorCommandTest extends TestCase
         $this->withOwnBookStackFolder(function (string $basePath) {
             exec("rm -rf $basePath/vendor");
             file_put_contents("$basePath/version", 'v25.02');
+            file_put_contents("$basePath/bootstrap/cache/packages.php", 'cat');
+            file_put_contents("$basePath/bootstrap/cache/services.php", 'dog');
             @mkdir("$basePath/dev/checksums", 0777, true);
             file_put_contents("$basePath/dev/checksums/vendor", '22e02ee72d21ff719c1073abbec8302f8e2096ba6d072e133051064ed24b45b1');
 
@@ -23,6 +25,8 @@ class DownloadVendorCommandTest extends TestCase
             $result->assertStdoutContains('Successfully downloaded & extracted vendor files into BookStack instance!');
 
             $this->assertDirectoryExists("$basePath/vendor/composer");
+            $this->assertFileDoesNotExist("$basePath/bootstrap/cache/packages.php");
+            $this->assertFileDoesNotExist("$basePath/bootstrap/cache/services.php");
         });
     }