Skip to content

PagesVersions: rename and save with explicit name don't handle unique-key collisions — raw PDOException on duplicate name (6a1aa2b2) #2238

@adrianbj

Description

@adrianbj

Short description of the issue

Commit 6a1aa2b2 added name support to PagesVersions with a UNIQUE KEY name_pages_id (name, pages_id) constraint. Two call paths can violate the constraint without graceful handling:

  1. renamePageVersion($page, $version, 'draft') when another version of the same page already has name 'draft'.
  2. savePageVersion($page, $newVersion, ['name' => 'draft']) when another version already has name 'draft'.

Expected behavior

A clear WireException (or an indication that the caller should pick a different name), not a raw PDO 1062 duplicate-key exception.

Actual behavior

  • renamePageVersion issues a bare UPDATE pages_versions SET name = ? WHERE ... with no pre-check and no try/catch on the unique-key constraint violation.
  • savePageVersion's upsert uses INSERT ... ON DUPLICATE KEY UPDATE keyed on the primary key (version, pages_id), not on the (name, pages_id) unique key — so it fails outright when the name already exists on a different version of the same page.

Optional: Suggestion for a possible fix

Pre-check or catch with friendly error:

try {
    // ... existing rename/save logic ...
} catch(\PDOException $e) {
    if($e->errorInfo[1] === 1062) {
        throw new WireException("A version named '$name' already exists for this page.");
    }
    throw $e;
}

Setup/Environment

  • ProcessWire version: dev @ 15c749ed
  • File: wire/modules/PagesVersions/PagesVersions.module.php
  • Introduced in commit 6a1aa2b2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions