Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/dav/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ public function __construct(IConfig $config, IAvailabilityCoordinator $coordinat
}

/**
* @return array{dav: array{chunking: string, search_supports_creation_time: bool, search_supports_upload_time: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
* @return array{dav: array{chunking: string, search_supports_creation_time: bool, search_supports_upload_time: bool, search_supports_last_activity: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
*/
public function getCapabilities() {
$capabilities = [
'dav' => [
'chunking' => '1.0',
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
]
];
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
public const LAST_ACTIVITY_PROPERTYNAME = '{http://nextcloud.org/ns}last_activity';
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count';
Expand Down Expand Up @@ -427,6 +428,10 @@
return $node->getFileInfo()->getCreationTime();
});

$propFind->handle(self::LAST_ACTIVITY_PROPERTYNAME, function () use ($node) {

Check notice

Code scanning / Psalm

MissingClosureReturnType Note

Closure does not have a return type, expecting mixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the bot only flagged this backport PR, this follows the same pattern as the other $propFind->handle() calls in the file and other backport PRs.

return $node->getFileInfo()->getLastActivity();
});

foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
$propFind->handle(self::FILE_METADATA_PREFIX . $metadataKey, $metadataValue);
}
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function getPropertyDefinitionsForScope(string $href, ?string $path): arr
new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition('{DAV:}creationdate', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition('{http://nextcloud.org/ns}upload_time', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition('{http://nextcloud.org/ns}last_activity', true, false, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
Expand Down Expand Up @@ -303,6 +304,8 @@ private function getSearchResultProperty(SearchResult $result, SearchPropertyDef
return $node->getNode()->getCreationTime();
case '{http://nextcloud.org/ns}upload_time':
return $node->getNode()->getUploadTime();
case '{http://nextcloud.org/ns}last_activity':
return $node->getNode()->getLastActivity();
case FilesPlugin::SIZE_PROPERTYNAME:
return $node->getSize();
case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
Expand Down Expand Up @@ -331,6 +334,8 @@ private function transformQuery(Query $query, ?SearchBinaryOperator $scopeOperat
$direction = $order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING;
if (str_starts_with($order->property->name, FilesPlugin::FILE_METADATA_PREFIX)) {
return new SearchOrder($direction, substr($order->property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)), IMetadataQuery::EXTRA);
} elseif ($order->property->name === FilesPlugin::LAST_ACTIVITY_PROPERTYNAME) {
return new SearchOrder($direction, 'last_activity');
} else {
return new SearchOrder($direction, $this->mapPropertyNameToColumn($order->property));
}
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"required": [
"chunking",
"search_supports_creation_time",
"search_supports_upload_time"
"search_supports_upload_time",
"search_supports_last_activity"
],
"properties": {
"chunking": {
Expand All @@ -43,6 +44,9 @@
"search_supports_upload_time": {
"type": "boolean"
},
"search_supports_last_activity": {
"type": "boolean"
},
"bulkupload": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/tests/unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testGetCapabilities(): void {
'chunking' => '1.0',
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
],
];
$this->assertSame($expected, $capabilities->getCapabilities());
Expand All @@ -52,6 +53,7 @@ public function testGetCapabilitiesWithBulkUpload(): void {
'chunking' => '1.0',
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
'bulkupload' => '1.0',
],
];
Expand All @@ -74,6 +76,7 @@ public function testGetCapabilitiesWithAbsence(): void {
'chunking' => '1.0',
'search_supports_creation_time' => true,
'search_supports_upload_time' => true,
'search_supports_last_activity' => true,
'absence-supported' => true,
'absence-replacement' => true,
],
Expand Down
3 changes: 3 additions & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -59,6 +60,7 @@ public function __construct(
private UserConfig $userConfig,
private ViewConfig $viewConfig,
private FilenameValidator $filenameValidator,
private IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -171,6 +173,7 @@ public function index($dir = '', $view = '', $fileid = null) {
$this->initialState->provideInitialState('storageStats', $storageInfo);
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
$this->initialState->provideInitialState('recent_limit', $this->appConfig->getAppValueInt('recent_limit', 100));

// File sorting user config
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
Expand Down
4 changes: 3 additions & 1 deletion apps/files/src/services/Recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type { FileStat, ResponseDataDetailed, SearchResult } from 'webdav'

import { getCurrentUser } from '@nextcloud/auth'
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL, davResultToNode } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { CancelablePromise } from 'cancelable-promise'
import { useUserConfigStore } from '../store/userconfig.ts'
import { pinia } from '../store/index.ts'
import { client } from './WebdavClient.ts'
import { getBaseUrl } from '@nextcloud/router'

const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14))
const recentLimit = loadState<number>('files', 'recent_limit', 100)

/**
* Helper to map a WebDAV result to a Nextcloud node
Expand Down Expand Up @@ -48,7 +50,7 @@ export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> =>
const contentsResponse = await client.search('/', {
signal: controller.signal,
details: true,
data: davGetRecentSearch(lastTwoWeeksTimestamp),
data: davGetRecentSearch(lastTwoWeeksTimestamp, recentLimit),
}) as ResponseDataDetailed<SearchResult>

const contents = contentsResponse.data.results
Expand Down
4 changes: 4 additions & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -46,6 +47,7 @@
class ViewControllerTest extends TestCase {
private ContainerInterface&MockObject $container;
private IAppManager&MockObject $appManager;
private IAppConfig&MockObject $appConfig;
private ICacheFactory&MockObject $cacheFactory;
private IConfig&MockObject $config;
private IEventDispatcher $eventDispatcher;
Expand All @@ -68,6 +70,7 @@ class ViewControllerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$this->appManager = $this->createMock(IAppManager::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->config = $this->createMock(IConfig::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->initialState = $this->createMock(IInitialState::class);
Expand Down Expand Up @@ -131,6 +134,7 @@ protected function setUp(): void {
$this->userConfig,
$this->viewConfig,
$filenameValidator,
$this->appConfig,
])
->onlyMethods([
'getStorageInfo',
Expand Down
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 @@ -154,6 +154,10 @@ public function getUploadTime(): int {
return $this->fileInfo->getUploadTime();
}

public function getLastActivity(): int {
return $this->fileInfo->getLastActivity();
}

public function getParentId(): int {
return $this->fileInfo->getParentId();
}
Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array

$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());

$joinExtendedCache = in_array('creation_time', $requestedFields) || in_array('upload_time', $requestedFields);
$orderFields = array_map(fn ($order) => $order->getField(), $searchQuery->getOrder());

$joinExtendedCache = in_array('creation_time', $requestedFields)
|| in_array('upload_time', $requestedFields)
|| in_array('last_activity', $orderFields);

$query = $builder->selectFileCache('file', $joinExtendedCache);

Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Cache/SearchBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders, ?IMe
if ($field === 'mtime') {
$field = $query->func()->add($field, $query->createNamedParameter(0));
}

if ($field === 'last_activity') {
$field = $query->func()->greatest('file.mtime', $query->createFunction('COALESCE(fe.upload_time, 0)'));
}
}
$query->addOrderBy($field, $order->getDirection());
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ public function getUploadTime(): int {
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;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ public function getUploadTime(): int {
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);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ public function getUploadTime(): int {
return $this->getFileInfo()->getUploadTime();
}

public function getLastActivity(): int {
return $this->getFileInfo()->getLastActivity();
}

public function getParentId(): int {
return $this->fileInfo->getParentId();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Files/Search/SearchOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private function sortFileInfoNoDirection(FileInfo $a, FileInfo $b): int {
return $a->getId() <=> $b->getId();
case 'permissions':
return $a->getPermissions() <=> $b->getPermissions();
case 'last_activity':
return $a->getLastActivity() <=> $b->getLastActivity();
default:
return 0;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/public/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ public function getCreationTime(): int;
*/
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 30.0.17
*/
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)
Expand Down
Loading