From: Matthias Schmidt Date: Thu, 27 Mar 2014 17:53:59 +0000 (+0100) Subject: Add redirect to package installation if package is imported as style X-Git-Tag: 2.1.0_Alpha_1~946 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b168bf953c39c255362caf5f63dfa7783bc70313;p=GitHub%2FWoltLab%2FWCF.git Add redirect to package installation if package is imported as style --- diff --git a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl index c4849dea14..622bcafd75 100644 --- a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl +++ b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl @@ -30,9 +30,9 @@ {if $excludingPackages|count > 0}
{lang}wcf.acp.package.install.error.excludingPackages{/lang}
{/if} @@ -40,13 +40,17 @@ {if $excludedPackages|count > 0}
{lang}wcf.acp.package.install.error.excludedPackages{/lang}
{/if} +{if $installingImportedStyle} +

{lang}wcf.acp.package.install.installingImportedStyle{/lang}

+{/if} +
{lang}wcf.acp.package.information.properties{/lang} diff --git a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl index bd87f769a0..3a17cd96bc 100644 --- a/wcfsetup/install/files/acp/templates/packageStartInstall.tpl +++ b/wcfsetup/install/files/acp/templates/packageStartInstall.tpl @@ -24,6 +24,10 @@

{lang}{@$pageTitle}{/lang}

+{if $errorField && $installingImportedStyle} +

{lang}wcf.acp.package.install.installingImportedStyle{/lang}

+{/if} + {include file='formError'}
diff --git a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php index 7a94c4d706..0e793e3ac1 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php @@ -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 != '' )); } diff --git a/wcfsetup/install/files/lib/acp/form/StyleImportForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleImportForm.class.php index 1a0e8a2b9e..f31756c1ab 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleImportForm.class.php @@ -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']); } diff --git a/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php index acd93779c6..3864f72b62 100644 --- a/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php @@ -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 )); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 438631aea9..116b40d9d8 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -928,6 +928,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> package}){if $excludingPackage->excludedPackageVersion} (ausgeschlossene Version: {$excludingPackage->excludedPackageVersion}){/if}]]> + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 744fa3d02d..2f19456d8d 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -928,6 +928,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> package}){if $excludingPackage->excludedPackageVersion} (excluded version: {$excludingPackage->excludedPackageVersion}){/if}]]> +