We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28855
    • 2 Posts
    Following Bob's guides, I've created a transport package for my extra. I've updated his example resolver, so that it will set the template for the new resources I create to the new template that's in the extra. However, no matter what I've tried, my resource always comes out with a template set to 0. Here's my resolver code:

    $modx = & $object->xpdo;

    $resources = array("members");
    $template_name = "FoundersComm";
    $success = true;

    $modx->log(xPDO::LOG_LEVEL_INFO, 'Running PHP Resolver.');
    switch ($options[xPDOTransport::PACKAGE_ACTION]) {
    /* This code will execute during an install */
    case xPDOTransport::ACTION_INSTALL:
    //Assign template to resources...
    $modx->log(xPDO::LOG_LEVEL_INFO, "Retrieving template $template_name");
    $tpl = $modx->getObject('modTemplate', array('templatename' => $template_name));
    if (!isset($tpl)) {
    $modx->log(xPDO::LOG_LEVEL_ERROR, "Could not retrieve template $template_name");
    return false;
    }

    foreach ($resources as $resource_name) {
    $modx->log(xPDO::LOG_LEVEL_INFO, "Updating resource $resource_name with template $template_name with ID " . $tpl->get('id'));
    $resource = $modx->getObject('modResource', array('pagetitle' => $resource_name));
    if (!$resource) {
    $modx->log(xPDO::LOG_LEVEL_ERROR, "Cannot get resource: $resource_name");
    return false;
    }

    $resource->set('template', $tpl->get('id'));

    if(!$resource->save()){
    $modx->log(xPDO::LOG_LEVEL_ERROR, "Failed to save resource: $resource_name");
    return false;
    }

    $new_res = $modx->getObject('modResource', array('pagetitle' => $resource_name));
    $modx->log(xPDO::LOG_LEVEL_INFO, "Resource $resource_name updated - template set to " . $new_res->get('template'));
    }
    break;

    /* This code will execute during an upgrade */
    case xPDOTransport::ACTION_UPGRADE:

    /* put any upgrade tasks (if any) here such as removing
    obsolete files, settings, elements, resources, etc.
    */

    $success = true;
    break;

    /* This code will execute during an uninstall */
    case xPDOTransport::ACTION_UNINSTALL:
    $modx->log(xPDO::LOG_LEVEL_INFO, 'Uninstalling . . .');
    $success = true;
    break;
    }
    $modx->log(xPDO::LOG_LEVEL_INFO, 'Script resolver actions completed');
    return $success;
      • 3749
      • 24,544 Posts
      What are you seeing in the log?

      Something I didn't know when I wrote the book is that resolvers execute at the end of the vehicle they're attached to (rather than at the end of the install). Your resolver must execute at a point where all templates and resources have already been created.

      Just moving the section that creates the resources in build.transport.php up above the section that creates the elements and attaching the resolver to the elements section might do the trick.


      ------------------------------------------------------------------------------------------
      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
        • 38971
        • 3 Posts
        Hey, Bob ... thanks for the quick reply!

        The log shows exactly what I would expect when everything executes successfully. In other words, the line

        $modx->log(xPDO::LOG_LEVEL_INFO, "Resource $resource_name updated - template set to " . $new_res->get('template'));

        prints a message in the log stating that the resource is updated with a valid template ID. Both the resource name and template ID are valid and correct.

        Another odd thing is that all resources in my installation have their template IDs reset to 0, not just the resource I explicitly change in the resolver. It's as though something else occurs after the installation is complete that wipes out all template IDs for all resources.
          • 3749
          • 24,544 Posts
          Can you post the code of your resolver?


          ------------------------------------------------------------------------------------------
          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
            • 38971
            • 3 Posts
            I must humbly confess my idiocy :<

            Somewhere along the line I introduced code that was first deleting and then re-creating the template. When I got rid of that, all worked as expected. Sorry for wasting anyone's time.
              • 3749
              • 24,544 Posts
              No problem, we've all between there.

              Keep an eye out for the release of MyComponent 3.0, which hopefully will make problems like this obsolete.
                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