Skip to content

fix: save snippets to a table that missed the 4.0.0 upgrade - #619

Closed
TallblokeUK wants to merge 2 commits into
corefrom
hotfix/table-upgrade/core
Closed

TallblokeUK wants to merge 2 commits into
corefrom
hotfix/table-upgrade/core

Conversation

@TallblokeUK

Copy link
Copy Markdown
Contributor

A snippets table that misses the 4.0.0 upgrade lacks the created_by and updated_by columns. Every write then fails: creating a snippet returns rest_cannot_create ("The snippet could not be created."), and editing one reports success while the change is not saved. Each site's version is recorded before its table is upgraded, so a failed upgrade is not retried.

Changes

  • save_snippet(): when an insert or update fails with an unknown-column error, the table is upgraded with DB::create_table() and the write is retried once. Any site's table, or the network table, is repaired by the first save made to it.
  • save_snippet(): a failed update now returns null, so the REST route responds with rest_cannot_update instead of returning the unchanged snippet as if it had been saved. The snippet's lock state is set only once the row is written.
  • New DB::upgrade_after_unknown_column(); DB::create_or_upgrade_tables() now returns whether every table was upgraded.
  • Settings → Advanced → Upgrade Database Table reports the database error when the upgrade fails, instead of always reporting success.

Verification

  • New DB_Test: a save to a table without the authorship columns upgrades it and succeeds, and a later edit is saved; a failed update returns null and leaves the stored code unchanged; create_or_upgrade_tables() reports success.
  • Full PHPUnit suite and PHPCS pass locally.
  • On a local site with updated_by dropped from the snippets table, 4.0.0 reproduces both symptoms (create returns 500, edit returns 200 without saving). With this change, create succeeds, the edit is saved, and the column is restored.

@TallblokeUK TallblokeUK added the run-tests Trigger automated tests label Oct 29, 2026
@TallblokeUK

Copy link
Copy Markdown
Contributor Author

Superseded by #620, which makes the same change against core-beta.

@TallblokeUK
TallblokeUK deleted the hotfix/table-upgrade/core branch October 29, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant