Merge pull request #32018 from nextcloud/cleanup/event/trashbin
Port files trashbin events to IEventDispatcher/IEventListenerpull/48323/head
commit
280f6df66c
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
namespace OCA\Files_Trashbin;
|
||||
|
||||
class Hooks {
|
||||
|
||||
/**
|
||||
* clean up user specific settings if user gets deleted
|
||||
* @param array $params array with uid
|
||||
*
|
||||
* This function is connected to the pre_deleteUser signal of OC_Users
|
||||
* to remove the used space for the trash bin stored in the database
|
||||
*/
|
||||
public static function deleteUser_hook($params) {
|
||||
$uid = $params['uid'];
|
||||
Trashbin::deleteUser($uid);
|
||||
}
|
||||
|
||||
public static function post_write_hook($params) {
|
||||
$user = \OC_User::getUser();
|
||||
if (!empty($user)) {
|
||||
Trashbin::resizeTrash($user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Trashbin\Listener;
|
||||
|
||||
use OCA\Files_Trashbin\Storage;
|
||||
use OCA\Files_Trashbin\Trashbin;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\Files\Events\BeforeFileSystemSetupEvent;
|
||||
use OCP\Files\Events\Node\NodeWrittenEvent;
|
||||
use OCP\User\Events\BeforeUserDeletedEvent;
|
||||
|
||||
/** @template-implements IEventListener<NodeWrittenEvent|BeforeUserDeletedEvent|BeforeFileSystemSetupEvent> */
|
||||
class EventListener implements IEventListener {
|
||||
private ?string $userId;
|
||||
|
||||
public function __construct(?string $userId = null) {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if ($event instanceof NodeWrittenEvent) {
|
||||
// Resize trash
|
||||
if (!empty($this->userId)) {
|
||||
Trashbin::resizeTrash($this->userId);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up user specific settings if user gets deleted
|
||||
if ($event instanceof BeforeUserDeletedEvent) {
|
||||
Trashbin::deleteUser($event->getUser()->getUID());
|
||||
}
|
||||
|
||||
if ($event instanceof BeforeFileSystemSetupEvent) {
|
||||
Storage::setupStorage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
namespace OCP\Files\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* Event triggered before the file system is setup
|
||||
*
|
||||
* @since 31.0.0
|
||||
*/
|
||||
class BeforeFileSystemSetupEvent extends Event {
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
private IUser $user,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 31.0.0
|
||||
*/
|
||||
public function getUser(): IUser {
|
||||
return $this->user;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue