feat(file-info): encapsulate logic to get last activity in getLastActivity function

Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
This commit is contained in:
Cristian Scheid 2026-03-23 08:58:12 -03:00 committed by backportbot[bot]
parent 7a21995bec
commit 229a3bbf0a
8 changed files with 32 additions and 6 deletions

View file

@ -448,8 +448,7 @@ class FilesPlugin extends ServerPlugin {
});
$propFind->handle(self::LAST_ACTIVITY_PROPERTYNAME, function () use ($node) {
$fileInfo = $node->getFileInfo();
return max($fileInfo->getUploadTime(), $fileInfo->getMTime());
return $node->getFileInfo()->getLastActivity();
});
foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {

View file

@ -306,7 +306,7 @@ class FileSearchBackend implements ISearchBackend {
case '{http://nextcloud.org/ns}upload_time':
return $node->getNode()->getUploadTime();
case '{http://nextcloud.org/ns}last_activity':
return max($node->getNode()->getUploadTime(), $node->getNode()->getMTime());
return $node->getNode()->getLastActivity();
case FilesPlugin::SIZE_PROPERTYNAME:
return $node->getSize();
case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:

View file

@ -154,6 +154,10 @@ class TrashItem implements ITrashItem {
return $this->fileInfo->getUploadTime();
}
public function getLastActivity(): int {
return $this->fileInfo->getLastActivity();
}
public function getParentId(): int {
return $this->fileInfo->getParentId();
}

View file

@ -379,6 +379,10 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
return (int)$this->data['upload_time'];
}
public function getLastActivity(): int {
return max($this->getUploadTime(), $this->getMTime());
}
public function getParentId(): int {
return $this->data['parent'] ?? -1;
}

View file

@ -546,6 +546,13 @@ class LazyFolder implements Folder {
return $this->__call(__FUNCTION__, func_get_args());
}
/**
* @inheritDoc
*/
public function getLastActivity(): int {
return $this->__call(__FUNCTION__, func_get_args());
}
public function getRelativePath($path) {
return PathHelper::getRelativePath($this->getPath(), $path);
}

View file

@ -475,6 +475,10 @@ class Node implements INode {
return $this->getFileInfo()->getUploadTime();
}
public function getLastActivity(): int {
return $this->getFileInfo()->getLastActivity();
}
public function getParentId(): int {
return $this->fileInfo->getParentId();
}

View file

@ -59,9 +59,7 @@ class SearchOrder implements ISearchOrder {
case 'permissions':
return $a->getPermissions() <=> $b->getPermissions();
case 'last_activity':
$timeA = max($a->getUploadTime(), $a->getMtime());
$timeB = max($b->getUploadTime(), $b->getMtime());
return $timeA <=> $timeB;
return $a->getLastActivity() <=> $b->getLastActivity();
default:
return 0;
}

View file

@ -282,6 +282,16 @@ interface FileInfo {
*/
public function getUploadTime(): int;
/**
* Get the last activity date as unix timestamp
*
* Last activity is the more recent of the upload time and the modification time
*
* @return int
* @since 34.0.0
*/
public function getLastActivity(): int;
/**
* Get the fileid or the parent folder
* or -1 if this item has no parent folder (because it is the root)