From: Alexander Ebert Date: Thu, 6 Oct 2011 15:02:19 +0000 (+0200) Subject: Support for optional packages (crash for sure!) X-Git-Tag: 2.0.0_Beta_1~1724 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=492816d3ac32a01142cc9a914f1fe2573574c45d;p=GitHub%2FWoltLab%2FWCF.git Support for optional packages (crash for sure!) --- diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 2a0a0ccb2b..9da7230fb4 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -100,6 +100,10 @@ class PackageInstallationDispatcher { $step = $this->executePIP($nodeData); break; + case 'optionalPackages': + $step = $this->selectOptionalPackages($nodeData); + break; + default: die("Unknown node type: '".$data['nodeType']."'"); break; @@ -336,6 +340,19 @@ class PackageInstallationDispatcher { return $installationStep; } + protected function selectOptionalPackages(array $nodeData) { + $installationStep = new PackageInstallationStep(); + + $document = $this->promptOptionalPackages($nodeData); + if ($document !== null && $document instanceof form\FormDocument) { + $installationStep->setDocument($document); + } + + $installationStep->setSplitNode(); + + return $installationStep; + } + /** * Extracts files from .tar (or .tar.gz) archive and installs them * @@ -403,6 +420,33 @@ class PackageInstallationDispatcher { } } + protected function promptOptionalPackages(array $packages) { + if (!PackageInstallationFormManager::findForm($this->queue, 'optionalPackages')) { + $container = new container\MultipleSelectionFormElementContainer(); + + foreach ($packages as $package) { + $optionalPackage = new element\MultipleSelectionFormElement($container); + $optionalPackage->setLabel($package['packageName']); + $optionalPackage->setValue($package['package']); + + $container->appendChild($optionalPackage); + } + + $document = new form\FormDocument('optionalPackages'); + $document->appendContainer($container); + + PackageInstallationFormManager::registerForm($this->queue, $document); + return $document; + } + else { + $document = PackageInstallationFormManager::getForm($this->queue, 'optionalPackages'); + $document->handleRequest(); + + $packages = $document->getValue('optionalPackages'); + die('
'.print_r($packages, true));
+		}
+	}
+	
 	/**
 	 * Returns current package id.
 	 *
diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php
index 2690fe61c0..2218da4e43 100644
--- a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php
+++ b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php
@@ -451,39 +451,49 @@ class PackageInstallationNodeBuilder {
 	 * not really matter at this point).
 	 */
 	protected function buildOptionalNodes() {
-		$packageNodes = array();
+		$packages = array();
 		
 		$optionalPackages = $this->installation->getArchive()->getOptionals();
 		foreach ($optionalPackages as $package) {
-			$packageNodes[] = array(
-				'data' => $package
-			);
+			// extract package
+			$index = $this->installation->getArchive()->getTar()->getIndexByFilename($package['file']);
+			if ($index === false) {
+				throw new SystemException("Unable to find required package '".$package['file']."' within archive.");
+			}
+			
+			$fileName = FileUtil::getTemporaryFilename('package_', preg_replace('!^.*(?=\.(?:tar\.gz|tgz|tar)$)!i', '', basename($package['file'])));
+			$this->installation->getArchive()->getTar()->extract($index, $fileName);
+			
+			// get archive data
+			$archive = new PackageArchive($fileName);
+			$archive->openArchive();
 			
-			$lastNode = $newNode;
+			$packages[] = array(
+				'archive' => $fileName,
+				'package' => $archive->getPackageInfo('name'),
+				'packageName' => $archive->getPackageInfo('packageName'),
+				'selected' => 0
+			);
 		}
 		
-		if (!empty($packageNodes)) {
+		if (!empty($packages)) {
 			$this->parentNode = $this->node;
 			$this->node = $this->getToken();
-			$this->sequenceNo = -1;
+			$this->sequenceNo = 0;
 			
 			$sql = "INSERT INTO	wcf".WCF_N."_package_installation_node
 						(queueID, processNo, sequenceNo, node, parentNode, nodeType, nodeData)
 				VALUES		(?, ?, ?, ?, ?, ?, ?)";
 			$statement = WCF::getDB()->prepareStatement($sql);
-			foreach ($packageNodes as $nodeData) {
-				$this->sequenceNo = 0;
-				
-				$statement->execute(array(
-					$this->installation->queue->queueID,
-					$this->installation->queue->processNo,
-					$this->sequenceNo,
-					$this->node,
-					$this->parentNode,
-					'optionalPackage',
-					serialize($nodeData['data'])
-				));
-			}
+			$statement->execute(array(
+				$this->installation->queue->queueID,
+				$this->installation->queue->processNo,
+				$this->sequenceNo,
+				$this->node,
+				$this->parentNode,
+				'optionalPackages',
+				serialize($packages)
+			));
 		}
 	}