We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8274 ☆ A M B ☆
    • 222 Posts
    I am building a conversion script (to save some of my sanity) and the first thing I want it to do is to duplicate a resource and all its children before I begin manipulating it.

    I can get the resource/duplicate processor to run and execute a duplicate. But, I can't seem to figure out how to get a reference to the new resource object so that I can change a few values (template, class_key) as well as get the id to do some transforming on the children.

    code is here:
    $resource = $modx->getObject('modResource', array('id'=>$id));
    $newObj = $modx->runProcessor('resource/duplicate', array(
    'id'=>$id,
     'duplicate_children'=>true,
    'name'=>'New Obj '.$resource->get('pagetitle')));
    


    Using MODx 2.3.2, and this is a snippet as I would only need to run it once, then delete the snippet.

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      something like that maybe:

      if ($response->isError()) {
          $updateerror = true;
          $errormsg = $response->getMessage();
      }else{
          $r = $response->getObject();
          if (isset($r['id'] && $resource = $modx->getObject('modResource',$r['id']))){
              //do something with $resource
          }
      }

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 8274 ☆ A M B ☆
        • 222 Posts
        The response->getObject() part was what I was missing.

        All fixed up.