Jump to content

Seeking Assistance with Deleting Pages without Templates in ProcessWire


SwimToWin
 Share

Recommended Posts

Hello Community, I've encountered an issue while using the Custom Page Class to import pages into ProcessWire. Currently, the Custom Page Class does not support the new Page() method, as documented in Issue #1864 on GitHub. Consequently, I've ended up with a significant number of test pages that lack a template assignment (specifically, the pages table has a number of entries with templates_id = 0).

When attempting to open these template-less pages via the URL /processwire/page/edit/?id=1234, I receive an Error 500.

This error message is shown when opening ProcessWire's admin interface:
image.thumb.png.c6d30625bd838669476e1f488026c006.png
PagesLoader: You must assign a template to the page before setting field values (title__data) [pageClass=ProcessWire\Page, template=]

Here are the methods I've attempted to remove these pages:

Deletion in ProcessWire editing interface: Cannot empty Trash due to missing template.

Direct Deletion Using ProcessWire API: Attempting to delete pages directly through ProcessWire's API, like so:

$pw = $pages->find("template.id=0");
foreach($pw as $p) {
    $p->delete();
}

This approach was not successful.

Database Query & Deletion: Running a direct query to identify and delete the pages results in a Server Error 500:

$ids = $database->query("SELECT * FROM pages WHERE templates_id = 0");
foreach($ids as $id) {
    $p = $pages->get($id);
    if($p->id) {
        $p->delete();
        echo "<br>Deleted: " . $p->id;
    }
}


Deletion by Specific ID Range: I also tried deleting pages by specifying an ID range, but this did not resolve the issue:

$pagesToDelete = $pages->find("id>1188");
foreach($pagesToDelete as $p) {
    printf('<br>%s (%s)', $p->title(), $p->id);
    $p->delete();
}


I am seeking advice on how to delete or update these pages effectively. Any insights or alternative methods you could provide would be greatly appreciated!

Thank you in advance!

PS: I suggested a fix that should prevent such scenarios: Gracefully handling errors in ProcessWire Custom Page Classes (Request #515).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...