We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5430
    • 247 Posts
    Can someone tell me why the resource/update process fails to work in the following?

    $resource = array(
        "pagetitle" => 'title text',
        'alias' => 'aliastext',
        "introtext" => 'teaser text',
        "content" => 'content string',
        "published" => 0,
        "tvs" => true,
        "tv1" => 'imagepath.jpg'
    );
    
     if ($update = $modx->getObject('modResource',array("pagetitle"=>$resource['pagetitle']))) {
         $id = $update->get('id');
         $resource['id'] = $id;
         $response = $modx->runProcessor('resource/update', $resource);
         unlink(MODX_CORE_PATH.'cache/resource/web/resources/'.$update->get('id').'cache.php');
     } else {
         $response = $modx->runProcessor('resource/create', $resource);
     }
    
    if ($response->isError()) {
        return $response->getMessage();
    }else{
        echo 'supposedly it worked';
    }


    The resource/create process runs just fine, but the resource/update process does nothing and produces no error message. The $response object appears to be empty, but print_r($response) crashes my page.

    Tried doing

    if ($response = $modx->runProcessor('resource/update', $resource)){
        // run some code here
    }


    This crashes my page too. What am I missing?

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

    [ed. note: claytonk last edited this post 8 years ago.]
      • 3749
      • 24,544 Posts
      Change this ironic line of code:

      'I'm a dumbass'


      to this:

      "I'm a dumbass"


      wink

      (And get yourself a good code editor that flags errors like this -- I think even Ace would catch this one.)
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 5430
        • 247 Posts
        Actually, that was something I put in for fun when I entered the code here, this isn't in the actual code, which contains a standard string with no quotes that would cause an error. (I do use a code editor)
          • 5430
          • 247 Posts
          Just for fun I reduced this to:
          $modx->runProcessor('resource/update', array('id'=>4,'pagetitle'=>'new title'));

          Just this, nothing else in the snippet, gets a crashed page (500 error) and nothing in the error log. What the heck?
          • discuss.answer
            • 5430
            • 247 Posts
            So, just for future reference. The resource/update processor won't work unless the "context_key" for the resource to be updated is included in the array.
              • 3749
              • 24,544 Posts
              I have to admit that I didn't know that. Apparently, I've been lucky enough not to leave it out. I would have thought that the processor would use 'web' if that was missing.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting