Commit | Line | Data |
---|---|---|
2026cec6 | 1 | <?php |
a9229942 | 2 | |
2026cec6 | 3 | namespace wcf\system\package\validation; |
a9229942 | 4 | |
2026cec6 AE |
5 | use wcf\system\exception\SystemException; |
6 | use wcf\system\package\PackageArchive; | |
7 | use wcf\system\WCF; | |
8 | ||
9 | /** | |
1615fc2e | 10 | * Represents exceptions occurred during validation of a package archive. This exception |
2026cec6 | 11 | * does not cause the details to be logged. |
a9229942 TD |
12 | * |
13 | * @author Alexander Ebert | |
14 | * @copyright 2001-2019 WoltLab GmbH | |
15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
16 | * @package WoltLabSuite\Core\System\Package\Validation | |
2026cec6 | 17 | */ |
a9229942 TD |
18 | class PackageValidationException extends SystemException |
19 | { | |
20 | /** | |
21 | * list of additional details for each subtype | |
22 | * @var string[] | |
23 | */ | |
24 | protected $details = []; | |
25 | ||
26 | /** | |
27 | * missing archive, expects the detail 'archive' and optionally 'targetArchive' | |
28 | * (extracting archive from the archive) | |
29 | * @var int | |
30 | */ | |
31 | const FILE_NOT_FOUND = 1; | |
32 | ||
33 | /** | |
34 | * missing package.xml, expects the detail 'archive' | |
35 | * @var int | |
36 | */ | |
37 | const MISSING_PACKAGE_XML = 2; | |
38 | ||
39 | /** | |
40 | * package name violates WCF's schema, expects the detail 'packageName' | |
41 | * @var int | |
42 | */ | |
43 | const INVALID_PACKAGE_NAME = 3; | |
44 | ||
45 | /** | |
46 | * package version violates WCF's schema, expects the detail 'packageVersion' | |
47 | * @var int | |
48 | */ | |
49 | const INVALID_PACKAGE_VERSION = 4; | |
50 | ||
51 | /** | |
52 | * package contains no install instructions and an update is not possible, expects the detail 'packageName' | |
53 | * @var int | |
54 | */ | |
55 | const NO_INSTALL_PATH = 5; | |
56 | ||
57 | /** | |
58 | * package is already installed and cannot be updated using current archive, expects the | |
59 | * details 'packageName', 'packageVersion' and 'deliveredPackageVersion' | |
60 | * @var int | |
61 | */ | |
62 | const NO_UPDATE_PATH = 6; | |
63 | ||
64 | /** | |
65 | * packages which exclude the current package, expects the detail 'packages' (list of \wcf\data\package\Package) | |
66 | * @var int | |
67 | */ | |
68 | const EXCLUDING_PACKAGES = 7; | |
69 | ||
70 | /** | |
71 | * packages which are excluded by current package, expects the detail 'packages' (list of \wcf\data\package\Package) | |
72 | * @var int | |
73 | */ | |
74 | const EXCLUDED_PACKAGES = 8; | |
75 | ||
76 | /** | |
77 | * package version is lower than the request version, expects the | |
78 | * details 'packageName', 'packageVersion' and 'deliveredPackageVersion' | |
79 | * @var int | |
80 | */ | |
81 | const INSUFFICIENT_VERSION = 9; | |
82 | ||
83 | /** | |
84 | * requirement is set but neither installed nor provided, expects the | |
85 | * details 'packageName', 'packageVersion' and 'package' (must be | |
86 | * an instance of \wcf\data\package\Package or null if not installed) | |
87 | * @var int | |
88 | */ | |
89 | const MISSING_REQUIREMENT = 10; | |
90 | ||
91 | /** | |
92 | * file reference for a package installation plugin is missing, expects the details 'pip', 'type' and 'value' | |
93 | * @var int | |
94 | */ | |
95 | const MISSING_INSTRUCTION_FILE = 11; | |
96 | ||
97 | /** | |
98 | * the uploaded version is already installed, expects the details 'packageName' and 'packageVersion' | |
99 | * @var int | |
100 | */ | |
101 | const ALREADY_INSTALLED = 12; | |
102 | ||
103 | /** | |
104 | * the provided API version string is invalid and does not fall into the range from `2017` through `2099` | |
105 | * @var int | |
106 | * @deprecated 5.2 | |
107 | */ | |
108 | const INVALID_API_VERSION = 13; | |
109 | ||
110 | /** | |
111 | * the package is not compatible with the current API version or any other of the supported ones | |
112 | * @var int | |
113 | * @deprecated 5.2 | |
114 | */ | |
115 | const INCOMPATIBLE_API_VERSION = 14; | |
116 | ||
117 | /** | |
118 | * the package lacks any sort of API compatibility data | |
119 | * @var int | |
120 | * @deprecated 5.2 | |
121 | */ | |
122 | const MISSING_API_VERSION = 15; | |
123 | ||
124 | /** | |
125 | * the void is not the only instruction | |
126 | * @var int | |
127 | */ | |
128 | const VOID_NOT_ALONE = 16; | |
129 | ||
130 | /** | |
131 | * the void is used during installation | |
132 | * @var int | |
133 | */ | |
134 | const VOID_ON_INSTALL = 17; | |
135 | ||
136 | /** | |
137 | * Creates a new PackageArchiveValidationException. | |
138 | * | |
139 | * @param int $code | |
140 | * @param string[] $details | |
141 | */ | |
142 | public function __construct($code, array $details = []) | |
143 | { | |
144 | $this->details = $details; | |
145 | ||
146 | parent::__construct($this->getLegacyMessage($code), $code); | |
147 | } | |
148 | ||
149 | /** | |
150 | * Returns exception details. | |
151 | * | |
152 | * @return string[] | |
153 | */ | |
154 | public function getDetails() | |
155 | { | |
156 | return $this->details; | |
157 | } | |
158 | ||
159 | /** | |
160 | * Returns the readable error message. | |
161 | * | |
162 | * @param int $code | |
163 | * @return string | |
164 | */ | |
165 | public function getErrorMessage($code = null) | |
166 | { | |
167 | if (!empty($this->details['legacyMessage'])) { | |
168 | return $this->details['legacyMessage']; | |
169 | } | |
170 | ||
171 | return WCF::getLanguage()->getDynamicVariable( | |
172 | 'wcf.acp.package.validation.errorCode.' . ($code === null ? $this->getCode() : $code), | |
173 | $this->getDetails() | |
174 | ); | |
175 | } | |
176 | ||
177 | /** | |
178 | * Returns legacy error messages to mimic WCF 2.0.x PackageArchive's exceptions. | |
179 | * | |
180 | * @param int $code | |
181 | * @return string | |
182 | */ | |
183 | protected function getLegacyMessage($code) | |
184 | { | |
185 | switch ($code) { | |
186 | case self::FILE_NOT_FOUND: | |
187 | if (isset($this->details['targetArchive'])) { | |
188 | return "tar archive '" . $this->details['targetArchive'] . "' not found in '" . $this->details['archive'] . "'."; | |
189 | } | |
190 | ||
191 | return "unable to find package file '" . $this->details['archive'] . "'"; | |
192 | break; | |
193 | ||
194 | case self::MISSING_PACKAGE_XML: | |
195 | return "package information file '" . PackageArchive::INFO_FILE . "' not found in '" . $this->details['archive'] . "'"; | |
196 | break; | |
197 | ||
198 | case self::INVALID_PACKAGE_NAME: | |
199 | return "'" . $this->details['packageName'] . "' is not a valid package name."; | |
200 | break; | |
201 | ||
202 | case self::INVALID_PACKAGE_VERSION: | |
203 | return "package version '" . $this->details['packageVersion'] . "' is invalid"; | |
204 | break; | |
205 | ||
206 | default: | |
207 | return $this->getErrorMessage($code); | |
208 | break; | |
209 | } | |
210 | } | |
211 | ||
212 | /** | |
213 | * @inheritDoc | |
214 | */ | |
215 | protected function logError() | |
216 | { | |
217 | // do not log errors | |
218 | } | |
2026cec6 | 219 | } |