if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
return array(
+ 'parent' => $items[key($items)]['parent'],
'path' => $items[key($items)]['path'],
+ 'storage' => $items[key($items)]['storage'],
'permissions' => $items[key($items)]['permissions'],
'uid_owner' => $items[key($items)]['uid_owner']
);
$source = \OCP\Share::getItemSharedWith('folder', $folder, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
if ($source) {
$source['path'] = $source['path'].substr($target, strlen($folder));
- return $source;
}
} else {
$source = \OCP\Share::getItemSharedWith('file', $target, \OC_Share_Backend_File::FORMAT_SHARED_STORAGE);
- if ($source) {
- return $source;
+ }
+ if ($source) {
+ if (isset($source['parent'])) {
+ $parent = $source['parent'];
+ while (isset($parent)) {
+ $query = \OC_DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
+ $item = $query->execute(array($parent))->fetchRow();
+ if (isset($item['parent'])) {
+ $parent = $item['parent'];
+ } else {
+ $fileOwner = $item['uid_owner'];
+ break;
+ }
+ }
+ } else {
+ $fileOwner = $source['uid_owner'];
}
+ $source['fileOwner'] = $fileOwner;
+ return $source;
}
\OCP\Util::writeLog('files_sharing', 'File source not found for: '.$target, \OCP\Util::ERROR);
return false;
*/
private function getFile($target) {
if (!isset($this->files[$target])) {
- $source = \OC_Share_Backend_File::getSource($target);
- if ($source) {
- $source['path'] = '/'.$source['uid_owner'].'/'.$source['path'];
- }
- $this->files[$target] = $source;
+ $this->files[$target] = \OC_Share_Backend_File::getSource($target);
}
return $this->files[$target];
}
private function getSourcePath($target) {
$source = $this->getFile($target);
if ($source) {
- \OC\Files\Filesystem::initMountPoints($source['uid_owner']);
- return $source['path'];
+ if (!isset($source['fullPath'])) {
+ \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
+ $mount = \OC\Files\Mount::findByNumericId($source['storage']);
+ if ($mount) {
+ $this->files[$target]['fullPath'] = $mount->getMountPoint().$source['path'];
+ } else {
+ $this->files[$target]['fullPath'] = false;
+ }
+ }
+ return $this->files[$target]['fullPath'];
}
return false;
}
}
$source = $this->getFile($path);
if ($source) {
- return $source['uid_owner'];
+ return $source['fileOwner'];
}
return false;
}
}
/**
+ * Find mounts by storage id
+ *
* @param string $id
- * @return \OC\Files\Storage\Storage[]
+ * @return Mount[]
*/
- public static function findById($id) {
+ public static function findByStorageId($id) {
if (strlen($id) > 64) {
$id = md5($id);
}
}
return $result;
}
+
+ /**
+ * Find mounts by numeric storage id
+ *
+ * @param string $id
+ * @return Mount
+ */
+ public static function findByNumericId($id) {
+ $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?');
+ $result = $query->execute(array($id))->fetchOne();
+ if ($result) {
+ $id = $result;
+ foreach (self::$mounts as $mount) {
+ if ($mount->getStorageId() === $id) {
+ return $mount;
+ }
+ }
+ }
+ return false;
+ }
}
*/
public function getPath($id) {
list($storage, $internalPath) = Cache\Cache::getById($id);
- $mounts = Mount::findById($storage);
+ $mounts = Mount::findByStorageId($storage);
foreach ($mounts as $mount) {
/**
* @var \OC\Files\Mount $mount
} else {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`,
`*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`,
- `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`';
+ `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`';
}
} else {
$select = '*';
$this->assertEquals(array($mount), \OC\Files\Mount::findById($id));
$mount2 = new \OC\Files\Mount($storage, '/foo/bar');
- $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id));
+ $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findByStorageId($id));
}
public function testLong() {
$id = $mount->getStorageId();
$storageId = $storage->getId();
- $this->assertEquals(array($mount), \OC\Files\Mount::findById($id));
- $this->assertEquals(array($mount), \OC\Files\Mount::findById($storageId));
- $this->assertEquals(array($mount), \OC\Files\Mount::findById(md5($storageId)));
+ $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($id));
+ $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId($storageId));
+ $this->assertEquals(array($mount), \OC\Files\Mount::findByStorageId(md5($storageId)));
}
}