]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/FaviconHandler.php
Added control-upon-access of the default favicon.ico file
[bookstack] / app / Uploads / FaviconHandler.php
index 3dc702ea62bb424fa983ffa2229352fbf1e399c6..c637356e068b479dca773409dcada15bbc2ad916 100644 (file)
@@ -35,25 +35,29 @@ class FaviconHandler
 
     /**
      * Restore the original favicon image.
+     * Returned boolean indicates if the copy occurred.
      */
-    public function restoreOriginal(): void
+    public function restoreOriginal(): bool
     {
-        $original = public_path('icon.ico');
-        if (!is_writeable($this->path)) {
-            return;
+        $permissionItem = file_exists($this->path) ? $this->path : dirname($this->path);
+        if (!is_writeable($permissionItem)) {
+            return false;
         }
 
-        copy($original, $this->path);
+        return copy($this->getOriginalPath(), $this->path);
     }
 
     /**
      * Restore the original favicon image if no favicon image is already in use.
+     * Returns a boolean to indicate if the file exists.
      */
-    public function restoreOriginalIfNotExists(): void
+    public function restoreOriginalIfNotExists(): bool
     {
-        if (!file_exists($this->path)) {
-            $this->restoreOriginal();
+        if (file_exists($this->path)) {
+            return true;
         }
+
+        return $this->restoreOriginal();
     }
 
     /**
@@ -64,6 +68,14 @@ class FaviconHandler
         return $this->path;
     }
 
+    /**
+     * Get the path of the original favicon copy.
+     */
+    public function getOriginalPath(): string
+    {
+        return public_path('icon.ico');
+    }
+
     /**
      * Convert PNG image data to ICO file format.
      * Built following the file format info from Wikipedia: