OK I’m trying to work out what is needed to package a sample site with templates, tv’s and resources to start with and to later add in required snippets too.
so I have one template and one resource with one tv.
So far I have managed to work out how to package the template and the resource and how to associate the 2 together.
what I can’t work out is how to create the tv and associate it to the template. this is what i have so far
/*Some variable setup above here snipped for ease */
require_once dirname(__FILE__) . '/build.config.php';
require_once MODX_CORE_PATH . '/model/modx/modx.class.php';
$modx = new modx();
$modx->initialize('mgr');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$modx->loadclass('transport.modPackageBuilder', '', false, true);
$builder = new modPackageBuilder($modx);
$builder->createPackage('splashSunrise', '0.1', 'alpha1');
$modx->log(modX::LOG_LEVEL_INFO, 'Templates');
$mainTemplate = $modx->newObject('modTemplate');
$mainTemplate->set('id', 1);
$mainTemplate->set('templatename', 'BaseTemplate');
$mainTemplate->set('content', file_get_contents($sources['templates'] . 'BaseTemplate.html'));
$modx->log(modX::LOG_LEVEL_INFO, 'Resources');
$homeResource = $modx->newObject('modResource');
$homeResource->set('id', 1);
$homeResource->set('pagetitle', 'Home');
$homeResource->set('published', 1);
$homeResource->set('content', file_get_contents($sources['resources'] . 'home.html'));
$mainTemplate->addMany($homeResource);
$modx->log(modX::LOG_LEVEL_INFO, 'TemplateVars');
$tagTemplateVar = $modx->newObject('modTemplateVar');
$tagTemplateVar->set('id', 1);
$tagTemplateVar->set('name', 'tags');
$mainTemplate->addMany($tagTemplateVar);
$attr = array(
xPDOTransport::UNIQUE_KEY => 'templatename',
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::RELATED_OBJECTS => true,
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array(
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::UNIQUE_KEY => 'pagetitle'
),
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array(
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::UNIQUE_KEY => 'id'
)
);
$vehicle = $builder->createVehicle($mainTemplate, $attr);
$modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers to category...');
$vehicle->resolve('file', array(
'source' => $sources['source_assets'] . '/templates',
'target' => "return MODX_ASSETS_PATH . '/';",
));
$builder->putVehicle($vehicle);
$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, "\nPackage Built. \nExecution time : {$totalTime}\n");
exit()
This runs and this is what i get out
[2011-05-24 13:20:03] (INFO @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
Created new transport package with signature: splashsunrise-0.1-alpha1
[2011-05-24 13:20:03] (INFO @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
Templates
[2011-05-24 13:20:03] (INFO @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
Resources
[2011-05-24 13:20:03] (INFO @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
TemplateVars
[2011-05-24 13:20:03] (ERROR @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
No foreign key definition for parentClass: modTemplate using relation alias: modTemplateVar
[2011-05-24 13:20:03] (INFO @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
Adding file resolvers to category...
[2011-05-24 13:20:03] (INFO @ /modx/splashSurprise/sourceFiles/trunk/_build/build.transport.php)
Package Built.
Execution time : 0.2527 s
This creates the template it creates the resources but nothing happens with the tv the main error that seems to be linked to this is
No foreign key definition for parentClass: modTemplate using relation alias: modTemplateVar
Having looked at the schema is see that the template has a modTemplateVarTemplate instead but can’t figure out how to use this to link the template and the tv.
Any help would be gratefully appreciated.