aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2023-11-23 07:52:27 -0100
committerGitHub <noreply@github.com>2023-11-23 07:52:27 -0100
commitee787cd1c6ee5c9934aebe282b3d0a151a0570a5 (patch)
tree823ae1b28f28739d650437bbf076b3de0a2134d9 /apps
parentf1a7fcea8111a36ff8ba8fcd57b91142f9e8c146 (diff)
parentfbe92d4a9018b8439946880148c2b907ea56c56c (diff)
downloadnextcloud-server-ee787cd1c6ee5c9934aebe282b3d0a151a0570a5.tar.gz
nextcloud-server-ee787cd1c6ee5c9934aebe282b3d0a151a0570a5.zip
Merge pull request #41459 from nextcloud/enh/noid/search-metadata-null
implements search on null/notnull metadata
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CalDAV/CachedSubscription.php4
-rw-r--r--apps/dav/lib/Files/FileSearchBackend.php31
2 files changed, 24 insertions, 11 deletions
diff --git a/apps/dav/lib/CalDAV/CachedSubscription.php b/apps/dav/lib/CalDAV/CachedSubscription.php
index dc7f66e59b4..4047f8dad0b 100644
--- a/apps/dav/lib/CalDAV/CachedSubscription.php
+++ b/apps/dav/lib/CalDAV/CachedSubscription.php
@@ -169,11 +169,11 @@ class CachedSubscription extends \Sabre\CalDAV\Calendar {
/**
* @param string $name
- * @param null|resource|string $calendarData
+ * @param null|resource|string $data
* @return null|string
* @throws MethodNotAllowed
*/
- public function createFile($name, $calendarData = null) {
+ public function createFile($name, $data = null) {
throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
}
diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php
index 3500d6b0fb3..419a0c5ed3b 100644
--- a/apps/dav/lib/Files/FileSearchBackend.php
+++ b/apps/dav/lib/Files/FileSearchBackend.php
@@ -39,6 +39,7 @@ use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
+use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
use OCP\Files\Search\ISearchOrder;
use OCP\Files\Search\ISearchQuery;
@@ -367,22 +368,30 @@ class FileSearchBackend implements ISearchBackend {
if (count($operator->arguments) !== 2) {
throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
}
- if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) {
- throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
- }
if (!($operator->arguments[1] instanceof Literal)) {
throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
}
-
+ $value = $operator->arguments[1]->value;
+ case Operator::OPERATION_IS_DEFINED:
+ if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) {
+ throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
+ }
$property = $operator->arguments[0];
- $value = $this->castValue($property, $operator->arguments[1]->value);
+
if (str_starts_with($property->name, FilesPlugin::FILE_METADATA_PREFIX)) {
- return new SearchComparison($trimmedType, substr($property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)), $value, IMetadataQuery::EXTRA);
+ $field = substr($property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX));
+ $extra = IMetadataQuery::EXTRA;
} else {
- return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($property), $value);
+ $field = $this->mapPropertyNameToColumn($property);
}
- // no break
+ return new SearchComparison(
+ $trimmedType,
+ $field,
+ $this->castValue($property, $value ?? ''),
+ $extra ?? ''
+ );
+
case Operator::OPERATION_IS_COLLECTION:
return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
default:
@@ -416,7 +425,11 @@ class FileSearchBackend implements ISearchBackend {
}
private function castValue(SearchPropertyDefinition $property, $value) {
- switch ($property->dataType) {
+ if ($value === '') {
+ return '';
+ }
+
+ switch ($property->dataType) {
case SearchPropertyDefinition::DATATYPE_BOOLEAN:
return $value === 'yes';
case SearchPropertyDefinition::DATATYPE_DECIMAL: