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
    Your transport.resources.php appears to be truncated. It should have more code at the end and finish with

    return $resources
      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
    • Quote from: BobRay at Dec 14, 2014, 10:49 PM
      Your transport.resources.php appears to be truncated. It should have more code at the end and finish with

      return $resources

      Thanks Bob, but that was not the issue.
      The code in my question got trucked, the full code is correct:

      <?php
      
      if (! function_exists('stripPhpTags')) {
          function stripPhpTags($filename) {
              $o = file_get_contents($filename);
              $o = str_replace('<' . '?' . 'php', '', $o);
              $o = str_replace('?>', '', $o);
              $o = trim($o);
              return $o;
          }
      }
      /* @var $modx modX */
      /* @var $sources array */
      /* @var xPDOObject[] $resources */
      
      
      $resources = array();
      
      /* Other resources */
      
      $properties = include $sources['data'].'properties/properties.support_theme_is_available_on_themesmodx.resource.php';
      $resources[22]->setProperties($properties);
      unset($properties);
      
      $resources[23] = $modx->newObject('modResource');
      $resources[23]->fromArray(array (
        'id' => 23,
        'type' => 'document',
        'contentType' => 'text/html',
        'pagetitle' => 'Ajax instant search included',
        'longtitle' => '',
        'description' => '',
        'alias' => 'ajax-instant-search-included',
        'link_attributes' => '',
        'published' => true,
        'isfolder' => false,
        'introtext' => 'With the Support theme from ThemesMODX comes Ajax instant search included.',
        'richtext' => true,
        'template' => 'News article',
        'menuindex' => 2,
        'searchable' => true,
        'cacheable' => true,
        'createdby' => 2,
        'editedby' => 2,
        'deleted' => false,
        'deletedon' => 0,
        'deletedby' => 0,
        'menutitle' => '',
        'donthit' => false,
        'privateweb' => false,
        'privatemgr' => false,
        'content_dispo' => 0,
        'hidemenu' => false,
        'class_key' => 'modDocument',
        'context_key' => 'web',
        'content_type' => 1,
        'hide_children_in_tree' => 0,
        'show_in_tree' => 0,
      ), '', true, true);
      $resources[23]->setContent(file_get_contents($sources['data'].'resources/ajax_instant_search_included.content.html'));
      
      
      $properties = include $sources['data'].'properties/properties.ajax_instant_search_included.resource.php';
      $resources[23]->setProperties($properties);
      unset($properties);
      
      return $resources;
      
        MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
        DESIGNfromWITHIN, MPThemes and Any Screen Size
        Follow me on Twitter | Read my blog | My code on GitHub
      • discuss.answer
        • 3749
        • 24,544 Posts
        In each of the resources in the transport resources file, the fromArray() final arguments should be , "", false, false). You don't want to preserve the keys in order to avoid collisions and you don't need the ad hoc values.



        In the resolver, I would do this:

        $sources = array(
            'data' => $modx->getOption('core_path') . 'components/cosmos/contentResources/',
        );
         
        // Check add content setting
        
        $addContent = $modx->getOption('add_content', $options, false);
        if ($addContent) {
          $path = $sources['data'] . 'transport.resources.php';
          if (! file_exists($path) {
              $modx->log(modX::LOG_LEVEL_ERROR, 'File does not exist: ' . $path);
          }
          // Add content
          $resources = include $path;
          $ok = true;
          if (! is_array($resources)) {
              $modx->log(modX::LOG_LEVEL_ERROR, 'Resources not an array');
              $ok = false;
          } 
          if (empty($resources) ) {
              $modx->log(modX::LOG_LEVEL_ERROR, 'Resources is empty');
              $ok = false;
          }
          if ($ok) {
              foreach ($resources as $resource) {
                 $resource->save();
             }
          }
        
        // ....
        
        }



          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