/**
  * @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;
 }
 /**
  * Verifies if all neccessary packages are present
  *
  * @param	string	$packageType
  * @param	string	$directory
  */
 public function verifyPackages($packageType, $directory)
 {
     $directory = $this->source->sourceDirectory . $directory;
     // break if package type is unknown
     if (!isset($this->package[$packageType])) {
         return;
     }
     foreach ($this->package[$packageType] as $packageName => $package) {
         // we do not care about referenced packages with an empty file attribute
         if (empty($package['file'])) {
             continue;
         }
         // check for file in optionals/requiredments folder
         if (file_exists($directory . $package['file'])) {
             continue;
         }
         // look for previously built packages
         $location = PackageHelper::searchPackage($packageName);
         if (!is_null($location)) {
             if (!@copy($location, $directory . $package['file'])) {
                 throw new SystemException('Unable to copy archive (' . $package['file'] . '), check permissions for directory ' . $directory);
             }
             // register temporary file
             PackageHelper::registerTemporaryFile($directory . $package['file']);
             continue;
         }
         // set minimum required version or null if version does not matter
         $minVersion = isset($package['minversion']) ? $package['minversion'] : null;
         // search within cached packages
         $location = PackageHelper::searchCachedPackage($this->source->sourceID, $packageName, $minVersion);
         if (!is_null($location)) {
             $packageData = new PackageReader($this->source, $location);
             $pb = new PackageBuilder($this->source, $packageData, $location, 'pn', array(), true, true);
             // add directory if it does not exist
             FileUtil::makePath(dirname($directory . $package['file']), 0777);
             // copy archive
             if (!@copy($pb->getArchiveLocation(), $directory . $package['file'])) {
                 throw new SystemException('Unable to copy archive (' . $package['file'] . '), check permissions for directory ' . $directory);
             }
             // register temporary file
             PackageHelper::registerTemporaryFile($directory . $package['file']);
             continue;
         }
         // we were unable to locate or build package, thus we have no chance to build this package
         throw new SystemException('Can not build package, ' . $package['file'] . ' not found.');
     }
 }