-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(files_versions): Add listener and interfaces to allow versions m…
…igration across storages Signed-off-by: Louis Chemineau <louis@chmn.me>
- Loading branch information
Showing
14 changed files
with
350 additions
and
20 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
65 changes: 65 additions & 0 deletions
65
apps/files_versions/lib/Listener/VersionStorageMoveListener.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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2024 Louis Chmn <louis@chmn.me> | ||
* | ||
* @author Louis Chmn <louis@chmn.me> | ||
* | ||
* @license GNU AGPL-3.0-or-later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
namespace OCA\Files_Versions\Listener; | ||
|
||
use Exception; | ||
use OCA\Files_Versions\Versions\IVersionManager; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Events\Node\BeforeNodeRenamedEvent; | ||
use OCP\Files\File; | ||
use OCP\IUserSession; | ||
|
||
/** @template-implements IEventListener<BeforeNodeRenamedEvent> */ | ||
class VersionStorageMoveListener implements IEventListener { | ||
public function __construct( | ||
private IVersionManager $versionManager, | ||
private IUserSession $userSession, | ||
) { | ||
} | ||
|
||
/** | ||
* @abstract Moves version across storages if necessary. | ||
* @param Event $event | ||
*/ | ||
public function handle(Event $event): void { | ||
/** @var BeforeNodeRenamedEvent $event **/ | ||
|
||
$source = $event->getSource(); | ||
$target = $event->getTarget(); | ||
|
||
if (!($target instanceof File)) { | ||
return; | ||
} | ||
|
||
$user = $this->userSession->getUser() ?? $source->getOwner(); | ||
|
||
if ($user === null) { | ||
throw new Exception("Cannot move versions across storages without a user."); | ||
} | ||
|
||
$this->versionManager->moveVersionsAcrossBackends($user, $source, $target); | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
apps/files_versions/lib/Versions/IVersionsImporterBackend.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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2024 Louis Chmn <louis@chmn.me> | ||
* | ||
* @author Louis Chmn <louis@chmn.me> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
namespace OCA\Files_Versions\Versions; | ||
|
||
use OCP\Files\Node; | ||
use OCP\IUser; | ||
|
||
/** | ||
* @since 29.0.0 | ||
*/ | ||
interface IVersionsImporterBackend { | ||
/** | ||
* Import the given versions for the target file. | ||
* | ||
* @param Node $target - The target is not yet created. | ||
* @param IVersion[] $versions | ||
* @since 29.0.0 | ||
*/ | ||
public function importVersionsForFile(IUser $user, Node $source, Node $target, array $versions): void; | ||
|
||
/** | ||
* Clear all versions for a file | ||
* | ||
* @since 29.0.0 | ||
*/ | ||
public function clearVersionsForFile(IUser $user, Node $node): void; | ||
} |
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
Oops, something went wrong.