if ($object->xpdo) {
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:
/** @var modX $modx */
$modx =& $object->xpdo;
$modelPath = $modx->getOption('myextra.core_path',null,$modx->getOption('core_path').'components/myextra/').'model/';
/** @var modTemplateVar $tv */
$tv = $modx->getObject('modTemplateVar',array(
'name' => 'TemplateVar1',
'name' => 'TemplateVar2',
'name' => 'TemplateVar3',
'name' => 'TemplateVar4',
'name' => 'TemplateVar5',
'name' => 'TemplateVar6',
));
if ($tv) {
$templates = array('sample.Template');
foreach ($templates as $templateName) {
/** @var modTemplate $template */
$template = $modx->getObject('modTemplate',array('templatename' => $templateName));
if ($template) {
/** @var modTemplateVarTemplate $templateVarTemplate */
$templateVarTemplate = $modx->getObject('modTemplateVarTemplate',array(
'templateid' => $template->get('id'),
'tmplvarid' => $tv->get('id'),
));
if (!$templateVarTemplate) {
$templateVarTemplate = $modx->newObject('modTemplateVarTemplate');
$templateVarTemplate->set('templateid',$template->get('id'));
$templateVarTemplate->set('tmplvarid',$tv->get('id'));
$templateVarTemplate->save();
}
}
}
}
break;
}
}
return true;
My TV's always return, with data after I reinstall the package.
I've seen this with MIGX and Articles. Articles even returns... the actual articles.
Maybe there's something in their code that will clue you into how it's accomplished?
xPDOTransport::UPDATE_OBJECT => false,
$categoryId = 12;
$tvs = $modx->getCollection('modTemplateVar', array('category' => $categoryId));
$template = $modx->getObject('modTemplate', array('templatename' => 'myTemplate'));
if ($template) {
$tvts = $template->getMany('TemplateVarTemplates');
}BTW, your resolver seems kind of muddled to me and I don't think the first part of it will do anything. getObject() will only get a single object, so you'd have to set up the array outside of the loop and call getObject() for each one. If they're all in the same category (as they should be), this would be simpler:
$categoryId = 12; $tvs = $modx->getCollection('modTemplateVar', array('category' => $categoryId));
Also, if there is only one template and you retrieve it with getObject(), you can do this:
$template = $modx->getObject('modTemplate', array('templatename' => 'myTemplate')); if ($template) { $tvts = $template->getMany('TemplateVarTemplates'); }
I can never remember the exact details, so you'll have to experiment, but I think if you set this in the attributes array of build.transport.php for the TVs, they won't be removed.
xPDOTransport::UPDATE_OBJECT => false,
Another option might be to create the TVs using $modx->newObject() in the resolver rather than in build.transport.php. In that case, PM might not know to delete them.