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. :)

brennaH
 
Fernandos replied on at Permalink Best Answer Reply
Fernandos
You have no need to explain sir. It makes totally sense to write a script for that purpose.

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:
<?php
$this_page_paths = $in_pg->getPagePaths();
$new_paths = array();
foreach($this_page_paths as $path){
if (!$path['ppIsCanonical']) {
  $new_paths[$path['ppID']] = $path['cPath'];
}
}
$new_paths['add_path'] = $add_alias;
$data = array();
$data['ppURL'] = $new_paths;
$in_pg->update($data);

More info on that here:http://bit.ly/ibxfKN
brennaH replied on at Permalink Reply
brennaH
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.
scottmcdhome replied on at Permalink Reply
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.