Skip to content

Commit b5f4764

Browse files
authored
Merge pull request #4823 from LibreSign/backport/4718/stable31
[stable31] fix: time stamp when then document signed
2 parents 2450113 + 97b7c47 commit b5f4764

23 files changed

+345
-88
lines changed

lib/Db/AccountFileMapper.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Libresign\Db;
1010

11+
use DateTimeInterface;
1112
use OCA\Libresign\Helper\Pagination;
1213
use OCP\AppFramework\Db\Entity;
1314
use OCP\AppFramework\Db\QBMapper;
@@ -184,9 +185,7 @@ private function formatListRow(array $row, string $url): array {
184185
'name' => $this->fileTypeMapper->getNameOfType($row['file_type']),
185186
'description' => $this->fileTypeMapper->getDescriptionOfType($row['file_type']),
186187
];
187-
$row['created_at'] = (new \DateTime())
188-
->setTimestamp((int)$row['created_at'])
189-
->format('Y-m-d H:i:s');
188+
$row['created_at'] = $row['created_at']->format(DateTimeInterface::ATOM);
190189
$row['file'] = [
191190
'name' => $row['name'],
192191
'status' => $row['status'],
@@ -227,16 +226,12 @@ private function assocFileToSignRequestAndFormat(array $files, array $signers):
227226
$data = [
228227
'description' => $signer->getDescription(),
229228
'displayName' => $signer->getDisplayName(),
230-
'request_sign_date' => (new \DateTime())
231-
->setTimestamp($signer->getCreatedAt())
232-
->format('Y-m-d H:i:s'),
233-
'sign_date' => null,
229+
'request_sign_date' => $signer->getCreatedAt()->format(DateTimeInterface::ATOM),
230+
'sign_date' => $signer->getSigned(),
234231
'signRequestId' => $signer->getId(),
235232
];
236-
if ($signer->getSigned()) {
237-
$data['sign_date'] = (new \DateTime())
238-
->setTimestamp($signer->getSigned())
239-
->format('Y-m-d H:i:s');
233+
if ($data['sign_date']) {
234+
$data['sign_date'] = $data['sign_date']->format(DateTimeInterface::ATOM);
240235
$totalSigned++;
241236
}
242237
$files[$key]['file']['signers'][] = $data;

lib/Db/File.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* @method ?string getUserId()
2525
* @method void setUuid(string $uuid)
2626
* @method string getUuid()
27-
* @method void setCreatedAt(int $createdAt)
28-
* @method int getCreatedAt()
27+
* @method void setCreatedAt(\DateTime $createdAt)
28+
* @method \DateTime getCreatedAt()
2929
* @method void setName(string $name)
3030
* @method string getName()
3131
* @method void setCallback(string $callback)
@@ -38,7 +38,7 @@
3838
class File extends Entity {
3939
protected int $nodeId = 0;
4040
protected string $uuid = '';
41-
protected int $createdAt = 0;
41+
protected ?\DateTime $createdAt = null;
4242
protected string $name = '';
4343
protected ?int $status = null;
4444
protected ?string $userId = null;
@@ -60,7 +60,7 @@ public function __construct() {
6060
$this->addType('signedHash', Types::STRING);
6161
$this->addType('userId', Types::STRING);
6262
$this->addType('uuid', Types::STRING);
63-
$this->addType('createdAt', Types::INTEGER);
63+
$this->addType('createdAt', Types::DATETIME);
6464
$this->addType('name', Types::STRING);
6565
$this->addType('callback', Types::STRING);
6666
$this->addType('status', Types::INTEGER);

lib/Db/SignRequest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
* @method string getUuid()
2121
* @method void setDescription(string $description)
2222
* @method ?string getDescription()
23-
* @method void setCreatedAt(int $createdAt)
24-
* @method int getCreatedAt()
25-
* @method void setSigned(int $signed)
26-
* @method ?int getSigned()
23+
* @method void setCreatedAt(\DateTime $createdAt)
24+
* @method \DateTime getCreatedAt()
25+
* @method void setSigned(\DateTime $signed)
26+
* @method ?\DateTime getSigned()
2727
* @method void setSignedHash(string $hash)
2828
* @method ?string getSignedHash()
2929
* @method void setDisplayName(string $displayName)
@@ -36,8 +36,8 @@ class SignRequest extends Entity {
3636
protected string $uuid = '';
3737
protected string $displayName = '';
3838
protected ?string $description = null;
39-
protected int $createdAt = 0;
40-
protected ?int $signed = null;
39+
protected ?\DateTime $createdAt = null;
40+
protected ?\DateTime $signed = null;
4141
protected ?string $signedHash = null;
4242
protected ?array $metadata = null;
4343
public function __construct() {
@@ -46,8 +46,8 @@ public function __construct() {
4646
$this->addType('uuid', Types::STRING);
4747
$this->addType('displayName', Types::STRING);
4848
$this->addType('description', Types::STRING);
49-
$this->addType('createdAt', Types::INTEGER);
50-
$this->addType('signed', Types::INTEGER);
49+
$this->addType('createdAt', Types::DATETIME);
50+
$this->addType('signed', Types::DATETIME);
5151
$this->addType('signedHash', Types::STRING);
5252
$this->addType('metadata', Types::JSON);
5353
}

lib/Db/SignRequestMapper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Libresign\Db;
1010

11+
use DateTimeInterface;
1112
use OCA\Libresign\Helper\Pagination;
1213
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
1314
use OCA\Libresign\Service\IdentifyMethodService;
@@ -550,9 +551,7 @@ private function formatListRow(array $row): array {
550551
'userId' => $row['user_id'],
551552
'displayName' => $this->userManager->get($row['user_id'])?->getDisplayName(),
552553
];
553-
$row['created_at'] = (new \DateTime())
554-
->setTimestamp((int)$row['created_at'])
555-
->format('Y-m-d H:i:s');
554+
$row['created_at'] = (new \DateTime($row['created_at']))->format(DateTimeInterface::ATOM);
556555
$row['file'] = $this->urlGenerator->linkToRoute('libresign.page.getPdf', ['uuid' => $row['uuid']]);
557556
$row['nodeId'] = (int)$row['node_id'];
558557
unset(
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 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\DB\QueryBuilder\IQueryBuilder;
15+
use OCP\Files\AppData\IAppDataFactory;
16+
use OCP\Files\IAppData;
17+
use OCP\IDBConnection;
18+
use OCP\Migration\IOutput;
19+
use OCP\Migration\SimpleMigrationStep;
20+
21+
class Version12000Date20250325143340 extends SimpleMigrationStep {
22+
protected IAppData $appData;
23+
public function __construct(
24+
protected IDBConnection $connection,
25+
private IAppDataFactory $appDataFactory,
26+
) {
27+
$this->appData = $appDataFactory->get('libresign');
28+
}
29+
30+
/**
31+
* @param IOutput $output
32+
* @param Closure(): ISchemaWrapper $schemaClosure
33+
* @param array $options
34+
*/
35+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
36+
$query = $this->connection->getQueryBuilder();
37+
$query->select('id')
38+
->addSelect('created_at')
39+
->from('libresign_file');
40+
$this->persitsData($query, 'backup-table-libresign_file_Version12000Date20250325143340.csv');
41+
42+
$query = $this->connection->getQueryBuilder();
43+
$query->select('id')
44+
->addSelect('created_at')
45+
->addSelect('signed')
46+
->from('libresign_sign_request');
47+
$this->persitsData($query, 'backup-table-libresign_sign_request_Version12000Date20250325143340.csv');
48+
}
49+
50+
private function persitsData(IQueryBuilder $query, string $filename): void {
51+
$cursor = $query->executeQuery();
52+
$row = $cursor->fetch();
53+
if ($row) {
54+
$folder = $this->appData->getFolder('/');
55+
$file = $folder->newFile($filename);
56+
$file->putContent('');
57+
$handle = $file->write();
58+
59+
fputcsv($handle, array_keys($row));
60+
fputcsv($handle, $row);
61+
while ($row = $cursor->fetch()) {
62+
fputcsv($handle, $row);
63+
}
64+
}
65+
$cursor->closeCursor();
66+
}
67+
68+
/**
69+
* @param IOutput $output
70+
* @param Closure(): ISchemaWrapper $schemaClosure
71+
* @param array $options
72+
* @return null|ISchemaWrapper
73+
*/
74+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
75+
/** @var ISchemaWrapper $schema */
76+
$schema = $schemaClosure();
77+
$tableFile = $schema->getTable('libresign_file');
78+
if ($tableFile->hasColumn('created_at')) {
79+
$tableFile->dropColumn('created_at');
80+
}
81+
82+
$tableSignRequest = $schema->getTable('libresign_sign_request');
83+
if ($tableSignRequest->hasColumn('created_at')) {
84+
$tableSignRequest->dropColumn('created_at');
85+
}
86+
if ($tableSignRequest->hasColumn('signed')) {
87+
$tableSignRequest->dropColumn('signed');
88+
}
89+
return $schema;
90+
}
91+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 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\DB\QueryBuilder\IQueryBuilder;
15+
use OCP\DB\Types;
16+
use OCP\Files\AppData\IAppDataFactory;
17+
use OCP\Files\IAppData;
18+
use OCP\IDBConnection;
19+
use OCP\Migration\IOutput;
20+
use OCP\Migration\SimpleMigrationStep;
21+
22+
/**
23+
* FIXME Auto-generated migration step: Please modify to your needs!
24+
*/
25+
class Version12000Date20250325155910 extends SimpleMigrationStep {
26+
protected IAppData $appData;
27+
public function __construct(
28+
protected IDBConnection $connection,
29+
private IAppDataFactory $appDataFactory,
30+
) {
31+
$this->appData = $appDataFactory->get('libresign');
32+
}
33+
34+
/**
35+
* @param IOutput $output
36+
* @param Closure(): ISchemaWrapper $schemaClosure
37+
* @param array $options
38+
* @return null|ISchemaWrapper
39+
*/
40+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
41+
/** @var ISchemaWrapper $schema */
42+
$schema = $schemaClosure();
43+
$tableFile = $schema->getTable('libresign_file');
44+
if (!$tableFile->hasColumn('created_at')) {
45+
$tableFile->addColumn('created_at', Types::DATETIME, [
46+
'notnull' => false,
47+
]);
48+
}
49+
50+
$tableSignRequest = $schema->getTable('libresign_sign_request');
51+
if (!$tableSignRequest->hasColumn('created_at')) {
52+
$tableSignRequest->addColumn('created_at', Types::DATETIME, [
53+
'notnull' => false,
54+
]);
55+
}
56+
if (!$tableSignRequest->hasColumn('signed')) {
57+
$tableSignRequest->addColumn('signed', Types::DATETIME, [
58+
'notnull' => false,
59+
]);
60+
}
61+
return $schema;
62+
}
63+
64+
/**
65+
* @param IOutput $output
66+
* @param Closure(): ISchemaWrapper $schemaClosure
67+
* @param array $options
68+
*/
69+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
70+
$this->updateFile();
71+
$this->updateSignRequest();
72+
}
73+
74+
private function updateFile(): void {
75+
$update = $this->connection->getQueryBuilder();
76+
$update->update('libresign_file')
77+
->set('created_at', $update->createParameter('created_at'))
78+
->where($update->expr()->eq('id', $update->createParameter('id')));
79+
80+
$folder = $this->appData->getFolder('/');
81+
$file = $folder->getFile('backup-table-libresign_file_Version12000Date20250325143340.csv');
82+
$handle = $file->read();
83+
fgetcsv($handle); // header
84+
while (($row = fgetcsv($handle)) !== false) {
85+
$update->setParameter('created_at', new \DateTime('@' . $row[1]), IQueryBuilder::PARAM_DATETIME_MUTABLE)
86+
->setParameter('id', $row[0]);
87+
$update->executeStatement();
88+
}
89+
}
90+
91+
private function updateSignRequest(): void {
92+
$update = $this->connection->getQueryBuilder();
93+
$update->update('libresign_sign_request')
94+
->set('created_at', $update->createParameter('created_at'))
95+
->set('signed', $update->createParameter('signed'))
96+
->where($update->expr()->eq('id', $update->createParameter('id')));
97+
98+
$folder = $this->appData->getFolder('/');
99+
$file = $folder->getFile('backup-table-libresign_sign_request_Version12000Date20250325143340.csv');
100+
$handle = $file->read();
101+
fgetcsv($handle); // header
102+
while (($row = fgetcsv($handle)) !== false) {
103+
$update->setParameter('created_at', new \DateTime('@' . $row[1]), IQueryBuilder::PARAM_DATETIME_MUTABLE)
104+
->setParameter('id', $row[0]);
105+
106+
if ($row[2]) {
107+
$update->setParameter('signed', new \DateTime('@' . $row[2]), IQueryBuilder::PARAM_DATETIME_MUTABLE);
108+
} else {
109+
$update->setParameter('signed', null, IQueryBuilder::PARAM_NULL);
110+
}
111+
$update->executeStatement();
112+
}
113+
}
114+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 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\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
class Version12000Date20250325174734 extends SimpleMigrationStep {
18+
/**
19+
* @param IOutput $output
20+
* @param Closure(): ISchemaWrapper $schemaClosure
21+
* @param array $options
22+
* @return null|ISchemaWrapper
23+
*/
24+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
25+
/** @var ISchemaWrapper $schema */
26+
$schema = $schemaClosure();
27+
$tableFile = $schema->getTable('libresign_file');
28+
if ($tableFile->hasColumn('created_at')) {
29+
$tableFile->modifyColumn('created_at', [
30+
'notnull' => true,
31+
]);
32+
}
33+
34+
$tableSignRequest = $schema->getTable('libresign_sign_request');
35+
if ($tableSignRequest->hasColumn('created_at')) {
36+
$tableSignRequest->modifyColumn('created_at', [
37+
'notnull' => true,
38+
]);
39+
}
40+
return $schema;
41+
}
42+
}

lib/ResponseDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
* password?: LibresignSignatureMethodPassword,
145145
* }
146146
* @psalm-type LibresignNotify = array{
147-
* date: int,
147+
* date: string,
148148
* method: "activity"|"notify"|"mail",
149149
* }
150150
* @psalm-type LibresignSigner = array{

0 commit comments

Comments
 (0)