3 namespace wcf\system\package\validation
;
5 use wcf\system\exception\SystemException
;
6 use wcf\system\package\PackageArchive
;
10 * Represents exceptions occurred during validation of a package archive. This exception
11 * does not cause the details to be logged.
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 class PackageValidationException
extends SystemException
20 * list of additional details for each subtype
23 protected $details = [];
26 * missing archive, expects the detail 'archive' and optionally 'targetArchive'
27 * (extracting archive from the archive)
30 const FILE_NOT_FOUND
= 1;
33 * missing package.xml, expects the detail 'archive'
36 const MISSING_PACKAGE_XML
= 2;
39 * package name violates WCF's schema, expects the detail 'packageName'
42 const INVALID_PACKAGE_NAME
= 3;
45 * package version violates WCF's schema, expects the detail 'packageVersion'
48 const INVALID_PACKAGE_VERSION
= 4;
51 * package contains no install instructions and an update is not possible, expects the detail 'packageName'
54 const NO_INSTALL_PATH
= 5;
57 * package is already installed and cannot be updated using current archive, expects the
58 * details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
61 const NO_UPDATE_PATH
= 6;
64 * packages which exclude the current package, expects the detail 'packages' (list of \wcf\data\package\Package)
67 const EXCLUDING_PACKAGES
= 7;
70 * packages which are excluded by current package, expects the detail 'packages' (list of \wcf\data\package\Package)
73 const EXCLUDED_PACKAGES
= 8;
76 * package version is lower than the request version, expects the
77 * details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
80 const INSUFFICIENT_VERSION
= 9;
83 * requirement is set but neither installed nor provided, expects the
84 * details 'packageName', 'packageVersion' and 'package' (must be
85 * an instance of \wcf\data\package\Package or null if not installed)
88 const MISSING_REQUIREMENT
= 10;
91 * file reference for a package installation plugin is missing, expects the details 'pip', 'type' and 'value'
94 const MISSING_INSTRUCTION_FILE
= 11;
97 * the uploaded version is already installed, expects the details 'packageName' and 'packageVersion'
100 const ALREADY_INSTALLED
= 12;
103 * the provided API version string is invalid and does not fall into the range from `2017` through `2099`
107 const INVALID_API_VERSION
= 13;
110 * the package is not compatible with the current API version or any other of the supported ones
114 const INCOMPATIBLE_API_VERSION
= 14;
117 * the package lacks any sort of API compatibility data
121 const MISSING_API_VERSION
= 15;
124 * the void is not the only instruction
127 const VOID_NOT_ALONE
= 16;
130 * the void is used during installation
133 const VOID_ON_INSTALL
= 17;
136 * an app with the same abbreviation is already installed
139 const DUPLICATE_ABBREVIATION
= 18;
142 * the version of an excluded package is invalid
146 const INVALID_EXCLUDED_PACKAGE_VERSION_NUMBER
= 19;
149 * the package excludes itself
153 const SELF_EXCLUDE
= 20;
156 * the package does not explicitly require com.woltlab.wcf
160 const MISSING_COM_WOLTLAB_WCF_REQUIREMENT
= 21;
163 * the package requires com.woltlab.wcf in an ancient version
167 const ANCIENT_COM_WOLTLAB_WCF_REQUIREMENT
= 22;
170 * the version of a required package is invalid
174 const INVALID_REQUIRED_PACKAGE_VERSION_NUMBER
= 23;
177 * an unknown tag is given in the <packageinformation>
181 const UNKNOWN_PACKAGE_INFORMATION
= 24;
184 * an unknown tag is given in the <authorinformation>
188 const UNKNOWN_AUTHOR_INFORMATION
= 25;
191 * no author information is given
195 const MISSING_AUTHOR_INFORMATION
= 26;
198 * no display name is given
202 const MISSING_DISPLAY_NAME
= 27;
205 * an duplicate tag is given in the <packageinformation>
209 const DUPLICATE_PACKAGE_INFORMATION
= 28;
212 * no version information is given
216 const MISSING_PACKAGE_VERSION
= 29;
219 * no release date is given
223 const MISSING_PACKAGE_DATE
= 30;
226 * the `package.xml` has syntax errors
230 const INVALID_PACKAGE_XML
= 31;
233 * Creates a new PackageArchiveValidationException.
236 * @param string[] $details
238 public function __construct($code, array $details = [])
240 $this->details
= $details;
242 parent
::__construct($this->getLegacyMessage($code), $code);
246 * Returns exception details.
250 public function getDetails()
252 return $this->details
;
256 * Returns the readable error message.
261 public function getErrorMessage($code = null)
263 if (!empty($this->details
['legacyMessage'])) {
264 return $this->details
['legacyMessage'];
267 return WCF
::getLanguage()->getDynamicVariable(
268 'wcf.acp.package.validation.errorCode.' . ($code === null ?
$this->getCode() : $code),
274 * Returns legacy error messages to mimic WCF 2.0.x PackageArchive's exceptions.
279 protected function getLegacyMessage($code)
282 case self
::FILE_NOT_FOUND
:
283 if (isset($this->details
['targetArchive'])) {
284 return "tar archive '" . $this->details
['targetArchive'] . "' not found in '" . $this->details
['archive'] . "'.";
287 return "unable to find package file '" . $this->details
['archive'] . "'";
290 case self
::MISSING_PACKAGE_XML
:
291 return "package information file '" . PackageArchive
::INFO_FILE
. "' not found in '" . $this->details
['archive'] . "'";
294 case self
::INVALID_PACKAGE_NAME
:
295 return "'" . $this->details
['packageName'] . "' is not a valid package name.";
298 case self
::INVALID_PACKAGE_VERSION
:
299 return "package version '" . $this->details
['packageVersion'] . "' is invalid";
303 return $this->getErrorMessage($code);
311 protected function logError()