|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Provides a layer for check / install / uninstall a plugin or theme |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Core |
|
9
|
|
|
* @package Market |
|
10
|
|
|
* @author Micha Schultz <[email protected]> |
|
11
|
|
|
* @copyright 2014 cSphere Team |
|
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
13
|
|
|
* @link http://www.csphere.eu |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace csphere\core\market; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Provides a layer for checkups to install and uninstall plugins |
|
20
|
|
|
* |
|
21
|
|
|
* @category Core |
|
22
|
|
|
* @package Market |
|
23
|
|
|
* @author Micha Schultz <[email protected]> |
|
24
|
|
|
* @copyright 2014 cSphere Team |
|
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
26
|
|
|
* @link http://www.csphere.eu |
|
27
|
|
|
**/ |
|
28
|
|
|
|
|
29
|
|
|
class Tools |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Short that will be used |
|
33
|
|
|
**/ |
|
34
|
|
|
private $_short = ''; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Type that will be used |
|
38
|
|
|
**/ |
|
39
|
|
|
private $_type = ''; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Local path |
|
43
|
|
|
**/ |
|
44
|
|
|
private $_path = ''; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Info xml file that will be used |
|
48
|
|
|
**/ |
|
49
|
|
|
private $_file = ''; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Remember positive existance checks |
|
53
|
|
|
**/ |
|
54
|
|
|
private $_existance = false; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Array of possible errors |
|
58
|
|
|
**/ |
|
59
|
|
|
private $_error = []; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get plugin for install / update / delete it |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $short Name of plugin or theme |
|
65
|
|
|
* @param string $type Type of input data |
|
66
|
|
|
* |
|
67
|
|
|
* @throws \Exception |
|
68
|
|
|
* |
|
69
|
|
|
* @return \csphere\core\market\Tools |
|
70
|
|
|
**/ |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
public function __construct($short, $type) |
|
73
|
|
|
{ |
|
74
|
|
|
|
|
75
|
|
|
$this->_path = \csphere\core\init\path(); |
|
76
|
|
|
|
|
77
|
|
|
$this->_type = $type; |
|
78
|
|
|
|
|
79
|
|
|
$this->_short = $short; |
|
80
|
|
|
|
|
81
|
|
|
$this->_file = $this->_path . 'csphere/' . $this->_type . 's' |
|
82
|
|
|
. '/' . $this->_short . '/' . $this->_type . '.xml'; |
|
83
|
|
|
|
|
84
|
|
|
//Check correct type |
|
85
|
|
|
if ($this->_type != 'plugin' && $this->_type != 'theme') { |
|
86
|
|
|
|
|
87
|
|
|
throw new \Exception('Only plugin oder theme is allowed as type'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// Check plugin / theme existence |
|
91
|
|
|
$this->_checkExistance(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Content of a directory as an array |
|
96
|
|
|
* |
|
97
|
|
|
* @return void |
|
98
|
|
|
**/ |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
private function _checkExistance() |
|
101
|
|
|
{ |
|
102
|
|
|
// Check for xml file |
|
103
|
|
|
if (file_exists($this->_file)) { |
|
104
|
|
|
|
|
105
|
|
|
$this->_existance = true; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Method to uninstall plugin with pre check |
|
111
|
|
|
* |
|
112
|
|
|
* @param boolean $action Perform uninstall after pre check, if true |
|
113
|
|
|
* |
|
114
|
|
|
* @return boolean |
|
115
|
|
|
**/ |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
public function uninstall($action = false) |
|
118
|
|
|
{ |
|
119
|
|
|
if (!$this->_existance) { |
|
120
|
|
|
|
|
121
|
|
|
array_push($this->_error, 'Sample Error'); |
|
122
|
|
|
|
|
123
|
|
|
return false; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
// Check plugin dependencies |
|
127
|
|
|
$loader = \csphere\core\service\Locator::get(); |
|
128
|
|
|
$xml = $loader->load('xml', $this->_type); |
|
129
|
|
|
$data = $xml->source($this->_type, $this->_short); |
|
130
|
|
|
|
|
131
|
|
|
$vendor = $data['vendor']; |
|
132
|
|
|
|
|
133
|
|
|
// Load plugin list |
|
134
|
|
|
$meta = new \csphere\core\plugins\Metadata(); |
|
135
|
|
|
$plugins = $meta->details(); |
|
136
|
|
|
|
|
137
|
|
|
foreach ($plugins as $plugin) { |
|
138
|
|
|
|
|
139
|
|
|
// Load plugin xml infos |
|
140
|
|
|
$data = $xml->source('plugin', $plugin['short']); |
|
141
|
|
|
|
|
142
|
|
|
$dependencies = $data['environment'][0]['needed']; |
|
143
|
|
|
|
|
144
|
|
|
foreach ($dependencies as $dependency) { |
|
145
|
|
|
|
|
146
|
|
|
$control_plugin = $vendor . '.' . $this->_short; |
|
147
|
|
|
$check_plugin = $dependency['vendor'] . '.' . $dependency['plugin']; |
|
148
|
|
|
|
|
149
|
|
|
if ($control_plugin == $check_plugin) { |
|
150
|
|
|
|
|
151
|
|
|
// Dependencies found, no uninstall |
|
152
|
|
|
return false; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if ($action) { |
|
158
|
|
|
|
|
159
|
|
|
//TODO Perform uninstall |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return true; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Checks if plugin oder theme exists |
|
167
|
|
|
* |
|
168
|
|
|
* @return boolean |
|
169
|
|
|
**/ |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
public function existance() |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->_existance; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.