/**
  * Gets a list of available updates.
  */
 protected function readUpdates()
 {
     if (WCF::getUser()->getPermission('admin.system.package.canUpdatePackage')) {
         require_once WCF_DIR . 'lib/acp/package/update/PackageUpdate.class.php';
         $this->updates = PackageUpdate::getAvailableUpdates();
     }
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     $this->os = PHP_OS;
     if (isset($_SERVER['SERVER_SOFTWARE'])) {
         $this->webserver = $_SERVER['SERVER_SOFTWARE'];
     }
     $this->sqlVersion = WCF::getDB()->getVersion();
     $this->sqlType = WCF::getDB()->getDBType();
     $this->readLoad();
     $this->readStat();
     // updates
     if (WCF::getUser()->getPermission('admin.system.package.canUpdatePackage')) {
         require_once WCF_DIR . 'lib/acp/package/update/PackageUpdate.class.php';
         $this->updates = PackageUpdate::getAvailableUpdates();
     }
     // news
     if (false) {
         $this->news = FeedReaderSource::getEntries(5);
         foreach ($this->news as $key => $news) {
             $this->news[$key]['description'] = preg_replace('/href="(.*?)"/e', '\'href="' . RELATIVE_WCF_DIR . 'acp/dereferrer.php?url=\'.rawurlencode(\'$1\').\'" class="externalURL"\'', $news['description']);
         }
     } else {
         $this->news = array();
     }
 }
 /**
  * @see	Page::assignVariables()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (!count($_POST)) {
         // refresh package database
         PackageUpdate::refreshPackageDatabase();
     }
     // get updatable packages
     $this->availableUpdates = PackageUpdate::getAvailableUpdates();
 }
 /**
  * @see Page::readData()
  */
 public function readData()
 {
     parent::readData();
     $this->os = PHP_OS;
     if (isset($_SERVER['SERVER_SOFTWARE'])) {
         $this->webserver = $_SERVER['SERVER_SOFTWARE'];
     }
     $this->sqlVersion = WCF::getDB()->getVersion();
     $this->sqlType = WCF::getDB()->getDBType();
     $this->readLoad();
     $this->readStat();
     // updates
     if (WCF::getUser()->getPermission('admin.system.package.canUpdatePackage')) {
         require_once WCF_DIR . 'lib/acp/package/update/PackageUpdate.class.php';
         $updates = PackageUpdate::getAvailableUpdates();
         //print_r($updates);exit;
         foreach ($updates as $update) {
             $versions = array_reverse($update['versions']);
             // find newest minor update
             $i = 0;
             $currentVersionStatus = preg_match('/(alpha|beta|RC)/i', $update['packageVersion']) ? 'unstable' : 'stable';
             foreach ($versions as $version) {
                 $newVersionStatus = preg_match('/(alpha|beta|RC)/i', $version['packageVersion']) ? 'unstable' : 'stable';
                 if ($currentVersionStatus == $newVersionStatus && preg_match('/^(\\d\\.\\d)/', $update['packageVersion'], $match1) && preg_match('/^(\\d\\.\\d)/', $version['packageVersion'], $match2)) {
                     if ($match1[1] == $match2[1]) {
                         $minorUpdate = $update;
                         $minorUpdate['version'] = $version;
                         $this->minorUpdates[] = $minorUpdate;
                         if ($i != 0) {
                             $this->majorUpdates[] = $update;
                         }
                         continue 2;
                     }
                 }
                 $i++;
             }
             $this->majorUpdates[] = $update;
         }
     }
     // news
     $this->news = FeedReaderSource::getEntries(5);
     foreach ($this->news as $key => $news) {
         $this->news[$key]['description'] = preg_replace_callback('/href="(.*?)"/', array('IndexPage', 'parseNewsFeedCallback'), $news['description']);
     }
 }
 /**
  * Gets a list of available updates.
  */
 protected function readUpdates()
 {
     if (WCF::getUser()->getPermission('admin.system.package.canUpdatePackage')) {
         require_once WCF_DIR . 'lib/acp/package/update/PackageUpdate.class.php';
         $this->updates = PackageUpdate::getAvailableUpdates();
         // kick wbb 3.0 updates
         if (CMS_DISABLE_WBB_UPDATES) {
             foreach ($this->updates as $packageID => $package) {
                 if ($package['package'] == 'com.woltlab.wbb') {
                     foreach ($package['versions'] as $version => $packageVersion) {
                         if (Package::compareVersion($version, '3.0.0 Beta 1', '>=')) {
                             unset($this->updates[$packageID]['versions'][$version]);
                         }
                     }
                     if (!count($this->updates[$packageID]['versions'])) {
                         $this->updates = PackageUpdate::getAvailableUpdates(false);
                         unset($this->updates[$packageID]);
                     } else {
                         $this->updates[$packageID]['version'] = end($this->updates[$packageID]['versions']);
                     }
                 }
             }
         }
     }
 }
 /**
  * @see Cronjob::execute()
  */
 public function execute($data)
 {
     require_once WCF_DIR . 'lib/acp/package/update/PackageUpdate.class.php';
     PackageUpdate::refreshPackageDatabaseAutomatically();
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     // refresh package database
     PackageUpdate::refreshPackageDatabase($this->packageUpdateServerIDs);
     // build conditions
     require_once WCF_DIR . 'lib/system/database/ConditionBuilder.class.php';
     $conditions = new ConditionBuilder();
     // update servers
     if (count($this->packageUpdateServerIDs)) {
         $conditions->add('packageUpdateServerID IN (' . implode(',', $this->packageUpdateServerIDs) . ')');
     }
     // name
     if (!empty($this->packageName)) {
         $condition = "packageName LIKE '%" . escapeString($this->packageName) . "%'";
         if ($this->searchDescription == 1) {
             $condition .= " OR packageDescription LIKE '%" . escapeString($this->packageName) . "%'";
         }
         $conditions->add('(' . $condition . ')');
     }
     // author
     if (!empty($this->author)) {
         $conditions->add("author LIKE '" . escapeString($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->standalone == 0 || $this->other == 0) && ($this->plugin == 1 || $this->standalone == 1 || $this->other == 1)) {
         if ($this->standalone == 1) {
             $condition = 'standalone = 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 standalone = 0";
                 }
                 $conditions->add('(' . $condition . ')');
             } else {
                 if ($this->other) {
                     $conditions->add("(standalone = 0 AND plugin = '')");
                 }
             }
         }
     }
     // search package database
     $packages = array();
     $packageUpdateIDs = '';
     $sql = "SELECT\tpackage, packageUpdateID\n\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t" . $conditions->get();
     $result = WCF::getDB()->sendQuery($sql, 1000);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!empty($packageUpdateIDs)) {
             $packageUpdateIDs .= ',';
         }
         $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
     $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 (" . $packageUpdateIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $packages[$row['package']][$row['packageUpdateID']][] = $row['packageVersion'];
     }
     foreach ($packages as $identifier => $packageUpdates) {
         if (count($packageUpdates) > 1) {
             foreach ($packageUpdates as $packageUpdateID => $versions) {
                 usort($versions, array('Package', 'compareVersion'));
                 $packageUpdates[$packageUpdateID] = array_pop($versions);
             }
             uasort($packageUpdates, array('Package', 'compareVersion'));
         }
         $keys = array_keys($packageUpdates);
         if (!empty($this->packageUpdateIDs)) {
             $this->packageUpdateIDs .= ',';
         }
         $this->packageUpdateIDs .= array_pop($keys);
     }
 }