Skip to content

Commit 97579c5

Browse files
committed
Fixed #4265
1 parent ac251dd commit 97579c5

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Craft Commerce
22

3+
## Unreleased
4+
5+
- Fixed a bug where PDF Link Duration didn't save. ([#4265](https://github.com/craftcms/commerce/issues/4265))
6+
37
## 4.11.0 - 2026-03-11
48

59
- Craft Commerce now requires Craft CMS 4.17.9 or later.

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static function editions(): array
212212
/**
213213
* @inheritDoc
214214
*/
215-
public string $schemaVersion = '4.9.0.1';
215+
public string $schemaVersion = '4.11.0.2';
216216

217217
/**
218218
* @inheritdoc

src/controllers/PdfsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function actionSave(): ?Response
111111
$pdf->enabled = $this->request->getBodyParam('enabled');
112112
$pdf->isDefault = $this->request->getBodyParam('isDefault');
113113
$pdf->language = $this->request->getBodyParam('language');
114+
$pdf->linkExpiry = (int)$this->request->getBodyParam('linkExpiry');
114115

115116
// Save it
116117
if ($pdfsService->savePdf($pdf)) {

src/migrations/Install.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public function createTables(): void
227227
'isDefault' => $this->boolean()->notNull()->defaultValue(false),
228228
'sortOrder' => $this->integer(),
229229
'language' => $this->string(),
230+
'linkExpiry' => $this->integer()->notNull()->defaultValue(86400),
230231
'dateCreated' => $this->dateTime()->notNull(),
231232
'dateUpdated' => $this->dateTime()->notNull(),
232233
'uid' => $this->uid(),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace craft\commerce\migrations;
4+
5+
use craft\commerce\db\Table;
6+
use craft\db\Migration;
7+
8+
/**
9+
* m260327_000000_ensure_link_expiry_on_pdfs migration.
10+
*/
11+
class m260327_000000_ensure_link_expiry_on_pdfs extends Migration
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public function safeUp(): bool
17+
{
18+
if (!$this->db->columnExists(Table::PDFS, 'linkExpiry')) {
19+
$this->addColumn(Table::PDFS, 'linkExpiry', $this->integer()->notNull()->defaultValue(86400)->after('language'));
20+
}
21+
22+
return true;
23+
}
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function safeDown(): bool
29+
{
30+
echo "m260327_000000_ensure_link_expiry_on_pdfs cannot be reverted.\n";
31+
return false;
32+
}
33+
}

src/services/Pdfs.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public function handleChangedPdf(ConfigEvent $event): void
335335
$pdfRecord->sortOrder = $data['sortOrder'];
336336
$pdfRecord->isDefault = $data['isDefault'];
337337
$pdfRecord->language = $data['language'] ?? PdfRecord::LOCALE_ORDER_LANGUAGE;
338+
$pdfRecord->linkExpiry = $data['linkExpiry'] ?? 86400;
338339

339340
$pdfRecord->uid = $pdfUid;
340341

@@ -641,7 +642,7 @@ private function _getPdfRecord(string $uid): PdfRecord
641642
*/
642643
private function _createPdfsQuery(): Query
643644
{
644-
return (new Query())
645+
$query = (new Query())
645646
->select([
646647
'description',
647648
'enabled',
@@ -658,5 +659,12 @@ private function _createPdfsQuery(): Query
658659
->orderBy('name')
659660
->from([Table::PDFS])
660661
->orderBy(['sortOrder' => SORT_ASC]);
662+
663+
// TODO: remove after next breakpoint
664+
if (Craft::$app->getDb()->columnExists(Table::PDFS, 'linkExpiry')) {
665+
$query->addSelect('linkExpiry');
666+
}
667+
668+
return $query;
661669
}
662670
}

0 commit comments

Comments
 (0)