// 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' ), ) );
$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);This question has been answered by BobRay. See the first response.
$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);
}