This has me stumped.
If I install and uninstall Wayfinder, it removes the snippet and the console shows:
Removed modSnippet instance with primary key 16
If I install and uninstall SPForm, no snippets or chunks are removed and there are no "Removed" messages for them in the console.
I don’t see any differences in the build.transport scripts other than the fact that the SPForm snippets and chunks are in a category:
/* create category */
$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 => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::UNIQUE_KEY => 'name',
),
'Chunks' => array (
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::UNIQUE_KEY => 'name',
),
)
);
$categoryObject= $modx->newObject('modCategory');
$categoryObject->set('id',1);
$categoryObject->set('category','SPForm');
/* add snippets to category */
$snippets = require_once $sources['data'].'transport.snippets.php';
$categoryObject->addMany($snippets);
/* add chunks to category */
$chunks = require_once $sources['data'].'transport.chunks.php';
$categoryObject->addMany($chunks);
/* build category */
$vehicle = $builder->createVehicle($categoryObject,$attr);
$vehicle->resolve('file',array(
'source' => $sources['source_assets'],
'target' => "return MODX_ASSETS_PATH . 'components/';",
));
$vehicle->resolve('file',array(
'source' => $sources['source_core'],
'target' => "return MODX_CORE_PATH . 'components/';",
));
$builder->putVehicle($vehicle);
/* done setting category/snippets/chunks */
Here’s the code of transport.snippets.php:
$snippets = array();
$snippets[1]= $modx->newObject('modSnippet');
$snippets[1]->fromArray(array(
'id' => 1,
'name' => 'SPForm',
'description' => 'SPForm '.$package_version.'-'.$package_release
.' - Creates a contact form for your site',
),'',true,true);
$snippets[1]->setContent(file_get_contents($sources['source_core'] . '/spform.inc.php'));
$properties = include $sources['data'].'properties.spform.php';
$snippets[1]->setProperties($properties);
unset($properties);
$snippets[2]= $modx->newObject('modSnippet');
$snippets[2]->fromArray(array(
'id' => 2,
'name' => 'SPFResponse',
'description' => 'SPForm "Thank You" page',
),'',true,true);
$snippets[2]->setContent(file_get_contents($sources['source_core'] . '/spfresponse.inc.php'));
$properties = include $sources['data'].'properties.spfresponse.php';
$snippets[2]->setProperties($properties);
unset($properties);
return $snippets;
On uninstall, the category is removed but the snippets and chunks are not. Is there some change I can make to build.transport.php that will cause them to be removed automatically on uninstall (or is this a bug)?