From 25c89d0a1c01d89d84fd0a5707597221d447e1e3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 14 Apr 2014 21:39:54 +0200 Subject: [PATCH] Updated package installation is now fully working There are still a bunch of missing language variables and initial errors occurring during upload aren't properly handled yet. Furthermore it does not check local packages (or those downloaded via HTTP). Additionally checks for package exclusions have been disabled for testing purposes. --- .../templates/packageInstallationConfirm.tpl | 52 ++++------- .../form/PackageStartInstallForm.class.php | 2 +- .../PackageInstallationConfirmPage.class.php | 86 ++----------------- ...anguagePackageInstallationPlugin.class.php | 8 ++ .../PackageValidationArchive.class.php | 44 ++++++++-- .../PackageValidationManager.class.php | 31 ++++++- wcfsetup/install/lang/de.xml | 3 + 7 files changed, 101 insertions(+), 125 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl index 622bcafd75..14de2d5c5f 100644 --- a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl +++ b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl @@ -23,28 +23,8 @@

{$archive->getLocalizedPackageInfo('packageDescription')}

-{if $missingPackages > 0} -

{lang}wcf.acp.package.install.error.missingRequirements{/lang}

-{/if} - -{if $excludingPackages|count > 0} -
{lang}wcf.acp.package.install.error.excludingPackages{/lang} - -
-{/if} - -{if $excludedPackages|count > 0} -
{lang}wcf.acp.package.install.error.excludedPackages{/lang} - -
+{if !$validationPassed} +

{lang}wcf.acp.package.validation.failed{/lang}

{/if} {if $installingImportedStyle} @@ -86,10 +66,10 @@ -{if $requiredPackages|count > 0} +{if !$validationPassed}
-

