mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat: add typed events for external storage config changes
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
e3551e576c
commit
c80c980e29
8 changed files with 100 additions and 0 deletions
|
|
@ -37,6 +37,9 @@ return array(
|
|||
'OCA\\Files_External\\Controller\\StoragesController' => $baseDir . '/../lib/Controller/StoragesController.php',
|
||||
'OCA\\Files_External\\Controller\\UserGlobalStoragesController' => $baseDir . '/../lib/Controller/UserGlobalStoragesController.php',
|
||||
'OCA\\Files_External\\Controller\\UserStoragesController' => $baseDir . '/../lib/Controller/UserStoragesController.php',
|
||||
'OCA\\Files_External\\Event\\StorageCreatedEvent' => $baseDir . '/../lib/Event/StorageCreatedEvent.php',
|
||||
'OCA\\Files_External\\Event\\StorageDeletedEvent' => $baseDir . '/../lib/Event/StorageDeletedEvent.php',
|
||||
'OCA\\Files_External\\Event\\StorageUpdatedEvent' => $baseDir . '/../lib/Event/StorageUpdatedEvent.php',
|
||||
'OCA\\Files_External\\Lib\\Auth\\AmazonS3\\AccessKey' => $baseDir . '/../lib/Lib/Auth/AmazonS3/AccessKey.php',
|
||||
'OCA\\Files_External\\Lib\\Auth\\AuthMechanism' => $baseDir . '/../lib/Lib/Auth/AuthMechanism.php',
|
||||
'OCA\\Files_External\\Lib\\Auth\\Builtin' => $baseDir . '/../lib/Lib/Auth/Builtin.php',
|
||||
|
|
@ -117,6 +120,7 @@ return array(
|
|||
'OCA\\Files_External\\Service\\GlobalStoragesService' => $baseDir . '/../lib/Service/GlobalStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\ImportLegacyStoragesService' => $baseDir . '/../lib/Service/ImportLegacyStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\LegacyStoragesService' => $baseDir . '/../lib/Service/LegacyStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\MountCacheService' => $baseDir . '/../lib/Service/MountCacheService.php',
|
||||
'OCA\\Files_External\\Service\\StoragesService' => $baseDir . '/../lib/Service/StoragesService.php',
|
||||
'OCA\\Files_External\\Service\\UserGlobalStoragesService' => $baseDir . '/../lib/Service/UserGlobalStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\UserStoragesService' => $baseDir . '/../lib/Service/UserStoragesService.php',
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ class ComposerStaticInitFiles_External
|
|||
'OCA\\Files_External\\Controller\\StoragesController' => __DIR__ . '/..' . '/../lib/Controller/StoragesController.php',
|
||||
'OCA\\Files_External\\Controller\\UserGlobalStoragesController' => __DIR__ . '/..' . '/../lib/Controller/UserGlobalStoragesController.php',
|
||||
'OCA\\Files_External\\Controller\\UserStoragesController' => __DIR__ . '/..' . '/../lib/Controller/UserStoragesController.php',
|
||||
'OCA\\Files_External\\Event\\StorageCreatedEvent' => __DIR__ . '/..' . '/../lib/Event/StorageCreatedEvent.php',
|
||||
'OCA\\Files_External\\Event\\StorageDeletedEvent' => __DIR__ . '/..' . '/../lib/Event/StorageDeletedEvent.php',
|
||||
'OCA\\Files_External\\Event\\StorageUpdatedEvent' => __DIR__ . '/..' . '/../lib/Event/StorageUpdatedEvent.php',
|
||||
'OCA\\Files_External\\Lib\\Auth\\AmazonS3\\AccessKey' => __DIR__ . '/..' . '/../lib/Lib/Auth/AmazonS3/AccessKey.php',
|
||||
'OCA\\Files_External\\Lib\\Auth\\AuthMechanism' => __DIR__ . '/..' . '/../lib/Lib/Auth/AuthMechanism.php',
|
||||
'OCA\\Files_External\\Lib\\Auth\\Builtin' => __DIR__ . '/..' . '/../lib/Lib/Auth/Builtin.php',
|
||||
|
|
@ -132,6 +135,7 @@ class ComposerStaticInitFiles_External
|
|||
'OCA\\Files_External\\Service\\GlobalStoragesService' => __DIR__ . '/..' . '/../lib/Service/GlobalStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\ImportLegacyStoragesService' => __DIR__ . '/..' . '/../lib/Service/ImportLegacyStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\LegacyStoragesService' => __DIR__ . '/..' . '/../lib/Service/LegacyStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\MountCacheService' => __DIR__ . '/..' . '/../lib/Service/MountCacheService.php',
|
||||
'OCA\\Files_External\\Service\\StoragesService' => __DIR__ . '/..' . '/../lib/Service/StoragesService.php',
|
||||
'OCA\\Files_External\\Service\\UserGlobalStoragesService' => __DIR__ . '/..' . '/../lib/Service/UserGlobalStoragesService.php',
|
||||
'OCA\\Files_External\\Service\\UserStoragesService' => __DIR__ . '/..' . '/../lib/Service/UserStoragesService.php',
|
||||
|
|
|
|||
24
apps/files_external/lib/Event/StorageCreatedEvent.php
Normal file
24
apps/files_external/lib/Event/StorageCreatedEvent.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Robin Appelman <robin@icewind.nl>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Event;
|
||||
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
class StorageCreatedEvent extends Event {
|
||||
public function __construct(
|
||||
private readonly StorageConfig $newConfig,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getNewConfig(): StorageConfig {
|
||||
return $this->newConfig;
|
||||
}
|
||||
}
|
||||
24
apps/files_external/lib/Event/StorageDeletedEvent.php
Normal file
24
apps/files_external/lib/Event/StorageDeletedEvent.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Robin Appelman <robin@icewind.nl>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Event;
|
||||
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
class StorageDeletedEvent extends Event {
|
||||
public function __construct(
|
||||
private readonly StorageConfig $oldConfig,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getOldConfig(): StorageConfig {
|
||||
return $this->oldConfig;
|
||||
}
|
||||
}
|
||||
29
apps/files_external/lib/Event/StorageUpdatedEvent.php
Normal file
29
apps/files_external/lib/Event/StorageUpdatedEvent.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Robin Appelman <robin@icewind.nl>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Event;
|
||||
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
class StorageUpdatedEvent extends Event {
|
||||
public function __construct(
|
||||
private readonly StorageConfig $oldConfig,
|
||||
private readonly StorageConfig $newConfig,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getOldConfig(): StorageConfig {
|
||||
return $this->oldConfig;
|
||||
}
|
||||
|
||||
public function getNewConfig(): StorageConfig {
|
||||
return $this->newConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,9 @@
|
|||
namespace OCA\Files_External\Service;
|
||||
|
||||
use OC\Files\Filesystem;
|
||||
use OCA\Files_External\Event\StorageCreatedEvent;
|
||||
use OCA\Files_External\Event\StorageDeletedEvent;
|
||||
use OCA\Files_External\Event\StorageUpdatedEvent;
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\MountConfig;
|
||||
|
||||
|
|
@ -62,9 +65,13 @@ class GlobalStoragesService extends StoragesService {
|
|||
protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
|
||||
// if mount point changed, it's like a deletion + creation
|
||||
if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
|
||||
$this->eventDispatcher->dispatchTyped(new StorageDeletedEvent($oldStorage));
|
||||
$this->eventDispatcher->dispatchTyped(new StorageCreatedEvent($newStorage));
|
||||
$this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
|
||||
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
|
||||
return;
|
||||
} else {
|
||||
$this->eventDispatcher->dispatchTyped(new StorageUpdatedEvent($oldStorage, $newStorage));
|
||||
}
|
||||
|
||||
$userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ use OC\Files\Filesystem;
|
|||
use OCA\Files\AppInfo\Application as FilesApplication;
|
||||
use OCA\Files\ConfigLexicon;
|
||||
use OCA\Files_External\AppInfo\Application;
|
||||
use OCA\Files_External\Event\StorageCreatedEvent;
|
||||
use OCA\Files_External\Event\StorageDeletedEvent;
|
||||
use OCA\Files_External\Lib\Auth\AuthMechanism;
|
||||
use OCA\Files_External\Lib\Auth\InvalidAuth;
|
||||
use OCA\Files_External\Lib\Backend\Backend;
|
||||
|
|
@ -244,6 +246,7 @@ abstract class StoragesService {
|
|||
// add new storage
|
||||
$allStorages[$configId] = $newStorage;
|
||||
|
||||
$this->eventDispatcher->dispatchTyped(new StorageCreatedEvent($newStorage));
|
||||
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
|
||||
|
||||
$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
|
||||
|
|
@ -455,6 +458,7 @@ abstract class StoragesService {
|
|||
$this->dbConfig->removeMount($id);
|
||||
|
||||
$deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
|
||||
$this->eventDispatcher->dispatchTyped(new StorageDeletedEvent($deletedStorage));
|
||||
$this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
|
||||
|
||||
// delete oc_storages entries and oc_filecache
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
namespace OCA\Files_External\Service;
|
||||
|
||||
use OC\Files\Filesystem;
|
||||
use OCA\Files_External\Event\StorageCreatedEvent;
|
||||
use OCA\Files_External\Event\StorageDeletedEvent;
|
||||
use OCA\Files_External\Lib\StorageConfig;
|
||||
use OCA\Files_External\MountConfig;
|
||||
use OCA\Files_External\NotFoundException;
|
||||
|
|
@ -72,6 +74,8 @@ class UserStoragesService extends StoragesService {
|
|||
protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
|
||||
// if mount point changed, it's like a deletion + creation
|
||||
if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
|
||||
$this->eventDispatcher->dispatchTyped(new StorageDeletedEvent($oldStorage));
|
||||
$this->eventDispatcher->dispatchTyped(new StorageCreatedEvent($newStorage));
|
||||
$this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
|
||||
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue