- adds cache remove event - expose storage id in event - emit events during cache move Signed-off-by: Robin Appelman <robin@icewind.nl>tags/v21.0.0beta1
@@ -219,6 +219,7 @@ return array( | |||
'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\\CacheRemoveEvent' => $baseDir . '/lib/public/Files/Cache/CacheRemoveEvent.php', | |||
'OCP\\Files\\Cache\\CacheUpdateEvent' => $baseDir . '/lib/public/Files/Cache/CacheUpdateEvent.php', | |||
'OCP\\Files\\Cache\\ICache' => $baseDir . '/lib/public/Files/Cache/ICache.php', | |||
'OCP\\Files\\Cache\\ICacheEntry' => $baseDir . '/lib/public/Files/Cache/ICacheEntry.php', |
@@ -248,6 +248,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'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\\CacheRemoveEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheRemoveEvent.php', | |||
'OCP\\Files\\Cache\\CacheUpdateEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheUpdateEvent.php', | |||
'OCP\\Files\\Cache\\ICache' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/ICache.php', | |||
'OCP\\Files\\Cache\\ICacheEntry' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/ICacheEntry.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) { | |||
$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 21.0.0 | |||
*/ | |||
public function getStorageId(): int { | |||
return $this->storageId; | |||
} | |||
} |
@@ -42,6 +42,7 @@ use Doctrine\DBAL\Driver\Statement; | |||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException; | |||
use OCP\DB\QueryBuilder\IQueryBuilder; | |||
use OCP\Files\Cache\CacheInsertEvent; | |||
use OCP\Files\Cache\CacheRemoveEvent; | |||
use OCP\Files\Cache\CacheUpdateEvent; | |||
use OCP\Files\Cache\ICache; | |||
use OCP\Files\Cache\ICacheEntry; | |||
@@ -284,7 +285,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 +310,7 @@ class Cache implements ICache { | |||
$query->execute(); | |||
} | |||
$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId)); | |||
$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId, $storageId)); | |||
return $fileId; | |||
} | |||
} catch (UniqueConstraintViolationException $e) { | |||
@@ -399,7 +401,7 @@ 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)); | |||
$this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $path, $id, $this->getNumericStorageId())); | |||
} | |||
} | |||
@@ -536,6 +538,8 @@ class Cache implements ICache { | |||
if ($entry->getMimeType() == FileInfo::MIMETYPE_FOLDER) { | |||
$this->removeChildren($entry); | |||
} | |||
$this->eventDispatcher->dispatch(CacheRemoveEvent::class, new CacheRemoveEvent($this->storage, $entry->getPath(), $entry->getId(), $this->getNumericStorageId())); | |||
} | |||
} | |||
@@ -677,9 +681,17 @@ class Cache implements ICache { | |||
$query->execute(); | |||
$this->connection->commit(); | |||
if ($sourceCache->getNumericStorageId() !== $this->getNumericStorageId()) { | |||
$this->eventDispatcher->dispatch(CacheRemoveEvent::class, new CacheRemoveEvent($this->storage, $sourcePath, $sourceId, $sourceCache->getNumericStorageId())); | |||
$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId())); | |||
} else { | |||
$this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId())); | |||
} | |||
} else { | |||
$this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); | |||
} | |||
} | |||
/** |
@@ -67,7 +67,7 @@ class CacheEntry implements ICacheEntry { | |||
public function getPath() { | |||
return $this->data['path']; | |||
return (string)$this->data['path']; | |||
} | |||
@@ -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 21.0.0 | |||
*/ | |||
class CacheRemoveEvent extends AbstractCacheEvent { | |||
} |
@@ -56,4 +56,10 @@ interface ICacheEvent { | |||
* @since 16.0.0 | |||
*/ | |||
public function getFileId(): int; | |||
/** | |||
* @return int | |||
* @since 21.0.0 | |||
*/ | |||
public function getStorageId(): int; | |||
} |