From 286114255e2a0fc629c51da37b7793279eaaf3c2 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 25 Apr 2019 12:59:07 +0200 Subject: [PATCH] Better error messages in FS_Model --- application/core/FS_Model.php | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/application/core/FS_Model.php b/application/core/FS_Model.php index bd3275110..4081bf8f4 100644 --- a/application/core/FS_Model.php +++ b/application/core/FS_Model.php @@ -17,7 +17,7 @@ class FS_Model extends CI_Model $this->filepath = $filepath; } - /** --------------------------------------------------------------- + /** * Read data from file system * * @return array @@ -25,10 +25,10 @@ class FS_Model extends CI_Model public function read($filename) { // Check Class-Attributes - if (is_null($this->filepath)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($this->filepath)) return error('The given filepath in not valid', EXIT_ERROR); // Check method parameters - if (is_null($filename)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($filename)) return error('The given filename is not valid', EXIT_ERROR); if (!is_null($data = $this->filesystemlib->read($this->filepath, $filename))) { @@ -36,11 +36,11 @@ class FS_Model extends CI_Model } else { - return error(EXIT_MODEL, EXIT_ERROR); + return error('An error occurred while reading a file', EXIT_ERROR); } } - /** --------------------------------------------------------------- + /** * Writing data to file system * * @param string $fileContent File content @@ -49,11 +49,11 @@ class FS_Model extends CI_Model public function write($filename, $content) { // Check Class-Attributes - if (is_null($this->filepath)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($this->filepath)) return error('The given filepath in not valid', EXIT_ERROR); // Check method parameters - if (is_null($filename)) return error(EXIT_MODEL, EXIT_ERROR); - if (is_null($content)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($content)) return error('The given file content is not valid', EXIT_ERROR); + if (is_null($filename)) return error('The given filename is not valid', EXIT_ERROR); if ($this->filesystemlib->write($this->filepath, $filename, base64_decode($content)) === true) { @@ -61,11 +61,11 @@ class FS_Model extends CI_Model } else { - return error(EXIT_MODEL, EXIT_ERROR); + return error('An error occurred while writing a file', EXIT_ERROR); } } - /** --------------------------------------------------------------- + /** * Append data to a file * * @param array $data File content @@ -74,11 +74,11 @@ class FS_Model extends CI_Model public function append($filename, $content) { // Check Class-Attributes - if (is_null($this->filepath)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($this->filepath)) return error('The given filepath in not valid', EXIT_ERROR); // Check method parameters - if (is_null($content)) return error(EXIT_MODEL, EXIT_ERROR); - if (is_null($filename)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($content)) return error('The given file content is not valid', EXIT_ERROR); + if (is_null($filename)) return error('The given filename is not valid', EXIT_ERROR); if ($this->filesystemlib->append($this->filepath, $filename, base64_decode($content)) === true) { @@ -86,11 +86,11 @@ class FS_Model extends CI_Model } else { - return error(EXIT_MODEL, EXIT_ERROR); + return error('An error occurred while appending to a file', EXIT_ERROR); } } - /** --------------------------------------------------------------- + /** * Delete data from file system * * @param string $id Primary Key for DELETE @@ -99,10 +99,10 @@ class FS_Model extends CI_Model public function remove($filename) { // Check Class-Attributes - if (is_null($this->filepath)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($this->filepath)) return error('The given filepath in not valid', EXIT_ERROR); // Check method parameters - if (is_null($filename)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($filename)) return error('The given filename is not valid', EXIT_ERROR); if ($this->filesystemlib->remove($this->filepath, $filename) === true) { @@ -110,11 +110,11 @@ class FS_Model extends CI_Model } else { - return error(EXIT_MODEL, EXIT_ERROR); + return error('An error occurred while removing a file', EXIT_ERROR); } } - /** --------------------------------------------------------------- + /** * Rename a file * * @param string $id Primary Key for DELETE @@ -123,11 +123,11 @@ class FS_Model extends CI_Model public function rename($filename, $newFilename) { // Check Class-Attributes - if (is_null($this->filepath)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($this->filepath)) return error('The given filepath in not valid', EXIT_ERROR); // Check method parameters - if (is_null($filename)) return error(EXIT_MODEL, EXIT_ERROR); - if (is_null($newFilename)) return error(EXIT_MODEL, EXIT_ERROR); + if (is_null($filename)) return error('The given filename is not valid', EXIT_ERROR); + if (is_null($newFilename)) return error('The given new filename is not valid', EXIT_ERROR); if ($this->filesystemlib->rename($this->filepath, $filename, $this->filepath, $newFilename) === true) { @@ -135,7 +135,7 @@ class FS_Model extends CI_Model } else { - return error(EXIT_MODEL, EXIT_ERROR); + return error('An error occurred while renaming a file', EXIT_ERROR); } } }