/** * Installs current package. * * @param array $nodeData */ protected function installPackage(array $nodeData) { $installationStep = new PackageInstallationStep(); // check requirements if (!empty($nodeData['requirements'])) { foreach ($nodeData['requirements'] as $package => $requirementData) { // get existing package if ($requirementData['packageID']) { $sql = "SELECT\tpackageName, packageVersion\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($requirementData['packageID'])); } else { // try to find matching package $sql = "SELECT\tpackageName, packageVersion\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package)); } $row = $statement->fetchArray(); // package is required but not available if ($row === false) { throw new SystemException("Package '" . $package . "' is required by '" . $nodeData['packageName'] . "', but is neither installed nor shipped."); } // check version requirements if ($requirementData['minVersion']) { if (Package::compareVersion($row['packageVersion'], $requirementData['minVersion']) < 0) { throw new SystemException("Package '" . $nodeData['packageName'] . "' requires the package '" . $row['packageName'] . "' in version '" . $requirementData['minVersion'] . "', but version '" . $row['packageVersion'] . "'"); } } } } unset($nodeData['requirements']); if (!$this->queue->packageID) { // create package entry $package = PackageEditor::create($nodeData); // update package id for current queue $queueEditor = new PackageInstallationQueueEditor($this->queue); $queueEditor->update(array('packageID' => $package->packageID)); // save excluded packages if (count($this->getArchive()->getExcludedPackages()) > 0) { $sql = "INSERT INTO\twcf" . WCF_N . "_package_exclusion \n\t\t\t\t\t\t\t(packageID, excludedPackage, excludedPackageVersion)\n\t\t\t\t\tVALUES \t\t(?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($this->getArchive()->getExcludedPackages() as $excludedPackage) { $statement->execute(array($package->packageID, $excludedPackage['name'], !empty($excludedPackage['version']) ? $excludedPackage['version'] : '')); } } // insert requirements and dependencies $requirements = $this->getArchive()->getAllExistingRequirements(); if (count($requirements) > 0) { $sql = "INSERT INTO\twcf" . WCF_N . "_package_requirement\n\t\t\t\t\t\t\t(packageID, requirement)\n\t\t\t\t\tVALUES\t\t(?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($requirements as $identifier => $possibleRequirements) { if (count($possibleRequirements) == 1) { $requirement = array_shift($possibleRequirements); } else { $requirement = $possibleRequirements[$this->selectedRequirements[$identifier]]; } $statement->execute(array($package->packageID, $requirement['packageID'])); } } // build requirement map Package::rebuildPackageRequirementMap($package->packageID); // rebuild dependencies Package::rebuildPackageDependencies($package->packageID); if ($this->action == 'update') { Package::rebuildParentPackageDependencies($package->packageID); } // reload queue $this->queue = new PackageInstallationQueue($this->queue->queueID); $this->package = null; if ($package->isApplication) { $host = RouteHandler::getHost(); $path = RouteHandler::getPath(array('acp')); // insert as application ApplicationEditor::create(array('domainName' => $host, 'domainPath' => $path, 'packageID' => $package->packageID)); } // insert dependencies on parent package if applicable $this->installPackageParent(); } if ($this->getPackage()->isApplication && $this->getPackage()->package != 'com.woltlab.wcf' && $this->getAction() == 'install') { if (empty($this->getPackage()->packageDir)) { $document = $this->promptPackageDir(); if ($document !== null && $document instanceof form\FormDocument) { $installationStep->setDocument($document); } $installationStep->setSplitNode(); } } else { if ($this->getPackage()->parentPackageID) { $packageEditor = new PackageEditor($this->getPackage()); $packageEditor->update(array('packageDir' => $this->getPackage()->getParentPackage()->packageDir)); } } return $installationStep; }