Skip to content

Commit 816affa

Browse files
authored
Merge pull request #7784 from LibreSign/fix/user-element-nodeid-not-null
fix: enforce non-null user element node id
2 parents aaa9694 + d63c17d commit 816affa

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Libresign\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\IDBConnection;
15+
use OCP\Migration\IOutput;
16+
use OCP\Migration\SimpleMigrationStep;
17+
18+
class Version18003Date20260616000000 extends SimpleMigrationStep {
19+
public function __construct(
20+
private IDBConnection $connection,
21+
) {
22+
}
23+
24+
/**
25+
* @param IOutput $output
26+
* @param Closure(): ISchemaWrapper $schemaClosure
27+
* @param array $options
28+
*/
29+
#[\Override]
30+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
31+
$qb = $this->connection->getQueryBuilder();
32+
$qb->delete('libresign_user_element')
33+
->where($qb->expr()->isNull('node_id'));
34+
$deleted = $qb->executeStatement();
35+
if ($deleted > 0) {
36+
$output->warning(sprintf(
37+
'Deleted %d row(s) from libresign_user_element with NULL node_id (corrupted rows with no associated file).',
38+
$deleted,
39+
));
40+
}
41+
}
42+
43+
/**
44+
* @param IOutput $output
45+
* @param Closure(): ISchemaWrapper $schemaClosure
46+
* @param array $options
47+
* @return ISchemaWrapper|null
48+
*/
49+
#[\Override]
50+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
51+
/** @var ISchemaWrapper $schema */
52+
$schema = $schemaClosure();
53+
54+
$table = $schema->getTable('libresign_user_element');
55+
$column = $table->getColumn('node_id');
56+
if ($column->getNotnull()) {
57+
return null;
58+
}
59+
60+
$column->setNotnull(true);
61+
return $schema;
62+
}
63+
}

0 commit comments

Comments
 (0)