rename cache event to follow new naming standards

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2020-11-26 15:39:46 +01:00
parent 23fb497ff5
commit 88f35d52d2
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
8 changed files with 103 additions and 17 deletions

View File

@ -218,8 +218,10 @@ 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\\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',

View File

@ -247,8 +247,10 @@ 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\\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',

View File

@ -41,8 +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\CacheRemoveEvent;
use OCP\Files\Cache\CacheEntryRemovedEvent;
use OCP\Files\Cache\CacheUpdateEvent;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
@ -92,6 +95,9 @@ class Cache implements ICache {
*/
protected $connection;
/**
* @var IEventDispatcher
*/
protected $eventDispatcher;
/** @var QuerySearchHelper */
@ -110,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);
}
@ -310,7 +316,9 @@ class Cache implements ICache {
$query->execute();
}
$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId, $storageId));
$event = new CacheEntryInsertedEvent($this->storage, $file, $fileId, $storageId);
$this->eventDispatcher->dispatch(CacheInsertEvent::class, $event);
$this->eventDispatcher->dispatchTyped($event);
return $fileId;
}
} catch (UniqueConstraintViolationException $e) {
@ -401,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, $this->getNumericStorageId()));
$event = new CacheEntryUpdatedEvent($this->storage, $path, $id, $this->getNumericStorageId());
$this->eventDispatcher->dispatch(CacheUpdateEvent::class, $event);
$this->eventDispatcher->dispatchTyped($event);
}
}
@ -539,7 +549,7 @@ class Cache implements ICache {
$this->removeChildren($entry);
}
$this->eventDispatcher->dispatch(CacheRemoveEvent::class, new CacheRemoveEvent($this->storage, $entry->getPath(), $entry->getId(), $this->getNumericStorageId()));
$this->eventDispatcher->dispatch(CacheEntryRemovedEvent::class, new CacheEntryRemovedEvent($this->storage, $entry->getPath(), $entry->getId(), $this->getNumericStorageId()));
}
}
@ -683,10 +693,14 @@ class Cache implements ICache {
$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()));
$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 {
$this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $targetPath, $sourceId, $this->getNumericStorageId()));
$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);

View File

@ -0,0 +1,35 @@
<?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 21.0.0
*/
class CacheEntryInsertedEvent extends AbstractCacheEvent implements ICacheEvent {
}

View File

@ -30,5 +30,5 @@ use OC\Files\Cache\AbstractCacheEvent;
*
* @since 21.0.0
*/
class CacheRemoveEvent extends AbstractCacheEvent {
class CacheEntryRemovedEvent extends AbstractCacheEvent implements ICacheEvent {
}

View File

@ -0,0 +1,35 @@
<?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 21.0.0
*/
class CacheEntryUpdatedEvent extends AbstractCacheEvent implements ICacheEvent {
}

View File

@ -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 {
}

View File

@ -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 {
}