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