Has anyone tried building a package with more than one snippet and/or more than one chunk in it? I’ve been trying all day to make it work.
I’ve probably making some simple mistake, but when I do it, only the last snippet and the last chunk make it into the package, and the properties I set for the first snippet get attached to the last one. The lexicon entries come through fine as do the readme.txt and license.txt.
SPForm has two snippets and four chunks. I’m building it with this code. The appropriate values are set in a multidimensional array $objectArray and each vehicle is built and added to the package in a loop. I know the values are ok because the echo statements look fine. The build code runs fine with no errors or warnings. Here’s the loop that does the work:
foreach($objectArray as $object) {
if (!file_exists($object['source_file'])) {
$modx->log(MODX_LOG_LEVEL_FATAL,"<b>Error</b> - Element source file not found: {$object['source_file']}<br />");
}
$modx->log(MODX_LOG_LEVEL_INFO,"Creating element from source file: {$object['source_file']}<br />");
// get the source from the actual element in your database OR
// manually create the object, grabbing the source from a file
echo " Creating newObject of type ". $object['object_type'] . "\n";
$c= $modx->newObject($object['object_type']);
echo " Setting name to " . $object['name'] . "\n";
$c->set('name', $object['name']);
echo " Setting description to " . $object['description'] . "\n";
$c->set('description', $object['description']);
echo " Setting category to " . $object['category'] . "\n";
$c->set('category', $object['category']);
echo " Setting " . $object['type'] . " from " . $object['source_file'] . "\n";
//$c->set($object['type'], file_get_contents($object['source_file']));
$c->setContent(file_get_contents($object['source_file']));
if($object['props_file'] != "") { // set the properties if there are any
require_once($object['props_file']);
$c->setProperties($spformProperties, true); // merge with current properties
}
// create a transport vehicle for the data object
$attributes= array(
XPDO_TRANSPORT_UNIQUE_KEY => 'name',
XPDO_TRANSPORT_UPDATE_OBJECT => true,
);
$vehicle = $builder->createVehicle($c, $attributes);
if ($object['resolver_source'] != "") { // create a resolver if one is specified
$modx->log(MODX_LOG_LEVEL_INFO,"Creating Resolver<br />");
if (!is_dir($object['resolver_source'])) {
$modx->log(MODX_LOG_LEVEL_FATAL,"<b>Error</b> - Resolver source directory not found: {$object['resolver_source']}<br />");
}
$modx->log(MODX_LOG_LEVEL_INFO,"Source: {$object['resolver_source']}<br />");
$modx->log(MODX_LOG_LEVEL_INFO,"Target: {$object['resolver_target']}<br /><br />");
$vehicle->resolve('file',array(
'source' => $object['resolver_source'],
'target' => $object['resolver_target'],
));
}
$builder->putVehicle($vehicle);
unset($c);
}
Here’s the console output from the install. Note that there’s only one snippet and one chunk referred to and no errors or warnings. Uninstall goes smoothly as well.
Attempting to install package with signature: SPForm-3.0.5-beta
Package found...now preparing to install.
Grabbing package workspace...
Workspace environment initiated, now installing package...
Object for class modNamespace not found using criteria Array
(
[name] => spform
)
Object for class modSnippet not found using criteria Array
(
[name] => SPFResponse
)
Object for class modChunk not found using criteria Array
(
[name] => spfresponseTpl
)
Object for class modLexiconTopic not found using criteria Array
(
[name] => default
[namespace] => spform
)
Object for class modLexiconEntry not found using criteria Array
(
[name] => hidden-last-name
[topic] => 44
[namespace] => spform
[language] => en
)
Object for class modLexiconEntry not found using criteria Array
(
[name] => send-to
[topic] => 44
[namespace] => spform
[language] => en
)
... more of the same (lexicon entry stuff).
Object for class modLexiconLanguage not found using criteria Array
(
[name] => en
)
Successfully installed package SPForm-3.0.5-beta
Any idea what I’m doing wrong?