Skip to content

Commit 4a86bdd

Browse files
committed
hotfix(build): trim changelog in transport metadata to current release only (#296)
Full changelog.txt (~33 KB, history from 1.0.0-alpha) was bundled into `modx_transport_packages.metadata` via `setPackageAttributes`. On MODX 3.x installs where that column is TEXT (65 535 bytes), serialized attributes (changelog + license + readme + requires) overflowed the column and the package install failed with: SQLSTATE 22001 / 1406 Data too long for column 'metadata' at row 1 Symptom reported by Alexey Naumov on modx.pro for 1.11.0-beta1 (#296). Full history previously fit because the file had been smaller — the 1.11.0 release added a large block. Fix: `readLatestChangelogEntry()` returns only the first `## [version]` block (current release) from Keep a Changelog file. For 1.11.0-beta1 the latest block is ~7.4 KB instead of 33 KB; total metadata is now well under the TEXT limit. The full changelog stays untouched in core/components/minishop3/docs/changelog.txt inside the package — users see complete history in the file, not in the package metadata viewer. Re-tagging the existing v1.11.0-beta1 (same approach as #293).
1 parent a0480e2 commit 4a86bdd

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

_build/build.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ public function process(): modPackageBuilder
109109
$this->builder->putVehicle($vehicle);
110110

111111
$this->builder->setPackageAttributes([
112-
'changelog' => $this->readDocFile('changelog.txt'),
112+
// Only the current release block from changelog goes into transport metadata.
113+
// Full history stays in core/components/minishop3/docs/changelog.txt inside
114+
// the package. Without trimming, serialized metadata exceeds the TEXT column
115+
// limit of modx_transport_packages.metadata on some MODX 3.x installs (#296).
116+
'changelog' => $this->readLatestChangelogEntry('changelog.txt'),
113117
'license' => $this->readDocFile('license.txt'),
114118
'readme' => $this->readDocFile('readme.txt'),
115119
'requires' => [
@@ -578,6 +582,36 @@ private function readDocFile(string $filename): string
578582
return $content;
579583
}
580584

585+
/**
586+
* Return only the latest release block from a Keep a Changelog-formatted file.
587+
*
588+
* "Latest" = the first `## [version]` heading and everything up to the next
589+
* `## [` heading (or end of file). Used to keep transport package metadata
590+
* small enough to fit into `modx_transport_packages.metadata` (TEXT column
591+
* on legacy MODX 3.x installs — see #296).
592+
*
593+
* Falls back to the full file when the format is unrecognised, and to an
594+
* empty string when the file is missing.
595+
*
596+
* @param string $filename
597+
* @return string
598+
*/
599+
private function readLatestChangelogEntry(string $filename): string
600+
{
601+
$full = $this->readDocFile($filename);
602+
if ($full === '') {
603+
return '';
604+
}
605+
606+
// Match the first "## [version]" block, capturing everything up to (but not
607+
// including) the next "## [" heading or end of input.
608+
if (preg_match('/^##\s+\[[^\]]+\][^\n]*\n.*?(?=^##\s+\[|\z)/ms', $full, $matches)) {
609+
return rtrim($matches[0]);
610+
}
611+
612+
return $full;
613+
}
614+
581615
/**
582616
* @param string $filename
583617
* @return string

0 commit comments

Comments
 (0)