コード例 #1
0
 /**
  * Installs optional packages for this package.
  */
 protected function installPackageOptionals()
 {
     if (count($this->packageArchive->getOptionals()) == 0) {
         // packages does not have any optional packages
         return true;
     }
     $installedOptionals = array();
     $optionalNames = '';
     foreach ($this->packageArchive->getOptionals() as $optional) {
         if (!empty($optionalNames)) {
             $optionalNames .= ',';
         }
         $optionalNames .= "'" . escapeString($optional['name']) . "'";
     }
     if ($this->action == 'update') {
         // try to find updatable optionals
         $sql = "SELECT\t*\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\tWHERE\tpackage IN (" . $optionalNames . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $installedOptionals[$row['package']][] = $row;
         }
         if (count($installedOptionals) > 0) {
             $queueInserts = '';
             foreach ($this->packageArchive->getOptionals() as $optional) {
                 if (isset($installedOptionals[$optional['name']])) {
                     // unzip and open package
                     // check the given filename
                     if (!FileUtil::isURL($optional['file'])) {
                         // filename is no url
                         // optional package is delivered with this package
                         $optional['file'] = $this->packageArchive->extractTar($optional['file'], 'optionalPackage_');
                         $optionalPackage = new PackageArchive($optional['file']);
                     } else {
                         $optionalPackage = new PackageArchive($optional['file']);
                         $optionalPackage->downloadArchive();
                     }
                     // open package archive
                     $optionalPackage->openArchive();
                     // get version number
                     $optionalVersion = $optionalPackage->getPackageInfo('version');
                     foreach ($installedOptionals[$optional['name']] as $installedOptional) {
                         if (Package::compareVersion($optionalVersion, $installedOptional['packageVersion']) == 1) {
                             // unzip tar
                             $optional['file'] = PackageArchive::unzipPackageArchive($optional['file']);
                             // add queue entry
                             if (!empty($queueInserts)) {
                                 $queueInserts .= ',';
                             }
                             $queueInserts .= "(" . $this->queueID . ", " . $this->processNo . ", " . WCF::getUser()->userID . ", '" . escapeString($installedOptional['package']) . "', " . $installedOptional['packageID'] . ", '" . escapeString($optional['file']) . "', 'optional', 0, 'update')";
                         }
                     }
                 }
             }
             if (!empty($queueInserts)) {
                 $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t\t\t\t(parentQueueID, processNo, userID, package, packageID, archive, packageType, cancelable, action)\n\t\t\t\t\t\tVALUES\t\t" . $queueInserts;
                 WCF::getDB()->sendQuery($sql);
                 return false;
             }
         }
         return true;
     } else {
         // check whether optional packages are already installed
         $sql = "SELECT\tDISTINCT package, packageID, isUnique\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\tWHERE\tpackage IN (" . $optionalNames . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $installedOptionals[$row['package']] = $row;
         }
         // build list of available optional packages
         $availableOptionals = array();
         foreach ($this->packageArchive->getOptionals() as $optional) {
             $optional['available'] = 1;
             $optional['installed'] = 0;
             if (isset($installedOptionals[$optional['name']]) && $installedOptionals[$optional['name']]['isUnique'] == 1) {
                 $optional['installed'] = 1;
                 $optional['available'] = 0;
             }
             // unzip and open package
             // check the given filename
             if (!FileUtil::isURL($optional['file'])) {
                 // filename is no url
                 // optional package is delivered with this package
                 $optional['file'] = $this->packageArchive->extractTar($optional['file'], 'optionalPackage_');
                 $optionalPackage = new PackageArchive($optional['file']);
             } else {
                 $optionalPackage = new PackageArchive($optional['file']);
                 $optionalPackage->downloadArchive();
             }
             // open package archive
             $optionalPackage->openArchive();
             // check requirements
             foreach ($optionalPackage->getOpenRequirements() as $requirement) {
                 // no filename for required package given
                 if (!isset($requirement['file'])) {
                     $optional['available'] = 0;
                     break;
                 }
             }
             // get name and description
             $optional['packageName'] = $optionalPackage->getPackageInfo('packageName');
             $optional['packageDescription'] = $optionalPackage->getPackageInfo('packageDescription');
             $availableOptionals[$optional['name']] = $optional;
         }
         // form send
         $queueInserts = '';
         if (isset($_POST['send'])) {
             $optionalPackages = array();
             if (isset($_POST['optionalPackages']) && is_array($_POST['optionalPackages'])) {
                 $optionalPackages = $_POST['optionalPackages'];
             }
             // build inserts
             foreach ($optionalPackages as $optionalPackage) {
                 if (!isset($availableOptionals[$optionalPackage]) || $availableOptionals[$optionalPackage]['available'] == 0 || $availableOptionals[$optionalPackage]['installed'] == 1) {
                     continue;
                 }
                 // unzip tar
                 $availableOptionals[$optionalPackage]['file'] = PackageArchive::unzipPackageArchive($availableOptionals[$optionalPackage]['file']);
                 if (!empty($queueInserts)) {
                     $queueInserts .= ',';
                 }
                 $cancelable = $this->getAction() == 'install' ? 1 : 0;
                 $queueInserts .= "(" . $this->queueID . ", " . $this->processNo . ", " . WCF::getUser()->userID . ", '" . escapeString($optionalPackage) . "', '" . escapeString($availableOptionals[$optionalPackage]['file']) . "', 'optional', " . $cancelable . ")";
                 $availableOptionals[$optionalPackage]['selected'] = true;
             }
         }
         // delete tmp files
         foreach ($availableOptionals as $availableOptional) {
             if (!isset($availableOptional['selected'])) {
                 @unlink($availableOptional['file']);
             }
         }
         // save inserts
         if (isset($_POST['send'])) {
             if (!empty($queueInserts)) {
                 $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t\t\t\t(parentQueueID, processNo, userID, package, archive, packageType, cancelable)\n\t\t\t\t\t\tVALUES\t\t" . $queueInserts;
                 WCF::getDB()->sendQuery($sql);
                 return false;
             } else {
                 return true;
             }
         }
         // sort optionals
         uasort($availableOptionals, create_function('$packageA,$packageB', 'return strcasecmp($packageA[\'packageName\'], $packageB[\'packageName\']);'));
         // show form
         WCF::getTPL()->assign(array('availableOptionals' => $availableOptionals));
         WCF::getTPL()->display('packageInstallationSelectOptionals');
         exit;
     }
 }