/** * Gets the package name of the first standalone application in WCFSetup.tar.gz. */ protected static function getPackageName() { // get package name $tar = new Tar(SETUP_FILE); foreach ($tar->getContentList() as $file) { if ($file['type'] != 'folder' && StringUtil::indexOf($file['filename'], 'install/packages/') === 0) { $packageFile = basename($file['filename']); $packageName = preg_replace('!\\.(tar\\.gz|tgz|tar)$!', '', $packageFile); if ($packageName != 'com.woltlab.wcf') { try { $archive = new PackageArchive(TMP_DIR . TMP_FILE_PREFIX . $packageFile); $archive->openArchive(); self::$setupPackageName = $archive->getPackageInfo('packageName'); $archive->getTar()->close(); break; } catch (SystemException $e) { } } } } $tar->close(); // assign package name WCF::getTPL()->assign('setupPackageName', self::$setupPackageName); }
/** * Tries to download a package from available update servers. * * @param string $package package identifier * @param array $packageUpdateVersions package update versions * @return string tmp filename of a downloaded package */ protected function downloadPackage($package, $packageUpdateVersions) { // get download from cache if ($filename = $this->getCachedDownload($package, $packageUpdateVersions[0]['package'])) { return $filename; } // download file $authorizationRequiredException = array(); $systemExceptions = array(); foreach ($packageUpdateVersions as $packageUpdateVersion) { try { // get auth data $authData = self::getAuthData($packageUpdateVersion); // send request if (!empty($packageUpdateVersion['file'])) { $response = self::sendRequest($packageUpdateVersion['file'], array(), $authData); } else { $response = self::sendRequest($packageUpdateVersion['server'], array('packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']), $authData); } // check response // check http code if ($response['httpStatusCode'] == 401) { throw new PackageUpdateAuthorizationRequiredException($packageUpdateVersion['packageUpdateServerID'], !empty($packageUpdateVersion['file']) ? $packageUpdateVersion['file'] : $packageUpdateVersion['server'], $response); } if ($response['httpStatusCode'] != 200) { throw new SystemException(WCF::getLanguage()->get('wcf.acp.packageUpdate.error.downloadFailed', array('$package' => $package)) . ' (' . $response['httpStatusLine'] . ')', 18009); } // write content to tmp file $filename = FileUtil::getTemporaryFilename('package_'); $file = new File($filename); $file->write($response['content']); $file->close(); unset($response['content']); // test package $archive = new PackageArchive($filename); $archive->openArchive(); $archive->getTar()->close(); // cache download in session $this->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename); return $filename; } catch (PackageUpdateAuthorizationRequiredException $e) { $authorizationRequiredException[] = $e; } catch (SystemException $e) { $systemExceptions[] = $e; } } if (count($authorizationRequiredException)) { throw array_shift($authorizationRequiredException); } if (count($systemExceptions)) { throw array_shift($systemExceptions); } return false; }
/** * Checks for conflicted exclusions. */ protected function checkExclusions() { $excludedPackages = $this->packageArchive->getConflictedExcludedPackages(); if (count($excludedPackages) > 0) { // this package exludes existing packages -> stop installation WCF::getTPL()->assign(array('excludedPackages' => $excludedPackages)); WCF::getTPL()->display('packageInstallationExcludedPackages'); exit; } $excludingPackages = $this->packageArchive->getConflictedExcludingPackages(); if (count($excludingPackages) > 0) { $stop = 1; // this package is excluded by existing packages $sql = "SELECT\t*\n\t\t\t\tFROM\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\tWHERE\tprocessNo = " . $this->processNo . "\n\t\t\t\t\tAND packageID IN (" . implode(',', array_keys($excludingPackages)) . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $archive = new PackageArchive($row['archive']); $archive->openArchive(); $newExclusions = $archive->getExcludedPackages(); if (!count($newExclusions) || !isset($newExclusions[$this->packageArchive->getPackageInfo('name')]) || isset($newExclusions[$this->packageArchive->getPackageInfo('name')]['version']) && Package::compareVersion($this->packageArchive->getPackageInfo('version'), $newExclusions[$this->packageArchive->getPackageInfo('name')]['version'], '<')) { unset($excludingPackages[$row['packageID']]); $stop = 0; } } if (count($excludingPackages) > 0) { WCF::getTPL()->assign(array('excludingPackages' => $excludingPackages, 'stop' => $stop, 'nextStep' => 'package')); WCF::getTPL()->display('packageInstallationExcludingPackages'); exit; } } }