*/ $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage('churchevents', '0.3', 'beta2'); //name, version, and release $builder->registerNamespace('churchevents', false, true, '{core_path}components/churchevents/'); // create system settings: $settings = array(); $settings['churchevents.allowRequests'] = $modx->newObject('modSystemSetting'); $settings['churchevents.allowRequests']->fromArray(array('key' => 'churchevents.allowRequests', 'value' => false, 'xtype' => 'combo-boolean', 'namespace' => 'churchevents', 'area' => 'ChurchEvents'), '', true, true); $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_FATAL, 'Adding settings failed.'); } foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attributes); $builder->putVehicle($vehicle); } $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($settings) . ' system settings.'); flush(); unset($settings, $setting, $attributes); // Packaging in Objects /* create category for orginization: */ $category = $modx->newObject('modCategory'); $category->set('id', 1); $category->set('category', 'ChurchEvents'); /* 1. Pack Snippet So, let's look at some examples for creating a vehicle before digging into our build script. This first example packages in a simple object, with some parameters: */
# include_once $sources['builder_includes'] . 'system.events.php'; /* * Create Category */ include_once $sources['builder_includes'] . 'category.php'; /* add plugins */ # include_once $sources['builder_includes'] . 'plugins.php'; /* add snippets */ include_once $sources['builder_includes'] . 'snippets.php'; /* add chunks */ include_once $sources['builder_includes'] . 'chunks.php'; /* * Create category vehicle */ include_once $sources['builder_includes'] . 'category.attributes.php'; $vehicle = $builder->createVehicle($category, $attr); // eof Create Category /* * Adding sources (3 sources by default) */ include_once $sources['resolvers'] . 'resolver.sources.php'; /* * Adding resolvers */ $modx->log(modX::LOG_LEVEL_INFO, 'Adding in PHP resolvers...'); flush(); include_once $sources['builder_includes'] . 'resolver.tables.wrapper.php'; include_once $sources['builder_includes'] . 'resolver.register.wrapper.php'; // eof adding resolvers $builder->putVehicle($vehicle); /*
if (!XPDO_CLI_MODE) { echo '<pre>'; } $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, PKG_NAMESPACE_PATH); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); /* load system settings */ if (defined('BUILD_SETTING_UPDATE')) { $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.'); } else { $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => BUILD_SETTING_UPDATE); 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); } /* load plugins events */ if (defined('BUILD_EVENT_UPDATE')) { $events = (include $sources['data'] . 'transport.events.php'); if (!is_array($events)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in events.'); } else { $attributes = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => BUILD_EVENT_UPDATE); foreach ($events as $event) { $vehicle = $builder->createVehicle($event, $attributes);
$builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); /* create plugin object */ $modx->log(xPDO::LOG_LEVEL_INFO, 'Adding in snippet.'); flush(); $object = $modx->newObject('modSnippet'); $object->set('name', PKG_NAME); $object->set('description', '<strong>' . PKG_VERSION . '-' . PKG_RELEASE . '</strong> Basic snippet for ' . PKG_NAME . '.'); $object->set('category', 0); $object->set('snippet', getSnippetContent($sources['snippets'] . 'snippet.multimedialibrary.php')); $properties = (include $sources['data'] . 'snippet.multimedialibrary.properties.php'); $object->setProperties($properties); unset($properties); /* create a transport vehicle for the data object */ $vehicle = $builder->createVehicle($object, 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/';")); $vehicle->resolve('file', array('source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';")); $builder->putVehicle($vehicle); /* SYSTEM SETTING */ /* ------------------------------------------------------ */ $modx->log(xPDO::LOG_LEVEL_INFO, 'Adding in system setting.'); flush(); $settings = array(); $settings = (include $sources['data'] . 'system.settings.php'); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false)); $builder->putVehicle($vehicle); } $modx->log(modX::LOG_LEVEL_INFO, 'Adding in PHP resolvers...'); $vehicle->resolve('php', array('source' => $sources['resolvers'] . 'resolve.tables.php'));
$modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); /* add plugin */ $plugin = $modx->newObject('modPlugin'); $plugin->fromArray(array('id' => 1, 'name' => 'ActiveDirectory', 'description' => '', 'plugincode' => getSnippetContent($sources['plugins'] . 'plugin.activedirectory.php')), '', true, true); $events = (include $sources['data'] . 'events/events.activedirectory.php'); if (is_array($events) && !empty($events)) { $modx->log(modX::LOG_LEVEL_INFO, 'Added ' . count($events) . ' events to ActiveDirectory plugin.'); $plugin->addMany($events); } unset($events); $attributes = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name', 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); $modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers to plugin...'); $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'] . 'resolver.extpack.php')); /* $vehicle->resolve('php',array( 'source' => $sources['resolvers'] . 'resolver.patch.php', ));*/ $builder->putVehicle($vehicle); unset($vehicle, $attributes, $plugin); /* load system settings */ $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.'); } else {
public function __construct($builder, $smarty, $object, $attributes) { $this->builder = $builder; $this->smarty = $smarty; $this->vehicle = $this->builder->createVehicle($object, $attributes); }
$builder->registerNamespace('quickcrumbs', false, true, '{core_path}components/quickcrumbs/'); /* create snippet object */ $modx->log(xPDO::LOG_LEVEL_INFO, 'Adding in snippet.'); flush(); $snippet = $modx->newObject('modSnippet'); $snippet->set('name', 'QuickCrumbs'); $snippet->set('description', '<strong>' . PKG_VERSION . '-' . PKG_RELEASE . '</strong> A quick and efficient bread crumbs snippet for MODx Revolution'); $snippet->set('category', 0); $snippet->set('snippet', file_get_contents($sources['source_core'] . '/quickcrumbs.snippet.php')); $properties = (include $sources['build'] . 'properties.inc.php'); if (!empty($properties)) { $snippet->setProperties($properties); } unset($properties); /* 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['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'), 'changelog' => file_get_contents($sources['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}"); exit;
echo '<pre>'; flush(); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); $modx->getService('lexicon', 'modLexicon'); $modx->lexicon->load(PKG_NAME_LOWER . ':properties'); /* load action/menu */ $attributes = 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')))); /* add namespace */ $namespace = $modx->newObject('modNamespace'); $namespace->set('name', NAMESPACE_NAME); $namespace->set('path', "{core_path}components/" . PKG_NAME_LOWER . "/"); $namespace->set('assets_path', "{assets_path}components/" . PKG_NAME_LOWER . "/"); $vehicle = $builder->createVehicle($namespace, array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true)); $builder->putVehicle($vehicle); $modx->log(modX::LOG_LEVEL_INFO, "Packaged in " . NAMESPACE_NAME . " namespace."); flush(); unset($vehicle, $namespace); /* create category */ $category = $modx->newObject('modCategory'); $category->set('id', 1); $category->set('category', PKG_NAME); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in category.'); flush(); /* create category vehicle */ $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'), 'Plugins' => array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'), 'PluginEvents' => array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => array('pluginid', 'event')), 'Templates' => array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'templatename'), 'TemplateVars' => array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'))); /* add plugins */ $plugins = (include $sources['data'] . 'transport.plugins.php'); if (!is_array($plugins)) {
$assets = MODX_ASSETS_PATH . 'components/' . PKG_NAME_LOWER . '/'; $sources = array('root' => $root, 'build' => $root . '_build/', 'resolvers' => $root . '_build/resolvers/', 'data' => $root . '_build/data/', 'properties' => $root . '_build/properties/', 'events' => $root . '_build/data/events/', 'source_core' => $root . 'core/components/' . PKG_NAME_LOWER, 'source_assets' => $root . 'assets/components/' . PKG_NAME_LOWER, 'plugins' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/plugins/', 'snippets' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/snippets/', 'lexicon' => $root . 'core/components/' . PKG_NAME_LOWER . '/lexicon/', 'docs' => $root . 'core/components/' . PKG_NAME_LOWER . '/docs/'); unset($root); $modx->initialize('mgr'); echo '<pre>'; $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); /* package snippets */ $snippet = (include $sources['data'] . 'transport.snippets.php'); $attr = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'); $i = 1; $vehicle = $builder->createVehicle($snippet, $attr); $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged core folder.'); flush(); $vehicle->resolve('file', array('source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';")); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged assets folder.'); flush(); $vehicle->resolve('php', array('source' => $sources['resolvers'] . 'dbchanges.resolver.php')); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged resolvers.'); flush(); $builder->putVehicle($vehicle); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged snippet.'); flush(); /* load system settings */ $settings = (include_once $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) {
$modx->initialize('mgr'); $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); echo '<pre>'; flush(); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); //------------------------------------------------------------------------------ //! Categories //------------------------------------------------------------------------------ $cat_attributes = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => array('category'), 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'), 'Plugins' => array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array('PluginEvents' => array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => array('pluginid', 'event')))))); $Category = $modx->newObject('modCategory'); $Category->set('category', PKG_NAME); $vehicle = $builder->createVehicle($Category, $cat_attributes); $builder->putVehicle($vehicle); //------------------------------------------------------------------------------ //! Snippets //------------------------------------------------------------------------------ // Not used: see $cat_attributes $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RELATED_OBJECTS => true, xPDOTransport::RELATED_OBJECT_ATTRIBUTES => $cat_attributes); $Snippet = $modx->newObject('modSnippet'); $Snippet->fromArray(array('name' => 'Glocation', 'description' => '<strong>Version ' . PKG_VERSION . '-' . PKG_RELEASE . '</strong> lookup latitude and longitude from a given address and set a series of placeholders. The results for any address are returned from cache whenever possible', 'snippet' => file_get_contents('../core/components/' . PKG_NAME_LOWER . '/elements/snippets/snippet.Glocation.php'))); $Category->addMany($Snippet); $Snippet = $modx->newObject('modSnippet'); $Snippet->fromArray(array('name' => 'Gmap', 'description' => '<strong>Version ' . PKG_VERSION . '-' . PKG_RELEASE . '</strong> Draws a Google Map of the area specified by &address or &latlng.', 'snippet' => file_get_contents('../core/components/' . PKG_NAME_LOWER . '/elements/snippets/snippet.Gmap.php'))); $Category->addMany($Snippet); $Snippet = $modx->newObject('modSnippet'); $Snippet->fromArray(array('name' => 'Gmarker', 'description' => '<strong>Version ' . PKG_VERSION . '-' . PKG_RELEASE . '</strong> A wrapper around getResources. This draws a Google Map with markers on it, e.g. if your pages contain addresses.', 'snippet' => file_get_contents('../core/components/' . PKG_NAME_LOWER . '/elements/snippets/snippet.Gmarker.php'))); $Category->addMany($Snippet);
$modx->initialize('mgr'); $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); $modx->getService('error', 'error.modError'); $modx->loadClass('transport.modPackageBuilder', '', false, true); if (!XPDO_CLI_MODE) { echo '<pre>'; } $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); //$builder->registerNamespace(PKG_NAME_LOWER, false, true, PKG_NAMESPACE_PATH); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); $attr = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'); $snippet = $modx->newObject('modSnippet'); $snippet->fromArray(array('name' => "extLinkRedirector", 'description' => '', 'snippet' => getSnippetContent($sources['source_core'] . '/elements/snippets/snippet.extlinkredirector.php')), '', true, true); $vehicle = $builder->createVehicle($snippet, $attr); flush(); $builder->putVehicle($vehicle); /* create the plugin object */ $plugin = $modx->newObject('modPlugin'); $plugin->set('id', 1); $plugin->set('name', 'extLinkRedirector'); $plugin->set('description', 'External Link Redirector plugin'); $plugin->set('plugincode', getSnippetContent($sources['source_core'] . '/elements/plugins/plugin.extlinkredirector.php')); $plugin->set('category', 0); $events = array(); $events['OnWebPagePrerender'] = $modx->newObject('modPluginEvent'); $events['OnWebPagePrerender']->fromArray(array('event' => 'OnWebPagePrerender', 'priority' => 0, 'propertyset' => 0), '', true, true); $plugin->addMany($events); /* load plugin properties */ $properties = (include $sources['data'] . 'properties.inc.php');
/** * 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.'); } }
$modx->initialize('mgr'); echo '<pre>'; $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_ABBR, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_ABBR, false, true, '{core_path}components/' . PKG_ABBR . '/'); /* load system settings */ $settings = (include_once $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_FATAL, 'No settings returned.'); } $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attributes); $builder->putVehicle($vehicle); } $modx->log(modX::LOG_LEVEL_INFO, 'Added in ' . count($settings) . ' system settings.'); flush(); unset($settings, $setting, $attributes); /* load property sets */ $propertySets = (include_once $sources['data'] . 'propertysets/transport.propertysets.php'); if (!is_array($propertySets)) { $modx->log(modX::LOG_LEVEL_FATAL, 'No property sets returned.'); } $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true); foreach ($propertySets as $propertySet) { $vehicle = $builder->createVehicle($propertySet, $attributes); $builder->putVehicle($vehicle); }
$modx->initialize('mgr'); echo '<pre>'; $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_ABBR, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_ABBR, false, true, '{core_path}components/' . PKG_ABBR . '/'); /* add snippet */ $modx->log(modX::LOG_LEVEL_INFO, 'Adding in snippet.'); flush(); $snippet = $modx->newObject('modSnippet'); $snippet->fromArray(array('id' => 0, 'name' => 'If', 'description' => 'Simple if (conditional) snippet', 'snippet' => getSnippetContent($sources['source_core'] . '/snippet.if.php')), '', true, true); $properties = (include $sources['build'] . 'properties.inc.php'); $snippet->setProperties($properties); /* create snippet vehicle */ $attr = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true); $vehicle = $builder->createVehicle($snippet, $attr); $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['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'))); $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;
/* used for nice formatting of log messages */ $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); //$builder->registerNamespace(PKG_NAME_LOWER,false,true,'{core_path}components/'.PKG_NAME_LOWER.'/'); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package.'); /* load system settings */ $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.'); } 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); /* create payment */ $payment = $modx->newObject('msPayment'); $payment->set('id', 1); $payment->set('name', 'Platron'); $payment->set('active', 0); $payment->set('class', 'Platron'); $payment->set('rank', 100); /* create payment vehicle */ $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => false); $vehicle = $builder->createVehicle($payment, $attributes);
$sources = array('root' => $root, 'build' => $root . '_build/', 'lexicon' => $root . '_build/lexicon/', 'resolvers' => $root . '_build/resolvers/', 'data' => $root . '_build/data/', 'source_core' => $root . 'core/components/xflickr', 'source_assets' => $root . 'assets/components/xflickr', 'docs' => $root . 'core/components/xflickr/docs/'); unset($root); /* override with your own defines here (see build.config.sample.php) */ require_once dirname(__FILE__) . '/build.config.php'; require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('mgr'); $modx->setLogLevel(MODX_LOG_LEVEL_INFO); $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage('xflickr', '0.1', 'alpha1'); $builder->registerNamespace('xflickr', false, true, '{core_path}components/xflickr/'); /* load action/menu */ $menu = (include $sources['data'] . 'transport.menu.php'); $vehicle = $builder->createVehicle($menu, array(XPDO_TRANSPORT_PRESERVE_KEYS => true, XPDO_TRANSPORT_UPDATE_OBJECT => true, XPDO_TRANSPORT_UNIQUE_KEY => 'text', XPDO_TRANSPORT_RELATED_OBJECTS => true, XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array('Action' => array(XPDO_TRANSPORT_PRESERVE_KEYS => false, XPDO_TRANSPORT_UPDATE_OBJECT => true, XPDO_TRANSPORT_UNIQUE_KEY => array('namespace', 'controller'))))); $builder->putVehicle($vehicle); unset($vehicle, $action); /* load system settings */ $settings = array(); include_once $sources['data'] . 'transport.settings.php'; $attributes = array(XPDO_TRANSPORT_UNIQUE_KEY => 'key', XPDO_TRANSPORT_PRESERVE_KEYS => true, XPDO_TRANSPORT_UPDATE_OBJECT => false); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attributes); $builder->putVehicle($vehicle); } unset($settings, $setting, $attributes); /* create category */ $category = $modx->newObject('modCategory'); $category->set('id', 1); $category->set('category', 'XFlickr');
$category = $modx->newObject('modCategory'); $category->set('id', 1); $category->set('category', 'MapsTv'); /* add snippets */ $modx->log(modX::LOG_LEVEL_INFO, 'Adding in snippets.'); $snippets = array(); $snippets[0] = $modx->newObject('modSnippet'); $snippets[0]->fromArray(array('id' => 1, 'name' => 'JSONtoChunk', 'description' => 'Custom output filter. If the input is an JSON array it will output the chunk you specified with placeholders for all the values.', 'snippet' => getSnippetContent($sources['source_core'] . '/elements/snippets/JSONtoChunk.snippet.php'))); if (is_array($snippets)) { $category->addMany($snippets); } else { $modx->log(modX::LOG_LEVEL_FATAL, 'Adding snippets failed.'); } /* create category vehicle */ $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'))); $vehicle = $builder->createVehicle($category, $attr); $builder->putVehicle($vehicle); // /* create category */ // $category= $modx->newObject('modCategory'); // $category->set('id',1); // $category->set('category',PKG_NAME); // $vehicle = $builder->createVehicle($category); // $category->addMany($plugin); // $snippet = $modx->newObject('modSnippet'); // $snippet->fromArray(array( // 'id' => 1, // 'name' => 'JSONtoChunk', // 'description' => 'Custom output filter. If the input is an JSON array it will output the chunk you specified with placeholders for all the values.', // 'snippet' => getSnippetContent($sources['source_core'].'/elements/snippets/JSONtoChunk.snippet.php'), // )); // $attr = array(
$release = 'pl'; $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage($name, $version, $release); $builder->registerNamespace('provisioner', false, true, '{core_path}components/provisioner/'); $base = dirname(dirname(__FILE__)) . '/'; $sources = array('root' => $base, 'assets' => $base . 'assets/components/provisioner/', 'docs' => $base . 'assets/components/provisioner/docs/', 'core' => $base . 'core/components/provisioner/', 'lexicon' => $base . 'core/components/provisioner/lexicon/', 'model' => $base . 'core/components/provisioner/model/', 'templates' => $base . 'core/components/provisioner/templates/', 'build' => $base . '_build/', 'data' => $base . '_build/data/', 'resolvers' => $base . '_build/resolvers/', 'source_core' => $base . 'core/components/provisioner', 'source_assets' => $base . 'assets/components/provisioner'); unset($base); $vehicles = array(); /* ACTIONS */ $menu = (require_once $sources['data'] . 'actions.data.php'); if (!$menu) { $modx->log(xPDO::LOG_LEVEL_FATAL, 'Menu not found!'); } $attr = 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')))); $vehicle = $builder->createVehicle($menu, $attr); $vehicles[] = $vehicle; /* SETTINGS */ require_once $sources['data'] . 'settings.data.php'; $attr = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'key'); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attr); $vehicles[] = $vehicle; } /* CATEGORY */ $attr = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => false, xPDOTransport::UNIQUE_KEY => 'category'); $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);
flush(); unset($snippets); /* add plugins */ $plugins = (include $sources['data'] . 'transport.plugins.php'); if (is_array($plugins)) { $category->addMany($plugins, 'Plugins'); } else { $plugins = array(); $modx->log(modX::LOG_LEVEL_ERROR, 'No plugins defined.'); } $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($plugins) . ' plugins.'); flush(); unset($plugins); /* create category vehicle */ $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::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true), 'Plugins' => 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($category, $attr); unset($category, $attr); $modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers ...'); $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); $vehicle->resolve('file', array('source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';")); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in folders.'); flush(); $builder->putVehicle($vehicle); /* load system settings */ $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'No settings defined.'); } else { $attr = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false); foreach ($settings as $setting) { $vehicle = $builder->createVehicle($setting, $attr);
$modx->setLogTarget('ECHO'); /* load builder */ $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); /* load system settings */ if (defined('BUILD_SETTING_UPDATE')) { $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.'); } else { $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => BUILD_SETTING_UPDATE); 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 file vehicle */ $object = array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';"); $attributes = array('vehicle_class' => 'xPDOFileVehicle'); $vehicle = $builder->createVehicle($object, $attributes); $vehicle->resolve('php', array('source' => dirname(__FILE__) . '/resolvers/resolve.settings.php')); $builder->putVehicle($vehicle); unset($object, $vehicle, $attributes); /* 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')));
$modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage('wayfinder', '2.1.1', 'rc1'); $builder->registerNamespace('wayfinder', false, true, '{core_path}components/wayfinder/'); /* get the source from the actual snippet in your database * [alternative] you could also manually create the object, grabbing the source * from a file */ $c = $modx->newObject('modSnippet'); $c->set('id', 1); $c->set('name', 'Wayfinder'); $c->set('description', 'Wayfinder for MODx Revolution 2.0.0-beta-5 and later.'); $c->set('snippet', file_get_contents($sources['source_core'] . '/wayfinder.snippet.php')); $c->set('category', 0); $properties = (include $sources['data'] . 'properties.inc.php'); $c->setProperties($properties, true); $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true); $vehicle = $builder->createVehicle($c, $attributes); $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['docs'] . 'license.txt'), 'readme' => file_get_contents($sources['docs'] . 'readme.txt'))); $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;
$builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); /* create category */ $modx->log(xPDO::LOG_LEVEL_INFO, 'Created category.'); $category = $modx->newObject('modCategory'); $category->set('id', 1); $category->set('category', PKG_NAME); /* add plugins */ $plugins = (include $sources['data'] . 'transport.plugins.php'); if (!is_array($plugins)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in plugins.'); } else { $category->addMany($plugins); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($plugins) . ' plugins.'); } $vehicle = $builder->createVehicle($category, array(xPDOTransport::UNIQUE_KEY => 'category', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RELATED_OBJECTS => true, xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array('Plugins' => array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'), 'PluginEvents' => array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => array('pluginid', 'event'))))); $modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers to category...'); $vehicle->resolve('file', array('source' => $sources['source_manager'], 'target' => "return MODX_MANAGER_PATH . 'components/';")); $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); foreach (array('extension') 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.'); } } $builder->putVehicle($vehicle); /* load system settings */ $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.');
$plugin->set('plugincode', getSnippetContent($sources['plugins'] . 'plugin.modldap.php')); //add properties to plugin $properties = (include $sources['data'] . 'plugin.modldap.properties.php'); $plugin->setProperties($properties); unset($properties); //add system events to plugin $events = (include $sources['data'] . 'plugin.modldap.event.php'); if (is_array($events) && !empty($events)) { $modx->log(modX::LOG_LEVEL_INFO, 'Added ' . count($events) . ' events to ModLDAP plugin.'); $plugin->addMany($events); } unset($events); //create vehicle for plugin $modx->log(modX::LOG_LEVEL_INFO, 'Create plugin vehicle'); flush(); $vehicle = $builder->createVehicle($plugin, array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name', 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'))))); $modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers to plugin...'); $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'] . 'resolver.modldap.php')); $builder->putVehicle($vehicle); unset($vehicle, $plugin); /* SNIPPETS */ /* ------------------------------------------------------ */ $modx->log(xPDO::LOG_LEVEL_INFO, 'Adding in plugin.'); flush(); $snippets = $modx->newObject('modSnippet'); $snippets->set('name', PKG_NAME . 'Debug'); $snippets->set('description', '<strong>' . PKG_VERSION . '-' . PKG_RELEASE . '</strong> Output data entries from LDAP'); $snippets->set('category', 0); $snippets->set('snippet', getSnippetContent($sources['snippets'] . 'snippet.modldapdebug.php'));
$modx->initialize('mgr'); echo '<pre>'; /* used for nice formatting of log messages */ $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->getService('error', 'error.modError'); $modx->setLogTarget('ECHO'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); /* add snippets */ $snippets = (include $sources['data'] . 'transport.snippets.php'); /* package in snippet */ $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true); $vehicle = $builder->createVehicle($snippets[0], $attributes); $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); $modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers to category...'); $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); $builder->putVehicle($vehicle); unset($properties, $snippet, $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'))); $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;
if (is_array($snippets)) { $category->addMany($snippets); } else { $modx->log(modX::LOG_LEVEL_FATAL, 'Adding snippets failed.'); } /* add chunks */ $modx->log(modX::LOG_LEVEL_INFO, 'Adding in chunks.'); $chunks = (include $sources['data'] . 'newspublisher/transport.chunks.php'); if (is_array($chunks)) { $category->addMany($chunks); } else { $modx->log(modX::LOG_LEVEL_FATAL, 'Adding chunks failed.'); } /* create category vehicle */ $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'))); $vehicle = $builder->createVehicle($category, $attr); $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); $vehicle->resolve('file', array('source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';")); $builder->putVehicle($vehicle); /* Add filebrowser action */ $modx->log(modX::LOG_LEVEL_INFO, 'Adding filebrowser action.'); $browserAction = (include $sources['data'] . 'transport.browseraction.php'); $vehicle = $builder->createVehicle($browserAction, array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => array('namespace', 'controller'))); $builder->putVehicle($vehicle); /* NewsPublisher access policy template */ $modx->log(modX::LOG_LEVEL_INFO, 'Adding access policy template.'); $template = (include $sources['data'] . 'transport.accesspolicytemplate.php'); $vehicle = $builder->createVehicle($template, array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name')); $modx->log(modX::LOG_LEVEL_INFO, 'Adding access policy template resolver.'); $vehicle->resolve('php', array('source' => $sources['resolvers'] . 'accesspolicytemplate.resolver.php')); $builder->putVehicle($vehicle);
$modx->log(MODX_LOG_LEVEL_INFO, 'Creating a new package: ' . $_PACKAGE['name'] . '-' . $_PACKAGE['version'] . '-' . $_PACKAGE['release']); $builder->createPackage($_PACKAGE['name'], $_PACKAGE['version'], $_PACKAGE['release']); $builder->registerNamespace($_PACKAGE['namespace'], $_PACKAGE['autoselects']); /* define some locations for file resources */ $sources = array('root' => dirname(dirname(__FILE__)) . '/', 'assets' => dirname(dirname(__FILE__)) . '/assets/'); /* set up some default attributes that define install behavior */ $attributes = array(xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RESOLVE_FILES => true, xPDOTransport::RESOLVE_PHP => true); $modx->log(modX::LOG_LEVEL_INFO, 'Loading vehicles into package.'); foreach ($_PACKAGE['vehicles'] as $vehicle) { $c = $modx->getObject($vehicle['class_key'], $vehicle['object']); if ($c == null) { continue; } if (!isset($vehicle['attributes'])) { $vehicle['attributes'] = array(); } $attr = array_merge($attributes, $vehicle['attributes']); $v = $builder->createVehicle($c, $attr); if (isset($vehicle['resolvers']) && !empty($vehicle['resolvers'])) { foreach ($vehicle['resolvers'] as $resolver) { $v->resolve($resolver['type'], $resolver); } } $builder->putVehicle($v); } /* zip up the package */ $modx->log(modX::LOG_LEVEL_INFO, 'Attempting to pack package.'); $builder->pack(); $filename = $modx->getOption('core_path') . 'packages/' . $_PACKAGE['name'] . '-' . $_PACKAGE['version'] . '-' . $_PACKAGE['release'] . '.transport.zip'; $modx->log(modX::LOG_LEVEL_WARN, $modx->lexicon('package_built') . ' - ' . $filename); return $modx->error->success($modx->lexicon('package_built') . ' - ' . $filename);
$modx->setLogTarget('ECHO'); $modx->getService('error', 'error.modError'); $modx->loadClass('transport.modPackageBuilder', '', false, true); $builder = new modPackageBuilder($modx); $builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE); $builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/' . PKG_NAME_LOWER . '/'); $modx->log(modX::LOG_LEVEL_INFO, 'Created Transport Package and Namespace.'); /* load system settings */ if (defined('BUILD_SETTING_UPDATE')) { $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.'); } else { $attributes = array(xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => BUILD_SETTING_UPDATE); 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); } /* load plugins events */ if (defined('BUILD_EVENT_UPDATE')) { $events = (include $sources['data'] . 'transport.events.php'); if (!is_array($events)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in events.'); } else { $attributes = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => BUILD_EVENT_UPDATE); foreach ($events as $event) { $vehicle = $builder->createVehicle($event, $attributes);
* based on which elements are present */ $attr = array(xPDOTransport::UNIQUE_KEY => 'category', xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RELATED_OBJECTS => true); if ($hasValidator) { $attr[xPDOTransport::ABORT_INSTALL_ON_VEHICLE_FAIL] = true; } if ($hasSnippets) { $attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Snippets'] = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'); } if ($hasPlugins) { $attr[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Plugins'] = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name'); } /* create a vehicle for the category and all the things * we've added to it. */ $vehicle = $builder->createVehicle($category, $attr); if ($hasValidator) { $modx->log(modX::LOG_LEVEL_INFO, 'Adding in Script Validator.'); $ret = $vehicle->validate('php', array('source' => $sources['validators'] . 'preinstall.script.php')); } /* package in script resolver if any */ if ($hasResolver) { $modx->log(modX::LOG_LEVEL_INFO, 'Adding in Script Resolver.'); $vehicle->resolve('php', array('source' => $sources['resolvers'] . 'install.script.php')); } if ($hasCore) { $vehicle->resolve('file', array('source' => $sources['source_core'], 'target' => "return MODX_CORE_PATH . 'components/';")); } if ($hasAssets) { $vehicle->resolve('file', array('source' => $sources['source_assets'], 'target' => "return MODX_ASSETS_PATH . 'components/';")); }
$modx->log(modX::LOG_LEVEL_INFO, 'Packaging in snippets...'); $snippets = (include $sources['data'] . 'transport.snippets.php'); if (empty($snippets)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in snippets.'); } $category->addMany($snippets); /* add chunks */ $chunks = (include $sources['data'] . 'transport.chunks.php'); if (is_array($chunks)) { $category->addMany($chunks); } else { $modx->log(modX::LOG_LEVEL_ERROR, 'Adding chunks failed.'); } /* create category vehicle */ $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'))); $vehicle = $builder->createVehicle($category, $attr); //-- Add file resolvers to get actual files added to the category $modx->log(modX::LOG_LEVEL_INFO, 'Adding file resolvers to category...'); $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); /* Settings */ $settings = (include $sources['data'] . 'transport.settings.php'); if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in settings.'); } 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); }
/* add Plugins */ $pluginList = $modx->fromJSON($_POST['plugins']); if (!empty($pluginList)) { $plugins = array(); foreach ($pluginList as $pluginData) { if (empty($pluginData['id'])) { continue; } $plugin = $modx->getObject('modPlugin', $pluginData['id']); if (empty($plugin)) { continue; } $pluginEvents = $plugin->getMany('PluginEvents'); $plugin->addMany($pluginEvents); $attr = array(xPDOTransport::PRESERVE_KEYS => false, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::UNIQUE_KEY => 'name', 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, $attr); $builder->putVehicle($vehicle); $plugins[] = $plugin; } if (empty($plugins)) { return $modx->error->failure('Error packaging plugins!'); } //$category->addMany($plugins,'Plugins'); $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($plugins) . ' plugins...'); } /* add Templates */ $tvs = array(); $tvMap = array(); $templateList = $modx->fromJSON($_POST['templates']); if (!empty($templateList)) { $templates = array();