Skip to content

Commit a8bb48e

Browse files
authored
Merge pull request #6091 from LibreSign/fix/migration-sign-request-status
fix: Update migration to properly set SignRequest status
2 parents 1bd3dc7 + 24542f2 commit a8bb48e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

lib/Migration/Version15000Date20251209000000.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
use Closure;
1212
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\QueryBuilder\IQueryBuilder;
1314
use OCP\DB\Types;
15+
use OCP\IDBConnection;
1416
use OCP\Migration\IOutput;
1517
use OCP\Migration\SimpleMigrationStep;
1618

@@ -19,6 +21,10 @@
1921
* - Adds 'signing_order', 'status', and 'released_at' columns to libresign_sign_request table
2022
*/
2123
class Version15000Date20251209000000 extends SimpleMigrationStep {
24+
public function __construct(
25+
private IDBConnection $db,
26+
) {
27+
}
2228
/**
2329
* @param IOutput $output
2430
* @param Closure(): ISchemaWrapper $schemaClosure
@@ -51,4 +57,37 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
5157

5258
return $schema;
5359
}
60+
61+
/**
62+
* @param IOutput $output
63+
* @param Closure(): ISchemaWrapper $schemaClosure
64+
* @param array $options
65+
*/
66+
#[\Override]
67+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
68+
// Update existing sign_request records with correct status
69+
// Only update records that have status = 0 (default)
70+
// Logic:
71+
// - If signed IS NOT NULL: status = 2 (SIGNED)
72+
// - Else if signed IS NULL AND file.status = 1: status = 1 (ABLE_TO_SIGN)
73+
// - Else: status = 0 (DRAFT) - already set by default
74+
75+
// First: Update status = 2 for signed requests (signed IS NOT NULL AND status = 0)
76+
$qb = $this->db->getQueryBuilder();
77+
$qb->update('libresign_sign_request')
78+
->set('status', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT))
79+
->where($qb->expr()->eq('status', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
80+
->andWhere($qb->expr()->isNotNull('signed'));
81+
$qb->executeStatement();
82+
83+
// Second: Update status = 1 for able_to_sign requests (status = 0 AND signed IS NULL AND file.status = 1)
84+
$qb = $this->db->getQueryBuilder();
85+
$qb->update('libresign_sign_request', 'sr')
86+
->innerJoin('sr', 'libresign_file', 'f', $qb->expr()->eq('sr.file_id', 'f.id'))
87+
->set('sr.status', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))
88+
->where($qb->expr()->eq('sr.status', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
89+
->andWhere($qb->expr()->isNull('sr.signed'))
90+
->andWhere($qb->expr()->eq('f.status', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)));
91+
$qb->executeStatement();
92+
}
5493
}

0 commit comments

Comments
 (0)