aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
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/Files/Cache/Cache.php24
-rw-r--r--lib/private/Files/Cache/Storage.php4
-rw-r--r--lib/public/Files/Cache/CacheInsertEvent.php72
5 files changed, 92 insertions, 10 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 5997825289e..a96a851a5ec 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -172,6 +172,7 @@ 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\\CacheInsertEvent' => $baseDir . '/lib/public/Files/Cache/CacheInsertEvent.php',
'OCP\\Files\\Cache\\ICache' => $baseDir . '/lib/public/Files/Cache/ICache.php',
'OCP\\Files\\Cache\\ICacheEntry' => $baseDir . '/lib/public/Files/Cache/ICacheEntry.php',
'OCP\\Files\\Cache\\IPropagator' => $baseDir . '/lib/public/Files/Cache/IPropagator.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index ff8bea3bd90..21717fef657 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -202,6 +202,7 @@ 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\\CacheInsertEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheInsertEvent.php',
'OCP\\Files\\Cache\\ICache' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/ICache.php',
'OCP\\Files\\Cache\\ICacheEntry' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/ICacheEntry.php',
'OCP\\Files\\Cache\\IPropagator' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/IPropagator.php',
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index 43e48e51654..17e870bcbb4 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -40,10 +40,12 @@ namespace OC\Files\Cache;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Doctrine\DBAL\Driver\Statement;
+use OCP\Files\Cache\CacheInsertEvent;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
use \OCP\Files\IMimeTypeLoader;
use OCP\Files\Search\ISearchQuery;
+use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
/**
@@ -71,6 +73,8 @@ class Cache implements ICache {
*/
protected $storageId;
+ private $storage;
+
/**
* @var Storage $storageCache
*/
@@ -84,18 +88,17 @@ class Cache implements ICache {
*/
protected $connection;
+ protected $eventDispatcher;
+
/** @var QuerySearchHelper */
protected $querySearchHelper;
/**
- * @param \OC\Files\Storage\Storage|string $storage
+ * @param IStorage $storage
*/
- public function __construct($storage) {
- if ($storage instanceof \OC\Files\Storage\Storage) {
- $this->storageId = $storage->getId();
- } else {
- $this->storageId = $storage;
- }
+ public function __construct(IStorage $storage) {
+ $this->storageId = $storage->getId();
+ $this->storage = $storage;
if (strlen($this->storageId) > 64) {
$this->storageId = md5($this->storageId);
}
@@ -103,6 +106,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->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader);
}
@@ -283,9 +287,11 @@ class Cache implements ICache {
}
if ($builder->execute()) {
- return (int)$this->connection->lastInsertId('*PREFIX*filecache');
+ $fileId = (int)$this->connection->lastInsertId('*PREFIX*filecache');
+ $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
+ return $fileId;
}
- } catch(UniqueConstraintViolationException $e) {
+ } catch (UniqueConstraintViolationException $e) {
// entry exists already
}
diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php
index 794c4872c93..5b37c1f43f8 100644
--- a/lib/private/Files/Cache/Storage.php
+++ b/lib/private/Files/Cache/Storage.php
@@ -28,6 +28,8 @@
namespace OC\Files\Cache;
+use OCP\Files\Storage\IStorage;
+
/**
* Handle the mapping between the string and numeric storage ids
*
@@ -61,7 +63,7 @@ class Storage {
* @throws \RuntimeException
*/
public function __construct($storage, $isAvailable = true) {
- if ($storage instanceof \OC\Files\Storage\Storage) {
+ if ($storage instanceof IStorage) {
$this->storageId = $storage->getId();
} else {
$this->storageId = $storage;
diff --git a/lib/public/Files/Cache/CacheInsertEvent.php b/lib/public/Files/Cache/CacheInsertEvent.php
new file mode 100644
index 00000000000..071f039d45f
--- /dev/null
+++ b/lib/public/Files/Cache/CacheInsertEvent.php
@@ -0,0 +1,72 @@
+<?php declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 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 OCP\Files\Storage\IStorage;
+use Symfony\Component\EventDispatcher\Event;
+
+/**
+ * @since 16.0.0
+ */
+class CacheInsertEvent extends Event {
+ private $storage;
+ private $path;
+ private $fileId;
+
+ /**
+ * CacheInsertEvent constructor.
+ *
+ * @param IStorage $storage
+ * @param string $path
+ * @param int $fileId
+ * @since 16.0.0
+ */
+ public function __construct(IStorage $storage, string $path, int $fileId) {
+ $this->storage = $storage;
+ $this->path = $path;
+ $this->fileId = $fileId;
+ }
+
+ /**
+ * @return IStorage
+ * @since 16.0.0
+ */
+ public function getStorage(): IStorage {
+ return $this->storage;
+ }
+
+ /**
+ * @return string
+ * @since 16.0.0
+ */
+ public function getPath(): string {
+ return $this->path;
+ }
+
+ /**
+ * @return int
+ * @since 16.0.0
+ */
+ public function getFileId(): int {
+ return $this->fileId;
+ }
+}