We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I'm working on an extra that installs a couple of resources (testing on 2.1.5).

    In the script resolver, I need to get those resources so that I can set a couple of System Settings with their IDs. This code, which I swear used to work, now fails:

    $modx =& $object->xpdo;
    $r = $modx->getObject('modResource', array('alias'=> 'pb-process'));
    if ($r) {
        $processId = $r->get('id');
        $settings['pb_process_id'] = $r->get('id');
    } else {
        $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not get PB_Process resource');
    }
    
    $r = $modx->getObject('modResource', array('alias'=> 'pb-process'));
    if ($r) {
        $processId = $r->get('id');
        $settings['pb_status_id'] = $r->get('id');
    } else {
        $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not get PB_Status resource');
    }


    I'm getting the error messages every time when the script resolver runs at the end of the install whether I use the pagetitle or alias in the search (pagetitles: PB_Process, PB_Status).

    The resources are definitely installed and the same getObject() code works fine when pasted in a snippet.

    Has something changed?


    ---------------------------------------------------------------------------------------------------------------
    PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
    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
      • 22303 MODX Staff
      • 10,725 Posts
      Nothing should have changed, and certainly not that I am aware of. Does it work in a previous version with no changes?
        • 3749
        • 24,544 Posts
        I'll have to check. It's a new extra , but I'm pretty sure I've used the same code in previous extras.

        Do you think the hyphen or the underscore could cause trouble in a resolver?
          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
          • 22303 MODX Staff
          • 10,725 Posts
          I doubt an underscore or hyphen in the pagetitle/alias would have any affect. I'm perplexed...
            • 3749
            • 24,544 Posts
            Let's not forget the possibility that I'm doing something stupid. wink
              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
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: BobRay at Jan 13, 2012, 10:50 AM
              Let's not forget the possibility that I'm doing something stupid. wink
              Do you by chance have any Extras installed which have added fields to the modResource (aka site_content) table?
                • 3749
                • 24,544 Posts
                No, definitely not.

                I should mention that I'm on XAMPP locally and that the resources are created in the main part of the package, not in the resolver.

                I have had trouble lately with MySQL crashing the Apache server. This happens sometimes when I run PhpMyAdmin. Apache restarts on its own and I can continue working. If something in the package is crashing Apache, maybe the getObject() call is timing out while Apache restarts. Would that make sense? Does xPDO have a timeout setting?

                I have some ideas for diagnosing this to try out later tonight.



                ---------------------------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                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
                  • 3749
                  • 24,544 Posts
                  OK, this is getting truly weird. I've looked in the DB -- the resources are there and every field is set properly.

                  I tried this code in the resolver:
                  <php
                          $r = $modx->getObject('modResource', array('alias'=> 'home-page'));
                          if ($r) {
                              $modx->log(xPDO::LOG_LEVEL_ERROR,'Retrieved Home Page');
                          } else {
                              $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not get Home Page');
                          }
                  
                          $r = $modx->getObject('modResource', array('alias'=> 'pb-process'));
                          if ($r) {
                              $processId = $r->get('id');
                              $settings['pb_process_id'] = $r->get('id');
                          } else {
                              $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not get PB_Process resource');
                          }
                          for ($i = 1; $i <= 20; $i++ ) {
                              $r = $modx->getObject('modResource', array('alias'=> 'pb-status'));
                              if ($r) break;
                          }
                          if ($r) {
                              $modx->log(xPDO::LOG_LEVEL_ERROR,'Retrieved PB_Status resource');
                              $processId = $r->get('id');
                              $settings['pb_status_id'] = $r->get('id');
                          } else {
                              $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not get PB_Status resource');
                          }
                  


                  The home page is retrieved, but neither of the new resources is. The resources are successfully removed on uninstall.

                  Here is the code that packages the resources:

                  <?php
                  if ($hasResources) {
                      $resources = include $sources['data'].'transport.resources.php';
                      if (!is_array($resources)) {
                          $modx->log(modX::LOG_LEVEL_ERROR,'Could not package in resources.');
                      } else {
                          $attributes= array(
                      xPDOTransport::PRESERVE_KEYS => false,
                      xPDOTransport::UPDATE_OBJECT => true,
                      xPDOTransport::UNIQUE_KEY => 'id',
                      xPDOTransport::RELATED_OBJECTS => true,
                      xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
                          'ContentType' => array(
                              xPDOTransport::PRESERVE_KEYS => false,
                              xPDOTransport::UPDATE_OBJECT => true,
                              xPDOTransport::UNIQUE_KEY => 'name',
                          ),
                      ),
                  );
                  foreach ($resources as $resource) {
                      $vehicle = $builder->createVehicle($resource,$attributes);
                      $builder->putVehicle($vehicle);
                  }
                          $modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($resources).' resources.');
                      }
                      unset($resources,$resource,$attributes);
                  }


                  I'm not sure what to try next except creating the resources in the resolver.


                  ---------------------------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                  MODx info for everyone: http://bobsguides.com/MODx.html [ed. note: BobRay last edited this post 14 years, 8 months ago.]
                    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
                    • 26903
                    • 1,336 Posts
                    Have you got database caching turned on?
                      Use MODx, or the cat gets it!
                      • 3749
                      • 24,544 Posts
                      Quote from: shamblett at Jan 14, 2012, 03:35 AM
                      Have you got database caching turned on?

                      It's off in System Settings.

                      I also find that I can't retrieve the two new System Settings the package creates (successfully), though I can retrieve the snippets and chunks.

                      IIRC, I ran into this problem quite a while ago with NewsPublisher. I refactored the NpEditThisButton snippet to to retrieve the resource and set the setting the first time the snippet runs rather than in the resolver, but it's not an ideal solution because the user might have changed the resource's pagetitle before running the snippet.

                      I filed a bug here: http://bugs.modx.com/issues/6685 [ed. note: BobRay last edited this post 14 years, 8 months ago.]
                        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