Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / package / validation / PackageValidationException.class.php
1 <?php
2 namespace wcf\system\package\validation;
3 use wcf\system\exception\SystemException;
4 use wcf\system\package\PackageArchive;
5 use wcf\system\WCF;
6
7 /**
8 * Represents exceptions occured during validation of a package archive. This exception
9 * does not cause the details to be logged.
10 *
11 * @author Alexander Ebert
12 * @copyright 2001-2014 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.package.validation
16 * @category Community Framework
17 */
18 class PackageValidationException extends SystemException {
19 /**
20 * list of additional details for each subtype
21 * @var array<string>
22 */
23 protected $details = array();
24
25 /**
26 * missing archive, expects the detail 'archive' and optionally 'targetArchive' (extracting archive from the archive)
27 * @var integer
28 */
29 const FILE_NOT_FOUND = 1;
30
31 /**
32 * missing package.xml, expects the detail 'archive'
33 * @var integer
34 */
35 const MISSING_PACKAGE_XML = 2;
36
37 /**
38 * package name violates WCF's schema, expects the detail 'packageName'
39 * @var integer
40 */
41 const INVALID_PACKAGE_NAME = 3;
42
43 /**
44 * package version violates WCF's schema, expects the detail 'packageVersion'
45 * @var integer
46 */
47 const INVALID_PACKAGE_VERSION = 4;
48
49 /**
50 * package contains no install instructions and an update is not possible, expects the detail 'packageName'
51 * @var integer
52 */
53 const NO_INSTALL_PATH = 5;
54
55 /**
56 * package is already installed and cannot be updated using current archive, expects the details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
57 * @var integer
58 */
59 const NO_UPDATE_PATH = 6;
60
61 /**
62 * packages which exclude the current package, expects the detail 'packages' (list of \wcf\data\package\Package)
63 * @var integer
64 */
65 const EXCLUDING_PACKAGES = 7;
66
67 /**
68 * packages which are excluded by current package, expects the detail 'packages' (list of \wcf\data\package\Package)
69 * @var integer
70 */
71 const EXCLUDED_PACKAGES = 8;
72
73 /**
74 * package version is lower than the request version, expects the details 'packageName', 'packageVersion' and 'deliveredPackageVersion'
75 * @var integer
76 */
77 const INSUFFICIENT_VERSION = 9;
78
79 /**
80 * requirement is set but neither installed nor provided, expects the details 'packageName' and 'packageVersion'
81 * @var integer
82 */
83 const MISSING_REQUIREMENT = 10;
84
85 /**
86 * file reference for a package installation plugin is missing, expects the details 'pip', 'type' and 'value'
87 * @var integer
88 */
89 const MISSING_INSTRUCTION_FILE = 11;
90
91 /**
92 * Creates a new PackageArchiveValidationException.
93 *
94 * @param integer $code
95 * @param array<string> $details
96 */
97 public function __construct($code, array $details = array()) {
98 parent::__construct($this->getLegacyMessage(), $code);
99
100 $this->details = $details;
101 }
102
103 /**
104 * Returns exception details.
105 *
106 * @return array<string>
107 */
108 public function getDetails() {
109 return $this->details;
110 }
111
112 /**
113 * Returns the readable error message.
114 *
115 * @return string
116 */
117 public function getErrorMessage() {
118 return WCF::getLanguage()->getDynamicVariable('wcf.acp.package.validation.errorCode.' . $this->getCode(), $this->getDetails());
119 }
120
121 /**
122 * Returns legacy error messages to mimic WCF 2.0.x PackageArchive's exceptions.
123 *
124 * @return string
125 */
126 protected function getLegacyMessage() {
127 switch ($this->getCode()) {
128 case self::FILE_NOT_FOUND:
129 if (isset($this->details['targetArchive'])) {
130 return "tar archive '".$this->details['targetArchive']."' not found in '".$this->details['archive']."'.";
131 }
132
133 return "unable to find package file '".$this->details['archive']."'";
134 break;
135
136 case self::MISSING_PACKAGE_XML:
137 return "package information file '".PackageArchive::INFO_FILE."' not found in '".$this->details['archive']."'";
138 break;
139
140 case self::INVALID_PACKAGE_NAME:
141 return "'".$this->details['packageName']."' is not a valid package name.";
142 break;
143
144 case self::INVALID_PACKAGE_VERSION:
145 return "package version '".$this->details['packageVersion']."' is invalid";
146 break;
147
148 default:
149 return 'Using getMessage() is discouraged, please use getErrorMessage() instead';
150 break;
151 }
152 }
153
154 /**
155 * @see \wcf\system\exception\LoggedException::logError()
156 */
157 protected function logError() {
158 // do not log errors
159 }
160 }