Skip to content

Commit

Permalink
feat: migrate owncloud guests-users to nextcloud guests
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jan 30, 2025
1 parent aa641e5 commit 21a5446
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Guests users can only access files shared to them and cannot create any files ou
<dependencies>
<nextcloud min-version="30" max-version="31" />
</dependencies>
<repair-steps>
<pre-migration>
<step>OCA\Guests\Migration\OwncloudGuestsMigration</step>
</pre-migration>
</repair-steps>
<commands>
<command>OCA\Guests\Command\ListCommand</command>
<command>OCA\Guests\Command\AddCommand</command>
Expand Down
78 changes: 78 additions & 0 deletions lib/Migration/OwncloudGuestsMigration.php
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

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

UndefinedClass

lib/Migration/OwncloudGuestsMigration.php:44:8: UndefinedClass: Class, interface or enum named Doctrine\DBAL\Schema\Schema does not exist (see https://psalm.dev/019)
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() {

}
}

0 comments on commit 21a5446

Please sign in to comment.