namespace wcf\acp\form;
use wcf\data\package\installation\queue\PackageInstallationQueue;
use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
-use wcf\data\package\Package;
use wcf\form\AbstractForm;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\SystemException;
* Shows the package install and update form.
*
* @author Marcel Werk
- * @copyright 2001-2014 WoltLab GmbH
+ * @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage acp.form
use wcf\data\package\Package;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
+use wcf\system\package\validation\PackageValidationException;
use wcf\system\io\Tar;
use wcf\system\WCF;
use wcf\util\DateUtil;
* Represents the archive of a package.
*
* @author Marcel Werk
- * @copyright 2001-2014 WoltLab GmbH
+ * @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.package
public function openArchive() {
// check whether archive exists and is a TAR archive
if (!file_exists($this->archive)) {
- throw new SystemException("unable to find package file '".$this->archive."'");
+ throw new SystemException("unable to find package file '".$this->archive."'", PackageValidationException::FILE_NOT_FOUND);
}
// open archive and read package information
// search package.xml in package archive
// throw error message if not found
if ($this->tar->getIndexByFilename(self::INFO_FILE) === false) {
- throw new SystemException("package information file '".(self::INFO_FILE)."' not found in '".$this->archive."'");
+ throw new SystemException("package information file '".(self::INFO_FILE)."' not found in '".$this->archive."'", PackageValidationException::MISSING_PACKAGE_XML);
}
// extract package.xml, parse XML
case 'version':
if (!Package::isValidVersion($element->nodeValue)) {
- throw new SystemException("package version '".$element->nodeValue."' is invalid");
+ throw new SystemException("package version '".$element->nodeValue."' is invalid", PackageValidationException::INVALID_PACKAGE_VERSION);
}
$this->packageInfo['version'] = $element->nodeValue;
$elements = $xpath->query('child::ns:requiredpackages/ns:requiredpackage', $package);
foreach ($elements as $element) {
if (!Package::isValidPackageName($element->nodeValue)) {
- throw new SystemException("'".$element->nodeValue."' is not a valid package name.");
+ throw new SystemException("'".$element->nodeValue."' is not a valid package name.", PackageValidationException::INVALID_PACKAGE_NAME);
}
// read attributes
$elements = $xpath->query('child::ns:optionalpackages/ns:optionalpackage', $package);
foreach ($elements as $element) {
if (!Package::isValidPackageName($element->nodeValue)) {
- throw new SystemException("'".$element->nodeValue."' is not a valid package name.");
+ throw new SystemException("'".$element->nodeValue."' is not a valid package name.", PackageValidationException::INVALID_PACKAGE_NAME);
}
// read attributes
$elements = $xpath->query('child::ns:excludedpackages/ns:excludedpackage', $package);
foreach ($elements as $element) {
if (!Package::isValidPackageName($element->nodeValue)) {
- throw new SystemException("'".$element->nodeValue."' is not a valid package name.");
+ throw new SystemException("'".$element->nodeValue."' is not a valid package name.", PackageValidationException::INVALID_PACKAGE_NAME);
}
// read attributes
use wcf\data\package\Package;
use wcf\data\package\PackageCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\SystemException;
use wcf\system\package\PackageArchive;
use wcf\system\WCF;
* Recursively validates the package archive and it's delivered requirements.
*
* @author Alexander Ebert
- * @copyright 2001-2014 WoltLab GmbH
+ * @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.package.validation
// check if package is installable or suitable for an update
$this->validateInstructions($requiredVersion);
}
- catch (\Exception $e) {
- $this->exception = $e;
+ catch (SystemException $e) {
+ if ($e->getCode()) {
+ $this->exception = new PackageValidationException($e->getCode(), array('legacyMessage' => $e->getMessage()));
+
+ return false;
+ }
- return false;
+ throw $e;
}
}
* @param array<string> $details
*/
public function __construct($code, array $details = array()) {
- parent::__construct($this->getLegacyMessage(), $code);
-
$this->details = $details;
+
+ parent::__construct($this->getLegacyMessage($code), $code);
}
/**
/**
* Returns the readable error message.
*
+ * @param integer $code
* @return string
*/
- public function getErrorMessage() {
- return WCF::getLanguage()->getDynamicVariable('wcf.acp.package.validation.errorCode.' . $this->getCode(), $this->getDetails());
+ public function getErrorMessage($code = null) {
+ if (!empty($this->details['legacyMessage'])) {
+ return $this->details['legacyMessage'];
+ }
+
+ return WCF::getLanguage()->getDynamicVariable('wcf.acp.package.validation.errorCode.' . ($code === null ? $this->getCode() : $code), $this->getDetails());
}
/**
* Returns legacy error messages to mimic WCF 2.0.x PackageArchive's exceptions.
*
+ * @param integer $code
* @return string
*/
- protected function getLegacyMessage() {
- switch ($this->getCode()) {
+ protected function getLegacyMessage($code) {
+ switch ($code) {
case self::FILE_NOT_FOUND:
if (isset($this->details['targetArchive'])) {
return "tar archive '".$this->details['targetArchive']."' not found in '".$this->details['archive']."'.";
break;
default:
- return 'Using getMessage() is discouraged, please use getErrorMessage() instead';
+ return $this->getErrorMessage($code);
break;
}
}
<?php
namespace wcf\system\package\validation;
-use wcf\data\package\installation\plugin\PackageInstallationPluginList;
use wcf\data\package\Package;
-use wcf\system\package\PackageArchive;
use wcf\system\SingletonFactory;
/**
* Manages recursive validation of package archives.
*
* @author Alexander Ebert
- * @copyright 2001-2014 WoltLab GmbH
+ * @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.package.validation