[Pkg-owncloud-commits] [php-sabredav] 182/275: IMoveTarget support in the object tree.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:56:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit a7366bedff165dd61eed68ff0eab618430c4a5f8
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Sun Aug 24 20:52:14 2014 -0400
IMoveTarget support in the object tree.
---
lib/DAV/FSExt/Directory.php | 45 +++++++++++++++++++++++++++++++++++++++++----
lib/DAV/IMoveTarget.php | 44 ++++++++++++++++++++++++++++++++++++++++++++
lib/DAV/Tree.php | 20 +++++++++++++++-----
3 files changed, 100 insertions(+), 9 deletions(-)
diff --git a/lib/DAV/FSExt/Directory.php b/lib/DAV/FSExt/Directory.php
index af5edd8..32aa00b 100644
--- a/lib/DAV/FSExt/Directory.php
+++ b/lib/DAV/FSExt/Directory.php
@@ -11,7 +11,7 @@ use Sabre\DAV;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Directory extends Node implements DAV\ICollection, DAV\IQuota {
+class Directory extends Node implements DAV\ICollection, DAV\IQuota, DAV\IMoveTarget {
/**
* Creates a new file in the directory
@@ -146,12 +146,49 @@ class Directory extends Node implements DAV\ICollection, DAV\IQuota {
*
* @return array
*/
- public function getQuotaInfo() {
+ function getQuotaInfo() {
- return array(
+ return [
disk_total_space($this->path)-disk_free_space($this->path),
disk_free_space($this->path)
- );
+ ];
+
+ }
+
+ /**
+ * Moves a node into this collection.
+ *
+ * It is up to the implementors to:
+ * 1. Create the new resource.
+ * 2. Remove the old resource.
+ * 3. Transfer any properties or other data.
+ *
+ * Generally you should make very sure that your collection can easily move
+ * the move.
+ *
+ * If you don't, just return false, which will trigger sabre/dav to handle
+ * the move itself. If you return true from this function, the assumption
+ * is that the move was successful.
+ *
+ * @param string $targetName New local file/collection name.
+ * @param string $sourcePath Full path to source node
+ * @param INode $sourceNode Source node itself
+ * @return bool
+ */
+ function moveInto($targetName, $sourcePath, DAV\INode $sourceNode) {
+
+ // We only support FSExt\ICollection or FSExt\IFile objects, so
+ // anything else we want to quickly reject.
+ if (!$sourceNode instanceof INode) {
+ return false;
+ }
+
+ // PHP allows us to access protected properties from other objects, as
+ // long as they are defined in a class that has a shared inheritence
+ // with the current class.
+ rename($sourceNode->path, $this->path . '/' . $targetName);
+
+ return true;
}
diff --git a/lib/DAV/IMoveTarget.php b/lib/DAV/IMoveTarget.php
new file mode 100644
index 0000000..3c821ef
--- /dev/null
+++ b/lib/DAV/IMoveTarget.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Sabre\DAV;
+
+/**
+ * By implementing this interface, a collection can effectively say "other
+ * nodes may be moved into this collection".
+ *
+ * The benefit of this, is that sabre/dav will by default perform a move, by
+ * tranfersing an entire directory tree, copying every collection, and deleting
+ * every item.
+ *
+ * If a backend supports a better optimized move operation, this can trigger
+ * some huge speed gains.
+ *
+ * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+interface IMoveTarget extends ICollection {
+
+ /**
+ * Moves a node into this collection.
+ *
+ * It is up to the implementors to:
+ * 1. Create the new resource.
+ * 2. Remove the old resource.
+ * 3. Transfer any properties or other data.
+ *
+ * Generally you should make very sure that your collection can easily move
+ * the move.
+ *
+ * If you don't, just return false, which will trigger sabre/dav to handle
+ * the move itself. If you return true from this function, the assumption
+ * is that the move was successful.
+ *
+ * @param string $targetName New local file/collection name.
+ * @param string $sourcePath Full path to source node
+ * @param INode $sourceNode Source node itself
+ * @return bool
+ */
+ function moveInto($targetName, $sourcePath, INode $sourceNode);
+
+}
diff --git a/lib/DAV/Tree.php b/lib/DAV/Tree.php
index dc9dbaf..c1bd24c 100644
--- a/lib/DAV/Tree.php
+++ b/lib/DAV/Tree.php
@@ -75,17 +75,27 @@ abstract class Tree {
* @param string $destinationPath The full destination path, so not just the destination parent node
* @return int
*/
- public function move($sourcePath, $destinationPath) {
+ function move($sourcePath, $destinationPath) {
list($sourceDir, $sourceName) = URLUtil::splitPath($sourcePath);
list($destinationDir, $destinationName) = URLUtil::splitPath($destinationPath);
if ($sourceDir===$destinationDir) {
- $renameable = $this->getNodeForPath($sourcePath);
- $renameable->setName($destinationName);
+ // If this is a 'local' rename, it means we can just trigger a rename.
+ $sourceNode = $this->getNodeForPath($sourcePath);
+ $sourceNode->setName($destinationName);
} else {
- $this->copy($sourcePath,$destinationPath);
- $this->getNodeForPath($sourcePath)->delete();
+ $newParentNode = $this->getNodeForPath($destinationDir);
+ $moveSuccess = false;
+ if ($newParentNode instanceof IMoveTarget) {
+ // The target collection may be able to handle the move
+ $sourceNode = $this->getNodeForPath($sourcePath);
+ $moveSuccess = $newParentNode->moveInto($destinationName, $sourcePath, $sourceNode);
+ }
+ if (!$moveSuccess) {
+ $this->copy($sourcePath,$destinationPath);
+ $this->getNodeForPath($sourcePath)->delete();
+ }
}
$this->markDirty($sourceDir);
$this->markDirty($destinationDir);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list