Bulk moving pages from one parent to another
Permalink
So, it's almost always a bad idea to go straight to the database and start updating foreign keys...but hear me out before you start rolling your collective eyes. I'd like to run a script that looks something like this:
UPDATE Pages set cParentID = 123 where cParentID = 456
The idea is to bulk move pages from one folder to another in the site (i.e. changing the parent). There are a significant number of pages (1000+) and doing this same task manually feels daunting to say the least. Grouping with folders won't work for reasons that are too boring to go into.
Generally, I am opposed to this sort of solution, but in this case I think it might be a clean way to solve a problem. I've done a couple tests in development and haven't noticed any problems. Can anyone tell me if they have tried this and destroyed their site? Concrete5 folks: really, really bad idea?
In my ideal alternate universe, someone has written an iron-clad utility to do exactly this and will link me to it in this discussion. :)
UPDATE Pages set cParentID = 123 where cParentID = 456
The idea is to bulk move pages from one folder to another in the site (i.e. changing the parent). There are a significant number of pages (1000+) and doing this same task manually feels daunting to say the least. Grouping with folders won't work for reasons that are too boring to go into.
Generally, I am opposed to this sort of solution, but in this case I think it might be a clean way to solve a problem. I've done a couple tests in development and haven't noticed any problems. Can anyone tell me if they have tried this and destroyed their site? Concrete5 folks: really, really bad idea?
In my ideal alternate universe, someone has written an iron-clad utility to do exactly this and will link me to it in this discussion. :)
Thanks for this - very helpful! The move() function is quite handy, as is the legacy aliasing code you have here. It wasn't necessary to go to the database directly at all...much, much better.
Guys, Help a newbie out.
I am not sure how to write a page that would run this code to do the move snippet.
Thanks.
Also, I found that if I do the manual sql update, you would also need to update the cChildren value for each cParent.
Thanks in advance.
I am not sure how to write a page that would run this code to do the move snippet.
Thanks.
Also, I found that if I do the manual sql update, you would also need to update the cChildren value for each cParent.
Thanks in advance.
Have a look into the api. Here's a direct link to the move() funtion.
http://concrete5.org/api/Pages/Page.html#move...
Here's some code that may help you get it done quickly:
More info on that here:http://bit.ly/ibxfKN