|
10 | 10 |
|
11 | 11 | use Closure; |
12 | 12 | use OCP\DB\ISchemaWrapper; |
| 13 | +use OCP\DB\QueryBuilder\IQueryBuilder; |
13 | 14 | use OCP\DB\Types; |
| 15 | +use OCP\IDBConnection; |
14 | 16 | use OCP\Migration\IOutput; |
15 | 17 | use OCP\Migration\SimpleMigrationStep; |
16 | 18 |
|
|
19 | 21 | * - Adds 'signing_order', 'status', and 'released_at' columns to libresign_sign_request table |
20 | 22 | */ |
21 | 23 | class Version15000Date20251209000000 extends SimpleMigrationStep { |
| 24 | + public function __construct( |
| 25 | + private IDBConnection $db, |
| 26 | + ) { |
| 27 | + } |
22 | 28 | /** |
23 | 29 | * @param IOutput $output |
24 | 30 | * @param Closure(): ISchemaWrapper $schemaClosure |
@@ -51,4 +57,37 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt |
51 | 57 |
|
52 | 58 | return $schema; |
53 | 59 | } |
| 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 | + } |
54 | 93 | } |
0 commit comments