Jump to content

Delete a bunch of older pages


tires
 Share

Recommended Posts

Hi!

How can i best delete older pages via the console or directly in the database.
There are several thousand pages so it is not possible to do it manually.
I would like to delete all pages before a certain date or those that are older than a year, for example.

Thanks!

Link to comment
Share on other sites

What about the examples on https://processwire.com/api/ref/page/delete/?

Due to processwire's database structure it seems almost impossible to delete records directly in the database... 😐

I would do such things in a template file.

You asked "via the console" - yet I don't no such way, but I'm curious, how could such a way look like?

Link to comment
Share on other sites

2 minutes ago, webdecker said:

You asked "via the console" - yet I don't no such way, but I'm curious, how could such a way look like?

By bootstrapping Processwire via external PHP script and execute it via console or web browser. Some infos can be found in this topic https://processwire.com/docs/front-end/include/. Another option may be RockMigrations from Bernhard https://processwire.com/modules/rock-migrations/.

  • Like 1
Link to comment
Share on other sites

1 minute ago, cwsoft said:

Another option may be RockMigrations from Bernhard https://processwire.com/modules/rock-migrations/.

Don't think that RockMigrations would help a lot here as the ->deletePage() method is not meant to be used for scalable scenarios. Though RockShell could help, because it's super simple to create new commands (see the docs here: https://www.baumrock.com/en/processwire/modules/rockshell/docs/custom/) and you can then execute this command via CLI whenever you need it, provide custom options if you want etc etc.

If it's a one-off task then bootstrapping PW and calling that file manually would be fine as well.

Link to comment
Share on other sites

Big thanks to all of you!

I simply used the $page->delete() in a template file like this:

// Find old pages
$pages = $pages->find("template=mytemplate, parent=myparent, sort=date, limit=50000");

// Delete old pages
foreach ($pages as $page){
	$page->delete(); 
};

 

  • Like 1
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...