mycomponents/PKG_NAME/_build/resolvers/install.script.php
case xPDOTransport::ACTION_INSTALL:
This question has been answered by BobRay. See the first response.
<?php
$parentResource = $modx->getObject('modResource', array('pagetitle' => 'something'));
$childResource = $modx->getObject('modResource', array('pagetitle' => 'somethingelse'));
$template = $modx->getObject('modTemplate', array('templatename' => 'something'));
if ($template) {
$templateId = $template->get('id');
} else {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Error getting template');
}
if ($parentResource && $childResource) {
$parentId = $parentResource->get('id');
$childResource->set('parent', $parentId);
$childResource->set('template', $templateId);
$childResource->save();
} else {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Error getting resources');
}
[...]
case xPDOTransport::ACTION_INSTALL:
//$modx->reloadContext('web');
$parentResource = $modx->getObject('modResource', array('pagetitle' => 'css'), false);
if ($parentResource) {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Retrieved css');
} else {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Could not get css');
}
$childResource = $modx->getObject('modResource', array('pagetitle' => 'style'), false);
if ($childResource) {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Retrieved style');
} else {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Could not get style');
}
$template = $modx->getObject('modTemplate', array('templatename' => 'automatCSSTemplate'), false);
if ($template) {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Retrieved automatCSSTemplate');
} else {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Could not get automatCSSTemplate');
}
if ($template) {
$templateId = $template->get('id');
} else {
$modx->log(MODX::LOG_LEVEL_ERROR, 'Error getting template');
}
if ($parentResource && $childResource){
$parentId = $parentResource->get('id');
$childResource->set('parent', $parentId);
$childResource->set('template', $templateId);
$childResource->save();
} else{
$modx->log(MODX::LOG_LEVEL_ERROR, 'Error getting resources');
}
[...]/* * MODX Console Output * * @date 2012-07-27 13:06:38 */ Attempting to install package with signature: automat-1.0.1-beta5 Package found...now preparing to install. Grabbing package workspace... Workspace environment initiated, now installing package... Running PHP Resolver. Could not get css Could not get style Retrieved automatCSSTemplate Error getting resources Script resolver actions completed Successfully installed package automat-1.0.1-beta5 /* EOF */
reloadContext('web');/* Transport Resources */
if ($hasResources) {
$resources = include $sources['data'] . 'transport.resources.php';
if (!is_array($resources)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in resources.');
} else {
$attributes = array(
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => false,
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);
}
$modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($resources) . ' resources.');
}
unset($resources, $resource, $attributes);
}