I've been in transport package hell for about two weeks now. I should say that this may be do to my platform (XAMPP/Vista), but I don't think so because people installing some of my extras have reported similar problems. I'm seeing this in both MODX 2.1.5 and MODX 2.2.0-rc3.
In its simplest form, my problem is this: My package creates a resource and a system setting. In my script resolver, I want to set the system setting to the ID of the resource.
In the script resolver, getObject() will not retrieve either the resource or the system setting (though it will retrieve any elements I create). The objects are in the DB and all their fields are set properly as far as I can tell. Database Caching is off.
My theory is that the DB is updated, but not the cache, and if the resource or system_setting cache exists and the object is not there, getObject() fails, (though it seems to me that getObject() should look in the DB if it doesn't find the object in the cache).
This isn't a problem normally because the create processors clear the cache, but as far as I can tell, Package Manager doesn't use the processors to create resources and system settings (TBH, I couldn't find the code that actually creates the object) and there's no way I can find to clear the cache in a script resolver. The following code in the resolver fails because the $context is not set (and there's no way I know of to set it, since it's a local variable in refresh() ):
<?php
$modx =& $object->xpdo;
$cm = $modx->getCacheManager();
$cm->refresh();
As workaround, I can set the system setting the first time the snippet runs, but there's a problem there too. After manually creating a system setting called aaDummy with an empty value, this code fails until I manually clear the cache or reload the page:
<?php
$ss = $modx->getOption('aaDummy');
if (empty($ss)) {
$obj = $modx->getObject('modSystemSetting', array('key' => 'aaDummy'));
if (! $obj) {
return "could not get system setting object";
} else {
$obj->set('value', '999');
$obj->save();
$cm = $modx->getCacheManager();
$cm->refresh();
}
}
$ss = $modx->getOption('aaDummy');
return 'Setting: ' . $ss;
The system setting is set correctly, but the page displays:
If I reload the page, the new system setting is there.
Maybe the cache just isn't being cleared properly on my system. I don't think it's a timing issue because if I add sleep(30) to the script resolver before getObject(), it still won't get either the resource or the system setting.
If I create a simple transport package that does nothing but create a resource and a system setting, getObject() still fails to get either one in a script resolver (either by alias or pagetitle).
I don't know what else to try.
---------------------------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
MODx info for everyone:
http://bobsguides.com/MODx.html