summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2023-11-20 13:32:36 -0100
committerMaxence Lange <maxence@artificial-owl.com>2023-11-20 13:32:54 -0100
commit22d6c8dcd44c239609e905558fbc835f1dcd840c (patch)
treeef9737d3156621647b86b0ddb7300a2519478396 /lib
parent0da05fc73b720702b76d8838228f3ce648793482 (diff)
downloadnextcloud-server-22d6c8dcd44c239609e905558fbc835f1dcd840c.tar.gz
nextcloud-server-22d6c8dcd44c239609e905558fbc835f1dcd840c.zip
add named metadata event
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/FilesMetadata/FilesMetadataManager.php8
-rw-r--r--lib/public/FilesMetadata/AMetadataEvent.php4
-rw-r--r--lib/public/FilesMetadata/Event/MetadataNamedEvent.php74
-rw-r--r--lib/public/FilesMetadata/IFilesMetadataManager.php7
6 files changed, 91 insertions, 4 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 39a3f2638f4..b4897900aea 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -290,6 +290,7 @@ return array(
'OCP\\FilesMetadata\\AMetadataEvent' => $baseDir . '/lib/public/FilesMetadata/AMetadataEvent.php',
'OCP\\FilesMetadata\\Event\\MetadataBackgroundEvent' => $baseDir . '/lib/public/FilesMetadata/Event/MetadataBackgroundEvent.php',
'OCP\\FilesMetadata\\Event\\MetadataLiveEvent' => $baseDir . '/lib/public/FilesMetadata/Event/MetadataLiveEvent.php',
+ 'OCP\\FilesMetadata\\Event\\MetadataNamedEvent' => $baseDir . '/lib/public/FilesMetadata/Event/MetadataNamedEvent.php',
'OCP\\FilesMetadata\\Exceptions\\FilesMetadataException' => $baseDir . '/lib/public/FilesMetadata/Exceptions/FilesMetadataException.php',
'OCP\\FilesMetadata\\Exceptions\\FilesMetadataKeyFormatException' => $baseDir . '/lib/public/FilesMetadata/Exceptions/FilesMetadataKeyFormatException.php',
'OCP\\FilesMetadata\\Exceptions\\FilesMetadataNotFoundException' => $baseDir . '/lib/public/FilesMetadata/Exceptions/FilesMetadataNotFoundException.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 4a09a5db6da..89f92f09177 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -323,6 +323,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\FilesMetadata\\AMetadataEvent' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/AMetadataEvent.php',
'OCP\\FilesMetadata\\Event\\MetadataBackgroundEvent' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/Event/MetadataBackgroundEvent.php',
'OCP\\FilesMetadata\\Event\\MetadataLiveEvent' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/Event/MetadataLiveEvent.php',
+ 'OCP\\FilesMetadata\\Event\\MetadataNamedEvent' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/Event/MetadataNamedEvent.php',
'OCP\\FilesMetadata\\Exceptions\\FilesMetadataException' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/Exceptions/FilesMetadataException.php',
'OCP\\FilesMetadata\\Exceptions\\FilesMetadataKeyFormatException' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/Exceptions/FilesMetadataKeyFormatException.php',
'OCP\\FilesMetadata\\Exceptions\\FilesMetadataNotFoundException' => __DIR__ . '/../../..' . '/lib/public/FilesMetadata/Exceptions/FilesMetadataNotFoundException.php',
diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php
index f9069335995..187eed67768 100644
--- a/lib/private/FilesMetadata/FilesMetadataManager.php
+++ b/lib/private/FilesMetadata/FilesMetadataManager.php
@@ -44,6 +44,7 @@ use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
+use OCP\FilesMetadata\Event\MetadataNamedEvent;
use OCP\FilesMetadata\Exceptions\FilesMetadataException;
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
@@ -89,7 +90,8 @@ class FilesMetadataManager implements IFilesMetadataManager {
*/
public function refreshMetadata(
Node $node,
- int $process = self::PROCESS_LIVE
+ int $process = self::PROCESS_LIVE,
+ string $namedEvent = ''
): IFilesMetadata {
try {
$metadata = $this->metadataRequestService->getMetadataFromFileId($node->getId());
@@ -98,8 +100,12 @@ class FilesMetadataManager implements IFilesMetadataManager {
}
// if $process is LIVE, we enforce LIVE
+ // if $process is NAMED, we go NAMED
+ // else BACKGROUND
if ((self::PROCESS_LIVE & $process) !== 0) {
$event = new MetadataLiveEvent($node, $metadata);
+ } elseif ((self::PROCESS_NAMED & $process) !== 0) {
+ $event = new MetadataNamedEvent($node, $metadata, $namedEvent);
} else {
$event = new MetadataBackgroundEvent($node, $metadata);
}
diff --git a/lib/public/FilesMetadata/AMetadataEvent.php b/lib/public/FilesMetadata/AMetadataEvent.php
index 87abc60a983..8cb8ea8d1b8 100644
--- a/lib/public/FilesMetadata/AMetadataEvent.php
+++ b/lib/public/FilesMetadata/AMetadataEvent.php
@@ -39,8 +39,8 @@ abstract class AMetadataEvent extends Event {
* @since 28.0.0
*/
public function __construct(
- private Node $node,
- private IFilesMetadata $metadata
+ protected Node $node,
+ protected IFilesMetadata $metadata
) {
parent::__construct();
}
diff --git a/lib/public/FilesMetadata/Event/MetadataNamedEvent.php b/lib/public/FilesMetadata/Event/MetadataNamedEvent.php
new file mode 100644
index 00000000000..f8cfcf9bd01
--- /dev/null
+++ b/lib/public/FilesMetadata/Event/MetadataNamedEvent.php
@@ -0,0 +1,74 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\FilesMetadata\Event;
+
+use OCP\Files\Node;
+use OCP\FilesMetadata\AMetadataEvent;
+use OCP\FilesMetadata\Model\IFilesMetadata;
+
+/**
+ * MetadataNamedEvent is an event similar to MetadataBackgroundEvent completed with a target name,
+ * used to limit the refresh of metadata only listeners capable of filtering themselves out.
+ *
+ * Meaning that when using this event, your app must implement a filter on the event's registered
+ * name returned by getName()
+ *
+ * This event is mostly triggered when a registered name is added to the files scan
+ * i.e. ./occ files:scan --generate-metadata [name]
+ *
+ * @see AMetadataEvent::getMetadata()
+ * @see AMetadataEvent::getNode()
+ * @see MetadataNamedEvent::getName()
+ * @since 28.0.0
+ */
+class MetadataNamedEvent extends AMetadataEvent {
+ /**
+ * @param Node $node
+ * @param IFilesMetadata $metadata
+ * @param string $name name assigned to the event
+ *
+ * @since 28.0.0
+ */
+ public function __construct(
+ Node $node,
+ IFilesMetadata $metadata,
+ private string $name = ''
+ ) {
+ parent::__construct($node, $metadata);
+ }
+
+ /**
+ * get the assigned name for the event.
+ * This is used to know if your app is the called one when running the
+ * ./occ files:scan --generate-metadata [name]
+ *
+ * @return string
+ * @since 28.0.0
+ */
+ public function getName(): string {
+ return $this->name;
+ }
+}
diff --git a/lib/public/FilesMetadata/IFilesMetadataManager.php b/lib/public/FilesMetadata/IFilesMetadataManager.php
index 6664c049d91..de6fc62ba94 100644
--- a/lib/public/FilesMetadata/IFilesMetadataManager.php
+++ b/lib/public/FilesMetadata/IFilesMetadataManager.php
@@ -42,6 +42,8 @@ interface IFilesMetadataManager {
public const PROCESS_LIVE = 1;
/** @since 28.0.0 */
public const PROCESS_BACKGROUND = 2;
+ /** @since 28.0.0 */
+ public const PROCESS_NAMED = 4;
/**
* initiate the process of refreshing the metadata in relation to a node
@@ -54,15 +56,18 @@ interface IFilesMetadataManager {
*
* @param Node $node related node
* @param int $process type of process
+ * @param string $namedEvent limit process to a named event
*
* @return IFilesMetadata
* @see self::PROCESS_BACKGROUND
* @see self::PROCESS_LIVE
+ * @see self::PROCESS_NAMED
* @since 28.0.0
*/
public function refreshMetadata(
Node $node,
- int $process = self::PROCESS_LIVE
+ int $process = self::PROCESS_LIVE,
+ string $namedEvent = ''
): IFilesMetadata;
/**