public function pack()
 {
     $this->builder->pack();
     if ($this->modx->gitpackagemanagement->getOption('remove_extracted_package')) {
         $this->modx->gitpackagemanagement->deleteDir($this->builder->directory . $this->builder->signature . '/');
     }
 }
Ejemplo n.º 2
0
} 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;
Ejemplo n.º 3
0
    $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);
        $builder->putVehicle($vehicle);
    }
    $modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($settings) . ' System Settings.');
}
unset($settings, $setting, $attr);
/* now pack in the license file, readme and changelog */
$modx->log(modX::LOG_LEVEL_INFO, 'Added 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')));
/* zip up package */
$modx->log(modX::LOG_LEVEL_INFO, 'Packing up transport package zip ...');
$built = $builder->pack();
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
if ($built) {
    $modx->log(modX::LOG_LEVEL_INFO, "\n<br />Package Built.<br />\nExecution time: {$totalTime}\n");
    ob_end_clean();
    $filename = $builder->filename;
    $directory = $builder->directory;
    header('Pragma: no-cache');
    header('Expires: 0');
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename=' . $filename);
Ejemplo n.º 4
0
 /**
  * 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.');
     }
 }