{lang}wcf.acp.package.dependencies.required{/lang} {#$requiredPackages|count}

+

{lang}wcf.acp.package.validation{/lang}

@@ -97,23 +77,23 @@ - - - {event name='columnHeads'} - - {foreach from=$requiredPackages item=$package} + {foreach from=$packageValidationArchives item=packageValidationArchive} + {assign var=exceptionMessage value=$packageValidationArchive->getExceptionMessage()} - - - - - - {event name='columns'} + + + + + {if $exceptionMessage} + + + + {/if} {/foreach}
{lang}wcf.acp.package.name{/lang} {lang}wcf.acp.package.identifier{/lang}{lang}wcf.acp.package.installation.requiredVersion{/lang} {lang}wcf.acp.package.installation.packageStatus{/lang}
{if $package[package]}{$package[package]->packageName|language}{/if}{@$package.name}{if $package.minversion|isset}{$package.minversion}{/if}{lang}wcf.acp.package.installation.packageStatus.{@$package.status}{/lang}getDepth()} style="padding-left: {@$packageValidationArchive->getDepth() * 14}px"{/if}>{$packageValidationArchive->getArchive()->getLocalizedPackageInfo('packageName')}{$packageValidationArchive->getArchive()->getPackageInfo('name')}
getDepth()} style="padding-left: {@$packageValidationArchive->getDepth() * 14}px"{/if}>{@$exceptionMessage}
@@ -122,7 +102,7 @@
- {if $missingPackages == 0 && $excludingPackages|count == 0 && $excludedPackages|count == 0} + {if $validationPassed} {/if}
diff --git a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php index 5e711b7525..28f8cadafe 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php @@ -139,7 +139,7 @@ class PackageStartInstallForm extends AbstractForm { if (!PackageValidationManager::getInstance()->validate($this->uploadPackage['name'], false)) { // TODO: do something - die("validation failed"); + die("validation failed: " . PackageValidationManager::getInstance()->getExceptionMessage()); } $this->package = PackageValidationManager::getInstance()->getPackageValidationArchive()->getPackage(); diff --git a/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php index 0fd64fa803..b86cbe5514 100644 --- a/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackageInstallationConfirmPage.class.php @@ -1,15 +1,12 @@ - */ - public $openRequirements = array(); - /** * package installation dispatcher object * @var \wcf\system\package\PackageInstallationDispatcher @@ -58,10 +43,10 @@ class PackageInstallationConfirmPage extends AbstractPage { public $queueID = 0; /** - * list of requirements - * @var array + * package validation result + * @var boolean */ - public $requirements = array(); + public $validationPassed = false; /** * true if the package to be installed was uploaded via the import style @@ -104,63 +89,7 @@ class PackageInstallationConfirmPage extends AbstractPage { $this->packageInstallationDispatcher = new PackageInstallationDispatcher($this->queue); // validate the package and all it's requirements - if (PackageValidationManager::getInstance()->validate($this->queue->archive, true)) { - die("success"); - } - else { - /*echo "
";
-			foreach (PackageValidationManager::getInstance()->getPackageValidationArchiveList() as $archive) {
-				echo '[' . $archive->getArchive()->getPackageInfo('name') . '] ' . $archive->getExceptionMessage() . "\n";
-			}
-			die("failed");*/
-			return;
-		}
-		
-		// get requirements
-		$this->requirements = $this->packageInstallationDispatcher->getArchive()->getRequirements();
-		$this->openRequirements = $this->packageInstallationDispatcher->getArchive()->getOpenRequirements();
-		
-		foreach ($this->requirements as &$requirement) {
-			if (isset($this->openRequirements[$requirement['name']])) {
-				$requirement['status'] = 'missing';
-				$requirement['action'] = $this->openRequirements[$requirement['name']]['action'];
-				
-				if (!isset($requirement['file'])) {
-					if ($requirement['action'] === 'update') {
-						$requirement['status'] = 'missingVersion';
-						$requirement['existingVersion'] = $this->openRequirements[$requirement['name']]['existingVersion'];
-					}
-					$this->missingPackages++;
-				}
-				else {
-					$requirement['status'] = 'delivered';
-					$packageArchive = new PackageArchive($this->packageInstallationDispatcher->getArchive()->extractTar($requirement['file']));
-					$packageArchive->openArchive();
-					
-					// make sure that the delivered package is correct
-					if ($requirement['name'] != $packageArchive->getPackageInfo('name')) {
-						$requirement['status'] = 'invalidDeliveredPackage';
-						$requirement['deliveredPackage'] = $packageArchive->getPackageInfo('name');
-						$this->missingPackages++;
-					}
-					else if (isset($requirement['minversion'])) {
-						// make sure that the delivered version is sufficient
-						if (Package::compareVersion($requirement['minversion'], $packageArchive->getPackageInfo('version')) > 0) {
-							$requirement['deliveredVersion'] = $packageArchive->getPackageInfo('version');
-							$requirement['status'] = 'missingVersion';
-							$this->missingPackages++;
-						}
-					}
-				}
-			}
-			else {
-				$requirement['status'] = 'installed';
-			}
-			
-			$requirement['package'] = PackageCache::getInstance()->getPackageByIdentifier($requirement['name']);
-		}
-		
-		unset($requirement);
+		$this->validationPassed = PackageValidationManager::getInstance()->validate($this->queue->archive, true);
 	}
 	
 	/**
@@ -171,12 +100,9 @@ class PackageInstallationConfirmPage extends AbstractPage {
 		
 		WCF::getTPL()->assign(array(
 			'archive' => $this->packageInstallationDispatcher->getArchive(),
-			/*'requiredPackages' => $this->requirements,
-			'missingPackages' => $this->missingPackages,
-			'excludingPackages' => $this->packageInstallationDispatcher->getArchive()->getConflictedExcludingPackages(),
-			'excludedPackages' => $this->packageInstallationDispatcher->getArchive()->getConflictedExcludedPackages(),*/
 			'packageValidationArchives' => PackageValidationManager::getInstance()->getPackageValidationArchiveList(),
 			'queue' => $this->queue,
+			'validationPassed' => $this->validationPassed,
 			'installingImportedStyle' => $this->installingImportedStyle
 		));
 	}
diff --git a/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php
index ca6164ddab..43b0314191 100644
--- a/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php
+++ b/wcfsetup/install/files/lib/system/package/plugin/LanguagePackageInstallationPlugin.class.php
@@ -4,6 +4,7 @@ use wcf\data\language\LanguageEditor;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\language\LanguageFactory;
+use wcf\system\package\PackageArchive;
 use wcf\system\WCF;
 use wcf\util\XML;
 
@@ -251,4 +252,11 @@ class LanguagePackageInstallationPlugin extends AbstractXMLPackageInstallationPl
 	 * @see	\wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
 	 */
 	protected function findExistingItem(array $data) { }
+	
+	/**
+	 * @see	\wcf\system\package\plugin\IPackageInstallationPlugin::isValid()
+	 */
+	public static function isValid(PackageArchive $archive, $instruction) {
+		return true;
+	}
 }
diff --git a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php
index 40587c3d10..c8a69b2247 100644
--- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php
+++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php
@@ -1,8 +1,8 @@
 addVirtualPackage($this->archive->getPackageInfo('name'), $this->archive->getPackageInfo('version'));
 				
 				// check for exclusions
