/**
  * @see wcf\page\IPage::assignVariables()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (!count($_POST)) {
         // refresh package database
         PackageUpdateDispatcher::refreshPackageDatabase();
     }
     // get updatable packages
     $this->availableUpdates = PackageUpdateDispatcher::getAvailableUpdates();
 }
 /**
  * @see wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // refresh package database
     PackageUpdateDispatcher::refreshPackageDatabase($this->packageUpdateServerIDs);
     // build conditions
     $conditions = new PreparedStatementConditionBuilder();
     // update servers
     if (count($this->packageUpdateServerIDs)) {
         $conditions->add("packageUpdateServerID IN (?)", array($this->packageUpdateServerIDs));
     }
     // name
     if (!empty($this->packageName)) {
         $condition = "packageName LIKE ?";
         $parameters = array('%' . $this->packageName . '%');
         if ($this->searchDescription) {
             $condition .= " OR packageDescription LIKE ?";
             $parameters[] = '%' . $this->packageName . '%';
         }
         $conditions->add('(' . $condition . ')', $parameters);
     }
     // author
     if (!empty($this->author)) {
         $conditions->add("author LIKE ?", array($this->author));
     }
     // ignore already installed uniques
     if ($this->ignoreUniques == 1) {
         $conditions->add("package NOT IN (SELECT package FROM wcf" . WCF_N . "_package WHERE isUnique = 1)");
     }
     // package type
     if (($this->plugin == 0 || $this->isApplication == 0 || $this->other == 0) && ($this->plugin == 1 || $this->isApplication == 1 || $this->other == 1)) {
         if ($this->isApplication == 1) {
             $condition = 'isApplication = 1';
             if ($this->plugin == 1) {
                 $condition .= " OR plugin IN (SELECT package FROM wcf" . WCF_N . "_package)";
             } else {
                 if ($this->other == 1) {
                     $condition .= " OR plugin = ''";
                 }
             }
             $conditions->add('(' . $condition . ')');
         } else {
             if ($this->plugin == 1) {
                 $condition = "plugin IN (SELECT package FROM wcf" . WCF_N . "_package)";
                 if ($this->other == 1) {
                     $condition .= " OR isApplication = 0";
                 }
                 $conditions->add('(' . $condition . ')');
             } else {
                 if ($this->other) {
                     $conditions->add("(isApplication = 0 AND plugin = '')");
                 }
             }
         }
     }
     // search package database
     $packages = array();
     $packageUpdateIDs = array();
     $sql = "SELECT\tpackage, packageUpdateID\n\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql, 1000);
     $statement->execute($conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         $packageUpdateIDs[] = $row['packageUpdateID'];
         if (!isset($packages[$row['package']])) {
             $packages[$row['package']] = array();
         }
         $packages[$row['package']][$row['packageUpdateID']] = array();
     }
     if (empty($packageUpdateIDs)) {
         throw new UserInputException('packageName');
     }
     // remove duplicates
     $condition = '';
     $statementParameters = array();
     foreach ($packageUpdateIDs as $packageUpdateID) {
         if (!empty($condition)) {
             $condition .= ',';
         }
         $condition .= '?';
         $statementParameters[] = $packageUpdateID;
     }
     $sql = "SELECT\t\tpuv.packageVersion, pu.package, pu.packageUpdateID\n\t\t\tFROM\t\twcf" . WCF_N . "_package_update_version puv\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_update pu\n\t\t\tON\t\t(pu.packageUpdateID = puv.packageUpdateID)\n\t\t\tWHERE\t\tpuv.packageUpdateID IN (" . $condition . ")";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($statementParameters);
     while ($row = $statement->fetchArray()) {
         $packages[$row['package']][$row['packageUpdateID']][] = $row['packageVersion'];
     }
     foreach ($packages as $identifier => $packageUpdates) {
         if (count($packageUpdates) > 1) {
             foreach ($packageUpdates as $packageUpdateID => $versions) {
                 usort($versions, array('wcf\\data\\package\\Package', 'compareVersion'));
                 $packageUpdates[$packageUpdateID] = array_pop($versions);
             }
             uasort($packageUpdates, array('wcf\\data\\package\\Package', 'compareVersion'));
         }
         $keys = array_keys($packageUpdates);
         if (!empty($this->packageUpdateIDs)) {
             $this->packageUpdateIDs .= ',';
         }
         $this->packageUpdateIDs .= array_pop($keys);
     }
 }