tires Posted November 30, 2023 Share Posted November 30, 2023 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 More sharing options...
webdecker Posted November 30, 2023 Share Posted November 30, 2023 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 More sharing options...
bernhard Posted November 30, 2023 Share Posted November 30, 2023 ? 2 Link to comment Share on other sites More sharing options...
cwsoft Posted November 30, 2023 Share Posted November 30, 2023 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/. 1 Link to comment Share on other sites More sharing options...
bernhard Posted November 30, 2023 Share Posted November 30, 2023 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 More sharing options...
cwsoft Posted November 30, 2023 Share Posted November 30, 2023 Seem I lost the overview of all your rockstar modules and snippets ?. Anyway keep on rocking. There is almost all times a useful RockX which fits your needs or solves a problem for you. 1 Link to comment Share on other sites More sharing options...
webdecker Posted November 30, 2023 Share Posted November 30, 2023 Thanks for the console hints! ? Link to comment Share on other sites More sharing options...
tires Posted November 30, 2023 Author Share Posted November 30, 2023 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(); }; 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now