Skip to content

Commit

Permalink
add IFileInfo::getParentId
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Aug 15, 2023
1 parent 5bc261b commit d729daa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions apps/files_trashbin/lib/Trash/TrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,8 @@ public function getCreationTime(): int {
public function getUploadTime(): int {
return $this->fileInfo->getUploadTime();
}

public function getParentId(): int {
return $this->fileInfo->getParentId();
}
}
4 changes: 4 additions & 0 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,8 @@ public function getCreationTime(): int {
public function getUploadTime(): int {
return (int) $this->data['upload_time'];
}

public function getParentId(): int {
return $this->data['parent'] ?? -1;
}
}
7 changes: 7 additions & 0 deletions lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,11 @@ public function getUploadTime(): int {
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());
}
}
15 changes: 8 additions & 7 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class Node implements INode {

protected ?FileInfo $fileInfo;

/**
* @var Node|null
*/
protected $parent;
protected ?INode $parent;

private bool $infoHasSubMountsIncluded;

Expand Down Expand Up @@ -300,13 +297,13 @@ public function getParent(): INode|IRootFolder {
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);
Expand Down Expand Up @@ -486,4 +483,8 @@ public function getCreationTime(): int {
public function getUploadTime(): int {
return $this->getFileInfo()->getUploadTime();
}

public function getParentId(): int {
return $this->fileInfo->getParentId();
}
}
9 changes: 9 additions & 0 deletions lib/public/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,13 @@ public function getCreationTime(): int;
* @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.1
*/
public function getParentId(): int;
}

0 comments on commit d729daa

Please sign in to comment.