pepebe
3/9/2014 - 2:40 PM

Move article resources from an articles parent to another non-articles parent.

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;