/**
  * Copy a file or folder in the cache
  *
  * @param \OCP\Files\Cache\ICache $sourceCache
  * @param ICacheEntry $sourceEntry
  * @param string $targetPath
  */
 public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath)
 {
     $this->put($targetPath, $this->cacheEntryToArray($sourceEntry));
     if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
         $folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
         foreach ($folderContent as $subEntry) {
             $subTargetPath = $targetPath . '/' . $subEntry->getName();
             $this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
         }
     }
 }
Beispiel #2
0
 /**
  * Move a file or folder in the cache
  *
  * @param \OCP\Files\Cache\ICache $sourceCache
  * @param string $sourcePath
  * @param string $targetPath
  * @throws \OC\DatabaseException
  */
 public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath)
 {
     // normalize source and target
     $sourcePath = $this->normalize($sourcePath);
     $targetPath = $this->normalize($targetPath);
     $sourceData = $sourceCache->get($sourcePath);
     $sourceId = $sourceData['fileid'];
     $newParentId = $this->getParentId($targetPath);
     list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
     list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
     // sql for final update
     $moveSql = 'UPDATE `*PREFIX*filecache` SET `storage` =  ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';
     if ($sourceData['mimetype'] === 'httpd/unix-directory') {
         //find all child entries
         $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?';
         $result = $this->connection->executeQuery($sql, [$sourceStorageId, $this->connection->escapeLikeParameter($sourcePath) . '/%']);
         $childEntries = $result->fetchAll();
         $sourceLength = strlen($sourcePath);
         $this->connection->beginTransaction();
         $query = $this->connection->prepare('UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ? WHERE `fileid` = ?');
         foreach ($childEntries as $child) {
             $newTargetPath = $targetPath . substr($child['path'], $sourceLength);
             $query->execute([$targetStorageId, $newTargetPath, md5($newTargetPath), $child['fileid']]);
         }
         $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]);
         $this->connection->commit();
     } else {
         $this->connection->executeQuery($moveSql, [$targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId]);
     }
 }
 /**
  * Returns the numeric storage id
  *
  * @return int
  */
 public function getNumericStorageId()
 {
     return $this->cache->getNumericStorageId();
 }