Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions apps/files_external/lib/Service/StoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ public function removeStorage(int $id) {
// delete oc_storages entries and oc_filecache
Storage::cleanByMountId($id);

// listeners remove the oc_mounts rows that cleanByMountId() uses to find the storages
$this->eventDispatcher->dispatchTyped(new StorageDeletedEvent($deletedStorage));
$this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null));

$this->updateOverwriteHomeFolders();
}

Expand Down
30 changes: 30 additions & 0 deletions apps/files_external/tests/Service/StoragesServiceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ public function testDeleteStorage(array $backendOptions, string $rustyStorageId)
// get numeric id for later check
$numericId = $storageCache->getNumericId();

$path = $this->getUniqueID('file');
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
$qb->insert('filecache')
->values([
'storage' => $qb->createNamedParameter($numericId, IQueryBuilder::PARAM_INT),
'path' => $qb->createNamedParameter($path),
'path_hash' => $qb->createNamedParameter(md5($path)),
'parent' => $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT),
'name' => $qb->createNamedParameter($path),
])
->executeStatement();

// listeners of StorageDeletedEvent clear the mount cache, like MountCacheService does
$this->eventDispatcher->method('dispatchTyped')
->willReturnCallback(function (Event $event) use ($mountCache, $user): void {
if ($event instanceof StorageDeletedEvent) {
$mountCache->removeMount('dummy', $user);
}
});

$this->service->removeStorage($id);

$caught = false;
Expand All @@ -317,6 +337,16 @@ public function testDeleteStorage(array $backendOptions, string $rustyStorageId)
$storages = $result->fetchAll();
$result->closeCursor();
$this->assertCount(0, $storages, 'expected 0 storages, got ' . json_encode($storages));

// filecache entries of the storage were removed
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
$result = $qb->select('fileid')
->from('filecache')
->where($qb->expr()->eq('storage', $qb->createNamedParameter($numericId, IQueryBuilder::PARAM_INT)))
->executeQuery();
$fileIds = $result->fetchFirstColumn();
$result->closeCursor();
$this->assertCount(0, $fileIds, 'expected 0 filecache entries, got ' . json_encode($fileIds));
}

protected function actualDeletedUnexistingStorageTest() {
Expand Down