$package = new xPDOTransport($xpdo, $signature, $directory); $namespace = new modNamespace($xpdo); $namespace->fromArray(['id' => PKG_NAME_LOWER, 'name' => PKG_NAME_LOWER, 'path' => '{core_path}components/' . PKG_NAME_LOWER . '/']); $package->put($namespace, [xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RESOLVE_FILES => true, xPDOTransport::RESOLVE_PHP => true, xPDOTransport::NATIVE_KEY => PKG_NAME_LOWER, 'namespace' => PKG_NAME_LOWER, 'package' => 'modx', 'resolve' => null, 'validate' => null]); $settings = (include $sources['data'] . 'transport.settings.php'); foreach ($settings as $setting) { $package->put($setting, [xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, 'class' => 'modSystemSetting', 'resolve' => null, 'validate' => null, 'package' => 'modx']); } $validators = []; array_push($validators, ['type' => 'php', 'source' => $sources['validators'] . 'validate.phpversion.php']); $resolvers = []; foreach ($sources['core'] as $file) { $directory = dirname($file); array_push($resolvers, ['type' => 'file', 'source' => $root . 'core/' . $file, 'target' => "return MODX_CORE_PATH . '{$directory}/';"]); } array_push($resolvers, ['type' => 'php', 'source' => $sources['resolvers'] . 'resolve.extension.php'], ['type' => 'php', 'source' => $sources['resolvers'] . 'resolve.settings.php']); $category = new modCategory($xpdo); $category->fromArray(['id' => 1, 'category' => PKG_NAME, 'parent' => 0]); $plugins = (include $sources['data'] . 'transport.plugins.php'); if (is_array($plugins)) { $category->addMany($plugins, 'Plugins'); } $package->put($category, [xPDOTransport::UNIQUE_KEY => 'category', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::ABORT_INSTALL_ON_VEHICLE_FAIL => true, xPDOTransport::RELATED_OBJECTS => true, xPDOTransport::RELATED_OBJECT_ATTRIBUTES => ['Plugins' => [xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::RELATED_OBJECTS => true], 'PluginEvents' => [xPDOTransport::UNIQUE_KEY => ['pluginid', 'event'], xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::RELATED_OBJECTS => true]], xPDOTransport::NATIVE_KEY => true, 'package' => 'modx', 'validate' => $validators, 'resolve' => $resolvers]); $package->setAttribute('changelog', file_get_contents($sources['docs'] . 'changelog.txt')); $package->setAttribute('license', file_get_contents($sources['docs'] . 'license.txt')); $package->setAttribute('readme', file_get_contents($sources['docs'] . 'readme.txt')); $package->setAttribute('requires', ['php' => '>=5.4']); $package->setAttribute('setup-options', ['source' => $sources['build'] . 'setup.options.php']); if ($package->pack()) { $xpdo->log(xPDO::LOG_LEVEL_INFO, "Package built"); }
$namespace->set('assets_path', '{assets_path}components/' . PKG_NAME_LOWER . '/'); $attributes = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true); $package->put($namespace, $attributes); $modx->log(xPDO::LOG_LEVEL_INFO, 'Added namespace ' . PKG_NAME_LOWER); flush(); /** @var array $attributes */ $attributes = array('vehicle_class' => 'xPDOFileVehicle'); $files = array(); $files[] = array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';"); /*$files[] = array( 'source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';", );*/ foreach ($files as $fileset) { $package->put($fileset, $attributes); } $modx->log(xPDO::LOG_LEVEL_INFO, 'Added ' . count($files) . ' file locations.'); flush(); /* now pack in the license file, readme and setup options */ $attributes = array('readme' => file_get_contents($sources['source_core'] . '/docs/readme.txt'), 'license' => file_get_contents($sources['source_core'] . '/docs/license.txt'), 'changelog' => file_get_contents($sources['source_core'] . '/docs/changelog.txt')); foreach ($attributes as $k => $v) { $package->setAttribute($k, $v); } $modx->log(xPDO::LOG_LEVEL_INFO, 'Added package attributes.'); flush(); /* zip up the package */ $package->pack(); $tend = explode(" ", microtime()); $tend = $tend[1] + $tend[0]; $totalTime = sprintf("%2.4f s", $tend - $tstart); $modx->log(xPDO::LOG_LEVEL_INFO, 'Transport package created. Execution time: ' . $totalTime);