<?php
define(MODX_CORE_PATH, '/path/to/a/valid/core/');
define(MODX_CONFIG_KEY, 'config');
require_once (MODX_CORE_PATH . 'model/modx/modx.class.php');
$modx= new modX();
$modx->initialize('mgr');
// set debugging on so you can see what's happening
$modx->setDebug(true);
// setup some variables to use
$name = 'filedownload';
$version = '2.5.97';
$release = 'beta-1';
// load the modPackageBuilder class and get an instance
$modx->loadClass('transport.modPackageBuilder','',false, true);
$builder = new modPackageBuilder($modx);
// create a new package
$builder->create($name, $version, $release);
// define some locations for file resources
$sources= array (
'root' => dirname(dirname(__FILE__)) . '/',
'assets' => dirname(dirname(__FILE__)) . '/assets/'
);
// get the source from the actual snippet in your database
//$c= $modx->getObject('modSnippet', array('name', 'FileDownload'));
// OR
// manually create the object, grabbing the source from a file
$c= $modx->newObject('modSnippet');
$c->set('name', 'FileDownload');
$c->set('description', '<strong>' . $version . ' ' . $release . '</strong> FileDownload for MODx 0.9.7');
$c->set('snippet', file_get_contents($sources['root'] . 'snippet.filedownload.php'));
// set up some attributes that define install behavior
$attributes= array(
XPDO_TRANSPORT_UNIQUE_KEY => 'name',
XPDO_TRANSPORT_PRESERVE_KEYS => true,
XPDO_TRANSPORT_UPDATE_OBJECT => true,
);
// create a transport vehicle for the data object
$vehicle = $builder->createVehicle($c, $attributes);
$vehicle->resolve('file',array(
'source' => $sources['assets'] . 'snippets/filedownload',
'target' => "return MODX_ASSETS_PATH . 'snippets/';",
));
// put the vehicle into the package
$builder->putVehicle($vehicle);
// zip up the package
$builder->pack();
?>[2008-05-03 14:30:02] (DEBUG @ /file:/C:/xampp/htdocs/MODx097/_build/mytransport.php)
No primary key value found for pk definition: id
[2008-05-03 14:30:02] (ERROR @ C:\xampp\htdocs\MODx097\core\xpdo\cache\xpdocachemanager.class.php : 132)
PHP warning: mkdir() [function.mkdir]: No such file or directory
[2008-05-03 14:30:02] (ERROR @ C:\xampp\htdocs\MODx097\core\xpdo\cache\xpdocachemanager.class.php : 132)
PHP warning: mkdir() [function.mkdir]: No such file or directory
...
[2008-05-03 14:30:02] (DEBUG @ /file:/C:/xampp/htdocs/MODx097/_build/mytransport.php)
Error fetching result set from statement: SELECT `modSession`.`id` AS `modSession_id`, `modSession`.`access` AS `modSession_access`, `modSession`.`data` AS `modSession_data` FROM `modx_session` AS `modSession` WHERE `modSession`.`id` = ? with bindings: Array
(
[0] => Array
(
[value] => 0ea2dd75cbe4db2caaf382f48f74e748
[type] => 2
[length] => 0
)
)
[2008-05-03 14:30:02] (WARN @ /file:/C:/xampp/htdocs/MODx097/_build/mytransport.php)
Error fetching result set from query: SELECT `modSession`.`id` AS `modSession_id`, `modSession`.`access` AS `modSession_access`, `modSession`.`data` AS `modSession_data` FROM `modx_session` AS `modSession` WHERE `modSession`.`id` = ? Array
(
[0] => 00000
)
...
2008-05-03 14:30:02] (DEBUG @ /file:/C:/xampp/htdocs/MODx097/_build/mytransport.php)
Returning validation rules: Array
(
)
[2008-05-03 14:30:02] (INFO @ /file:/C:/xampp/htdocs/MODx097/_build/mytransport.php)
Validation called but no rules were found.

[2008-05-03 14:30:02] (ERROR @ C:\xampp\htdocs\MODx097\core\xpdo\cache\xpdocachemanager.class.php : 132) PHP warning: mkdir() [function.mkdir]: No such file or directory
If you run it from the web, it’ll work fine. For the time being, I do not have a proper handler for using the CLI interface with the modX class where sessions are not allowed, but the errors in this regard are ignorable. As are the ones related to validation. If you comment out the $modx->setDebug(true) line, you won’t see any of these messages except the actual ERROR level message:
[2008-05-03 14:30:02] (ERROR @ C:\xampp\htdocs\MODx097\core\xpdo\cache\xpdocachemanager.class.php : 132) PHP warning: mkdir() [function.mkdir]: No such file or directory
This makes me think there may be an issue with the permissions on your /core/cache or core/packages/ directory? Not sure on this one.
function writeTree($dirname, $mode= 0777) {
$written= false;
if (!empty ($dirname)) {
$dirname= strtr(trim($dirname), '\\', '/');
if ($dirname{strlen($dirname) - 1} == '/') $dirname = substr($dirname, 0, strlen($dirname) - 1);
-->>> [color=red] if (is_dir($dirname) || @mkdir($dirname, $mode)) {[/color]
$written= true;
} elseif (!$this->writeTree(dirname($dirname), $mode)) {
$written= false;
} else {
$written= @ mkdir($dirname, $mode);
}
if ($written && !is_writable($dirname)) {
@ chmod($dirname, $mode);
}
}
if (!$written) {
$this->xpdo->_log(XPDO_LOG_LEVEL_ERROR, "Could not create directory {$dirname}");
}
return $written;
}
Ah, yes that is by design; I believe the modErrorHandler class just needs to be adjusted to not log the suppressed errors unless an option is set.