Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
'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\\CacheUpdateEvent' => $baseDir . '/lib/public/Files/Cache/CacheUpdateEvent.php',
'OCP\\Files\\Cache\\ICache' => $baseDir . '/lib/public/Files/Cache/ICache.php',
Expand Down
3 changes: 3 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ 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\\CacheUpdateEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/CacheUpdateEvent.php',
'OCP\\Files\\Cache\\ICache' => __DIR__ . '/../../..' . '/lib/public/Files/Cache/ICache.php',
Expand Down
12 changes: 11 additions & 1 deletion lib/private/Files/Cache/AbstractCacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ class AbstractCacheEvent extends Event implements ICacheEvent {
protected $storage;
protected $path;
protected $fileId;
protected $storageId;

/**
* @param IStorage $storage
* @param string $path
* @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;
}

/**
Expand Down Expand Up @@ -80,4 +82,12 @@ public function setPath(string $path): void {
public function getFileId(): int {
return $this->fileId;
}

/**
* @return int
* @since 21.0.0
*/
public function getStorageId(): int {
return $this->storageId;
}
}
34 changes: 30 additions & 4 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
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\CacheEntryRemovedEvent;
use OCP\Files\Cache\CacheUpdateEvent;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
Expand Down Expand Up @@ -91,6 +95,9 @@ class Cache implements ICache {
*/
protected $connection;

/**
* @var IEventDispatcher
*/
protected $eventDispatcher;

/** @var QuerySearchHelper */
Expand All @@ -109,7 +116,7 @@ public function __construct(IStorage $storage) {
$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);
}

Expand Down Expand Up @@ -284,7 +291,8 @@ public function insert($file, array $data) {
$data['name'] = basename($file);

[$values, $extensionValues] = $this->normalizeData($data);
$values['storage'] = $this->getNumericStorageId();
$storageId = $this->getNumericStorageId();
$values['storage'] = $storageId;

try {
$builder = $this->connection->getQueryBuilder();
Expand All @@ -308,7 +316,9 @@ public function insert($file, array $data) {
$query->execute();
}

$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
$event = new CacheEntryInsertedEvent($this->storage, $file, $fileId, $storageId);
$this->eventDispatcher->dispatch(CacheInsertEvent::class, $event);
$this->eventDispatcher->dispatchTyped($event);
return $fileId;
}
} catch (UniqueConstraintViolationException $e) {
Expand Down Expand Up @@ -399,7 +409,9 @@ public function update($id, array $data) {
$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));
$event = new CacheEntryUpdatedEvent($this->storage, $path, $id, $this->getNumericStorageId());
$this->eventDispatcher->dispatch(CacheUpdateEvent::class, $event);
$this->eventDispatcher->dispatchTyped($event);
}
}

Expand Down Expand Up @@ -536,6 +548,8 @@ public function remove($file) {
if ($entry->getMimeType() == FileInfo::MIMETYPE_FOLDER) {
$this->removeChildren($entry);
}

$this->eventDispatcher->dispatch(CacheEntryRemovedEvent::class, new CacheEntryRemovedEvent($this->storage, $entry->getPath(), $entry->getId(), $this->getNumericStorageId()));
}
}

Expand Down Expand Up @@ -677,9 +691,21 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
$query->execute();

$this->connection->commit();

if ($sourceCache->getNumericStorageId() !== $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 {
$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);
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getStorageId() {


public function getPath() {
return $this->data['path'];
return (string)$this->data['path'];
}


Expand Down
35 changes: 35 additions & 0 deletions lib/public/Files/Cache/CacheEntryInsertedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <[email protected]>
*
* @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 {
}
34 changes: 34 additions & 0 deletions lib/public/Files/Cache/CacheEntryRemovedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <[email protected]>
*
* @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 CacheEntryRemovedEvent extends AbstractCacheEvent implements ICacheEvent {
}
35 changes: 35 additions & 0 deletions lib/public/Files/Cache/CacheEntryUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <[email protected]>
*
* @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 {
}
5 changes: 2 additions & 3 deletions lib/public/Files/Cache/CacheInsertEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

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 {
}
5 changes: 2 additions & 3 deletions lib/public/Files/Cache/CacheUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

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 {
}
6 changes: 6 additions & 0 deletions lib/public/Files/Cache/ICacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ public function setPath(string $path): void;
* @since 16.0.0
*/
public function getFileId(): int;

/**
* @return int
* @since 21.0.0
*/
public function getStorageId(): int;
}