-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32018 from nextcloud/cleanup/event/trashbin
Port files trashbin events to IEventDispatcher/IEventListener
- Loading branch information
Showing
14 changed files
with
147 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.