fix(add-page-by-form): patch Grav-2.0 edit-mode header fatal + deploy wiring
Adding a new photo while editing an entry 500s: add-page-by-form's edit branch
reads existing frontmatter via `(array)$page->header()`, but Grav 2.0's
Grav\Common\Page\Header keeps data in a protected `items`, so the cast mangles
keys and `$original_frontmatter['photos']` is never set → array_merge(null,…)
TypeError. Fix: use Header::toArray() (clean keys, stdClass fallback) + guard the
per-field merge. Grav 2.0.7 does not change this — only the plugin fix does.
add-page-by-form is abandoned upstream (last release 2023-09) and its dir is
git-ignored/GPM-managed, so the fix is tracked as deploy/patches/*.patch and
re-applied after any GPM install/update:
- make apply-plugin-patches (local) — chained into install-plugins
- make remote-apply-plugin-patches-{test,prod} — piped over SSH into
`patch -p1 --forward`; chained into remote-install-plugins / remote-update-plugins
Content syncs don't touch user/plugins/, so the patch survives them; only a GPM
op wipes it (now auto-restored). Runbook + README document the step and a
verify check. Remove once the plugin is forked.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Local plugin patches
|
||||
|
||||
Patches for **third-party, GPM-managed plugins** that live under
|
||||
`user/plugins/` — which is **git-ignored** (see `user/.gitignore`), so these
|
||||
edits do **not** travel with the content repo and are **overwritten by
|
||||
`make install-plugins`** / a fresh image build. Keep the fix here (tracked) and
|
||||
re-apply it after any plugin (re)install, until the plugin is forked upstream.
|
||||
|
||||
### Local (dev)
|
||||
|
||||
```sh
|
||||
make apply-plugin-patches # git apply, idempotent (skips if applied)
|
||||
```
|
||||
|
||||
`make install-plugins` runs this automatically as its last step.
|
||||
|
||||
### Remote (test / prod)
|
||||
|
||||
```sh
|
||||
make remote-apply-plugin-patches-test
|
||||
make remote-apply-plugin-patches-prod
|
||||
```
|
||||
|
||||
Each patch is piped over SSH into `patch -p1 --forward` at the webroot (no scp),
|
||||
so it is a no-op when already applied. **Runs automatically** as the last step of
|
||||
`remote-install-plugins-*` and `remote-update-plugins-*` — GPM lays down pristine
|
||||
plugins, so the patch must follow every GPM install/update. Content pulls
|
||||
(git-sync / `remote-fetch-content`) do **not** touch `user/plugins/`, so the patch
|
||||
survives ordinary content syncs. Requires the `patch` tool on the server.
|
||||
|
||||
Verify a patch is live on a server:
|
||||
`grep -c toArray user/plugins/add-page-by-form/add-page-by-form.php` (≥1 = applied).
|
||||
|
||||
## add-page-by-form-grav2-header.patch
|
||||
|
||||
Fixes a fatal when **adding a new photo while editing an entry** (front-end
|
||||
journal edit, milestone M2 / R9).
|
||||
|
||||
- **Plugin:** `add-page-by-form` 3.3.0 (abandoned upstream — last release Sept 2023).
|
||||
- **Bug:** the edit-mode branch reads existing frontmatter with
|
||||
`(array)$pages->get($folder)->header()`. On Grav 2.0 `header()` returns a
|
||||
`Grav\Common\Page\Header` object whose data sits in a **protected** `items`
|
||||
property, so the `(array)` cast produces mangled keys (`\0*\0items`) and
|
||||
`$original_frontmatter['photos']` is never set → `array_merge(null, …)`
|
||||
throws a `TypeError` (PHP 8) on any edit that uploads a new file.
|
||||
- **Fix:** use `Header::toArray()` (clean keys) with a fallback to the cast for
|
||||
classic stdClass headers, and guard the per-field merge against a
|
||||
missing/non-array original.
|
||||
|
||||
Remove this patch once `add-page-by-form` is forked and the fix lands in the
|
||||
fork (then pin the fork instead of the GPM package).
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/b/user/plugins/add-page-by-form/add-page-by-form.php 2026-07-05 12:03:55.849015242 +0200
|
||||
+++ b/user/plugins/add-page-by-form/add-page-by-form.php 2026-07-05 11:55:06.175609339 +0200
|
||||
@@ -619,7 +619,19 @@
|
||||
if ($overwrite_mode !== 'false') {
|
||||
if (file_exists($new_page_folder)) {
|
||||
if ($overwrite_mode === 'edit') {
|
||||
- $original_frontmatter = (array)$pages->get($new_page_folder)->header();
|
||||
+ // intotheeast patch (temporary, pending upstream fork):
|
||||
+ // On Grav 2.0 header() returns a Grav\Common\Page\Header
|
||||
+ // object whose data sits in a PROTECTED `items` property,
|
||||
+ // so the original `(array)$header` yields mangled keys
|
||||
+ // (\0*\0items) and every frontmatter lookup below misses —
|
||||
+ // `array_merge($original_frontmatter['photos'], …)` then
|
||||
+ // fatals under PHP 8. Use toArray() (clean keys) when the
|
||||
+ // Header exposes it; fall back to the cast for a plain
|
||||
+ // stdClass (classic pages).
|
||||
+ $__header = $pages->get($new_page_folder)->header();
|
||||
+ $original_frontmatter = (is_object($__header) && method_exists($__header, 'toArray'))
|
||||
+ ? $__header->toArray()
|
||||
+ : (array)$__header;
|
||||
} else {
|
||||
Folder::delete($new_page_folder);
|
||||
}
|
||||
@@ -708,7 +720,13 @@
|
||||
|
||||
$file_fields_updated = array();
|
||||
foreach ($file_fields as $file_field => $uploads) {
|
||||
- $file_fields_updated[$file_field] = array_merge($original_frontmatter[$file_field], $uploads);
|
||||
+ // intotheeast patch: entries that render from folder-scanned
|
||||
+ // media carry no matching frontmatter key, so fall back to []
|
||||
+ // rather than fatal array_merge() on a missing/null original.
|
||||
+ $existing = (isset($original_frontmatter[$file_field]) && is_array($original_frontmatter[$file_field]))
|
||||
+ ? $original_frontmatter[$file_field]
|
||||
+ : array();
|
||||
+ $file_fields_updated[$file_field] = array_merge($existing, $uploads);
|
||||
|
||||
// Get any (uploaded and then) deleted files
|
||||
foreach ($copy_files['deleted'] as $file_to_delete) {
|
||||
Reference in New Issue
Block a user