summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2019-02-07 16:35:02 +0100
committerGitHub <noreply@github.com>2019-02-07 16:35:02 +0100
commitbaa6a2d52cb48cb666ae0bfd0f75459c190086f8 (patch)
treed252c71f3934f607bb29335b9c25fe1555e217cf /lib/private
parent0e9903c420aee76648e61c4c14b750ea01125bb1 (diff)
parent0ccd970f9d7c154dc4c2aedcbedd6658ca69a1c3 (diff)
downloadnextcloud-server-baa6a2d52cb48cb666ae0bfd0f75459c190086f8.tar.gz
nextcloud-server-baa6a2d52cb48cb666ae0bfd0f75459c190086f8.zip
Merge pull request #13748 from nextcloud/cache-insert-event
add event for inserting cache entries
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/Cache/Cache.php24
-rw-r--r--lib/private/Files/Cache/Storage.php4
2 files changed, 18 insertions, 10 deletions
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;