diff options
Diffstat (limited to 'lib/Kolab/DAV')
-rw-r--r-- | lib/Kolab/DAV/Collection.php | 14 | ||||
-rw-r--r-- | lib/Kolab/DAV/File.php | 11 | ||||
-rw-r--r-- | lib/Kolab/DAV/Node.php | 31 |
3 files changed, 40 insertions, 16 deletions
diff --git a/lib/Kolab/DAV/Collection.php b/lib/Kolab/DAV/Collection.php index b148ece..bec17a3 100644 --- a/lib/Kolab/DAV/Collection.php +++ b/lib/Kolab/DAV/Collection.php @@ -28,7 +28,7 @@ use \Exception; /** * Collection class */ -class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection +class Collection extends Node implements \Sabre\DAV\ICollection { const ROOT_DIRECTORY = 'files'; @@ -51,9 +51,9 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection $folders = $folders['list']; } catch (Exception $e) { + $this->throw_exception($e); } - // get subfolders foreach ($folders as $folder) { // need root-folders or subfolders of specified folder @@ -114,7 +114,7 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection * exist. * * @param string $name - * @throws Sabre\DAV\Exception\NotFound + * @throws Sabre\DAV\Exception * @return INode */ public function getChild($name) @@ -174,6 +174,8 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection * * @param string $name Name of the file * @param resource|string $data Initial payload + * + * @throws Sabre\DAV\Exception * @return null|string */ public function createFile($name, $data = null) @@ -190,7 +192,7 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection $this->backend->file_create($filename, $filedata); } catch (Exception $e) { -// throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } // reset cache @@ -201,7 +203,7 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection * Creates a new subdirectory * * @param string $name - * @throws Exception\Forbidden + * @throws Sabre\DAV\Exception * @return void */ public function createDirectory($name) @@ -217,7 +219,7 @@ class Collection extends \Kolab\DAV\Node implements \Sabre\DAV\ICollection $this->backend->folder_create($folder); } catch (Exception $e) { - throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } // reset cache diff --git a/lib/Kolab/DAV/File.php b/lib/Kolab/DAV/File.php index 8e402c4..b7e0b20 100644 --- a/lib/Kolab/DAV/File.php +++ b/lib/Kolab/DAV/File.php @@ -23,7 +23,6 @@ namespace Kolab\DAV; -use \rcube; use \Exception; use \DateTime; @@ -51,6 +50,7 @@ class File extends Node implements \Sabre\DAV\IFile, \Sabre\DAV\IProperties * return an ETag, and just return null. * * @param resource $data + * @throws Sabre\DAV\Exception * @return string|null */ public function put($data) @@ -61,13 +61,14 @@ class File extends Node implements \Sabre\DAV\IFile, \Sabre\DAV\IProperties $this->backend->file_update($this->path, $filedata); } catch (Exception $e) { -// throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } try { $this->data = $this->backend->file_info($this->path); } catch (Exception $e) { + $this->throw_exception($e); } return $this->getETag(); @@ -78,6 +79,7 @@ class File extends Node implements \Sabre\DAV\IFile, \Sabre\DAV\IProperties * * This method may either return a string or a readable stream resource * + * @throws Sabre\DAV\Exception * @return mixed */ public function get() @@ -88,7 +90,7 @@ class File extends Node implements \Sabre\DAV\IFile, \Sabre\DAV\IProperties rewind($fp); } catch (Exception $e) { -// throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } return $fp; @@ -97,6 +99,7 @@ class File extends Node implements \Sabre\DAV\IFile, \Sabre\DAV\IProperties /** * Delete the current file * + * @throws Sabre\DAV\Exception * @return void */ public function delete() @@ -105,7 +108,7 @@ class File extends Node implements \Sabre\DAV\IFile, \Sabre\DAV\IProperties $this->backend->file_delete($this->path); } catch (Exception $e) { -// throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } // reset cache diff --git a/lib/Kolab/DAV/Node.php b/lib/Kolab/DAV/Node.php index beba2a9..9e72f8f 100644 --- a/lib/Kolab/DAV/Node.php +++ b/lib/Kolab/DAV/Node.php @@ -23,8 +23,6 @@ namespace Kolab\DAV; -use \rcube; -use \rcube_mime; use \Exception; /** @@ -99,7 +97,7 @@ class Node implements \Sabre\DAV\INode /** * Deletes the current node (folder) * - * @throws Sabre\DAV\Exception\Forbidden + * @throws Sabre\DAV\Exception * @return void */ public function delete() @@ -108,7 +106,7 @@ class Node implements \Sabre\DAV\INode $this->backend->folder_delete($this->path); } catch (Exception $e) { - throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } // reset cache @@ -120,7 +118,7 @@ class Node implements \Sabre\DAV\INode /** * Renames the node * - * @throws Sabre\DAV\Exception\Forbidden + * @throws Sabre\DAV\Exception * @param string $name The new name * @return void */ @@ -136,7 +134,7 @@ class Node implements \Sabre\DAV\INode $this->backend->$method($this->path, $newname); } catch (Exception $e) { - throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); + $this->throw_exception($e); } // reset cache @@ -193,4 +191,25 @@ class Node implements \Sabre\DAV\INode return $filedata; } + + /** + * Convert Chwala exceptions to Sabre exceptions + * + * @param Exception Chwala exception + * @throws Sabre\DAV\Exception + */ + protected function throw_exception($e) + { + $error = $e->getCode(); + $msg = $e->getMessage(); + + if ($error == \file_storage::ERROR_UNAVAILABLE) { + throw new \Sabre\DAV\Exception\ServiceUnavailable($msg); + } + else if ($error == \kolab_storage::ERROR_FORBIDDEN) { + throw new \Sabre\DAV\Exception\Forbidden($msg); + } + + throw new \Sabre\DAV\Exception($msg); + } } |