-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move version rollback hook to event
Signed-off-by: ailkiv <a.ilkiv.ye@gmail.com>
- Loading branch information
Showing
7 changed files
with
90 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Files_Versions\Events; | ||
|
||
use OCP\EventDispatcher\Event; | ||
use OCA\Files_Versions\Versions\IVersion; | ||
|
||
/** | ||
* Class VersionRestoredEvent | ||
* | ||
* Event that is called after a successful restore of a previous version | ||
* | ||
* @package OCA\Files_Versions | ||
*/ | ||
class VersionRestoredEvent extends Event { | ||
public function __construct(private IVersion $version) { | ||
} | ||
|
||
/** | ||
* Version that was restored | ||
*/ | ||
public function getVersion(): IVersion { | ||
return $this->version; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/files_versions/lib/Listener/LegacyRollbackListener.php
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Files_Versions\Listener; | ||
|
||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCA\Files_Versions\Events\VersionRestoredEvent; | ||
|
||
/** | ||
* This listener is designed to be compatible with third-party code | ||
* that can still use a hook. This listener will be removed in | ||
* the next version and the rollback hook will stop working. | ||
* | ||
* @template-implements IEventListener<VersionRestoredEvent> | ||
*/ | ||
class LegacyRollbackListener implements IEventListener { | ||
public function handle(Event $event): void { | ||
if (!($event instanceof VersionRestoredEvent)) { | ||
return; | ||
} | ||
|
||
$version = $event->getVersion(); | ||
\OC_Hook::emit('\OCP\Versions', 'rollback', [ | ||
'path' => $version->getVersionPath(), | ||
'revision' => $version->getRevisionId(), | ||
'node' => $version->getSourceFile(), | ||
]); | ||
} | ||
} |
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