/** * copyNode * * @param INode $source * @param ICollection $destinationParent * @param string $destinationName * @return void */ protected function copyNode(INode $source, ICollection $destinationParent, $destinationName = null) { if (!$destinationName) { $destinationName = $source->getName(); } if ($source instanceof IFile) { $data = $source->get(); // If the body was a string, we need to convert it to a stream if (is_string($data)) { $stream = fopen('php://temp', 'r+'); fwrite($stream, $data); rewind($stream); $data = $stream; } $destinationParent->createFile($destinationName, $data); $destination = $destinationParent->getChild($destinationName); } elseif ($source instanceof ICollection) { $destinationParent->createDirectory($destinationName); $destination = $destinationParent->getChild($destinationName); foreach ($source->getChildren() as $child) { $this->copyNode($child, $destination); } } if ($source instanceof IProperties && $destination instanceof IProperties) { $props = $source->getProperties([]); $propPatch = new PropPatch($props); $destination->propPatch($propPatch); $propPatch->commit(); } }
/** * Adds tags and favorites properties to the response, * if requested. * * @param PropFind $propFind * @param \Sabre\DAV\INode $node * @return void */ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { if (!$node instanceof \OCA\DAV\Connector\Sabre\Node) { return; } // need prefetch ? if ($node instanceof \OCA\DAV\Connector\Sabre\Directory && $propFind->getDepth() !== 0 && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)))) { // note: pre-fetching only supported for depth <= 1 $folderContent = $node->getChildren(); $fileIds[] = (int) $node->getId(); foreach ($folderContent as $info) { $fileIds[] = (int) $info->getId(); } $tags = $this->getTagger()->getTagsForObjects($fileIds); if ($tags === false) { // the tags API returns false on error... $tags = array(); } $this->cachedTags = $this->cachedTags + $tags; $emptyFileIds = array_diff($fileIds, array_keys($tags)); // also cache the ones that were not found foreach ($emptyFileIds as $fileId) { $this->cachedTags[$fileId] = []; } } $tags = null; $isFav = null; $propFind->handle(self::TAGS_PROPERTYNAME, function () use($tags, &$isFav, $node) { list($tags, $isFav) = $this->getTagsAndFav($node->getId()); return new TagList($tags); }); $propFind->handle(self::FAVORITE_PROPERTYNAME, function () use($isFav, $node) { if (is_null($isFav)) { list(, $isFav) = $this->getTagsAndFav($node->getId()); } return $isFav; }); }