Skip to content

Commit ded9475

Browse files
committed
Use repair step instead of migration to conditionally drop table.
Signed-off-by: Antoon P. <antoon.prins@surf.nl>
1 parent 592b99b commit ded9475

5 files changed

Lines changed: 69 additions & 60 deletions

File tree

apps/cloud_federation_api/appinfo/info.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
<dependencies>
2222
<nextcloud min-version="34" max-version="34"/>
2323
</dependencies>
24+
<repair-steps>
25+
<post-migration>
26+
<step>OCA\CloudFederationAPI\Migration\DropFederatedInvitesTable</step>
27+
</post-migration>
28+
</repair-steps>
2429
</info>

apps/cloud_federation_api/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
'OCA\\CloudFederationAPI\\Controller\\OCMRequestController' => $baseDir . '/../lib/Controller/OCMRequestController.php',
1313
'OCA\\CloudFederationAPI\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php',
1414
'OCA\\CloudFederationAPI\\Migration\\Version1016Date202502262004' => $baseDir . '/../lib/Migration/Version1016Date202502262004.php',
15-
'OCA\\CloudFederationAPI\\Migration\\Version1018Date20260202110547' => $baseDir . '/../lib/Migration/Version1018Date20260202110547.php',
15+
'OCA\\CloudFederationAPI\\Migration\\DropFederatedInvitesTable' => $baseDir . '/../lib/Migration/DropFederatedInvitesTable.php',
1616
'OCA\\CloudFederationAPI\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
1717
);

apps/cloud_federation_api/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ComposerStaticInitCloudFederationAPI
2727
'OCA\\CloudFederationAPI\\Controller\\OCMRequestController' => __DIR__ . '/..' . '/../lib/Controller/OCMRequestController.php',
2828
'OCA\\CloudFederationAPI\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php',
2929
'OCA\\CloudFederationAPI\\Migration\\Version1016Date202502262004' => __DIR__ . '/..' . '/../lib/Migration/Version1016Date202502262004.php',
30-
'OCA\\CloudFederationAPI\\Migration\\Version1018Date20260202110547' => __DIR__ . '/..' . '/../lib/Migration/Version1018Date20260202110547.php',
30+
'OCA\\CloudFederationAPI\\Migration\\DropFederatedInvitesTable' => __DIR__ . '/..' . '/../lib/Migration/DropFederatedInvitesTable.php',
3131
'OCA\\CloudFederationAPI\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
3232
);
3333

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\CloudFederationAPI\Migration;
11+
12+
use Closure;
13+
use OC\DB\Connection;
14+
use OC\DB\SchemaWrapper;
15+
use OCP\AppFramework\Services\IAppConfig;
16+
use OCP\DB\ISchemaWrapper;
17+
use OCP\IDBConnection;
18+
use OCP\Migration\Attributes\DropTable;
19+
use OCP\Migration\IOutput;
20+
use OCP\Migration\IRepairStep;
21+
use OCP\Migration\SimpleMigrationStep;
22+
use Override;
23+
24+
class DropFederatedInvitesTable implements IRepairStep {
25+
26+
public function __construct(
27+
protected Connection $db,
28+
) {
29+
}
30+
31+
public function getName(): string {
32+
return 'Conditionally drop the federated_invites table';
33+
}
34+
35+
/**
36+
* Drops the federated_invites table unless it contains data.
37+
*
38+
* @param IOutput $output
39+
* @return void
40+
*/
41+
public function run(IOutput $output): void {
42+
$table_name = 'federated_invites';
43+
$schema = new SchemaWrapper($this->db);
44+
if (!$schema->hasTable($table_name)) {
45+
echo("$table_name does not exist");
46+
return;
47+
}
48+
$qb = $this->db->getQueryBuilder();
49+
$qb->select('*')
50+
->from($table_name)
51+
->setMaxResults(1);
52+
$result = $qb->executeQuery();
53+
$hasRows = $result->fetchOne();
54+
if(!$hasRows) {
55+
$schema->dropTable($table_name);
56+
$schema->performDropTableCalls();
57+
$output->info('Table federated_invites dropped');
58+
} else {
59+
$output->info('Table federated_invites contains data. Table will be kept.');
60+
}
61+
}
62+
}

apps/cloud_federation_api/lib/Migration/Version1018Date20260202110547.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)