Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/Migration/Version15000Date20251209000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

Expand All @@ -19,6 +21,10 @@
* - Adds 'signing_order', 'status', and 'released_at' columns to libresign_sign_request table
*/
class Version15000Date20251209000000 extends SimpleMigrationStep {
public function __construct(
private IDBConnection $db,
) {
}
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
Expand Down Expand Up @@ -51,4 +57,37 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
#[\Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
// Update existing sign_request records with correct status
// Only update records that have status = 0 (default)
// Logic:
// - If signed IS NOT NULL: status = 2 (SIGNED)
// - Else if signed IS NULL AND file.status = 1: status = 1 (ABLE_TO_SIGN)
// - Else: status = 0 (DRAFT) - already set by default

// First: Update status = 2 for signed requests (signed IS NOT NULL AND status = 0)
$qb = $this->db->getQueryBuilder();
$qb->update('libresign_sign_request')
->set('status', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT))
->where($qb->expr()->eq('status', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->isNotNull('signed'));
$qb->executeStatement();

// Second: Update status = 1 for able_to_sign requests (status = 0 AND signed IS NULL AND file.status = 1)
$qb = $this->db->getQueryBuilder();
$qb->update('libresign_sign_request', 'sr')
->innerJoin('sr', 'libresign_file', 'f', $qb->expr()->eq('sr.file_id', 'f.id'))
->set('sr.status', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))
->where($qb->expr()->eq('sr.status', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->isNull('sr.signed'))
->andWhere($qb->expr()->eq('f.status', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)));
$qb->executeStatement();
}
}
Loading