/** * Get branch with further informations * * @param string $name * @param WireHttp $http */ protected function getBranchInformations($name, $http) { $branch = array('name' => $name, 'title' => ucfirst($name), 'zipURL' => str_replace('{branch}', $name, self::zipURL), 'version' => '', 'versionURL' => str_replace('{branch}', $name, self::versionURL)); switch ($name) { case 'master': $branch['title'] = 'Stable/Master'; break; default: $branch['title'] = 'Specific commit sha'; break; } $content = $http->get($branch['versionURL']); $branch['version'] = $this->getVersion($content); return $branch; }
/** * Check all site modules for newer versions from the directory * * @param bool $onlyNew Only return array of modules with new versions available * @param OutputInterface $output * @return array of array( * 'ModuleName' => array( * 'title' => 'Module Title', * 'local' => '1.2.3', // current installed version * 'remote' => '1.2.4', // directory version available, or boolean false if not found in directory * 'new' => true|false, // true if newer version available, false if not * 'requiresVersions' => array('ModuleName' => array('>', '1.2.3')), // module requirements * ) * ) * @throws WireException * */ public function getModuleVersion($onlyNew = false, $output, $module) { // get current module data $info = \ProcessWire\wire('modules')->getModuleInfoVerbose($module); $versions = array('title' => $info['title'], 'local' => \ProcessWire\wire('modules')->formatVersion($info['version']), 'remote' => false, 'new' => 0, 'requiresVersions' => $info['requiresVersions']); // get latest module data $url = trim(\ProcessWire\wire('config')->moduleServiceURL, '/') . "/{$module}/?apikey=" . \ProcessWire\wire('sanitizer')->name(\ProcessWire\wire('config')->moduleServiceKey); $http = new WireHttp(); $data = $http->getJSON($url); if (!$data || !is_array($data)) { $output->writeln("<error>Error retrieving data from web service URL - {$http->getError()}</error>"); return array(); } if ($data['status'] !== 'success') { $error = \ProcessWire\wire('sanitizer')->entities($data['error']); $output->writeln("<error>Error reported by web service: {$error}</error>"); return array(); } // yeah, received data sucessfully! // get versions and compare them $versions['remote'] = $data['module_version']; $new = version_compare($versions['remote'], $versions['local']); $versions['new'] = $new; $versions['download_url'] = $data['project_url'] . '/archive/master.zip'; // local is up-to-date or newer than remote if ($new <= 0) { if ($onlyNew) { $versions = array(); } } else { // remote is newer than local $versions['requiresVersions'] = $data['requires_versions']; } if ($onlyNew && !$versions['remote']) { $versions = array(); } return $versions; }