/**
  * Saves the stack of package installations in the package installation queue table.
  */
 public function savePackageInstallationStack()
 {
     // get new process no
     require_once WCF_DIR . 'lib/acp/package/PackageInstallationQueue.class.php';
     $processNo = PackageInstallationQueue::getNewProcessNo();
     // build inserts
     $inserts = '';
     foreach ($this->packageInstallationStack as $package) {
         // unzip tar
         $package['archive'] = PackageArchive::unzipPackageArchive($package['archive']);
         if (!empty($inserts)) {
             $inserts .= ',';
         }
         $inserts .= "(" . $processNo . ", " . WCF::getUser()->userID . ", '" . escapeString($package['package']) . "', " . $package['packageID'] . ", '" . escapeString($package['archive']) . "', '" . escapeString($package['action']) . "')";
     }
     // save inserts
     if (!empty($inserts)) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t\t(processNo, userID, package, packageID, archive, action)\n\t\t\t\tVALUES\t\t" . $inserts;
         WCF::getDB()->sendQuery($sql);
     }
     return $processNo;
 }
 /**
  * Adds an uninstall entry to the package installation queue.
  * 
  * @param	Package		$package
  * @param	array		$packages
  */
 public static function addQueueEntries(Package $package, $packages = array())
 {
     // get new process no
     $processNo = PackageInstallationQueue::getNewProcessNo();
     // add dependent packages to queue
     $inserts = '';
     $userID = WCF::getUser()->userID;
     foreach ($packages as $dependentPackage) {
         if (!empty($inserts)) {
             $inserts .= ',';
         }
         $inserts .= "(" . $processNo . ", " . $userID . ", '" . escapeString($dependentPackage['packageName']) . "', " . $dependentPackage['packageID'] . ", 'uninstall')";
     }
     // add uninstalling package to queue
     if (!empty($inserts)) {
         $inserts .= ',';
     }
     $inserts .= "(" . $processNo . ", " . $userID . ", '" . escapeString($package->getName()) . "', " . $package->getPackageID() . ", 'uninstall')";
     // insert queue entry (entries)
     $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t(processNo, userID, package, packageID, action)\n\t\t\tVALUES\t\t" . $inserts;
     WCF::getDB()->sendQuery($sql);
     // open queue
     HeaderUtil::redirect('index.php?page=Package&action=openQueue&processNo=' . $processNo . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     exit;
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     parent::save();
     // get new process no
     require_once WCF_DIR . 'lib/acp/package/PackageInstallationQueue.class.php';
     $processNo = PackageInstallationQueue::getNewProcessNo();
     // set installationType for redirecting after finish installation
     $type = 'other';
     if ($this->package === null) {
         $type = 'install';
     }
     // insert queue entry
     $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t(processNo, userID, package, packageID, archive, action, confirmInstallation, cancelable, installationType)\n\t\t\tVALUES\t\t(" . $processNo . ",\n\t\t\t\t\t" . WCF::getUser()->userID . ",\n\t\t\t\t\t'" . escapeString($this->archive->getPackageInfo('name')) . "',\n\t\t\t\t\t" . $this->packageID . ",\n\t\t\t\t\t'" . escapeString(!empty($this->uploadPackage['tmp_name']) ? $this->uploadPackage['tmp_name'] : $this->downloadPackage) . "',\n\t\t\t\t\t'" . ($this->package != null ? 'update' : 'install') . "',\n\t\t\t\t\t1,\n\t\t\t\t\t" . ($this->package != null ? 0 : 1) . ",\n\t\t\t\t\t'" . $type . "')";
     WCF::getDB()->sendQuery($sql);
     $this->queueID = WCF::getDB()->getInsertID();
     $this->saved();
     // open queue
     HeaderUtil::redirect('index.php?page=Package&action=openQueue&processNo=' . $processNo . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     exit;
 }