Add redirect to package installation if package is imported as style
authorMatthias Schmidt <gravatronics@live.com>
Thu, 27 Mar 2014 17:53:59 +0000 (18:53 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 27 Mar 2014 17:53:59 +0000 (18:53 +0100)
wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl
wcfsetup/install/files/acp/templates/packageStartInstall.tpl
wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php
wcfsetup/install/files/lib/acp/form/StyleImportForm.class.php
wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index c4849dea147341c0c86a3eb6fa49695546a12a47..622bcafd756c90b4a467f1cdfdc834616a3fa5a7 100644 (file)
@@ -30,9 +30,9 @@
 {if $excludingPackages|count > 0}
        <div class="error">{lang}wcf.acp.package.install.error.excludingPackages{/lang}
                <ul>
-               {foreach from=$excludingPackages item=excludingPackage}
-                       <li>{lang}wcf.acp.package.install.error.excludingPackages.excludingPackage{/lang}</li>
-               {/foreach}
+                       {foreach from=$excludingPackages item=excludingPackage}
+                               <li>{lang}wcf.acp.package.install.error.excludingPackages.excludingPackage{/lang}</li>
+                       {/foreach}
                </ul>
        </div>
 {/if}
 {if $excludedPackages|count > 0}
        <div class="error">{lang}wcf.acp.package.install.error.excludedPackages{/lang}
                <ul>
-               {foreach from=$excludedPackages item=excludedPackage}
-                       <li>{lang}wcf.acp.package.install.error.excludedPackages.excludedPackage{/lang}</li>
-               {/foreach}
+                       {foreach from=$excludedPackages item=excludedPackage}
+                               <li>{lang}wcf.acp.package.install.error.excludedPackages.excludedPackage{/lang}</li>
+                       {/foreach}
                </ul>
        </div>
 {/if}
 
+{if $installingImportedStyle}
+       <p class="info">{lang}wcf.acp.package.install.installingImportedStyle{/lang}</p>
+{/if}
+
 <div class="container containerPadding marginTop">
        <fieldset>
                <legend>{lang}wcf.acp.package.information.properties{/lang}</legend>
index bd87f769a02eb0f3d3b72e30625ba8e4ef7739b9..3a17cd96bcbb383b19d9109ab1acfdd88f0e9f0d 100644 (file)
        <h1>{lang}{@$pageTitle}{/lang}</h1>
 </header>
 
+{if $errorField && $installingImportedStyle}
+       <p class="info">{lang}wcf.acp.package.install.installingImportedStyle{/lang}</p>
+{/if}
+
 {include file='formError'}
 
 <div class="contentNavigation">
index 7a94c4d7061a41bb79cb240189c59451be50b261..0e793e3ac1f2a1b93db1e419713650cec6bfb304 100755 (executable)
@@ -60,14 +60,34 @@ class PackageStartInstallForm extends AbstractForm {
         */
        public $queue = null;
        
+       /**
+        * location of the package uploaded via style import
+        * @var string
+        */
+       public $stylePackageImportLocation = '';
+       
+       /**
+        * @see \wcf\page\IPage::readParameters()
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               $this->stylePackageImportLocation = WCF::getSession()->getVar('stylePackageImportLocation');
+               if ($this->stylePackageImportLocation) {
+                       $_POST['t'] = WCF::getSession()->getSecurityToken();
+               }
+       }
+       
        /**
         * @see \wcf\form\IForm::readFormParameters()
         */
        public function readFormParameters() {
                parent::readFormParameters();
                
-               if (isset($_POST['downloadPackage'])) $this->downloadPackage = StringUtil::trim($_POST['downloadPackage']);
-               if (isset($_FILES['uploadPackage'])) $this->uploadPackage = $_FILES['uploadPackage'];
+               if (!$this->stylePackageImportLocation) {
+                       if (isset($_POST['downloadPackage'])) $this->downloadPackage = StringUtil::trim($_POST['downloadPackage']);
+                       if (isset($_FILES['uploadPackage'])) $this->uploadPackage = $_FILES['uploadPackage'];
+               }
        }
        
        /**
@@ -76,7 +96,19 @@ class PackageStartInstallForm extends AbstractForm {
        public function validate() {
                parent::validate();
                
-               if (!empty($this->uploadPackage['name'])) {
+               if ($this->stylePackageImportLocation) {
+                       $this->archive = new PackageArchive($this->stylePackageImportLocation, $this->package);
+                       
+                       try {
+                               $this->validateArchive('uploadPackage');
+                       }
+                       catch (UserInputException $e) {
+                               WCF::getSession()->unregister('stylePackageImportLocation');
+                               
+                               throw $e;
+                       }
+               }
+               else if (!empty($this->uploadPackage['name'])) {
                        $this->validateUploadPackage();
                }
                else if (!empty($this->downloadPackage)) {
@@ -207,6 +239,14 @@ class PackageStartInstallForm extends AbstractForm {
                // obey foreign key
                $packageID = ($this->package) ? $this->package->packageID : null;
                
+               $archive = $this->downloadPackage;
+               if ($this->stylePackageImportLocation) {
+                       $archive = $this->stylePackageImportLocation;
+               }
+               else if (!empty($this->uploadPackage['tmp_name'])) {
+                       $archive = $this->uploadPackage['name'];
+               }
+               
                // insert queue
                $isApplication = $this->archive->getPackageInfo('isApplication');
                $this->queue = PackageInstallationQueueEditor::create(array(
@@ -215,7 +255,7 @@ class PackageStartInstallForm extends AbstractForm {
                        'package' => $this->archive->getPackageInfo('name'),
                        'packageName' => $this->archive->getLocalizedPackageInfo('packageName'),
                        'packageID' => $packageID,
-                       'archive' => (!empty($this->uploadPackage['tmp_name']) ? $this->uploadPackage['name'] : $this->downloadPackage),
+                       'archive' => $archive,
                        'action' => ($this->package != null ? 'update' : 'install'),
                        'isApplication' => (!$isApplication ? '0' : '1')
                ));
@@ -233,7 +273,8 @@ class PackageStartInstallForm extends AbstractForm {
                parent::assignVariables();
                
                WCF::getTPL()->assign(array(
-                       'package' => $this->package
+                       'package' => $this->package,
+                       'installingImportedStyle' => $this->stylePackageImportLocation != ''
                ));
        }
        
index 1a0e8a2b9e11fd85e2a03690d5143f4bde24217e..f31756c1ab99f9d3086dd217a9b92c150a6a1181 100644 (file)
@@ -3,8 +3,13 @@ namespace wcf\acp\form;
 use wcf\data\style\StyleEditor;
 use wcf\form\AbstractForm;
 use wcf\system\cache\builder\StyleCacheBuilder;
+use wcf\system\exception\SystemException;
 use wcf\system\exception\UserInputException;
+use wcf\system\package\PackageArchive;
+use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
+use wcf\util\FileUtil;
+use wcf\util\HeaderUtil;
 
 /**
  * Shows the style import form.
@@ -62,6 +67,46 @@ class StyleImportForm extends AbstractForm {
                        throw new UserInputException('source', 'uploadFailed');
                }
                
+               try {
+                       // check if the uploaded file is a package
+                       $archive = new PackageArchive($this->source['tmp_name']);
+                       $archive->openArchive();
+                       
+                       // check if the package includes a style
+                       if ($archive->getPackageInfo('isApplication')) {
+                               throw new SystemException("Package is application");
+                       }
+                       
+                       $containsStyle = false;
+                       $installInstructions = $archive->getInstallInstructions();
+                       foreach ($installInstructions as $instruction) {
+                               if ($instruction['pip'] == 'style') {
+                                       $containsStyle = true;
+                                       break;
+                               }
+                       }
+                       
+                       if (!$containsStyle) {
+                               throw new SystemException("Package contains no style");
+                       }
+                       
+                       $filename = FileUtil::getTemporaryFilename('package_', preg_replace('!^.*(?=\.(?:tar\.gz|tgz|tar)$)!i', '', basename($this->source['name'])));
+                       
+                       if (!@move_uploaded_file($this->source['tmp_name'], $filename)) {
+                               throw new SystemException("Cannot move uploaded file");
+                       }
+                       
+                       WCF::getSession()->register('stylePackageImportLocation', $filename);
+                       
+                       HeaderUtil::redirect(LinkHandler::getInstance()->getLink('PackageStartInstall', array(
+                               'action' => 'install'
+                       )));
+                       exit;
+               }
+               catch (SystemException $e) {
+                       // ignore errors
+               }
+               
                try {
                        $this->style = StyleEditor::import($this->source['tmp_name']);
                }
index acd93779c6bb2136465b982821c2a12d28be4ec0..3864f72b62825c6e6de357b82d2e1f53df8ba601 100644 (file)
@@ -62,6 +62,13 @@ class PackageInstallationConfirmPage extends AbstractPage {
         */
        public $requirements = array();
        
+       /**
+        * true if the package to be installed was uploaded via the import style
+        * form
+        * @var boolean
+        */
+       public $installingImportedStyle = false;
+       
        /**
         * @see \wcf\page\IPage::readParameters()
         */
@@ -80,6 +87,11 @@ class PackageInstallationConfirmPage extends AbstractPage {
                else {
                        WCF::getSession()->checkPermissions(array('admin.system.package.canUpdatePackage'));
                }
+               
+               $this->installingImportedStyle = WCF::getSession()->getVar('stylePackageImportLocation') !== null;
+               if ($this->installingImportedStyle) {
+                       WCF::getSession()->unregister('stylePackageImportLocation');
+               }
        }
        
        /**
@@ -149,7 +161,8 @@ class PackageInstallationConfirmPage extends AbstractPage {
                        'missingPackages' => $this->missingPackages,
                        'excludingPackages' => $this->packageInstallationDispatcher->getArchive()->getConflictedExcludingPackages(),
                        'excludedPackages' => $this->packageInstallationDispatcher->getArchive()->getConflictedExcludedPackages(),
-                       'queue' => $this->queue
+                       'queue' => $this->queue,
+                       'installingImportedStyle' => $this->installingImportedStyle
                ));
        }
        
index 438631aea93233da4a1effa351bb645e6f48ac6c..116b40d9d8b661fa09093d07958dd2c455cb8b0d 100644 (file)
@@ -928,6 +928,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.package.install.error.excludingPackages"><![CDATA[Die folgenden bereits installierten Pakete schließen eine Installation dieses Pakets aus:]]></item>
                <item name="wcf.acp.package.install.error.excludingPackages.excludingPackage"><![CDATA[„{$excludingPackage}“ ({$excludingPackage->package}){if $excludingPackage->excludedPackageVersion} (ausgeschlossene Version: {$excludingPackage->excludedPackageVersion}){/if}]]></item>
                <item name="wcf.acp.package.install.error.missingRequirements"><![CDATA[Die Abhängigkeiten dieses Paketes konnten nicht aufgelöst werden.]]></item>
+               <item name="wcf.acp.package.install.installingImportedStyle"><![CDATA[Bei der hochgeladenen Datei handelt es sich um ein Paket, welches einen Stil enthält.]]></item>
                <item name="wcf.acp.package.install.optionalPackage.missingRequirements"><![CDATA[Installation nicht möglich, nicht alle benötigten Pakete sind installiert.]]></item>
                <item name="wcf.acp.package.install.step.prepare"><![CDATA[Installation wird vorbereitet …]]></item>
                <item name="wcf.acp.package.install.title"><![CDATA[Paket-Installation]]></item>
index 744fa3d02d95bb3e9cc9b609409fc324d4fd8303..2f19456d8db37105e8564d1b13ea211d7a9a6cdd 100644 (file)
@@ -928,6 +928,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.package.install.error.excludingPackages"><![CDATA[The following, already installed packages prohibit installing this package:]]></item>
                <item name="wcf.acp.package.install.error.excludingPackages.excludingPackage"><![CDATA[“{$excludingPackage}” ({$excludingPackage->package}){if $excludingPackage->excludedPackageVersion} (excluded version: {$excludingPackage->excludedPackageVersion}){/if}]]></item>
                <item name="wcf.acp.package.install.error.missingRequirements"><![CDATA[Unable to resolve requirements of this package.]]></item>
+               <item name="wcf.acp.package.install.installingImportedStyle"><![CDATA[The uploaded file is a package containg a style.]]></item>
                <item name="wcf.acp.package.install.optionalPackage.missingRequirements"><![CDATA[Unable to install, some or all required packages are not installed.]]></item>
                <item name="wcf.acp.package.install.step.prepare"><![CDATA[Preparing Installation …]]></item>
                <item name="wcf.acp.package.install.title"><![CDATA[Installation]]></item>