We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41662
    • 1 Posts
    Hi there,

    I am fairly new to the Modx community and was looking for some support with an obscure error that I am encountering. I have Modx Revo 2.2 installed on my Windows XP machine and am running from xampp locally (PHP version 5.3.8, mysql 5.0.8, apache 2.2). I am working on a piece of functionality that will create a new child resource automatically whenever the parent resource is selected in the resource tree. I have a custom plugin that handles this logic just fine, but it only seems to work when delete my cache. So, on executing this code with no cache it works, but a new cache is subsequently created when the plugin runs. When I try to run the plugin again with a cache in place, I get the following error:

    An error occurred: {"modx-resource-tree":["\/root\/web_0"],"undefined-sort-default":"menuindex","undefined-sort":"menuindex"}

    I am unsure as to what this error means exactly and how to go about fixing it. I know that it caused by the cached version of the plugin being called as the error doesn't occur when I clear the cache. I have tried forcing the cache to clear itself each time the plugin is executed, just as a temporary solution to continue development, but this seems to have no effect. Has anyone encountered this sort of error before? I would appreciate any advice that can be given. The code for the plugin is as follows:

    if ('my-resource' == $resource->get('alias')) {
    $gtpl = $modx->getObject('modTemplate', array('templatename' => 'mytemplate'));
    // Create the suggested table folder
    $fields['createdby'] = $modx->user->id;
    $fields['parent'] = $id;
    $fields['template'] = $gtpl->get('id');
    $fields['alias'] = 'aliasname';
    $fields['uri'] = 'uriname'.md5(time());
    $fields['isfolder'] = 0;
    $fields['uri_override'] = 1;
    $fields['hidemenu'] = 0;
    $fields['pagetitle'] = 'mypagetitle';
    $fields['published'] = 1;
    $fields['show_in_tree'] = 0;

    $response = $modx->runProcessor('resource/create', $fields);

    if ($response->isError()) { /* An error occurred */
    if ($response->hasFieldErrors()) {
    $fieldErrors = $response->getAllErrors();
    $errorMessage = implode("\n", $fieldErrors);
    } else {
    $errorMessage = 'An error occurred: ' . $response->getMessage();
    }
    $modx->log(xPDO::LOG_LEVEL_ERROR,$errorMessage);
    echo $errorMessage;
    die;
    } else {
    $modx->cacheManager->refresh();
    }
    }

    Thank You smiley [ed. note: bluesteel last edited this post 14 years ago.]
      • 3749
      • 24,544 Posts
      I wonder if you're trying to create a resource with a duplicate alias.

      That code will always crash on any error because you can't use echo in a plugin (and of course "die" would kill it anyway).

      Plugins are tough to debug. Sometimes it helps to look at the cached version of the plugin in the core/cache directory.

      This can also help. Create a chunk called debug and put this at the top of the plugin:

      function my_debug($message, $clear = false)    {
              /* @var $chunk modChunk */
              $chunk = $modx->getObject('modChunk', array('name' => 'debug'));
      
              /* attempt to create it */
              if (!$chunk) {
                  $chunk = $modx->newObject('modChunk', array('name' => 'debug'));
                  $chunk->save();
                  $chunk = $getObject('modChunk', array('name' => 'debug'));
              }
              if ($clear) {
                  $content = '';
              } else {
                  $content = $chunk->getContent();
              }
              $content .= $message;
              $chunk->setContent($content);
              $chunk->save();
      }
      
      /* clear the debug log */
      my_debug("Errors\n", true);
      



      Then you can set $msg to whatever you want at various points in your plugin and call my_debug($msg). The message will be appended to the chunk content and you can look at it with QuickEdit by right-clicking on the debug chunk without leaving the plugin editing panel.

      What event is the plugin connected to?



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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