-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate owncloud guests-users to nextcloud guests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
namespace OCA\Guests\Migration; | ||
|
||
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\IRepairStep; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class OwncloudGuestsMigration implements IRepairStep { | ||
|
||
protected $cachedUserIDs = []; | ||
|
||
public function __construct( | ||
protected LoggerInterface $logger, | ||
protected IDBConnection $db, | ||
protected IConfig $config, | ||
) {} | ||
|
||
public function getName(): string { | ||
return 'Converts owncloud guests to nextcloud guests'; | ||
} | ||
|
||
public function run(IOutput $output): void { | ||
if (!$this->shouldRun()) { | ||
$this->logger->info('Skipping owncloud guests migration, no owncloud guests found'); | ||
return; | ||
} | ||
} | ||
|
||
protected function shouldRun(): bool{ | ||
$schema = $this->db->createSchema(); | ||
$prefix = $this->config->getSystemValueString('dbtableprefix', 'oc_'); | ||
|
||
$tableName = $prefix . 'preferences'; | ||
if (!$schema->hasTable($tableName)) { | ||
Check failure on line 44 in lib/Migration/OwncloudGuestsMigration.php GitHub Actions / static-psalm-analysis dev-stable30UndefinedClass
|
||
return false; | ||
} | ||
|
||
// Get all rows where configkey `isGuest` is set to 1 | ||
$query = $this->db->getQueryBuilder(); | ||
$query->select('userid') | ||
->from($tableName) | ||
->where($query->expr()->eq('appid', $query->createNamedParameter('owncloud'))) | ||
->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('isGuest'))) | ||
->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('1'))); | ||
|
||
$result = $query->executeQuery(); | ||
$count = $result->rowCount(); | ||
if ($count === 0) { | ||
return false; | ||
} | ||
|
||
$this->logger->info("Found $count owncloud guests to migrate"); | ||
$this->cachedUserIDs = $result->fetchAll(); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* For each old guest user, we do the following: | ||
* 1. Create a new guest with the same username and password | ||
* 2. register a new transfer | ||
* 3. Delete the old user | ||
* 4. Delete the old preferences row | ||
*/ | ||
protected function runStep() { | ||
|
||
} | ||
} |