} } $vehicle = $builder->createVehicle($category, $attr); /* now pack in resolvers */ $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/';")); foreach ($BUILD_RESOLVERS as $resolver) { if ($vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.' . $resolver . '.php'))) { $modx->log(modX::LOG_LEVEL_INFO, 'Added resolver "' . $resolver . '" to category.'); } else { $modx->log(modX::LOG_LEVEL_INFO, 'Could not add resolver "' . $resolver . '" to category.'); } } flush(); $builder->putVehicle($vehicle); $builder->setPackageAttributes(array('changelog' => file_get_contents($sources['docs'] . 'changelog.txt'), 'license' => file_get_contents($sources['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'))); $modx->log(modX::LOG_LEVEL_INFO, 'Added package attributes and setup options.'); /* zip up package */ $modx->log(modX::LOG_LEVEL_INFO, 'Packing up transport package zip...'); $builder->pack(); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime); $signature = $builder->getSignature(); $signature = $builder->getSignature(); if (defined('PKG_AUTO_INSTALL') && PKG_AUTO_INSTALL) { $sig = explode('-', $signature); $versionSignature = explode('.', $sig[1]);
} else { $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attributes); $builder->putVehicle($vehicle); } $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($settings) . ' System Settings.'); } unset($settings, $setting, $attributes); //-- ADD IN THE CONTEXT MENU ITEMS $modx->log(modX::LOG_LEVEL_INFO, 'Packaging in menu...'); $menu = (include $sources['data'] . 'transport.menu.php'); if (empty($menu)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in menu.'); } $vehicle = $builder->createVehicle($menu, array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'text', xPDOTransport::RELATED_OBJECTS => true, xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array('Action' => array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => array('namespace', 'controller'))))); $modx->log(modX::LOG_LEVEL_INFO, 'Adding in PHP resolvers...'); $vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.tables.php')); $builder->putVehicle($vehicle); unset($vehicle, $menu); //-- ADD DOCS (changelog, license) TO THE PACKAGE $modx->log(modX::LOG_LEVEL_INFO, 'Adding package attributes and setup options...'); $builder->setPackageAttributes(array('license' => file_get_contents($sources['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'), 'changelog' => file_get_contents($sources['docs'] . 'changelog.txt'), 'setup-options' => array('source' => $sources['build'] . 'setup.options.php'))); /* zip up package */ $modx->log(modX::LOG_LEVEL_INFO, 'Packing up transport package zip...'); $builder->pack(); $tend = explode(" ", microtime()); $tend = $tend[1] + $tend[0]; $totalTime = sprintf("%2.4f s", $tend - $tstart); $modx->log(modX::LOG_LEVEL_INFO, "\n<br />Package Built.<br />\nExecution time: {$totalTime}\n"); exit;
/* create a transport vehicle for the data object */ $vehicle = $builder->createVehicle($snippet,array( xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name', )); $vehicle->resolve('file',array( 'source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';", )); $builder->putVehicle($vehicle); /* now pack in the license file, readme and setup options */ $builder->setPackageAttributes(array( 'license' => file_get_contents($sources['source_core'] . '/docs/license.txt'), 'readme' => file_get_contents($sources['source_core'] . '/docs/readme.txt'), 'changelog' => file_get_contents($sources['source_core'] . '/docs/changelog.txt'), )); /* zip up the package */ $builder->pack(); $mtime= microtime(); $mtime= explode(" ", $mtime); $mtime= $mtime[1] + $mtime[0]; $tend= $mtime; $totalTime= ($tend - $tstart); $totalTime= sprintf("%2.4f s", $totalTime); $modx->log(xPDO::LOG_LEVEL_INFO, "Package Built."); $modx->log(xPDO::LOG_LEVEL_INFO, "Execution time: {$totalTime}");
$attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attributes); $builder->putVehicle($vehicle); } $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($settings) . ' System Settings.'); unset($settings, $setting, $attributes); } } /* Next-to-last step - pack in the license file, readme.txt, changelog, * and setup options */ $attr = array('license' => file_get_contents($sources['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'), 'changelog' => file_get_contents($sources['docs'] . 'changelog.txt')); if (!empty($props['install.options'])) { $attr['setup-options'] = array('source' => $sources['install_options'] . 'user.input.php'); } else { $attr['setup-options'] = array(); } $builder->setPackageAttributes($attr); /* Last step - zip up the package */ $builder->pack(); /* report how long it took */ $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime); $modx->log(xPDO::LOG_LEVEL_INFO, "Package Built."); $modx->log(xPDO::LOG_LEVEL_INFO, "Execution time: {$totalTime}"); exit;
$vehicle = $builder->createVehicle($category, $attr); $vehicles[] = $vehicle; /* CONTEXT */ $attr = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => 'key'); $vehicle = $builder->createVehicle($context, $attr); $vehicles[] = $vehicle; /* USER GROUP */ $attr = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => 'name'); $vehicle = $builder->createVehicle($usergroup, $attr); $vehicles[] = $vehicle; /* Resolve the files on the last vehicle */ $vehicle = end($vehicles); $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/';")); $vehicle->resolve('php', array('type' => 'php', 'source' => $sources['resolvers'] . 'resolver.php')); /* Pack the vehicles*/ foreach ($vehicles as $vehicle) { $builder->putVehicle($vehicle); } /* Pack in the license file, readme and setup options */ $builder->setPackageAttributes(array('license' => file_get_contents($sources['docs'] . 'LICENSE.txt'), 'readme' => file_get_contents($sources['docs'] . 'README.txt'))); /* zip up the package */ $builder->pack(); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime); echo "\nExecution time: {$totalTime}\n"; exit;
$vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); foreach ($BUILD_RESOLVERS as $resolver) { if ($vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.' . $resolver . '.php'))) { $modx->log(modX::LOG_LEVEL_INFO, 'Added resolver "' . $resolver . '" to category.'); } else { $modx->log(modX::LOG_LEVEL_INFO, 'Could not add resolver "' . $resolver . '" to category.'); } } flush(); $builder->putVehicle($vehicle); /* now pack in the license file, readme and setup options */ $package_attributes = array('changelog' => file_get_contents($sources['docs'] . 'changelog.txt'), 'license' => file_get_contents($sources['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'), 'chunks' => $BUILD_CHUNKS, 'setup-options' => array('source' => $sources['build'] . 'setup.options.php')); if (file_exists($sources['build'] . 'setup.options.php')) { $package_attributes['setup-options'] = array('source' => $sources['build'] . 'setup.options.php'); } $builder->setPackageAttributes($package_attributes); $modx->log(modX::LOG_LEVEL_INFO, 'Added package attributes and setup options.'); /* zip up package */ $modx->log(modX::LOG_LEVEL_INFO, 'Packing up transport package zip...'); $builder->pack(); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime); $signature = $builder->getSignature(); if (defined('PKG_AUTO_INSTALL') && PKG_AUTO_INSTALL) { $sig = explode('-', $signature); $versionSignature = explode('.', $sig[1]); /* @var modTransportPackage $package */
} else { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not set plugin properties.'); } $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RELATED_OBJECTS => true, xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array('PluginEvents' => array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => array('pluginid', 'event')))); $vehicle = $builder->createVehicle($plugin, $attributes); $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/';")); $vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.whicheditor.php')); $builder->putVehicle($vehicle); /* load system settings */ $settings = (include $sources['data'] . 'transport.settings.php'); $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attributes); $builder->putVehicle($vehicle); } /* now pack in the license file, readme and setup options */ $modx->log(xPDO::LOG_LEVEL_INFO, 'Setting Package Attributes...'); flush(); $builder->setPackageAttributes(array('license' => file_get_contents($sources['docs'] . 'license.txt'))); $modx->log(xPDO::LOG_LEVEL_INFO, 'Zipping up package...'); flush(); $builder->pack(); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime); $modx->log(modX::LOG_LEVEL_INFO, "\n<br />Package Built.<br />\nExecution time: {$totalTime}\n"); exit;
$vehicle = $builder->createVehicle($Setting, $attributes); $builder->putVehicle($vehicle); $Setting = $modx->newObject('modSystemSetting'); $Setting->fromArray(array('key' => 'gmarker.region', 'value' => '', 'xtype' => 'textfield', 'namespace' => PKG_NAME_LOWER, 'area' => 'default'), '', true, true); $vehicle = $builder->createVehicle($Setting, $attributes); $builder->putVehicle($vehicle); //------------------------------------------------------------------------------ //! Files //------------------------------------------------------------------------------ /* // Assets $vehicle->resolve('file', array( 'source' => MODX_ASSETS_PATH .'components/'.PKG_NAME_LOWER.'/assets/components/'.PKG_NAME_LOWER, 'target' => "return MODX_ASSETS_PATH . 'components/';", )); $builder->putVehicle($vehicle); */ // Core: TODO - this shouldn't be hard-coded! $vehicle->resolve('file', array('source' => MODX_ASSETS_PATH . 'components/' . PKG_NAME_LOWER . '/core/components/' . PKG_NAME_LOWER, 'target' => "return MODX_CORE_PATH . 'components/';")); $builder->putVehicle($vehicle); //------------------------------------------------------------------------------ //! DOCS //------------------------------------------------------------------------------ $builder->setPackageAttributes(array('license' => file_get_contents(MODX_ASSETS_PATH . 'components/' . PKG_NAME_LOWER . '/core/components/' . PKG_NAME_LOWER . '/docs/license.txt'), 'readme' => file_get_contents(MODX_ASSETS_PATH . 'components/' . PKG_NAME_LOWER . '/core/components/' . PKG_NAME_LOWER . '/docs/readme.txt'), 'changelog' => file_get_contents(MODX_ASSETS_PATH . 'components/' . PKG_NAME_LOWER . '/core/components/' . PKG_NAME_LOWER . '/docs/changelog.txt'))); // Add everything we put into the category $vehicle = $builder->createVehicle($Category, $cat_attributes); $builder->putVehicle($vehicle); // Zip up the package $builder->pack(); echo '<br/>Package complete. Check your ' . MODX_CORE_PATH . 'packages/ directory for the newly created package.'; /*EOF*/
public function setPackageAttributes($attributes) { $this->builder->setPackageAttributes($attributes); }
/** * Unified build script: build a MODX transport package from files contained * inside $pkg_root_dir * * @param string $pkg_root_dir path to local package root (w trailing slash) * * @throws Exception */ public function build($pkg_root_dir) { $pkg_root_dir = self::get_dir($pkg_root_dir); $this->build_prep($pkg_root_dir); $this->config['is_build'] = true; // TODO $this->config['force_static'] = false; // TODO $required = array('package_name', 'namespace', 'version', 'release'); foreach ($required as $k) { if (!$this->get($k)) { throw new Exception('Missing required configuration parameter: ' . $k); } } $this->modx->log(modX::LOG_LEVEL_INFO, 'Beginning build of package "' . $this->get('package_name') . '"'); $this->modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($this->modx); $sanitized_package_name = $this->get('package_name'); $builder->createPackage($sanitized_package_name, $this->get('version'), $this->get('release')); $builder->registerNamespace($this->get('namespace'), false, true, '{core_path}components/' . $this->get('namespace') . '/'); // Tests (Validators): this is run BEFORE your package code is in place // so you cannot reference/include package files from your validator! They won't exist when the code is run. $validator_file = $this->get_core_path($pkg_root_dir) . rtrim($this->get('validators_dir'), '/') . '/install.php'; if (file_exists($validator_file)) { $this->modx->log(modX::LOG_LEVEL_INFO, 'Packaging validator ' . $validator_file); $config = $this->config; $config['source'] = $validator_file; $validator_attributes = array('vehicle_class' => 'xPDOScriptVehicle', 'source' => $validator_file, xPDOTransport::ABORT_INSTALL_ON_VEHICLE_FAIL => $this->get('abort_install_on_fail')); $vehicle = $builder->createVehicle($config, $validator_attributes); $builder->putVehicle($vehicle); } else { $this->modx->log(modX::LOG_LEVEL_DEBUG, 'No validator detected at ' . $validator_file); } $Category = $this->modx->newObject('modCategory'); $Category->set('category', $this->get('category')); // Import Elements $chunks = self::_get_elements('modChunk', $pkg_root_dir); $plugins = self::_get_elements('modPlugin', $pkg_root_dir); $snippets = self::_get_elements('modSnippet', $pkg_root_dir); $tvs = self::_get_elements('modTemplateVar', $pkg_root_dir); $templates = self::_get_elements('modTemplate', $pkg_root_dir); if ($chunks) { $Category->addMany($chunks); } if ($plugins) { $Category->addMany($plugins); } if ($snippets) { $Category->addMany($snippets); } if ($templates) { $Category->addMany($templates); } if ($tvs) { $Category->addMany($tvs); } // TODO: skip this if there are no elements //if (empty($chunks) && empty($plugins) && empty($snippets) && empty($templates) && empty($tvs)) { $build_attributes = array(); $build_attributes = $this->get_build_attributes($Category, 'modCategory'); $this->modx->log(modX::LOG_LEVEL_DEBUG, 'build_attributes for ' . $Category->_class . "\n" . print_r($build_attributes, true)); $vehicle = $builder->createVehicle($Category, $build_attributes); //} //$builder->putVehicle($vehicle); // Files...: TODO: these need their own builder // We package these from the temporary copies inside of repoman's cache. // Assets if (file_exists($this->build_assets_path) && is_dir($this->build_assets_path)) { $this->modx->log(modX::LOG_LEVEL_INFO, 'Packing assets from ' . $this->build_assets_path); $vehicle->resolve('file', array('source' => rtrim($this->build_assets_path, '/'), 'target' => "return MODX_ASSETS_PATH . 'components/';")); } // Core if (file_exists($this->build_core_path) && is_dir($this->build_core_path)) { $this->modx->log(modX::LOG_LEVEL_INFO, 'Packing core files from ' . $this->build_core_path); $vehicle->resolve('file', array('source' => rtrim($this->build_core_path, '/'), 'target' => "return MODX_CORE_PATH . 'components/';")); } $builder->putVehicle($vehicle); // Migrations: we attach our all-purpose resolver to handle migrations $config = $this->config; $config['source'] = dirname(__FILE__) . '/resolver.php'; $attributes = array('vehicle_class' => 'xPDOScriptVehicle'); $vehicle = $builder->createVehicle($config, $attributes); $builder->putVehicle($vehicle); // Add Version Setting $repoman_version_build_attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true); $VersionSetting = $this->modx->newObject('modSystemSetting'); $VersionSetting->set('key', $this->get('namespace') . '.version'); $VersionSetting->set('value', $this->get('version')); $VersionSetting->set('xtype', 'textfield'); $VersionSetting->set('namespace', $this->get('namespace')); $VersionSetting->set('area', $this->get('namespace') . ':default'); $vehicle = $builder->createVehicle($VersionSetting, $repoman_version_build_attributes); $builder->putVehicle($vehicle); // Optionally Load Seed data $dirs = $this->get_seed_dirs($pkg_root_dir); foreach ($dirs as $d) { $objects = $this->crawl_dir($d); foreach ($objects as $classname => $info) { foreach ($info as $k => $Obj) { $build_attributes = $this->get_build_attributes($Obj, $classname); $this->modx->log(modX::LOG_LEVEL_DEBUG, $classname . ' created'); $vehicle = $builder->createVehicle($Obj, $build_attributes); $builder->putVehicle($vehicle); } } } // Package Attributes (Documents) $dir = $this->get_docs_path($pkg_root_dir); // defaults $docs = array('readme' => 'This package was built using Repoman (https://github.com/craftsmancoding/repoman/)', 'changelog' => 'No change log defined.', 'license' => file_get_contents(dirname(dirname(dirname(__FILE__))) . '/docs/license.txt')); if (file_exists($dir) && is_dir($dir)) { $files = array(); $build_docs = $this->get('build_docs'); if (!empty($build_docs) && is_array($build_docs)) { foreach ($build_docs as $d) { $files[] = $dir . $d; } } else { $files = glob($dir . '*.{html,txt}', GLOB_BRACE); } foreach ($files as $f) { $stub = basename($f, '.txt'); $stub = basename($stub, '.html'); $docs[$stub] = file_get_contents($f); if (strtolower($stub) == 'readme') { $docs['readme'] = $docs['readme'] . "\n\n" . 'This package was built using Repoman (https://github.com/craftsmancoding/repoman/)'; } $this->modx->log(modX::LOG_LEVEL_INFO, "Adding doc {$stub} from {$f}"); } } else { $this->modx->log(modX::LOG_LEVEL_INFO, 'No documents found in ' . $dir); } $builder->setPackageAttributes($docs); // Zip up the package $builder->pack(); $zip = strtolower($sanitized_package_name) . '-' . $this->get('version') . '-' . $this->get('release') . '.transport.zip'; $this->modx->log(modX::LOG_LEVEL_INFO, 'Build complete: ' . MODX_CORE_PATH . 'packages/' . $zip); if (!file_exists(MODX_CORE_PATH . 'packages/' . $zip)) { throw new Exception('Transport package not created: ' . $zip . ' Please review the logs.'); } }
'source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';", )); */ $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); foreach ($BUILD_RESOLVERS as $resolver) { if ($vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.' . $resolver . '.php'))) { $modx->log(modX::LOG_LEVEL_INFO, 'Added resolver "' . $resolver . '" to category.'); } else { $modx->log(modX::LOG_LEVEL_INFO, 'Could not add resolver "' . $resolver . '" to category.'); } } flush(); $builder->putVehicle($vehicle); /* now pack in the license file, readme and setup options */ $builder->setPackageAttributes(array('changelog' => file_get_contents($sources['docs'] . 'changelog.txt'), 'license' => file_get_contents($sources['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'), 'chunks' => @$BUILD_CHUNKS, 'setup-options' => array('source' => $sources['build'] . 'setup.options.php'), 'resolve_files_remove' => false)); $modx->log(modX::LOG_LEVEL_INFO, 'Added package attributes and setup options.'); /* zip up package */ $modx->log(modX::LOG_LEVEL_INFO, 'Packing up transport package zip...'); $builder->pack(); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tend = $mtime; $totalTime = $tend - $tstart; $totalTime = sprintf("%2.4f s", $totalTime); $signature = $builder->getSignature(); if (defined('PKG_AUTO_INSTALL') && PKG_AUTO_INSTALL) { $sig = explode('-', $signature); $versionSignature = explode('.', $sig[1]); /* @var modTransportPackage $package */