From fe0de5fc10f61a7bb3173a04a986b145789b9160 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 30 Jun 2013 18:27:55 +0200 Subject: [PATCH] improved move operation for sabre's objecttree --- lib/connector/sabre/objecttree.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php index 23cbd20cf4..f51b991d12 100644 --- a/lib/connector/sabre/objecttree.php +++ b/lib/connector/sabre/objecttree.php @@ -46,4 +46,28 @@ class ObjectTree extends \Sabre_DAV_ObjectTree { return $node; } + + /** + * Moves a file from one location to another + * + * @param string $sourcePath The path to the file which should be moved + * @param string $destinationPath The full destination path, so not just the destination parent node + * @throws \Sabre_DAV_Exception_Forbidden + * @return int + */ + public function move($sourcePath, $destinationPath) { + + $sourceNode = $this->getNodeForPath($sourcePath); + if ($sourceNode instanceof \Sabre_DAV_ICollection and $this->nodeExists($destinationPath)) { + throw new \Sabre_DAV_Exception_Forbidden('Could not copy directory ' . $sourceNode . ', target exists'); + } + list($sourceDir,) = \Sabre_DAV_URLUtil::splitPath($sourcePath); + list($destinationDir,) = \Sabre_DAV_URLUtil::splitPath($destinationPath); + + Filesystem::rename($sourcePath, $destinationPath); + + $this->markDirty($sourceDir); + $this->markDirty($destinationDir); + + } }