Move article resources from an articles parent to another non-articles parent.
<?php
/* Start: scriptProperties */
/* Mandatory */
$oldParent = 1005;
$newParent = 1062;
/* Optional */
$newTemplate = "";
/* End: scriptProperties */
$newTemplate = !empty($newTemplate) ? $newTemplate : false;
$object = $modx->getObject('modResource', $oldParent);
$children = $object->getMany('Children');
$count = count($children);
foreach($children as $key => $child) {
$child->set('class_key', 'modDocument');
$child->set('parent', $newParent);
if($newTemplate){
$child->set('template', $newTemplate);
}
$child->set('show_in_tree', 1);
$child->save();
}
return 'Moved ' . $count . ' articles from ' . $oldParent . ' to ' . $newParent;