]> git.mxchange.org Git - friendica.git/commitdiff
Storage: throw StorageException on errors
authorfabrixxm <fabrix.xm@gmail.com>
Thu, 29 Nov 2018 07:34:00 +0000 (08:34 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 21 Jan 2019 14:10:47 +0000 (09:10 -0500)
src/Model/Storage/Filesystem.php
src/Model/Storage/StorageException.php [new file with mode: 0644]

index 07af0f13572832cf9f57b301500647cfe7d10136..1cfb5effe831fcebe928cac90dd1ad8896a97b44 100644 (file)
@@ -58,13 +58,13 @@ class Filesystem implements IStorage
                if (!is_dir($path)) {
                        if (!mkdir($path, 0770, true)) {
                                Logger::log("Failed to create dirs {$path}");
-                               echo L10n::t("Filesystem storage failed to create '%s'. Check you write permissions.", $path);
+                               throw new StorageException(L10n::t("Filesystem storage failed to create '%s'. Check you write permissions.", $path));
                                killme();
                        }
                }
 
                $base = self::getBasePath();
-               
+
                while ($path !== $base) {
                        if (!is_file($path . "/index.html")) {
                                file_put_contents($path . "/index.html", "");
@@ -98,7 +98,7 @@ class Filesystem implements IStorage
                $r = file_put_contents($file, $data);
                if ($r === FALSE) {
                        Logger::log("Failed to write data to {$file}");
-                       echo L10n::t("Filesystem storage failed to save data to '%s'. Check your write permissions", $file);
+                       throw new StorageException(L10n::t("Filesystem storage failed to save data to '%s'. Check your write permissions", $file));
                        killme();
                }
                return $ref;
@@ -108,7 +108,7 @@ class Filesystem implements IStorage
        {
                $file = self::pathForRef($ref);
                // return true if file doesn't exists. we want to delete it: success with zero work!
-               if (!is_file($file)) { 
+               if (!is_file($file)) {
                        return true;
                }
                return unlink($file);
diff --git a/src/Model/Storage/StorageException.php b/src/Model/Storage/StorageException.php
new file mode 100644 (file)
index 0000000..4321bc1
--- /dev/null
@@ -0,0 +1,15 @@
+
+<?php
+/**
+ * @file src/Model/Storage/StorageException.php
+ * @brief Storage backend system
+ */
+
+namespace Friendica\Model\Storage;
+
+/**
+ * @brief Storage Exception
+ */
+class StorageException extends \Exception
+{
+}