Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-09-16 17:08:51 +0300
committerGitHub <noreply@github.com>2021-09-16 17:08:51 +0300
commitc7ab27c28da65f495a2e4b344d005eefd2cc22b6 (patch)
treed69e057a0a3c0121ae24a104831e43afb0bbce71 /lib
parenta5b5e53b077b04f981c76720c007c20d9e3cb053 (diff)
parentc0b701f7f153f11899df64fcc0e383a09a989753 (diff)
Merge pull request #28820 from nextcloud/backport/24113/stable20
[stable20] extend cache events
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php3
-rw-r--r--lib/composer/composer/autoload_static.php3
-rw-r--r--lib/private/Files/Cache/AbstractCacheEvent.php12
-rw-r--r--lib/private/Files/Cache/Cache.php33
-rw-r--r--lib/private/Files/Cache/CacheEntry.php2
-rw-r--r--lib/public/Files/Cache/CacheEntryInsertedEvent.php34
-rw-r--r--lib/public/Files/Cache/CacheEntryRemovedEvent.php34
-rw-r--r--lib/public/Files/Cache/CacheEntryUpdatedEvent.php34
-rw-r--r--lib/public/Files/Cache/CacheInsertEvent.php5
-rw-r--r--lib/public/Files/Cache/CacheUpdateEvent.php5
-rw-r--r--lib/public/Files/Cache/ICacheEvent.php6
11 files changed, 159 insertions, 12 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index bf45be993c1..0d840b1fa01 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -218,6 +218,9 @@ return array(
'OCP\\Federation\\ICloudIdManager' => $baseDir . '/lib/public/Federation/ICloudIdManager.php',
'OCP\\Files' => $baseDir . '/lib/public/Files.php',
'OCP\\Files\\AlreadyExistsException' => $baseDir . '/lib/public/Files/AlreadyExistsException.php',
+ 'OCP\\Files\\Cache\\CacheEntryInsertedEvent' => $baseDir . '/lib/public/Files/Cache/CacheEntryInsertedEvent.php',
+ 'OCP\\Files\\Cache\\CacheEntryRemovedEvent' => $baseDir . '/lib/public/Files/Cache/CacheEntryRemovedEvent.php',
+ 'OCP\\Files\\Cache\\CacheEntryUpdatedEvent' => $baseDir . '/lib/public/Files/Cache/CacheEntryUpdatedEvent.php',
'OCP\\Files\\Cache\\CacheInsertEvent' => $baseDir . '/lib/public/Files/Cache/CacheInsertEvent.php',
'OCP\\Files\\Cache\\CacheUpdateEvent' => $baseDir . '/lib/public/Files/Cache/CacheUpdateEvent.php',
'OCP\\Files\\Cache\\ICache' => $baseDir . '/lib/public/Files/Cache/ICache.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index c9853784fcb..a9ddd0726aa 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -247,6 +247,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Federation\\ICloudIdManager' => __DIR__ . '/../../..' . '/lib/public/Federation/ICloudIdManager.php',
'OCP\\Files' => __DIR__ . '/../../..' . '/lib/public/Files.php',
'OCP\\Files\\AlreadyExistsException' => __DIR__ . '/../../..' . '/lib/public/Files/AlreadyExistsException.php',
+ 'OCP\\Files\\Cache\\CacheEntryInsertedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheEntryInsertedEvent.php',
+ 'OCP\\Files\\Cache\\CacheEntryRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheEntryRemovedEvent.php',
+ 'OCP\\Files\\Cache\\CacheEntryUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheEntryUpdatedEvent.php',
'OCP\\Files\\Cache\\CacheInsertEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheInsertEvent.php',
'OCP\\Files\\Cache\\CacheUpdateEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheUpdateEvent.php',
'OCP\\Files\\Cache\\ICache' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/ICache.php',
diff --git a/lib/private/Files/Cache/AbstractCacheEvent.php b/lib/private/Files/Cache/AbstractCacheEvent.php
index a4029476fa5..d9c097626bd 100644
--- a/lib/private/Files/Cache/AbstractCacheEvent.php
+++ b/lib/private/Files/Cache/AbstractCacheEvent.php
@@ -36,6 +36,7 @@ class AbstractCacheEvent extends Event implements ICacheEvent {
protected $storage;
protected $path;
protected $fileId;
+ protected $storageId;
/**
* @param IStorage $storage
@@ -43,10 +44,11 @@ class AbstractCacheEvent extends Event implements ICacheEvent {
* @param int $fileId
* @since 16.0.0
*/
- public function __construct(IStorage $storage, string $path, int $fileId) {
+ public function __construct(IStorage $storage, string $path, int $fileId, int $storageId = -1) {
$this->storage = $storage;
$this->path = $path;
$this->fileId = $fileId;
+ $this->storageId = $storageId;
}
/**
@@ -80,4 +82,12 @@ class AbstractCacheEvent extends Event implements ICacheEvent {
public function getFileId(): int {
return $this->fileId;
}
+
+ /**
+ * @return int
+ * @since 20.0.13
+ */
+ public function getStorageId(): int {
+ return $this->storageId;
+ }
}
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index be2862cc0fa..2bc7fbb9541 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -41,7 +41,11 @@ namespace OC\Files\Cache;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Cache\CacheEntryInsertedEvent;
+use OCP\Files\Cache\CacheEntryUpdatedEvent;
use OCP\Files\Cache\CacheInsertEvent;
+use OCP\Files\Cache\CacheEntryRemovedEvent;
use OCP\Files\Cache\CacheUpdateEvent;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
@@ -91,6 +95,9 @@ class Cache implements ICache {
*/
protected $connection;
+ /**
+ * @var IEventDispatcher
+ */
protected $eventDispatcher;
/** @var QuerySearchHelper */
@@ -109,7 +116,7 @@ class Cache implements ICache {
$this->storageCache = new Storage($storage);
$this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
$this->connection = \OC::$server->getDatabaseConnection();
- $this->eventDispatcher = \OC::$server->getEventDispatcher();
+ $this->eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader);
}
@@ -284,7 +291,8 @@ class Cache implements ICache {
$data['name'] = basename($file);
[$values, $extensionValues] = $this->normalizeData($data);
- $values['storage'] = $this->getNumericStorageId();
+ $storageId = $this->getNumericStorageId();
+ $values['storage'] = $storageId;
try {
$builder = $this->connection->getQueryBuilder();
@@ -308,7 +316,9 @@ class Cache implements ICache {
$query->execute();
}
- $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
+ $event = new CacheEntryInsertedEvent($this->storage, $file, $fileId, $storageId);
+ $this->eventDispatcher->dispatch(CacheInsertEvent::class, $event);
+ $this->eventDispatcher->dispatchTyped($event);
return $fileId;
}
} catch (UniqueConstraintViolationException $e) {
@@ -399,7 +409,9 @@ class Cache implements ICache {
$path = $this->getPathById($id);
// path can still be null if the file doesn't exist
if ($path !== null) {
- $this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $path, $id));
+ $event = new CacheEntryUpdatedEvent($this->storage, $path, $id, $this->getNumericStorageId());
+ $this->eventDispatcher->dispatch(CacheUpdateEvent::class, $event);
+ $this->eventDispatcher->dispatchTyped($event);
}
}
@@ -536,6 +548,8 @@ class Cache implements ICache {
if ($entry->getMimeType() == FileInfo::MIMETYPE_FOLDER) {
$this->removeChildren($entry);
}
+
+ $this->eventDispatcher->dispatchTyped(new CacheEntryRemovedEvent($this->storage, $entry->getPath(), $entry->getId(), $this->getNumericStorageId()));
}
}
@@ -681,6 +695,17 @@ class Cache implements ICache {
$query->execute();
$this->connection->commit();
+
+ if ($sourceCache->getNumericStorageId() !== $this->getNumericStorageId()) {
+ $this->eventDispatcher->dispatchTyped(new CacheEntryRemovedEvent($this->storage, $sourcePath, $sourceId, $sourceCache->getNumericStorageId()));
+ $event = new CacheEntryInsertedEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId());
+ $this->eventDispatcher->dispatch(CacheInsertEvent::class, $event);
+ $this->eventDispatcher->dispatchTyped($event);
+ } else {
+ $event = new CacheEntryUpdatedEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId());
+ $this->eventDispatcher->dispatch(CacheUpdateEvent::class, $event);
+ $this->eventDispatcher->dispatchTyped($event);
+ }
} else {
$this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath);
}
diff --git a/lib/private/Files/Cache/CacheEntry.php b/lib/private/Files/Cache/CacheEntry.php
index 744b88b5b51..2869e190eda 100644
--- a/lib/private/Files/Cache/CacheEntry.php
+++ b/lib/private/Files/Cache/CacheEntry.php
@@ -67,7 +67,7 @@ class CacheEntry implements ICacheEntry, \ArrayAccess {
public function getPath() {
- return $this->data['path'];
+ return (string)$this->data['path'];
}
diff --git a/lib/public/Files/Cache/CacheEntryInsertedEvent.php b/lib/public/Files/Cache/CacheEntryInsertedEvent.php
new file mode 100644
index 00000000000..e9ab2d64559
--- /dev/null
+++ b/lib/public/Files/Cache/CacheEntryInsertedEvent.php
@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
+ *
+ * @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\Files\Cache;
+
+use OC\Files\Cache\AbstractCacheEvent;
+
+/**
+ * Event for when an existing entry in the cache gets inserted
+ *
+ * @since 20.0.13
+ */
+class CacheEntryInsertedEvent extends AbstractCacheEvent implements ICacheEvent {
+}
diff --git a/lib/public/Files/Cache/CacheEntryRemovedEvent.php b/lib/public/Files/Cache/CacheEntryRemovedEvent.php
new file mode 100644
index 00000000000..5c302d147d5
--- /dev/null
+++ b/lib/public/Files/Cache/CacheEntryRemovedEvent.php
@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
+ *
+ * @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\Files\Cache;
+
+use OC\Files\Cache\AbstractCacheEvent;
+
+/**
+ * Event for when an existing entry in the cache gets removed
+ *
+ * @since 20.0.13
+ */
+class CacheEntryRemovedEvent extends AbstractCacheEvent implements ICacheEvent {
+}
diff --git a/lib/public/Files/Cache/CacheEntryUpdatedEvent.php b/lib/public/Files/Cache/CacheEntryUpdatedEvent.php
new file mode 100644
index 00000000000..f264613ba44
--- /dev/null
+++ b/lib/public/Files/Cache/CacheEntryUpdatedEvent.php
@@ -0,0 +1,34 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
+ *
+ * @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\Files\Cache;
+
+use OC\Files\Cache\AbstractCacheEvent;
+
+/**
+ * Event for when an existing entry in the cache gets updated
+ *
+ * @since 20.0.13
+ */
+class CacheEntryUpdatedEvent extends AbstractCacheEvent implements ICacheEvent {
+}
diff --git a/lib/public/Files/Cache/CacheInsertEvent.php b/lib/public/Files/Cache/CacheInsertEvent.php
index 84fc1a2e928..08ab15f9a2d 100644
--- a/lib/public/Files/Cache/CacheInsertEvent.php
+++ b/lib/public/Files/Cache/CacheInsertEvent.php
@@ -26,12 +26,11 @@ declare(strict_types=1);
namespace OCP\Files\Cache;
-use OC\Files\Cache\AbstractCacheEvent;
-
/**
* Event for when a new entry gets added to the cache
*
* @since 16.0.0
+ * @deprecated 21.0.0 use CacheEntryInsertedEvent instead
*/
-class CacheInsertEvent extends AbstractCacheEvent {
+class CacheInsertEvent extends CacheEntryInsertedEvent {
}
diff --git a/lib/public/Files/Cache/CacheUpdateEvent.php b/lib/public/Files/Cache/CacheUpdateEvent.php
index f20056d2666..54397045398 100644
--- a/lib/public/Files/Cache/CacheUpdateEvent.php
+++ b/lib/public/Files/Cache/CacheUpdateEvent.php
@@ -26,12 +26,11 @@ declare(strict_types=1);
namespace OCP\Files\Cache;
-use OC\Files\Cache\AbstractCacheEvent;
-
/**
* Event for when an existing entry in the cache gets updated
*
* @since 16.0.0
+ * @deprecated 21.0.0 use CacheEntryUpdatedEvent instead
*/
-class CacheUpdateEvent extends AbstractCacheEvent {
+class CacheUpdateEvent extends CacheEntryUpdatedEvent {
}
diff --git a/lib/public/Files/Cache/ICacheEvent.php b/lib/public/Files/Cache/ICacheEvent.php
index 634666f594a..dab6a94cbaa 100644
--- a/lib/public/Files/Cache/ICacheEvent.php
+++ b/lib/public/Files/Cache/ICacheEvent.php
@@ -56,4 +56,10 @@ interface ICacheEvent {
* @since 16.0.0
*/
public function getFileId(): int;
+
+ /**
+ * @return int
+ * @since 20.0.13
+ */
+ public function getStorageId(): int;
}