Skip to content

PagesEditor::saveSort() — 'sorted' hook fires inconsistently depending on call shape (ad04e666) #2239

@adrianbj

Description

@adrianbj

Short description of the issue

The new PagesEditor::saveSort() method added in commit ad04e666 only fires the $pages->sorted() hook when $page is a Page instance — but whether $page is a Page or an int depends on which call shape the caller uses:

  • saveSort(123) — internally resolves $page = $this->pages->get(123) → Page → hook fires.
  • saveSort(123, 5) — passes the int through unchanged → $page stays an int → hook does not fire.

Same operation (save a sort value), different observable behavior.

Expected behavior

The sorted hook fires consistently regardless of whether the caller passes a Page object or a numeric ID.

Actual behavior

In wire/core/Pages/PagesEditor.php:

if($result && $page instanceof Page) {
    $this->pages->sorted($page, false, 1);
}

Additional concern: rowCount() > 0 is used to decide $result. If the sort value already matches the requested value, rowCount() returns 0, indistinguishable from "page not found" or "DB error."

Optional: Suggestion for a possible fix

if($result) {
    if(!$page instanceof Page) {
        $page = $this->pages->get((int) $page);
        if(!$page->id) return $result;
    }
    $this->pages->sorted($page, false, 1);
}

Setup/Environment

  • ProcessWire version: dev @ 15c749ed
  • File: wire/core/Pages/PagesEditor.php
  • Introduced in commit ad04e666

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