-				if (true || WCF_VERSION != '2.1.0 Alpha 1 (Typhoon)') {
+				// TODO: exclusions are not checked for testing purposes
+				//	 REMOVE THIS BEFORE *ANY* PUBLIC RELEASE
+				if (WCF_VERSION != '2.1.0 Alpha 1 (Typhoon)') {
 					$this->validateExclusion();
 				}
 				
@@ -138,6 +140,15 @@ class PackageValidationArchive implements \RecursiveIterator {
 		
 	}
 	
+	/**
+	 * Validates if the package has suitable install or update instructions. Setting $deepInspection
+	 * to true will cause every single instruction to be validated against the corresponding PIP.
+	 * 
+	 * Please be aware that unknown PIPs will be silently ignored and will not cause any error!
+	 * 
+	 * @param	string		$requiredVersion
+	 * @param	boolean		$deepInspection
+	 */
 	protected function validateInstructions($requiredVersion, $deepInspection) {
 		$package = $this->getPackage();
 		
@@ -157,7 +168,9 @@ class PackageValidationArchive implements \RecursiveIterator {
 				throw new PackageValidationException(PackageValidationException::NO_INSTALL_PATH, array('packageName' => $this->archive->getPackageInfo('name')));
 			}
 			
-			$this->validatePackageInstallationPlugins('install', $instructions);
+			if ($deepInspection) {
+				$this->validatePackageInstallationPlugins('install', $instructions);
+			}
 		}
 		else {
 			// package is already installed, check update path
@@ -169,11 +182,18 @@ class PackageValidationArchive implements \RecursiveIterator {
 				));
 			}
 			
-			$this->validatePackageInstallationPlugins('update', $this->archive->getUpdateInstructions());
+			if ($deepInspection) {
+				$this->validatePackageInstallationPlugins('update', $this->archive->getUpdateInstructions());
+			}
 		}
-		exit;
 	}
 	
+	/**
+	 * Validates install or update instructions against the corresponding PIP, unknown PIPs will be silently ignored.
+	 * 
+	 * @param	string		$type
+	 * @param	array	$instructions
+	 */
 	protected function validatePackageInstallationPlugins($type, array $instructions) {
 		for ($i = 0, $length = count($instructions); $i < $length; $i++) {
 			$instruction = $instructions[$i];
@@ -187,6 +207,9 @@ class PackageValidationArchive implements \RecursiveIterator {
 		}
 	}
 	
+	/**
+	 * Validates if an installed package excludes the current package and vice versa.
+	 */
 	protected function validateExclusion() {
 		$excludingPackages = $this->archive->getConflictedExcludingPackages();
 		if (!empty($excludingPackages)) {
@@ -216,10 +239,21 @@ class PackageValidationArchive implements \RecursiveIterator {
 		return $this->exception->getMessage();
 	}
 	
+	/**
+	 * Returns the package archive object.
+	 * 
+	 * @return	\wcf\system\package\PackageArchive
+	 */
 	public function getArchive() {
 		return $this->archive;
 	}
 	
+	/**
+	 * Returns the package object based on the package archive's package identifier or null
+	 * if the package isn't already installed.
+	 * 
+	 * @return	\wcf\data\package\Package
+	 */
 	public function getPackage() {
 		if ($this->package === null) {
 			$this->package = PackageCache::getInstance()->getPackageByIdentifier($this->archive->getPackageInfo('name'));
diff --git a/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php b/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php
index c599971b11..1e68507e9a 100644
--- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php
+++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php
@@ -1,9 +1,9 @@
 getPackageValidationArchiveList() as $packageArchive) {
+			if ($packageArchive->getExceptionMessage()) {
+				return $packageArchive->getExceptionMessage();
+			}
+		}
+		
+		return '';
+	}
+	
+	/**
+	 * Validates an instruction against the corresponding package installation plugin.
+	 * 
+	 * Please be aware that unknown PIPs will silently ignored and cause no error.
+	 *  
+	 * @param	\wcf\data\package\PackageArchive	$archive
+	 * @param	string					$pip
+	 * @param	string					$instruction
+	 * @return	boolean
+	 */
 	public function validatePackageInstallationPluginInstruction(PackageArchive $archive, $pip, $instruction) {
 		if (isset($this->packageInstallationPlugins[$pip])) {
 			return call_user_func(array($this->packageInstallationPlugins[$pip], 'isValid'), $archive, $instruction);
 		}
-		echo "(default success)\n";
+		
 		return true;
 	}
 }
diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml
index faff0f4261..bc825abfec 100644
--- a/wcfsetup/install/lang/de.xml
+++ b/wcfsetup/install/lang/de.xml
@@ -992,6 +992,9 @@ GmbH=Gesellschaft mit beschränkter Haftung]]>
 		
 		
 		
+		
+		
+		
 		
 		{foreach from=$packages item=package}
  • „{$package}“ ({$package->package})
  • {/foreach}]]>
    -- 2.20.1