public function process() { $attributes = array(); $attributesToGet = explode(',', $this->getProperty('attributes', '')); foreach ($attributesToGet as $attribute) { $attributes[$attribute] = $this->transport->getAttribute($attribute); /* if setup options, include setup file */ if ($attribute == 'setup-options') { @ob_start(); $options = $this->package->toArray(); $options[xPDOTransport::PACKAGE_ACTION] = $this->package->previousVersionInstalled() ? xPDOTransport::ACTION_UPGRADE : xPDOTransport::ACTION_INSTALL; $attributeFile = $this->modx->getOption('core_path') . 'packages/' . $this->package->signature . '/' . $attribute . '.php'; if (file_exists($attributeFile) && $attribute != '') { $modx =& $this->modx; $attributes['setup-options'] = (include $attributeFile); } @ob_end_clean(); } else { if (in_array($attribute, array('readme', 'license', 'changelog'))) { $attributes[$attribute] = htmlentities($attributes[$attribute], ENT_COMPAT, 'UTF-8'); } } } return $this->success('', $attributes); }
public function process() { $attributes = array(); $attributesToGet = explode(',', $this->getProperty('attributes', '')); foreach ($attributesToGet as $attribute) { $attributes[$attribute] = $this->transport->getAttribute($attribute); /* if setup options, include setup file */ if ($attribute == 'setup-options') { @ob_start(); $options = $this->package->toArray(); $options[xPDOTransport::PACKAGE_ACTION] = empty($this->package->installed) ? xPDOTransport::ACTION_INSTALL : xPDOTransport::ACTION_UPGRADE; $attributeFile = $this->modx->getOption('core_path') . 'packages/' . $this->package->signature . '/' . $attribute . '.php'; if (file_exists($attributeFile) && $attribute != '') { $modx =& $this->modx; $attributes['setup-options'] = (include $attributeFile); } @ob_end_clean(); } } return $this->success('', $attributes); }
public function process() { $requires = $this->transport->getAttribute('requires'); $dep = $this->package->checkDependencies($requires); $download = $this->package->checkDownloadedDependencies($dep); $returnArray = array(); foreach ($requires as $pkg => $constraints) { if (isset($dep[$pkg])) { $installed = false; } else { $installed = true; } if (isset($download[$pkg])) { $downloaded = true; $signature = $download[$pkg]; } else { $downloaded = false; $signature = ''; } //@TODO: Get downlaoded property properly from somewhere and add signature property that will be needed for running installation $returnArray[] = array('name' => $pkg, 'parentSignature' => $this->getProperty('signature'), 'constraints' => $constraints, 'installed' => $installed, 'downloaded' => $downloaded, 'signature' => $signature); } return $this->outputArray($returnArray, count($returnArray)); }
/** * Uninstall files or folders represented by and stored in this vehicle. * * @access protected * @param xPDOTransport &$transport A reference the transport this vehicle is stored in. * @param array $options Optional attributes that can be applied to vehicle uninstall process. * @return boolean True if the files are uninstalled successfully. */ protected function _uninstallFiles(&$transport, $options) { $uninstalled = false; $vOptions = $this->get($transport, $options); if (isset($vOptions['object']) && isset($vOptions['object']['source']) && isset($vOptions['object']['target'])) { $object = $vOptions['object']; $fileName = $object['name']; $fileSource = $transport->path . $object['source']; $fileTarget = eval($object['target']); $preExistingMode = xPDOTransport::PRESERVE_PREEXISTING; if (isset($vOptions[xPDOTransport::PREEXISTING_MODE])) { $preExistingMode = (int) $vOptions[xPDOTransport::PREEXISTING_MODE]; } $cacheManager = $transport->xpdo->getCacheManager(); $path = $fileTarget . $fileName; $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Uninstalling files from xPDOFileVehicle: ' . $path); if ($this->validate($transport, $object, $vOptions)) { if (!isset($vOptions[xPDOTransport::UNINSTALL_FILES]) || $vOptions[xPDOTransport::UNINSTALL_FILES] == true) { $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Removing files from xPDOFileVehicle: ' . $path); if ($cacheManager && file_exists($path)) { if (is_dir($path) && $cacheManager->deleteTree($path, array_merge(array('deleteTop' => true, 'skipDirs' => false, 'extensions' => array()), $vOptions))) { $uninstalled = true; } elseif (is_file($path) && unlink($path)) { $uninstalled = true; } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not remove files from path: ' . $path); } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not find files to remove at path: ' . $path); } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Skipping removal of files according to vehicle attributes.'); $uninstalled = true; } $preservedArchive = $transport->path . $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.preserved.zip'; if ($preExistingMode === xPDOTransport::RESTORE_PREEXISTING && file_exists($preservedArchive)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Attempting to restore files to {$fileTarget} from archive {$preservedArchive}"); $unpackedResult = xPDOTransport::_unpack($transport->xpdo, $preservedArchive, $fileTarget); if ($unpackedResult > 0) { $uninstalled = true; } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error unpacking preserved files from archive {$preservedArchive}"); } } if (!$this->resolve($transport, $object, $vOptions)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not resolve vehicle for object: ' . print_r($object, true)); if ($transport->xpdo->getDebug() === true) { $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Could not resolve vehicle: ' . print_r($vOptions, true)); } } } else { //$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not validate vehicle for object: ' . print_r($object, true)); if ($transport->xpdo->getDebug() === true) { $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Could not validate vehicle: ' . print_r($vOptions, true)); } } } return $uninstalled; }
$root = dirname(dirname(__FILE__)) . '/'; $sources = ['build' => $root . '_build/', 'data' => $root . '_build/data/', 'plugins' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/plugins/', 'docs' => $root . 'docs/', 'resolvers' => $root . '_build/resolvers/', 'validators' => $root . '_build/validators/', 'core' => ['components/slackify/']]; $signature = join('-', [PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE]); $directory = $root . '_packages/'; //$directory = __DIR__ . '/../../../core/packages/'; // local place $filename = $directory . $signature . '.transport.zip'; if (file_exists($filename)) { unlink($filename); } if (file_exists($directory . $signature) && is_dir($directory . $signature)) { $cacheManager = $xpdo->getCacheManager(); if ($cacheManager) { $cacheManager->deleteTree($directory . $signature, true, false, []); } } $package = new xPDOTransport($xpdo, $signature, $directory); $namespace = new modNamespace($xpdo); $namespace->fromArray(['id' => PKG_NAME_LOWER, 'name' => PKG_NAME_LOWER, 'path' => '{core_path}components/' . PKG_NAME_LOWER . '/']); $package->put($namespace, [xPDOTransport::UNIQUE_KEY => 'name', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, xPDOTransport::RESOLVE_FILES => true, xPDOTransport::RESOLVE_PHP => true, xPDOTransport::NATIVE_KEY => PKG_NAME_LOWER, 'namespace' => PKG_NAME_LOWER, 'package' => 'modx', 'resolve' => null, 'validate' => null]); $settings = (include $sources['data'] . 'transport.settings.php'); foreach ($settings as $setting) { $package->put($setting, [xPDOTransport::UNIQUE_KEY => 'key', xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true, 'class' => 'modSystemSetting', 'resolve' => null, 'validate' => null, 'package' => 'modx']); } $validators = []; array_push($validators, ['type' => 'php', 'source' => $sources['validators'] . 'validate.phpversion.php']); $resolvers = []; foreach ($sources['core'] as $file) { $directory = dirname($file); array_push($resolvers, ['type' => 'file', 'source' => $root . 'core/' . $file, 'target' => "return MODX_CORE_PATH . '{$directory}/';"]); } array_push($resolvers, ['type' => 'php', 'source' => $sources['resolvers'] . 'resolve.extension.php'], ['type' => 'php', 'source' => $sources['resolvers'] . 'resolve.settings.php']);
/* remove pre-existing package files and directory */ if (file_exists($packageDirectory . 'core.transport.zip')) { @unlink($packageDirectory . 'core.transport.zip'); } if (file_exists($packageDirectory . 'core') && is_dir($packageDirectory . 'core')) { $cacheManager->deleteTree($packageDirectory . 'core', array('deleteTop' => true, 'skipDirs' => false, 'extensions' => '*')); } if (!file_exists($packageDirectory . 'core') && !file_exists($packageDirectory . 'core.transport.zip')) { $xpdo->log(xPDO::LOG_LEVEL_INFO, 'Removed pre-existing core/ and core.transport.zip.'); flush(); } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not remove core/ and core.transport.zip before starting build.'); flush(); } /* create core transport package */ $package = new xPDOTransport($xpdo, 'core', $packageDirectory); unset($packageDirectory); $xpdo->setPackage('modx', MODX_CORE_PATH . 'model/'); $xpdo->loadClass('modAccess'); $xpdo->loadClass('modAccessibleObject'); $xpdo->loadClass('modAccessibleSimpleObject'); $xpdo->loadClass('modPrincipal'); $xpdo->log(xPDO::LOG_LEVEL_INFO, 'Core transport package created.'); flush(); /* core namespace */ $namespace = $xpdo->newObject('modNamespace'); $namespace->set('name', 'core'); $namespace->set('path', '{core_path}'); $namespace->set('assets_path', '{assets_path}'); $package->put($namespace, array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true)); unset($namespace);
/** * Resolve any dependencies of the artifact represented in this vehicle. * * @param xPDOTransport &$transport A reference to the xPDOTransport in * which this vehicle is stored. * @param mixed &$object An object reference to resolve dependencies for. * Use this to make the artifact or other important data available to the * resolver scripts. * @param array $options Additional options for the resolution process. * @return boolean Indicates if the resolution was successful. */ public function resolve(&$transport, &$object, $options = array()) { $resolved = false; if (isset($this->payload['resolve'])) { while (list($rKey, $r) = each($this->payload['resolve'])) { $type = $r['type']; $body = $r['body']; $preExistingMode = xPDOTransport::PRESERVE_PREEXISTING; if (!empty($options[xPDOTransport::PREEXISTING_MODE])) { $preExistingMode = intval($options[xPDOTransport::PREEXISTING_MODE]); } switch ($type) { case 'file': if (isset($options[xPDOTransport::RESOLVE_FILES]) && !$options[xPDOTransport::RESOLVE_FILES]) { $resolved = true; continue; } if ($transport->xpdo->getDebug() === true) { $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Resolving transport files: " . print_r($this, true)); } $fileMeta = $transport->xpdo->fromJSON($body, true); $fileName = $fileMeta['name']; $fileSource = $transport->path . $fileMeta['source']; $fileTarget = eval($fileMeta['target']); $fileTargetPath = $fileTarget . $fileName; $preservedArchive = $transport->path . $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $rKey . '.preserved.zip'; $cacheManager = $transport->xpdo->getCacheManager(); switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_UPGRADE: case xPDOTransport::ACTION_INSTALL: // if package is installing if ($cacheManager && file_exists($fileSource) && !empty($fileTarget)) { $copied = array(); if ($preExistingMode === xPDOTransport::PRESERVE_PREEXISTING && file_exists($fileTargetPath)) { $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, "Attempting to preserve files at {$fileTargetPath} into archive {$preservedArchive}"); $preserved = xPDOTransport::_pack($transport->xpdo, $preservedArchive, $fileTarget, $fileName); } if (is_dir($fileSource)) { $copied = $cacheManager->copyTree($fileSource, $fileTarget, array_merge($options, array('copy_return_file_stat' => true))); } elseif (is_file($fileSource)) { $copied = $cacheManager->copyFile($fileSource, $fileTarget, array_merge($options, array('copy_return_file_stat' => true))); } if (empty($copied)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy {$fileSource} to {$fileTargetPath}"); } else { if ($preExistingMode === xPDOTransport::PRESERVE_PREEXISTING && is_array($copied)) { foreach ($copied as $copiedFile => $stat) { if (isset($stat['overwritten'])) { $transport->_preserved[$options['guid']]['files'][substr($copiedFile, strlen($fileTarget))] = $stat; } } } $resolved = true; } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy {$fileSource} to {$fileTargetPath}"); } break; case xPDOTransport::ACTION_UNINSTALL: /* if package is uninstalling user can override whether or not files from resolver are removed however default action is to remove */ if (!isset($options[xPDOTransport::RESOLVE_FILES_REMOVE]) || $options[xPDOTransport::RESOLVE_FILES_REMOVE] !== false) { $path = $fileTarget . $fileName; $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Removing files in file resolver: ' . $path); if ($cacheManager && file_exists($path)) { if (is_dir($path) && $cacheManager->deleteTree($path, array_merge(array('deleteTop' => true, 'skipDirs' => false, 'extensions' => array()), $options))) { $resolved = true; } elseif (is_file($path) && unlink($path)) { $resolved = true; } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not remove files from path: ' . $path); } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not find files to remove.'); } } else { /* action was chosen not to remove, send log message and continue */ $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Skipping removing of files according to vehicle attributes.'); $resolved = true; } if ($preExistingMode === xPDOTransport::RESTORE_PREEXISTING && file_exists($preservedArchive)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Attempting to restore files to {$fileTarget} from archive {$preservedArchive}"); $unpackedResult = xPDOTransport::_unpack($transport->xpdo, $preservedArchive, $fileTarget); if ($unpackedResult > 0) { $resolved = true; } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error unpacking preserved files from archive {$preservedArchive}"); } } break; } break; case 'php': if (isset($options[xPDOTransport::RESOLVE_PHP]) && !$options[xPDOTransport::RESOLVE_PHP]) { continue; } $fileMeta = $transport->xpdo->fromJSON($body, true); $fileName = $fileMeta['name']; $fileSource = $transport->path . $fileMeta['source']; if (!($resolved = (include $fileSource))) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOVehicle resolver failed: type php ({$fileSource})"); } break; default: $transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support resolvers of type {$type}."); break; } } } else { $resolved = true; } return $resolved; }
/** * @return bool */ public function installPackage() { /* add required core data */ $this->install->xpdo->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true); $packageDirectory = MODX_CORE_PATH . 'packages/'; $packageState = $this->install->settings->get('unpacked') == 1 ? xPDOTransport::STATE_UNPACKED : xPDOTransport::STATE_PACKED; $package = xPDOTransport::retrieve($this->install->xpdo, $packageDirectory . 'core.transport.zip', $packageDirectory, $packageState); if (!is_object($package) || !$package instanceof xPDOTransport) { $this->addResult(modInstallRunner::RESULT_FAILURE, '<p class="notok">' . $this->install->lexicon('package_execute_err_retrieve', array('path' => $this->install->settings->get('core_path'))) . '</p>'); return false; } if (!defined('MODX_BASE_PATH')) { define('MODX_BASE_PATH', $this->install->settings->get('context_web_path')); } if (!defined('MODX_ASSETS_PATH')) { $assetsDefault = $this->install->settings->get('context_assets_path', $this->install->settings->get('context_web_path') . 'assets/'); define('MODX_ASSETS_PATH', $assetsDefault); } if (!defined('MODX_MANAGER_PATH')) { define('MODX_MANAGER_PATH', $this->install->settings->get('context_mgr_path')); } if (!defined('MODX_CONNECTORS_PATH')) { define('MODX_CONNECTORS_PATH', $this->install->settings->get('context_connectors_path')); } if (!defined('MODX_BASE_URL')) { define('MODX_BASE_URL', $this->install->settings->get('context_web_url')); } if (!defined('MODX_ASSETS_URL')) { $assetsDefault = $this->install->settings->get('context_assets_url', $this->install->settings->get('context_web_url') . 'assets/'); define('MODX_ASSETS_URL', $assetsDefault); } if (!defined('MODX_MANAGER_URL')) { define('MODX_MANAGER_URL', $this->install->settings->get('context_mgr_url')); } if (!defined('MODX_CONNECTORS_URL')) { define('MODX_CONNECTORS_URL', $this->install->settings->get('context_connectors_url')); } return $package->install(array(xPDOTransport::RESOLVE_FILES => $this->install->settings->get('inplace') == 0 ? 1 : 0, xPDOTransport::INSTALL_FILES => $this->install->settings->get('inplace') == 0 ? 1 : 0, xPDOTransport::PREEXISTING_MODE => xPDOTransport::REMOVE_PREEXISTING)); }
/** * Unpack the package to prepare for installation and return a manifest. * * @param xPDO &$xpdo A reference to an xPDO instance. * @param string $from Filename of the archive containing the transport package. * @param string $to The root path where the contents of the archive should be extracted. This * path must be writable by the user executing the PHP process on the server. * @param integer $state The current state of the package, i.e. packed or unpacked. * @return array The manifest which is included after successful extraction. */ public static function unpack(&$xpdo, $from, $to, $state = xPDOTransport::STATE_PACKED) { $manifest = null; if ($state !== xPDOTransport::STATE_UNPACKED) { $resources = xPDOTransport::_unpack($xpdo, $from, $to); } else { $resources = true; } if ($resources) { $manifestFilename = $to . basename($from, '.transport.zip') . '/manifest.php'; if (file_exists($manifestFilename)) { $manifest = @(include $manifestFilename); } else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not find package manifest at {$manifestFilename}"); } } return $manifest; }
/** * Gets the package's transport mechanism. * * @access public * @param integer $state The state of the package. * @return mixed The package. */ public function getTransport($state = -1) { if (!is_object($this->package) || !($this->package instanceof xPDOTransport)) { if ($this->xpdo->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true)) { $workspace = $this->getOne('Workspace'); if ($workspace) { $packageDir = $workspace->get('path') . 'packages/'; $sourceFile = $this->get('source'); if ($sourceFile) { $transferred= file_exists($packageDir . $sourceFile); if (!$transferred) { /* if no transport zip, attempt to get it */ if (!$transferred= $this->transferPackage($sourceFile, $packageDir)) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,$this->xpdo->lexicon('package_err_transfer',array( 'sourceFile' => $sourceFile, 'packageDir' => $packageDir, ))); } else { $sourceFile= basename($sourceFile); } } if ($transferred) { if ($state < 0) { /* if directory is missing but zip exists, and DB state value is incorrect, fix here */ $targetDir = basename($sourceFile, '.transport.zip'); $state = is_dir($packageDir.$targetDir) ? $this->get('state') : xPDOTransport::STATE_PACKED; } /* retrieve the package */ $this->package = xPDOTransport :: retrieve($this->xpdo, $packageDir . $sourceFile, $packageDir, $state); if ($this->package) { /* set to unpacked state */ if ($state == xPDOTransport::STATE_PACKED) { $this->set('state', xPDOTransport::STATE_UNPACKED); } $this->set('source', $sourceFile); $this->set('attributes', $this->package->attributes); $this->save(); } } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,$this->xpdo->lexicon('package_err_source_nf')); } } } } return $this->package; }
/** * Installs a transport package. * * @param string The package signature. * @param array $attributes An array of installation attributes. * @return array An array of error messages collected during the process. */ public function installPackage($pkg, array $attributes = array()) { $errors = array(); /* instantiate the modX class */ if (@(require_once MODX_CORE_PATH . 'model/modx/modx.class.php')) { $modx = new modX(MODX_CORE_PATH . 'config/'); if (!is_object($modx) || !$modx instanceof modX) { $errors[] = '<p>' . $this->lexicon('modx_err_instantiate') . '</p>'; } else { /* try to initialize the mgr context */ $modx->initialize('mgr'); if (!$modx->_initialized) { $errors[] = '<p>' . $this->lexicon('modx_err_instantiate_mgr') . '</p>'; } else { $loaded = $modx->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true); if (!$loaded) { $errors[] = '<p>' . $this->lexicon('transport_class_err_load') . '</p>'; } $packageDirectory = MODX_CORE_PATH . 'packages/'; $packageState = isset($attributes[xPDOTransport::PACKAGE_STATE]) ? $attributes[xPDOTransport::PACKAGE_STATE] : xPDOTransport::STATE_PACKED; $package = xPDOTransport::retrieve($modx, $packageDirectory . $pkg . '.transport.zip', $packageDirectory, $packageState); if ($package) { if (!$package->install($attributes)) { $errors[] = '<p>' . $this->lexicon('package_err_install', array('package' => $pkg)) . '</p>'; } else { $modx->log(xPDO::LOG_LEVEL_INFO, $this->lexicon('package_installed', array('package' => $pkg))); } } else { $errors[] = '<p>' . $this->lexicon('package_err_nf', array('package' => $pkg)) . '</p>'; } } } } else { $errors[] = '<p>' . $this->lexicon('modx_class_err_nf') . '</p>'; } return $errors; }
public function latest($identifier, $constraint = '*', array $args = array()) { $latest = array(); if (strpos($identifier, '-') === false) { /** @var modRestResponse $response */ $response = $this->request('package/versions', 'GET', array_merge(array('package' => $identifier, 'constraint' => $constraint), $args)); if ($response) { if (!$response->isError()) { $xml = $response->toXml(); /** @var SimpleXMLElement $resolver */ foreach ($xml as $resolver) { $node = array(); if (xPDOTransport::satisfies((string) $resolver->version, $constraint)) { $this->fromXML($resolver, $node); array_push($latest, $node); } } } else { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $response->getError(), '', __METHOD__, __FILE__, __LINE__); } } } else { $response = $this->request('package/update', 'GET', array_merge(array('signature' => $identifier, 'constraint' => $constraint), $args)); if ($response) { if (!$response->isError()) { $xml = $response->toXml(); foreach ($xml as $resolver) { $node = array(); if (xPDOTransport::satisfies((string) $resolver->version, $constraint)) { $this->fromXML($resolver, $node); array_push($latest, $node); } } } } } return $latest; }
require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('mgr'); $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget('ECHO'); $targetDirectory = dirname(dirname(__FILE__)) . '/_packages/'; } else { $targetDirectory = MOREPROVIDER_BUILD_TARGET; } /* define build paths */ $root = dirname(dirname(__FILE__)) . '/'; $sources = array('root' => $root, 'build' => $root . '_build/', 'data' => $root . '_build/data/', 'validators' => $root . '_build/validators/', 'resolvers' => $root . '_build/resolvers/', 'chunks' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/chunks/', 'snippets' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/snippets/', 'plugins' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/plugins/', 'lexicon' => $root . 'core/components/' . PKG_NAME_LOWER . '/lexicon/', 'docs' => $root . 'core/components/' . PKG_NAME_LOWER . '/docs/', 'elements' => $root . 'core/components/' . PKG_NAME_LOWER . '/elements/', 'source_assets' => $root . 'assets/components/' . PKG_NAME_LOWER . '/', 'source_core' => $root . 'core/components/' . PKG_NAME_LOWER . '/'); unset($root); $modx->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true); /** @var xPDOTransport $package */ $package = new xPDOTransport($modx, PKG_NAME_LOWER, $targetDirectory); $package->signature = PKG_NAME_LOWER . '-' . PKG_VERSION . '-' . PKG_RELEASE; $modx->log(xPDO::LOG_LEVEL_INFO, 'Creating transport package for ' . PKG_NAME); flush(); /* include namespace */ $namespace = $modx->newObject('modNamespace'); $namespace->set('name', PKG_NAME_LOWER); $namespace->set('path', '{core_path}components/' . PKG_NAME_LOWER . '/'); $namespace->set('assets_path', '{assets_path}components/' . PKG_NAME_LOWER . '/'); $attributes = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true); $package->put($namespace, $attributes); $modx->log(xPDO::LOG_LEVEL_INFO, 'Added namespace ' . PKG_NAME_LOWER); flush(); /** @var array $attributes */ $attributes = array('vehicle_class' => 'xPDOFileVehicle'); $files = array();
/** * Uninstalls vehicle artifacts from the transport host. */ public function uninstall(&$transport, $options) { $uninstalled = false; $vOptions = $this->get($transport, $options); if (isset($vOptions['object']) && isset($vOptions['object']['source']) && isset($vOptions['object']['target']) && isset($vOptions['object']['name'])) { if ($transport->xpdo->getDebug() === true) { $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Installing Vehicle: " . print_r($vOptions, true)); } $state = isset($vOptions['state']) ? $vOptions['state'] : xPDOTransport::STATE_UNPACKED; $pkgSource = $transport->path . $vOptions['object']['source'] . $vOptions['object']['name']; $pkgTarget = eval($vOptions['object']['target']); $object = xPDOTransport::retrieve($transport->xpdo, $pkgSource, $pkgTarget, $state); if ($this->validate($transport, $object, $vOptions)) { $uninstalled = $object->uninstall($vOptions); if (!$uninstalled) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not uninstall vehicle: ' . print_r($vOptions, true)); } elseif (!$this->resolve($transport, $object, $vOptions)) { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not resolve vehicle: ' . print_r($vOptions, true)); } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not validate vehicle: ' . print_r($vOptions, true)); } } else { $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not load vehicle: ' . print_r($vOptions, true)); } return $uninstalled; }
public function checkDownloadedDependencies(array $dependencies) { $satisfied = array(); foreach ($dependencies as $package => $constraint) { if (strtolower($package) === strtolower($this->identifier)) { continue; } /* get latest installed package version */ $latestQuery = $this->xpdo->newQuery('modTransportPackage', array(array("UCASE({$this->xpdo->escape('package_name')}) LIKE UCASE({$this->xpdo->quote($package)})"), 'installed:IS' => null)); $latestQuery->sortby('installed', 'DESC'); /** @var modTransportPackage $latest */ $latest = $this->xpdo->getObject('modTransportPackage', $latestQuery); if ($latest) { $latest->parseSignature(); if (xPDOTransport::satisfies($latest->version, $constraint)) { $satisfied[strtolower($package)] = $latest->signature; continue; } } } return $satisfied; }
/** * Test xPDOTransport::nextSignificantRelease() * * @param string $version * @param string $expected * @dataProvider providerNextSignificantRelease */ public function testNextSignificantRelease($version, $expected) { $this->assertEquals($expected, xPDOTransport::nextSignificantRelease($version)); }