BobRay,
I had no problems doing the scenario you described. I created 2 categories, one that packages chunks, the other snippets, then attached 2 resolvers to the snippet category, and in the resolver changed the snippet description based upon input from setup-options. It worked fine.
So as to your problem, I can’t really help you unless you show me your entire build script. I can’t figure out if you have problems elsewhere, say in your resolver, with only partial code from the build script.
Thanks for pluggin away at this.
P.S. Here’s my code to my build script:
<?php
/**
* @package test
* @subpackage build
*/
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
set_time_limit(0);
$root = dirname(dirname(__FILE__)) . '/';
$sources= array (
'root' => $root,
'build' => $root . '_build/',
'lexicon' => $root . '_build/lexicon/',
'resolvers' => $root . '_build/resolvers/',
'docs' => $root . 'test/docs/',
);
/* override with your own defines here (see build.config.sample.php) */
require_once $sources['build'].'build.config.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx= new modX();
$modx->initialize('mgr');
echo '<pre>';
$modx->setLogLevel(MODX_LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
/* load packagebuilder and transport package */
$modx->loadClass('transport.modPackageBuilder','',false, true);
$builder = new modPackageBuilder($modx);
$builder->createPackage('test','0.1','alpha');
$builder->registerNamespace('test',false);
/* add in snippets */
$attr = array(
XPDO_TRANSPORT_UNIQUE_KEY => 'category',
XPDO_TRANSPORT_PRESERVE_KEYS => false,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
XPDO_TRANSPORT_RELATED_OBJECTS => true,
XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array (
'modSnippet' => array (
XPDO_TRANSPORT_PRESERVE_KEYS => false,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
XPDO_TRANSPORT_UNIQUE_KEY => 'name',
)
)
);
$category= $modx->newObject('modCategory');
$category->set('id',1);
$category->set('category','TestCompSnippets');
$snippets = array();
for ($i=1;$i<4;$i++) {
$c= $modx->newObject('modSnippet');
$c->set('id',$i);
$c->set('name', 'TestSnippet'.$i);
$c->set('description', 'Test '.$i);
$c->set('snippet', file_get_contents($sources['root'] . 'test/elements/snippet'.$i.'.class.php'));
$snippets[] = $c;
}
$category->addMany($snippets,'modSnippet');
$vehicle = $builder->createVehicle($category,$attr);
$vehicle->resolve('file',array(
'source' => $sources['root'] . 'test',
'target' => "return MODX_ASSETS_PATH . 'components/';",
));
$vehicle->resolve('php',array(
'source' => $sources['resolvers'] . 'test.resolver.php',
));
$builder->putVehicle($vehicle);
/* create chunks */
$attr = array(
XPDO_TRANSPORT_UNIQUE_KEY => 'category',
XPDO_TRANSPORT_PRESERVE_KEYS => false,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
XPDO_TRANSPORT_RELATED_OBJECTS => true,
XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array (
'modChunk' => array (
XPDO_TRANSPORT_PRESERVE_KEYS => false,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
XPDO_TRANSPORT_UNIQUE_KEY => 'name',
)
)
);
$category= $modx->newObject('modCategory');
$category->set('id',2);
$category->set('category','TestCompChunks');
$chunks = array();
for ($i=1;$i<2;$i++) {
$c = $modx->newObject('modChunk');
$c->set('id',$i);
$c->set('name', 'TestChunk'.$i);
$c->set('description', 'Test Chunk '.$i);
$c->set('snippet', file_get_contents($sources['root'] . 'test/elements/chunk'.$i.'.tpl'));
$chunks[] = $c;
}
$category->addMany($chunks);
$vehicle = $builder->createVehicle($category,$attr);
$builder->putVehicle($vehicle);
/* build in lexicon */
$builder->buildLexicon($sources['lexicon']);
/* now pack in the license file, readme and setup options */
$builder->setPackageAttributes(array(
'license' => file_get_contents($sources['docs'] . 'license.txt'),
'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
'setup-options' => file_get_contents($sources['build'] . 'setup.options.tpl'),
));
/* pack */
$builder->pack();
$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tend= $mtime;
$totalTime= ($tend - $tstart);
$totalTime= sprintf("%2.4f s", $totalTime);
$modx->log(MODX_LOG_LEVEL_INFO,"\n<br />Package Built.<br />\nExecution time: {$totalTime}\n");
exit();
And my resolver:
<?php
$success= false;
switch ($options[XPDO_TRANSPORT_PACKAGE_ACTION]) {
case XPDO_TRANSPORT_ACTION_INSTALL:
case XPDO_TRANSPORT_ACTION_UPGRADE:
$snippet = $object->xpdo->getObject('modSnippet',array('name' => 'TestSnippet1'));
if ($snippet != null) {
$snippet->set('description',$options['snippetDescription']);
$snippet->save();
} else {
$object->xpdo->log(XPDO_LOG_LEVEL_ERROR,'TestSnippet1 could not be found, so the description could not be changed.');
}
$success= true;
break;
case XPDO_TRANSPORT_ACTION_UNINSTALL:
$success= true;
break;
}
return $success;
And my setup.options.tpl:
<label for="snippetDescription">Snippet 1 Description:</label>
<input type="text" name="snippetDescription" id="snippetDescription" width="300" value="The first test snippet." />