Support for optional packages (crash for sure!)
authorAlexander Ebert <ebert@woltlab.com>
Thu, 6 Oct 2011 15:02:19 +0000 (17:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 6 Oct 2011 15:02:19 +0000 (17:02 +0200)
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php

index 2a0a0ccb2b4f41cf9c46383f8a7384662c3a37f3..9da7230fb4aa7dda48803ae93159c741023d5bd9 100644 (file)
@@ -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('<pre>'.print_r($packages, true));
+               }
+       }
+       
        /**
         * Returns current package id.
         *
index 2690fe61c01f24fd296cdb001c6e695f57f232ad..2218da4e437f12b74588f3a1ee832cfd7190f035 100644 (file)
@@ -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)
+                       ));
                }
        }