We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I have something like this, it does not work [I am guessing]:

    part of the transport build script:
    // Load the resources
    include_once ($sources['source_data']).'include.resources.php';
    
    // Prepare category tree
    $attr = array(
    	xPDOTransport::UNIQUE_KEY => 'category',
    	xPDOTransport::PRESERVE_KEYS => false,
    	xPDOTransport::UPDATE_OBJECT => true,
    	xPDOTransport::RELATED_OBJECTS => true,
    	xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array(
    		'Snippets' => array(
    	        xPDOTransport::PRESERVE_KEYS => true,
    	        xPDOTransport::UPDATE_OBJECT => true,
    	        xPDOTransport::UNIQUE_KEY => 'name'
    		),
    		'Chunks' => array(
    	        xPDOTransport::PRESERVE_KEYS => true,
    	        xPDOTransport::UPDATE_OBJECT => true,
    	        xPDOTransport::UNIQUE_KEY => 'name'
    		),
    		'Templates' => array(
    	        xPDOTransport::PRESERVE_KEYS => true,
    	        xPDOTransport::UPDATE_OBJECT => true,
    	        xPDOTransport::UNIQUE_KEY => 'templatename'
    		),	
    		'Resources' => array(
    	        xPDOTransport::PRESERVE_KEYS => true,
    	        xPDOTransport::UPDATE_OBJECT => true,
    	        xPDOTransport::UNIQUE_KEY => 'pagetitle'
    		),		
    	)
    );




    the included include.resources.php:
    $modx->log(modX::LOG_LEVEL_INFO, 'Adding Resources');
    $resources = array();
    
    $resources[1] = $modx->newObject('modResource');
    $resources[1]->fromArray(array(
    	//'id' => 999,
    	'type' => 'document',
    	'contentType' => 'text/html',
    	'content' => file_get_contents($sources['source_resources'] . 'AddProgram.res.tpl'),
    	'pagetitle' => 'This is the pagetitle',
    ), '', true, true);
    
    
    $category->addMany($resources);





    Does not work, what is the correct way:


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

      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
    • discuss.answer
      • 3749
      • 24,544 Posts
      At least one of you problems is that Resources don't have a category, so adding them to a category object isn't going to work.

      Here's one way to add them:


      $root = dirname(dirname(__FILE__)) . '/';
      $sources = array(
          'root' => $root,
          'build' => $root . '_build/',
          'config' => $root . '_build/config/',
          'utilities' => $root . '_build/utilities/',
          /* note that the next two must not have a trailing slash */
          'source_core' => $root . 'core/components/' . PKG_NAME_LOWER,
          'source_assets' => $root . 'assets/components/' . PKG_NAME_LOWER,
          'resolvers' => $root . '_build/resolvers/',
          'validators' => $root . '_build/validators/',
          'data' => $root . '_build/data/',
          'docs' => $root . 'core/components/' . PKG_NAME_LOWER . '/docs/',
          'install_options' => $root . '_build/install.options/',
          'subpackages' => $root . '_build/subpackages/',
      
      );
      $hasResources = file_exists($sources['data'] . 'transport.resources.php');
      
      if ($hasResources) {
          $resources = include $sources['data'] . 'transport.resources.php';
          if (!is_array($resources)) {
              die('Resources not an array'));
          } else {
              $attributes = array(
                  xPDOTransport::PRESERVE_KEYS => false,
                  xPDOTransport::UPDATE_OBJECT => true,
                  xPDOTransport::UNIQUE_KEY => 'pagetitle',
                  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);
              }
          }
          unset($resources, $resource, $attributes);
      }
      


      FYI, the code above is modified slightly from the code of the MyComponent extra, a package building environment. MyComponent has a universal build.transport.php file that works for just about any package.

      If you're just doing one package, it might not be worth the effort, but if you're going to build more of them or maintain the one you're building, MyComponent is definitely worth it.

      I can do a complete package for release with MyComponent in about 20 minutes, tops, not counting the time it takes to write the actual code of the components in the package.

      Even if you're not going to use MyComponent, you might want to use its build.transport.php file and stick to its standard file naming and file location standards in case you want to start using it later.

        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
        • 26503
        • 620 Posts
        Hmm interesting - I'll have to give it a try. could be a real time saver!

        Thanks!
          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525