public function process() { $this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('package_update_info_provider_scan', array('provider' => $this->provider->get('name')))); /* get provider client */ $loaded = $this->provider->getClient(); if (!$loaded) { return $this->failure($this->modx->lexicon('provider_err_no_client')); } $packages = $this->getPackages(); if (is_string($packages)) { return $this->failure($packages); } /* if no newer packages were found */ if (count($packages) < 1) { $msg = $this->modx->lexicon('package_err_uptodate', array('signature' => $this->package->get('signature'))); $this->modx->log(modX::LOG_LEVEL_INFO, $msg); return $this->failure($msg); } $list = array(); /** @var SimpleXMLObject $p */ foreach ($packages as $package) { $packageArray = array('id' => (string) $package->id, 'package' => (string) $package->package, 'version' => (string) $package->version, 'release' => (string) $package->release, 'signature' => (string) $package->signature, 'location' => (string) $package->location, 'info' => (string) $package->location . '::' . (string) $package->signature); $list[] = $packageArray; } return $this->success('', $list); }
/** * Prepare the soon-to-be-created Transport Package object * * @return modTransportPackage */ public function getTransportPackage() { /** @var modTransportPackage $package */ $this->package = $this->modx->newObject('transport.modTransportPackage'); $this->package->set('signature', $this->signature); $this->package->set('state', 1); $this->package->set('workspace', 1); $this->package->set('created', date('Y-m-d h:i:s')); $this->package->set('provider', $this->provider->get('id')); return $this->package; }
public function process() { $this->modx->log(modX::LOG_LEVEL_INFO, $this->modx->lexicon('package_update_info_provider_scan', array('provider' => $this->provider->get('name')))); $packages = $this->provider->latest($this->getProperty('signature')); if (is_string($packages)) { return $this->failure($packages); } /* if no newer packages were found */ if (count($packages) < 1) { $msg = $this->modx->lexicon('package_err_uptodate', array('signature' => $this->package->get('signature'))); $this->modx->log(modX::LOG_LEVEL_INFO, $msg); return $this->failure($msg); } $list = array(); /** @var SimpleXMLElement $package */ foreach ($packages as $package) { $packageArray = array('id' => (string) $package['id'], 'package' => (string) $package['package'], 'version' => (string) $package['version'], 'release' => (string) $package['release'], 'signature' => (string) $package['signature'], 'location' => (string) $package['location'], 'info' => (string) $package['location'] . '::' . (string) $package['signature']); $list[] = $packageArray; } return $this->success('', $list); }
/** * Load the provider for the package * @return boolean */ public function loadProvider() { $provider = $this->getProperty('provider'); if (empty($provider)) { $c = $this->modx->newQuery('transport.modTransportProvider'); $c->where(array('name:=' => 'modxcms.com', 'OR:name:=' => 'modx.com')); $this->provider = $this->modx->getObject('transport.modTransportProvider', $c); if (!empty($this->provider)) { $this->setProperty('provider', $this->provider->get('id')); } } else { $this->provider = $this->modx->getObject('transport.modTransportProvider', $provider); } return !empty($this->provider); }
/** * Download and install the package from the provider * * @param string $packageName * @param \modTransportProvider $provider * @param array $options * @return bool */ private function download($packageName, $provider, $options = array()) { $this->modx->getVersionData(); $product_version = $this->modx->version['code_name'] . '-' . $this->modx->version['full_version']; $response = $provider->verify(); if ($response !== true) { $this->output->writeln("<error>Could not download {$packageName} because the provider cannot be verified.</error>"); $error = $response; if (!empty($error) && is_string($error)) { $this->output->writeln("Message from Provider: {$error}"); } return false; } $provider->getClient(); $this->output->writeln("Searching <comment>{$provider->get('name')}</comment> for <comment>{$packageName}</comment>..."); // Request package information from the chosen provider $response = $provider->request('package', 'GET', array('supports' => $product_version, 'query' => $packageName)); // Check for a proper response if (!empty($response)) { $foundPackages = simplexml_load_string($response->response); $helper = $this->getHelper('question'); $packages = array(); foreach ($foundPackages as $foundPkg) { $packages[strtolower((string) $foundPkg->name)] = array('name' => (string) $foundPkg->name, 'version' => (string) $foundPkg->version, 'location' => (string) $foundPkg->location, 'signature' => (string) $foundPkg->signature); } // Ensure the exact match is always first if (isset($packages[strtolower($packageName)])) { $packages = array($packageName => $packages[strtolower($packageName)]) + $packages; } foreach ($packages as $package) { if ($this->modx->getCount('transport.modTransportPackage', array('signature' => $package['signature']))) { $this->output->writeln("<info>Package {$package['name']} {$package['version']} is already installed.</info>"); if ($this->interactive) { continue; } else { return true; } } if ($this->interactive) { if (!$helper->ask($this->input, $this->output, new ConfirmationQuestion("Do you want to install <info>{$package['name']} ({$package['version']})</info>? <comment>[Y/n]</comment>: ", true))) { continue; } } // Run the core processor to download the package from the provider $this->output->writeln("<comment>Downloading {$package['name']} ({$package['version']})...</comment>"); $response = $this->modx->runProcessor('workspace/packages/rest/download', array('provider' => $provider->get('id'), 'info' => join('::', array($package['location'], $package['signature'])))); // If we have an error, show it and cancel. if ($response->isError()) { $this->output->writeln("<error>Could not download package {$package['name']}. Reason: {$response->getMessage()}</error>"); return false; } $this->output->writeln("<comment>Installing {$package['name']}...</comment>"); // Grab the package object $obj = $response->getObject(); if ($package = $this->modx->getObject('transport.modTransportPackage', array('signature' => $obj['signature']))) { // Install the package return $package->install($options); } } } return true; }