/** * @see Action::execute() */ public function execute() { // call execute event parent::execute(); if ($this->source->enableCheckout && $this->checkoutRepository) { // load scm driver $className = ucfirst(Source::validateSCM($this->source->scm)); // check out repository require_once WCF_DIR . 'lib/system/scm/' . $className . '.class.php'; call_user_func(array($className, 'checkout'), $this->source->url, $this->source->sourceDirectory, array('username' => $this->source->username, 'password' => $this->source->password)); // set revision $revision = $this->source->getHeadRevision(); $this->source->update(null, null, null, null, null, null, null, $revision); } // rebuild package data if requested if ($this->rebuildPackageData) { require_once PB_DIR . 'lib/system/package/PackageHelper.class.php'; PackageHelper::readPackages($this->source); } // call executed event $this->executed(); // forward HeaderUtil::redirect('index.php?page=SourceView&sourceID=' . $this->source->sourceID . SID_ARG_2ND_NOT_ENCODED); exit; }
/** * @see CacheBuilder::getData() */ public function getData($cacheResource) { list($cache, $sourceID) = explode('-', $cacheResource['cache']); $data = array('packages' => array(), 'hashes' => array()); // get associated packages $sql = "SELECT\t\tpackageName, version, directory, packageType\n\t\t\tFROM\t\tpb" . PB_N . "_source_package\n\t\t\tWHERE\t\tsourceID = " . intval($sourceID) . "\n\t\t\tORDER BY\tpackageName ASC"; $result = WCF::getDB()->sendQuery($sql); // assign data ordered by package name while ($row = WCF::getDB()->fetchArray($result)) { $hash = PackageHelper::getHash($sourceID, $row['packageName'], $row['directory']); $row['sourceID'] = $sourceID; $data['packages'][$hash] = $row; $data['hashes'][$row['packageName']][] = $hash; } return $data; }
protected static function readPackageCache() { self::$packageCache = array('hashes' => array(), 'packages' => array()); // read accessible sources require_once PB_DIR . 'lib/data/source/SourceList.class.php'; $sourceList = new SourceList(); $sourceList->sqlLimit = 0; $sourceList->hasAccessCheck = true; $sourceList->readObjects(); $sources = $sourceList->getObjects(); foreach ($sources as $source) { self::$sources[$source->sourceID] = $source; } foreach (WCF::getUser()->getAccessibleSourceIDs() as $sourceID) { $cacheName = 'packages-' . $sourceID; WCF::getCache()->addResource($cacheName, PB_DIR . 'cache/cache.' . $cacheName . '.php', PB_DIR . 'lib/system/cache/CacheBuilderPackages.class.php'); $cache = WCF::getCache()->get($cacheName); self::$packageCache['hashes'] = array_merge(self::$packageCache['hashes'], $cache['hashes']); self::$packageCache['packages'] = array_merge(self::$packageCache['packages'], $cache['packages']); } }
/** * gets the name and the hash of the requested package * * @return void */ protected function getRequestedPackage() { // get directory $sourceData = WCF::getSession()->getVar('source' . $this->source->sourceID); // get package name if ($sourceData !== null) { $sourceData = unserialize($sourceData); $this->directory = $sourceData['directory']; foreach ($this->cachedPackages['packages'] as $package) { if ($package['directory'] == $this->directory) { $this->requestedPackageName = $package['packageName']; $this->requestedPackageHash = PackageHelper::getHash($this->source->sourceID, $package['packageName'], $this->directory); return; } } } throw new IllegalLinkException(); }
/** * @see Action::execute() */ public function execute() { // call execute event parent::execute(); // save selection if ($this->saveSelection) { $sql = ''; foreach ($this->packages as $packageName => $packageData) { if (!empty($sql)) { $sql .= ','; } $sql .= "(" . $this->source->sourceID . ",\r\n\t\t\t\t\t'" . escapeString($this->directory) . "',\r\n\t\t\t\t\t'" . escapeString($packageName) . "',\r\n\t\t\t\t\t'" . escapeString($packageData['hash']) . "',\r\n\t\t\t\t\t'" . escapeString($packageData['directory']) . "'\r\n\t\t\t\t\t)"; } if (!empty($sql)) { $sql = "INSERT INTO\t\tpb" . PB_N . "_selected_package\r\n\t\t\t\t\t\t\t\t(sourceID, directory, packageName, hash, resourceDirectory)\r\n\t\t\t\t\tVALUES\t\t\t" . $sql . "\r\n\t\t\t\t\tON DUPLICATE KEY UPDATE\tresourceDirectory = VALUES(resourceDirectory)"; WCF::getDB()->sendQuery($sql); } } // set package resources PackageHelper::registerPackageResources($this->packages); // read package $pr = new PackageReader($this->source->sourceID, $this->directory); try { // build package $pb = new PackageBuilder($this->source, $pr, $this->directory, $this->filename); if ($this->wcfSetupResource) { require_once PB_DIR . 'lib/system/package/StandalonePackageBuilder.class.php'; $spb = new StandalonePackageBuilder($this->source, $this->wcfSetupResource); $spb->createWcfSetup($pb->getArchiveLocation()); } } catch (SystemException $e) { PackageHelper::clearTemporaryFiles(); throw $e; } // clear previously created archives PackageHelper::clearTemporaryFiles(); // call executed event $this->executed(); // forward HeaderUtil::redirect('index.php?page=SourceView&sourceID=' . $this->source->sourceID . SID_ARG_2ND_NOT_ENCODED); exit; }
/** * Builds any combination of archive names * * @param string $pattern */ protected function generateArchiveName($pattern) { // recursively call method if pattern is an array if (is_array($pattern)) { foreach ($pattern as $filename) { if (!$filename) { continue; } $this->generateArchiveName($filename); } return; } // dummy values if ($this->currentDirectory === null || !isset($this->packages[$this->currentDirectory])) { $data = array('pn' => 'packageName', 'pv' => 'packageVersion', 'pr' => 'r' . $this->source->revision, 't' => DateUtil::formatTime('%Y-%m-%d %H:%M:%S', TIME_NOW, false)); } else { $data = array('pn' => $this->packages[$this->currentDirectory]['packageName'], 'pv' => $this->packages[$this->currentDirectory]['version'], 'pr' => 'r' . $this->source->revision, 't' => DateUtil::formatTime('%Y-%m-%d %H:%M:%S', TIME_NOW, false)); } // get filename $this->filenames[$pattern] = PackageHelper::getArchiveName($pattern, $data); }
/** * Creates complete archive. * * @param string $directory * @param string $filename */ public function createArchive($directory, $filename, $removeAfter) { $buildDirectory = ''; $directories = array('acptemplates', 'files', 'pip', 'templates'); $directory = FileUtil::addTrailingSlash($this->source->sourceDirectory . $directory); $location = ''; // skip if no directory was given if (!is_dir($directory)) { throw new SystemException('Given directory "' . $directory . '" is not valid.'); } $buildDirectory = FileUtil::addTrailingSlash($this->source->buildDirectory); $location = $buildDirectory . $filename; $package = new TarWriter($location, true); // read correct directory for languages $languagesInRoot = true; $languagesExist = false; if (file_exists($directory . self::LANGUAGE_DIR) && is_dir($directory . self::LANGUAGE_DIR)) { $languagesExist = true; $xml = new XML($directory . 'package.xml'); $nodes = $xml->getChildren(); foreach ($nodes as $node) { if ($node->getName() != 'instructions') { continue; } $subNodes = $xml->getChildren($node); foreach ($subNodes as $subNode) { if ($subNode->getName() != 'languages') { continue; } if (substr($xml->getCDATA($subNode), 0, strlen(self::LANGUAGE_DIR) + 1) == self::LANGUAGE_DIR . '/') { $languagesInRoot = false; } } } } // if files should be in root skip languages directory and copy language files into root if ($languagesExist && $languagesInRoot) { $this->excludeFiles[] = self::LANGUAGE_DIR; $files = DirectoryUtil::getInstance($directory . self::LANGUAGE_DIR . '/', false)->getFilesObj(SORT_DESC); foreach ($files as $filename => $obj) { if ($filename == '.svn') { continue; } # $obj->isDir()) continue; copy($directory . self::LANGUAGE_DIR . '/' . $filename, $directory . $filename); // register them for removing PackageHelper::registerTemporaryFile($directory . $filename); } } // try to open directory $dir = DirectoryUtil::getInstance($directory, false); foreach ($dir->getFiles() as $filename) { // skip files if (in_array($filename, $this->excludeFiles)) { continue; } if ($this->ignoreDotFiles && substr($filename, 0, 1) == '.' && !in_array($filename, $this->allowedDotFiles)) { continue; } /* easteregg if ($filename == 'package.xml') { copy($directory.$filename, $directory.$filename.'.bak'); $new = file_get_contents($directory.$filename); $new = str_replace('</packageinformation>', '<!--meta name="generator" content="PackageBuilder'.(SHOW_VERSION_NUMBER ? ' v'.PACKAGE_VERSION : '').'"--></packageinformation>', $new); file_put_contents($directory.$filename, $new); } */ // handle files if (!is_dir($directory . $filename)) { // add file $package->add($directory . $filename, '', $directory); /* easteregg if ($filename == 'package.xml') { unlink($directory.$filename); rename($directory.$filename.'.bak', $directory.$filename); } */ continue; } // skip directories if (in_array($filename, $directories)) { // create tarball from special directories $archive = new TarWriter($buildDirectory . $filename . '.tar', false); $this->addFilesRecursive($archive, $directory, $filename, $filename . '/'); $archive->create(); // add previously created tarball $package->add($buildDirectory . $filename . '.tar', '', $buildDirectory); } else { // add sourceDirectory $this->addFilesRecursive($package, $directory, $filename); } } // create complete package $package->create(); // cleanup, remove previous created tarballs DirectoryUtil::destroy($this->source->buildDirectory); $dir = DirectoryUtil::getInstance($this->source->buildDirectory); $dir->removePattern('/.*\\.tar$/'); if ($removeAfter) { PackageHelper::registerTemporaryFile($location); } return $location; }