add IFileInfo::getParentId

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/38150/head
Robin Appelman 2023-08-14 21:12:12 +07:00
parent e718cbc661
commit 9055fef5ef
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
5 changed files with 32 additions and 7 deletions

@ -186,4 +186,8 @@ class TrashItem implements ITrashItem {
public function getUploadTime(): int {
return $this->fileInfo->getUploadTime();
}
public function getParentId(): int {
return $this->fileInfo->getParentId();
}
}

@ -412,4 +412,8 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
public function getUploadTime(): int {
return (int) $this->data['upload_time'];
}
public function getParentId(): int {
return $this->data['parent'] ?? -1;
}
}

@ -551,4 +551,11 @@ class LazyFolder implements Folder {
public function getRelativePath($path) {
return PathHelper::getRelativePath($this->getPath(), $path);
}
public function getParentId(): int {
if (isset($this->data['parent'])) {
return $this->data['parent'];
}
return $this->__call(__FUNCTION__, func_get_args());
}
}

@ -59,10 +59,7 @@ class Node implements INode {
protected ?FileInfo $fileInfo;
/**
* @var Node|null
*/
protected $parent;
protected ?INode $parent;
private bool $infoHasSubMountsIncluded;
@ -300,13 +297,13 @@ class Node implements INode {
return $this->root;
}
// gather the metadata we already know about our parent
$parentData = [
'path' => $newPath,
'fileid' => $this->getFileInfo()->getParentId(),
];
if ($this->fileInfo instanceof \OC\Files\FileInfo && isset($this->fileInfo['parent'])) {
$parentData['fileid'] = $this->fileInfo['parent'];
}
// and create lazy folder with it instead of always querying
$this->parent = new LazyFolder(function () use ($newPath) {
return $this->root->get($newPath);
}, $parentData);
@ -486,4 +483,8 @@ class Node implements INode {
public function getUploadTime(): int {
return $this->getFileInfo()->getUploadTime();
}
public function getParentId(): int {
return $this->fileInfo->getParentId();
}
}

@ -299,4 +299,13 @@ interface FileInfo {
* @since 18.0.0
*/
public function getUploadTime(): int;
/**
* Get the fileid or the parent folder
* or -1 if this item has no parent folder (because it is the root)
*
* @return int
* @since 28.0.0
*/
public function getParentId(): int;
}