aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Cache/Cache.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2019-01-22 17:08:32 +0100
committerRobin Appelman <robin@icewind.nl>2019-02-07 15:51:30 +0100
commit748bcd407b4079adeceff3455749ad1e4d316c9d (patch)
tree9ae604f077275240486ce5b6e4077f4635695f80 /lib/private/Files/Cache/Cache.php
parenta1aa6ee70d45d359d7e277873106a668aa642305 (diff)
downloadnextcloud-server-748bcd407b4079adeceff3455749ad1e4d316c9d.tar.gz
nextcloud-server-748bcd407b4079adeceff3455749ad1e4d316c9d.zip
add event for inserting cache entries
this provides a reliable way for apps to listen to new files without the need to of cache wrappers to hook into inserts themselves (something which isn't 100% reliable) Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Cache/Cache.php')
-rw-r--r--lib/private/Files/Cache/Cache.php24
1 files changed, 15 insertions, 9 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
}