@@ -30,13 +30,13 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearchPlugin { |
33 | - /** |
|
34 | - * @param string $search |
|
35 | - * @param int $limit |
|
36 | - * @param int $offset |
|
37 | - * @param ISearchResult $searchResult |
|
38 | - * @return bool whether the plugin has more results |
|
39 | - * @since 13.0.0 |
|
40 | - */ |
|
41 | - public function search($search, $limit, $offset, ISearchResult $searchResult); |
|
33 | + /** |
|
34 | + * @param string $search |
|
35 | + * @param int $limit |
|
36 | + * @param int $offset |
|
37 | + * @param ISearchResult $searchResult |
|
38 | + * @return bool whether the plugin has more results |
|
39 | + * @since 13.0.0 |
|
40 | + */ |
|
41 | + public function search($search, $limit, $offset, ISearchResult $searchResult); |
|
42 | 42 | } |
@@ -30,21 +30,21 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearch { |
33 | - /** |
|
34 | - * @param string $search |
|
35 | - * @param array $shareTypes |
|
36 | - * @param bool $lookup |
|
37 | - * @param int $limit |
|
38 | - * @param int $offset |
|
39 | - * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available |
|
40 | - * @since 13.0.0 |
|
41 | - */ |
|
42 | - public function search($search, array $shareTypes, $lookup, $limit, $offset); |
|
33 | + /** |
|
34 | + * @param string $search |
|
35 | + * @param array $shareTypes |
|
36 | + * @param bool $lookup |
|
37 | + * @param int $limit |
|
38 | + * @param int $offset |
|
39 | + * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available |
|
40 | + * @since 13.0.0 |
|
41 | + */ |
|
42 | + public function search($search, array $shareTypes, $lookup, $limit, $offset); |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and |
|
46 | - * 'class' with the class name of the plugin |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function registerPlugin(array $pluginInfo); |
|
44 | + /** |
|
45 | + * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and |
|
46 | + * 'class' with the class name of the plugin |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function registerPlugin(array $pluginInfo); |
|
50 | 50 | } |
@@ -30,44 +30,44 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearchResult { |
33 | - /** |
|
34 | - * @param SearchResultType $type |
|
35 | - * @param array $matches |
|
36 | - * @param array|null $exactMatches |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null); |
|
33 | + /** |
|
34 | + * @param SearchResultType $type |
|
35 | + * @param array $matches |
|
36 | + * @param array|null $exactMatches |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param SearchResultType $type |
|
43 | - * @param string $collaboratorId |
|
44 | - * @return bool |
|
45 | - * @since 13.0.0 |
|
46 | - */ |
|
47 | - public function hasResult(SearchResultType $type, $collaboratorId); |
|
41 | + /** |
|
42 | + * @param SearchResultType $type |
|
43 | + * @param string $collaboratorId |
|
44 | + * @return bool |
|
45 | + * @since 13.0.0 |
|
46 | + */ |
|
47 | + public function hasResult(SearchResultType $type, $collaboratorId); |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param SearchResultType $type |
|
51 | - * @since 13.0.0 |
|
52 | - */ |
|
53 | - public function unsetResult(SearchResultType $type); |
|
49 | + /** |
|
50 | + * @param SearchResultType $type |
|
51 | + * @since 13.0.0 |
|
52 | + */ |
|
53 | + public function unsetResult(SearchResultType $type); |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param SearchResultType $type |
|
57 | - * @since 13.0.0 |
|
58 | - */ |
|
59 | - public function markExactIdMatch(SearchResultType $type); |
|
55 | + /** |
|
56 | + * @param SearchResultType $type |
|
57 | + * @since 13.0.0 |
|
58 | + */ |
|
59 | + public function markExactIdMatch(SearchResultType $type); |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param SearchResultType $type |
|
63 | - * @return bool |
|
64 | - * @since 13.0.0 |
|
65 | - */ |
|
66 | - public function hasExactIdMatch(SearchResultType $type); |
|
61 | + /** |
|
62 | + * @param SearchResultType $type |
|
63 | + * @return bool |
|
64 | + * @since 13.0.0 |
|
65 | + */ |
|
66 | + public function hasExactIdMatch(SearchResultType $type); |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - * @since 13.0.0 |
|
71 | - */ |
|
72 | - public function asArray(); |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + * @since 13.0.0 |
|
71 | + */ |
|
72 | + public function asArray(); |
|
73 | 73 | } |
@@ -30,203 +30,203 @@ |
||
30 | 30 | use OCP\ICache; |
31 | 31 | |
32 | 32 | class InfoParser { |
33 | - /** @var \OCP\ICache|null */ |
|
34 | - private $cache; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param ICache|null $cache |
|
38 | - */ |
|
39 | - public function __construct(ICache $cache = null) { |
|
40 | - $this->cache = $cache; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $file the xml file to be loaded |
|
45 | - * @return null|array where null is an indicator for an error |
|
46 | - */ |
|
47 | - public function parse($file) { |
|
48 | - if (!file_exists($file)) { |
|
49 | - return null; |
|
50 | - } |
|
51 | - |
|
52 | - if(!is_null($this->cache)) { |
|
53 | - $fileCacheKey = $file . filemtime($file); |
|
54 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
55 | - return json_decode($cachedValue, true); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - libxml_use_internal_errors(true); |
|
60 | - $loadEntities = libxml_disable_entity_loader(false); |
|
61 | - $xml = simplexml_load_file($file); |
|
62 | - |
|
63 | - libxml_disable_entity_loader($loadEntities); |
|
64 | - if ($xml === false) { |
|
65 | - libxml_clear_errors(); |
|
66 | - return null; |
|
67 | - } |
|
68 | - $array = $this->xmlToArray($xml); |
|
69 | - |
|
70 | - if (is_null($array)) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - |
|
74 | - if (!array_key_exists('info', $array)) { |
|
75 | - $array['info'] = []; |
|
76 | - } |
|
77 | - if (!array_key_exists('remote', $array)) { |
|
78 | - $array['remote'] = []; |
|
79 | - } |
|
80 | - if (!array_key_exists('public', $array)) { |
|
81 | - $array['public'] = []; |
|
82 | - } |
|
83 | - if (!array_key_exists('types', $array)) { |
|
84 | - $array['types'] = []; |
|
85 | - } |
|
86 | - if (!array_key_exists('repair-steps', $array)) { |
|
87 | - $array['repair-steps'] = []; |
|
88 | - } |
|
89 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
90 | - $array['repair-steps']['install'] = []; |
|
91 | - } |
|
92 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
93 | - $array['repair-steps']['pre-migration'] = []; |
|
94 | - } |
|
95 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
96 | - $array['repair-steps']['post-migration'] = []; |
|
97 | - } |
|
98 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
99 | - $array['repair-steps']['live-migration'] = []; |
|
100 | - } |
|
101 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
102 | - $array['repair-steps']['uninstall'] = []; |
|
103 | - } |
|
104 | - if (!array_key_exists('background-jobs', $array)) { |
|
105 | - $array['background-jobs'] = []; |
|
106 | - } |
|
107 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
108 | - $array['two-factor-providers'] = []; |
|
109 | - } |
|
110 | - if (!array_key_exists('commands', $array)) { |
|
111 | - $array['commands'] = []; |
|
112 | - } |
|
113 | - if (!array_key_exists('activity', $array)) { |
|
114 | - $array['activity'] = []; |
|
115 | - } |
|
116 | - if (!array_key_exists('filters', $array['activity'])) { |
|
117 | - $array['activity']['filters'] = []; |
|
118 | - } |
|
119 | - if (!array_key_exists('settings', $array['activity'])) { |
|
120 | - $array['activity']['settings'] = []; |
|
121 | - } |
|
122 | - if (!array_key_exists('providers', $array['activity'])) { |
|
123 | - $array['activity']['providers'] = []; |
|
124 | - } |
|
125 | - |
|
126 | - if (array_key_exists('types', $array)) { |
|
127 | - if (is_array($array['types'])) { |
|
128 | - foreach ($array['types'] as $type => $v) { |
|
129 | - unset($array['types'][$type]); |
|
130 | - if (is_string($type)) { |
|
131 | - $array['types'][] = $type; |
|
132 | - } |
|
133 | - } |
|
134 | - } else { |
|
135 | - $array['types'] = []; |
|
136 | - } |
|
137 | - } |
|
138 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
139 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
140 | - } |
|
141 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
142 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
143 | - } |
|
144 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
145 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
146 | - } |
|
147 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
148 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
149 | - } |
|
150 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
151 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
152 | - } |
|
153 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
154 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
155 | - } |
|
156 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
157 | - $array['commands'] = $array['commands']['command']; |
|
158 | - } |
|
159 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | - } |
|
162 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | - } |
|
165 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | - } |
|
168 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | - ) { |
|
172 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | - } |
|
174 | - |
|
175 | - if(!is_null($this->cache)) { |
|
176 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
177 | - } |
|
178 | - return $array; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param \SimpleXMLElement $xml |
|
183 | - * @return array |
|
184 | - */ |
|
185 | - public function xmlToArray($xml) { |
|
186 | - if (!$xml->children()) { |
|
187 | - return (string)$xml; |
|
188 | - } |
|
189 | - |
|
190 | - $array = []; |
|
191 | - foreach ($xml->children() as $element => $node) { |
|
192 | - $totalElement = count($xml->{$element}); |
|
193 | - |
|
194 | - if (!isset($array[$element])) { |
|
195 | - $array[$element] = $totalElement > 1 ? [] : ""; |
|
196 | - } |
|
197 | - /** @var \SimpleXMLElement $node */ |
|
198 | - // Has attributes |
|
199 | - if ($attributes = $node->attributes()) { |
|
200 | - $data = [ |
|
201 | - '@attributes' => [], |
|
202 | - ]; |
|
203 | - if (!count($node->children())){ |
|
204 | - $value = (string)$node; |
|
205 | - if (!empty($value)) { |
|
206 | - $data['@value'] = (string)$node; |
|
207 | - } |
|
208 | - } else { |
|
209 | - $data = array_merge($data, $this->xmlToArray($node)); |
|
210 | - } |
|
211 | - foreach ($attributes as $attr => $value) { |
|
212 | - $data['@attributes'][$attr] = (string)$value; |
|
213 | - } |
|
214 | - |
|
215 | - if ($totalElement > 1) { |
|
216 | - $array[$element][] = $data; |
|
217 | - } else { |
|
218 | - $array[$element] = $data; |
|
219 | - } |
|
220 | - // Just a value |
|
221 | - } else { |
|
222 | - if ($totalElement > 1) { |
|
223 | - $array[$element][] = $this->xmlToArray($node); |
|
224 | - } else { |
|
225 | - $array[$element] = $this->xmlToArray($node); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - return $array; |
|
231 | - } |
|
33 | + /** @var \OCP\ICache|null */ |
|
34 | + private $cache; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param ICache|null $cache |
|
38 | + */ |
|
39 | + public function __construct(ICache $cache = null) { |
|
40 | + $this->cache = $cache; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $file the xml file to be loaded |
|
45 | + * @return null|array where null is an indicator for an error |
|
46 | + */ |
|
47 | + public function parse($file) { |
|
48 | + if (!file_exists($file)) { |
|
49 | + return null; |
|
50 | + } |
|
51 | + |
|
52 | + if(!is_null($this->cache)) { |
|
53 | + $fileCacheKey = $file . filemtime($file); |
|
54 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
55 | + return json_decode($cachedValue, true); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + libxml_use_internal_errors(true); |
|
60 | + $loadEntities = libxml_disable_entity_loader(false); |
|
61 | + $xml = simplexml_load_file($file); |
|
62 | + |
|
63 | + libxml_disable_entity_loader($loadEntities); |
|
64 | + if ($xml === false) { |
|
65 | + libxml_clear_errors(); |
|
66 | + return null; |
|
67 | + } |
|
68 | + $array = $this->xmlToArray($xml); |
|
69 | + |
|
70 | + if (is_null($array)) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + |
|
74 | + if (!array_key_exists('info', $array)) { |
|
75 | + $array['info'] = []; |
|
76 | + } |
|
77 | + if (!array_key_exists('remote', $array)) { |
|
78 | + $array['remote'] = []; |
|
79 | + } |
|
80 | + if (!array_key_exists('public', $array)) { |
|
81 | + $array['public'] = []; |
|
82 | + } |
|
83 | + if (!array_key_exists('types', $array)) { |
|
84 | + $array['types'] = []; |
|
85 | + } |
|
86 | + if (!array_key_exists('repair-steps', $array)) { |
|
87 | + $array['repair-steps'] = []; |
|
88 | + } |
|
89 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
90 | + $array['repair-steps']['install'] = []; |
|
91 | + } |
|
92 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
93 | + $array['repair-steps']['pre-migration'] = []; |
|
94 | + } |
|
95 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
96 | + $array['repair-steps']['post-migration'] = []; |
|
97 | + } |
|
98 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
99 | + $array['repair-steps']['live-migration'] = []; |
|
100 | + } |
|
101 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
102 | + $array['repair-steps']['uninstall'] = []; |
|
103 | + } |
|
104 | + if (!array_key_exists('background-jobs', $array)) { |
|
105 | + $array['background-jobs'] = []; |
|
106 | + } |
|
107 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
108 | + $array['two-factor-providers'] = []; |
|
109 | + } |
|
110 | + if (!array_key_exists('commands', $array)) { |
|
111 | + $array['commands'] = []; |
|
112 | + } |
|
113 | + if (!array_key_exists('activity', $array)) { |
|
114 | + $array['activity'] = []; |
|
115 | + } |
|
116 | + if (!array_key_exists('filters', $array['activity'])) { |
|
117 | + $array['activity']['filters'] = []; |
|
118 | + } |
|
119 | + if (!array_key_exists('settings', $array['activity'])) { |
|
120 | + $array['activity']['settings'] = []; |
|
121 | + } |
|
122 | + if (!array_key_exists('providers', $array['activity'])) { |
|
123 | + $array['activity']['providers'] = []; |
|
124 | + } |
|
125 | + |
|
126 | + if (array_key_exists('types', $array)) { |
|
127 | + if (is_array($array['types'])) { |
|
128 | + foreach ($array['types'] as $type => $v) { |
|
129 | + unset($array['types'][$type]); |
|
130 | + if (is_string($type)) { |
|
131 | + $array['types'][] = $type; |
|
132 | + } |
|
133 | + } |
|
134 | + } else { |
|
135 | + $array['types'] = []; |
|
136 | + } |
|
137 | + } |
|
138 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
139 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
140 | + } |
|
141 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
142 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
143 | + } |
|
144 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
145 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
146 | + } |
|
147 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
148 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
149 | + } |
|
150 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
151 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
152 | + } |
|
153 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
154 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
155 | + } |
|
156 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
157 | + $array['commands'] = $array['commands']['command']; |
|
158 | + } |
|
159 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | + } |
|
162 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | + } |
|
165 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | + } |
|
168 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | + ) { |
|
172 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | + } |
|
174 | + |
|
175 | + if(!is_null($this->cache)) { |
|
176 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
177 | + } |
|
178 | + return $array; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param \SimpleXMLElement $xml |
|
183 | + * @return array |
|
184 | + */ |
|
185 | + public function xmlToArray($xml) { |
|
186 | + if (!$xml->children()) { |
|
187 | + return (string)$xml; |
|
188 | + } |
|
189 | + |
|
190 | + $array = []; |
|
191 | + foreach ($xml->children() as $element => $node) { |
|
192 | + $totalElement = count($xml->{$element}); |
|
193 | + |
|
194 | + if (!isset($array[$element])) { |
|
195 | + $array[$element] = $totalElement > 1 ? [] : ""; |
|
196 | + } |
|
197 | + /** @var \SimpleXMLElement $node */ |
|
198 | + // Has attributes |
|
199 | + if ($attributes = $node->attributes()) { |
|
200 | + $data = [ |
|
201 | + '@attributes' => [], |
|
202 | + ]; |
|
203 | + if (!count($node->children())){ |
|
204 | + $value = (string)$node; |
|
205 | + if (!empty($value)) { |
|
206 | + $data['@value'] = (string)$node; |
|
207 | + } |
|
208 | + } else { |
|
209 | + $data = array_merge($data, $this->xmlToArray($node)); |
|
210 | + } |
|
211 | + foreach ($attributes as $attr => $value) { |
|
212 | + $data['@attributes'][$attr] = (string)$value; |
|
213 | + } |
|
214 | + |
|
215 | + if ($totalElement > 1) { |
|
216 | + $array[$element][] = $data; |
|
217 | + } else { |
|
218 | + $array[$element] = $data; |
|
219 | + } |
|
220 | + // Just a value |
|
221 | + } else { |
|
222 | + if ($totalElement > 1) { |
|
223 | + $array[$element][] = $this->xmlToArray($node); |
|
224 | + } else { |
|
225 | + $array[$element] = $this->xmlToArray($node); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + return $array; |
|
231 | + } |
|
232 | 232 | } |
@@ -33,92 +33,92 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class GroupPlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
37 | - protected $shareWithGroupOnly; |
|
36 | + protected $shareeEnumeration; |
|
37 | + protected $shareWithGroupOnly; |
|
38 | 38 | |
39 | - /** @var IGroupManager */ |
|
40 | - private $groupManager; |
|
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var IUserSession */ |
|
44 | - private $userSession; |
|
39 | + /** @var IGroupManager */ |
|
40 | + private $groupManager; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var IUserSession */ |
|
44 | + private $userSession; |
|
45 | 45 | |
46 | - public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) { |
|
47 | - $this->groupManager = $groupManager; |
|
48 | - $this->config = $config; |
|
49 | - $this->userSession = $userSession; |
|
46 | + public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) { |
|
47 | + $this->groupManager = $groupManager; |
|
48 | + $this->config = $config; |
|
49 | + $this->userSession = $userSession; |
|
50 | 50 | |
51 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
52 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
53 | - } |
|
51 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
52 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
53 | + } |
|
54 | 54 | |
55 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | - $hasMoreResults = false; |
|
57 | - $result = ['wide' => [], 'exact' => []]; |
|
55 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | + $hasMoreResults = false; |
|
57 | + $result = ['wide' => [], 'exact' => []]; |
|
58 | 58 | |
59 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
60 | - $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
59 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
60 | + $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
61 | 61 | |
62 | - if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
|
63 | - $hasMoreResults = true; |
|
64 | - } |
|
62 | + if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
|
63 | + $hasMoreResults = true; |
|
64 | + } |
|
65 | 65 | |
66 | - $userGroups = []; |
|
67 | - if (!empty($groups) && $this->shareWithGroupOnly) { |
|
68 | - // Intersect all the groups that match with the groups this user is a member of |
|
69 | - $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
70 | - $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
71 | - $groupIds = array_intersect($groupIds, $userGroups); |
|
72 | - } |
|
66 | + $userGroups = []; |
|
67 | + if (!empty($groups) && $this->shareWithGroupOnly) { |
|
68 | + // Intersect all the groups that match with the groups this user is a member of |
|
69 | + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
70 | + $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
71 | + $groupIds = array_intersect($groupIds, $userGroups); |
|
72 | + } |
|
73 | 73 | |
74 | - $lowerSearch = strtolower($search); |
|
75 | - foreach ($groups as $group) { |
|
76 | - // FIXME: use a more efficient approach |
|
77 | - $gid = $group->getGID(); |
|
78 | - if (!in_array($gid, $groupIds)) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
82 | - $result['exact'][] = [ |
|
83 | - 'label' => $group->getDisplayName(), |
|
84 | - 'value' => [ |
|
85 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
86 | - 'shareWith' => $gid, |
|
87 | - ], |
|
88 | - ]; |
|
89 | - } else { |
|
90 | - $result['wide'][] = [ |
|
91 | - 'label' => $group->getDisplayName(), |
|
92 | - 'value' => [ |
|
93 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
94 | - 'shareWith' => $gid, |
|
95 | - ], |
|
96 | - ]; |
|
97 | - } |
|
98 | - } |
|
74 | + $lowerSearch = strtolower($search); |
|
75 | + foreach ($groups as $group) { |
|
76 | + // FIXME: use a more efficient approach |
|
77 | + $gid = $group->getGID(); |
|
78 | + if (!in_array($gid, $groupIds)) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
82 | + $result['exact'][] = [ |
|
83 | + 'label' => $group->getDisplayName(), |
|
84 | + 'value' => [ |
|
85 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
86 | + 'shareWith' => $gid, |
|
87 | + ], |
|
88 | + ]; |
|
89 | + } else { |
|
90 | + $result['wide'][] = [ |
|
91 | + 'label' => $group->getDisplayName(), |
|
92 | + 'value' => [ |
|
93 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
94 | + 'shareWith' => $gid, |
|
95 | + ], |
|
96 | + ]; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - if ($offset === 0 && empty($result['exact'])) { |
|
101 | - // On page one we try if the search result has a direct hit on the |
|
102 | - // user id and if so, we add that to the exact match list |
|
103 | - $group = $this->groupManager->get($search); |
|
104 | - if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
105 | - array_push($result['exact'], [ |
|
106 | - 'label' => $group->getDisplayName(), |
|
107 | - 'value' => [ |
|
108 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
109 | - 'shareWith' => $group->getGID(), |
|
110 | - ], |
|
111 | - ]); |
|
112 | - } |
|
113 | - } |
|
100 | + if ($offset === 0 && empty($result['exact'])) { |
|
101 | + // On page one we try if the search result has a direct hit on the |
|
102 | + // user id and if so, we add that to the exact match list |
|
103 | + $group = $this->groupManager->get($search); |
|
104 | + if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
105 | + array_push($result['exact'], [ |
|
106 | + 'label' => $group->getDisplayName(), |
|
107 | + 'value' => [ |
|
108 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
109 | + 'shareWith' => $group->getGID(), |
|
110 | + ], |
|
111 | + ]); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - if (!$this->shareeEnumeration) { |
|
116 | - $result['wide'] = []; |
|
117 | - } |
|
115 | + if (!$this->shareeEnumeration) { |
|
116 | + $result['wide'] = []; |
|
117 | + } |
|
118 | 118 | |
119 | - $type = new SearchResultType('groups'); |
|
120 | - $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
119 | + $type = new SearchResultType('groups'); |
|
120 | + $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
121 | 121 | |
122 | - return $hasMoreResults; |
|
123 | - } |
|
122 | + return $hasMoreResults; |
|
123 | + } |
|
124 | 124 | } |
@@ -33,54 +33,54 @@ |
||
33 | 33 | |
34 | 34 | class LookupPlugin implements ISearchPlugin { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
38 | - /** @var IClientService */ |
|
39 | - private $clientService; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | + /** @var IClientService */ |
|
39 | + private $clientService; |
|
40 | 40 | |
41 | - public function __construct(IConfig $config, IClientService $clientService) { |
|
42 | - $this->config = $config; |
|
43 | - $this->clientService = $clientService; |
|
44 | - } |
|
41 | + public function __construct(IConfig $config, IClientService $clientService) { |
|
42 | + $this->config = $config; |
|
43 | + $this->clientService = $clientService; |
|
44 | + } |
|
45 | 45 | |
46 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
47 | - if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') { |
|
48 | - return false; |
|
49 | - } |
|
46 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
47 | + if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') { |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
52 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
53 | - $result = ['wide' => [], 'exact' => []]; |
|
51 | + $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
52 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
53 | + $result = ['wide' => [], 'exact' => []]; |
|
54 | 54 | |
55 | - try { |
|
56 | - $client = $this->clientService->newClient(); |
|
57 | - $response = $client->get( |
|
58 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
59 | - [ |
|
60 | - 'timeout' => 10, |
|
61 | - 'connect_timeout' => 3, |
|
62 | - ] |
|
63 | - ); |
|
55 | + try { |
|
56 | + $client = $this->clientService->newClient(); |
|
57 | + $response = $client->get( |
|
58 | + $lookupServerUrl . '/users?search=' . urlencode($search), |
|
59 | + [ |
|
60 | + 'timeout' => 10, |
|
61 | + 'connect_timeout' => 3, |
|
62 | + ] |
|
63 | + ); |
|
64 | 64 | |
65 | - $body = json_decode($response->getBody(), true); |
|
65 | + $body = json_decode($response->getBody(), true); |
|
66 | 66 | |
67 | - $result = []; |
|
68 | - foreach ($body as $lookup) { |
|
69 | - $result[] = [ |
|
70 | - 'label' => $lookup['federationId'], |
|
71 | - 'value' => [ |
|
72 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
73 | - 'shareWith' => $lookup['federationId'], |
|
74 | - ], |
|
75 | - 'extra' => $lookup, |
|
76 | - ]; |
|
77 | - } |
|
78 | - } catch (\Exception $e) { |
|
79 | - } |
|
67 | + $result = []; |
|
68 | + foreach ($body as $lookup) { |
|
69 | + $result[] = [ |
|
70 | + 'label' => $lookup['federationId'], |
|
71 | + 'value' => [ |
|
72 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
73 | + 'shareWith' => $lookup['federationId'], |
|
74 | + ], |
|
75 | + 'extra' => $lookup, |
|
76 | + ]; |
|
77 | + } |
|
78 | + } catch (\Exception $e) { |
|
79 | + } |
|
80 | 80 | |
81 | - $type = new SearchResultType('lookup'); |
|
82 | - $searchResult->addResultSet($type, $result, []); |
|
81 | + $type = new SearchResultType('lookup'); |
|
82 | + $searchResult->addResultSet($type, $result, []); |
|
83 | 83 | |
84 | - return false; |
|
85 | - } |
|
84 | + return false; |
|
85 | + } |
|
86 | 86 | } |
@@ -61,1189 +61,1189 @@ |
||
61 | 61 | * upgrading and removing apps. |
62 | 62 | */ |
63 | 63 | class OC_App { |
64 | - static private $appVersion = []; |
|
65 | - static private $adminForms = array(); |
|
66 | - static private $personalForms = array(); |
|
67 | - static private $appInfo = array(); |
|
68 | - static private $appTypes = array(); |
|
69 | - static private $loadedApps = array(); |
|
70 | - static private $altLogin = array(); |
|
71 | - static private $alreadyRegistered = []; |
|
72 | - const officialApp = 200; |
|
73 | - |
|
74 | - /** |
|
75 | - * clean the appId |
|
76 | - * |
|
77 | - * @param string|boolean $app AppId that needs to be cleaned |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function cleanAppId($app) { |
|
81 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check if an app is loaded |
|
86 | - * |
|
87 | - * @param string $app |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public static function isAppLoaded($app) { |
|
91 | - return in_array($app, self::$loadedApps, true); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * loads all apps |
|
96 | - * |
|
97 | - * @param string[] | string | null $types |
|
98 | - * @return bool |
|
99 | - * |
|
100 | - * This function walks through the ownCloud directory and loads all apps |
|
101 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | - * exists. |
|
103 | - * |
|
104 | - * if $types is set, only apps of those types will be loaded |
|
105 | - */ |
|
106 | - public static function loadApps($types = null) { |
|
107 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - // Load the enabled apps here |
|
111 | - $apps = self::getEnabledApps(); |
|
112 | - |
|
113 | - // Add each apps' folder as allowed class path |
|
114 | - foreach($apps as $app) { |
|
115 | - $path = self::getAppPath($app); |
|
116 | - if($path !== false) { |
|
117 | - self::registerAutoloading($app, $path); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - // prevent app.php from printing output |
|
122 | - ob_start(); |
|
123 | - foreach ($apps as $app) { |
|
124 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | - self::loadApp($app); |
|
126 | - } |
|
127 | - } |
|
128 | - ob_end_clean(); |
|
129 | - |
|
130 | - return true; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * load a single app |
|
135 | - * |
|
136 | - * @param string $app |
|
137 | - */ |
|
138 | - public static function loadApp($app) { |
|
139 | - self::$loadedApps[] = $app; |
|
140 | - $appPath = self::getAppPath($app); |
|
141 | - if($appPath === false) { |
|
142 | - return; |
|
143 | - } |
|
144 | - |
|
145 | - // in case someone calls loadApp() directly |
|
146 | - self::registerAutoloading($app, $appPath); |
|
147 | - |
|
148 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | - self::requireAppFile($app); |
|
151 | - if (self::isType($app, array('authentication'))) { |
|
152 | - // since authentication apps affect the "is app enabled for group" check, |
|
153 | - // the enabled apps cache needs to be cleared to make sure that the |
|
154 | - // next time getEnableApps() is called it will also include apps that were |
|
155 | - // enabled for groups |
|
156 | - self::$enabledAppsCache = array(); |
|
157 | - } |
|
158 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
159 | - } |
|
160 | - |
|
161 | - $info = self::getAppInfo($app); |
|
162 | - if (!empty($info['activity']['filters'])) { |
|
163 | - foreach ($info['activity']['filters'] as $filter) { |
|
164 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
165 | - } |
|
166 | - } |
|
167 | - if (!empty($info['activity']['settings'])) { |
|
168 | - foreach ($info['activity']['settings'] as $setting) { |
|
169 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
170 | - } |
|
171 | - } |
|
172 | - if (!empty($info['activity']['providers'])) { |
|
173 | - foreach ($info['activity']['providers'] as $provider) { |
|
174 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
175 | - } |
|
176 | - } |
|
177 | - if (!empty($info['collaboration']['collaborators']['searchPlugins'])) { |
|
178 | - foreach ($info['collaboration']['collaborators']['searchPlugins'] as $plugin) { |
|
179 | - \OC::$server->getCollaboratorSearch()->registerPlugin($plugin); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @internal |
|
186 | - * @param string $app |
|
187 | - * @param string $path |
|
188 | - */ |
|
189 | - public static function registerAutoloading($app, $path) { |
|
190 | - $key = $app . '-' . $path; |
|
191 | - if(isset(self::$alreadyRegistered[$key])) { |
|
192 | - return; |
|
193 | - } |
|
194 | - self::$alreadyRegistered[$key] = true; |
|
195 | - // Register on PSR-4 composer autoloader |
|
196 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
197 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
198 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
199 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
200 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
201 | - } |
|
202 | - |
|
203 | - // Register on legacy autoloader |
|
204 | - \OC::$loader->addValidRoot($path); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Load app.php from the given app |
|
209 | - * |
|
210 | - * @param string $app app name |
|
211 | - */ |
|
212 | - private static function requireAppFile($app) { |
|
213 | - try { |
|
214 | - // encapsulated here to avoid variable scope conflicts |
|
215 | - require_once $app . '/appinfo/app.php'; |
|
216 | - } catch (Error $ex) { |
|
217 | - \OC::$server->getLogger()->logException($ex); |
|
218 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
219 | - if (!in_array($app, $blacklist)) { |
|
220 | - self::disable($app); |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * check if an app is of a specific type |
|
227 | - * |
|
228 | - * @param string $app |
|
229 | - * @param string|array $types |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public static function isType($app, $types) { |
|
233 | - if (is_string($types)) { |
|
234 | - $types = array($types); |
|
235 | - } |
|
236 | - $appTypes = self::getAppTypes($app); |
|
237 | - foreach ($types as $type) { |
|
238 | - if (array_search($type, $appTypes) !== false) { |
|
239 | - return true; |
|
240 | - } |
|
241 | - } |
|
242 | - return false; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * get the types of an app |
|
247 | - * |
|
248 | - * @param string $app |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - private static function getAppTypes($app) { |
|
252 | - //load the cache |
|
253 | - if (count(self::$appTypes) == 0) { |
|
254 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
255 | - } |
|
256 | - |
|
257 | - if (isset(self::$appTypes[$app])) { |
|
258 | - return explode(',', self::$appTypes[$app]); |
|
259 | - } else { |
|
260 | - return array(); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * read app types from info.xml and cache them in the database |
|
266 | - */ |
|
267 | - public static function setAppTypes($app) { |
|
268 | - $appData = self::getAppInfo($app); |
|
269 | - if(!is_array($appData)) { |
|
270 | - return; |
|
271 | - } |
|
272 | - |
|
273 | - if (isset($appData['types'])) { |
|
274 | - $appTypes = implode(',', $appData['types']); |
|
275 | - } else { |
|
276 | - $appTypes = ''; |
|
277 | - $appData['types'] = []; |
|
278 | - } |
|
279 | - |
|
280 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
281 | - |
|
282 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
283 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
284 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
285 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * get all enabled apps |
|
292 | - */ |
|
293 | - protected static $enabledAppsCache = array(); |
|
294 | - |
|
295 | - /** |
|
296 | - * Returns apps enabled for the current user. |
|
297 | - * |
|
298 | - * @param bool $forceRefresh whether to refresh the cache |
|
299 | - * @param bool $all whether to return apps for all users, not only the |
|
300 | - * currently logged in one |
|
301 | - * @return string[] |
|
302 | - */ |
|
303 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
304 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
305 | - return array(); |
|
306 | - } |
|
307 | - // in incognito mode or when logged out, $user will be false, |
|
308 | - // which is also the case during an upgrade |
|
309 | - $appManager = \OC::$server->getAppManager(); |
|
310 | - if ($all) { |
|
311 | - $user = null; |
|
312 | - } else { |
|
313 | - $user = \OC::$server->getUserSession()->getUser(); |
|
314 | - } |
|
315 | - |
|
316 | - if (is_null($user)) { |
|
317 | - $apps = $appManager->getInstalledApps(); |
|
318 | - } else { |
|
319 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
320 | - } |
|
321 | - $apps = array_filter($apps, function ($app) { |
|
322 | - return $app !== 'files';//we add this manually |
|
323 | - }); |
|
324 | - sort($apps); |
|
325 | - array_unshift($apps, 'files'); |
|
326 | - return $apps; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * checks whether or not an app is enabled |
|
331 | - * |
|
332 | - * @param string $app app |
|
333 | - * @return bool |
|
334 | - * |
|
335 | - * This function checks whether or not an app is enabled. |
|
336 | - */ |
|
337 | - public static function isEnabled($app) { |
|
338 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * enables an app |
|
343 | - * |
|
344 | - * @param string $appId |
|
345 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
346 | - * @throws \Exception |
|
347 | - * @return void |
|
348 | - * |
|
349 | - * This function set an app as enabled in appconfig. |
|
350 | - */ |
|
351 | - public function enable($appId, |
|
352 | - $groups = null) { |
|
353 | - self::$enabledAppsCache = []; // flush |
|
354 | - |
|
355 | - // Check if app is already downloaded |
|
356 | - $installer = new Installer( |
|
357 | - \OC::$server->getAppFetcher(), |
|
358 | - \OC::$server->getHTTPClientService(), |
|
359 | - \OC::$server->getTempManager(), |
|
360 | - \OC::$server->getLogger(), |
|
361 | - \OC::$server->getConfig() |
|
362 | - ); |
|
363 | - $isDownloaded = $installer->isDownloaded($appId); |
|
364 | - |
|
365 | - if(!$isDownloaded) { |
|
366 | - $installer->downloadApp($appId); |
|
367 | - } |
|
368 | - |
|
369 | - $installer->installApp($appId); |
|
370 | - |
|
371 | - $appManager = \OC::$server->getAppManager(); |
|
372 | - if (!is_null($groups)) { |
|
373 | - $groupManager = \OC::$server->getGroupManager(); |
|
374 | - $groupsList = []; |
|
375 | - foreach ($groups as $group) { |
|
376 | - $groupItem = $groupManager->get($group); |
|
377 | - if ($groupItem instanceof \OCP\IGroup) { |
|
378 | - $groupsList[] = $groupManager->get($group); |
|
379 | - } |
|
380 | - } |
|
381 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
382 | - } else { |
|
383 | - $appManager->enableApp($appId); |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * @param string $app |
|
389 | - * @return bool |
|
390 | - */ |
|
391 | - public static function removeApp($app) { |
|
392 | - if (\OC::$server->getAppManager()->isShipped($app)) { |
|
393 | - return false; |
|
394 | - } |
|
395 | - |
|
396 | - $installer = new Installer( |
|
397 | - \OC::$server->getAppFetcher(), |
|
398 | - \OC::$server->getHTTPClientService(), |
|
399 | - \OC::$server->getTempManager(), |
|
400 | - \OC::$server->getLogger(), |
|
401 | - \OC::$server->getConfig() |
|
402 | - ); |
|
403 | - return $installer->removeApp($app); |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * This function set an app as disabled in appconfig. |
|
408 | - * |
|
409 | - * @param string $app app |
|
410 | - * @throws Exception |
|
411 | - */ |
|
412 | - public static function disable($app) { |
|
413 | - // flush |
|
414 | - self::$enabledAppsCache = array(); |
|
415 | - |
|
416 | - // run uninstall steps |
|
417 | - $appData = OC_App::getAppInfo($app); |
|
418 | - if (!is_null($appData)) { |
|
419 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
420 | - } |
|
421 | - |
|
422 | - // emit disable hook - needed anymore ? |
|
423 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
424 | - |
|
425 | - // finally disable it |
|
426 | - $appManager = \OC::$server->getAppManager(); |
|
427 | - $appManager->disableApp($app); |
|
428 | - } |
|
429 | - |
|
430 | - // This is private as well. It simply works, so don't ask for more details |
|
431 | - private static function proceedNavigation($list) { |
|
432 | - usort($list, function($a, $b) { |
|
433 | - if (isset($a['order']) && isset($b['order'])) { |
|
434 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
435 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
436 | - return isset($a['order']) ? -1 : 1; |
|
437 | - } else { |
|
438 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
439 | - } |
|
440 | - }); |
|
441 | - |
|
442 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
443 | - foreach ($list as $index => &$navEntry) { |
|
444 | - if ($navEntry['id'] == $activeApp) { |
|
445 | - $navEntry['active'] = true; |
|
446 | - } else { |
|
447 | - $navEntry['active'] = false; |
|
448 | - } |
|
449 | - } |
|
450 | - unset($navEntry); |
|
451 | - |
|
452 | - return $list; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Get the path where to install apps |
|
457 | - * |
|
458 | - * @return string|false |
|
459 | - */ |
|
460 | - public static function getInstallPath() { |
|
461 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
462 | - return false; |
|
463 | - } |
|
464 | - |
|
465 | - foreach (OC::$APPSROOTS as $dir) { |
|
466 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
467 | - return $dir['path']; |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
472 | - return null; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * search for an app in all app-directories |
|
478 | - * |
|
479 | - * @param string $appId |
|
480 | - * @return false|string |
|
481 | - */ |
|
482 | - public static function findAppInDirectories($appId) { |
|
483 | - $sanitizedAppId = self::cleanAppId($appId); |
|
484 | - if($sanitizedAppId !== $appId) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - static $app_dir = array(); |
|
488 | - |
|
489 | - if (isset($app_dir[$appId])) { |
|
490 | - return $app_dir[$appId]; |
|
491 | - } |
|
492 | - |
|
493 | - $possibleApps = array(); |
|
494 | - foreach (OC::$APPSROOTS as $dir) { |
|
495 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
496 | - $possibleApps[] = $dir; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - if (empty($possibleApps)) { |
|
501 | - return false; |
|
502 | - } elseif (count($possibleApps) === 1) { |
|
503 | - $dir = array_shift($possibleApps); |
|
504 | - $app_dir[$appId] = $dir; |
|
505 | - return $dir; |
|
506 | - } else { |
|
507 | - $versionToLoad = array(); |
|
508 | - foreach ($possibleApps as $possibleApp) { |
|
509 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
510 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
511 | - $versionToLoad = array( |
|
512 | - 'dir' => $possibleApp, |
|
513 | - 'version' => $version, |
|
514 | - ); |
|
515 | - } |
|
516 | - } |
|
517 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
518 | - return $versionToLoad['dir']; |
|
519 | - //TODO - write test |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Get the directory for the given app. |
|
525 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
526 | - * |
|
527 | - * @param string $appId |
|
528 | - * @return string|false |
|
529 | - */ |
|
530 | - public static function getAppPath($appId) { |
|
531 | - if ($appId === null || trim($appId) === '') { |
|
532 | - return false; |
|
533 | - } |
|
534 | - |
|
535 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
536 | - return $dir['path'] . '/' . $appId; |
|
537 | - } |
|
538 | - return false; |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Get the path for the given app on the access |
|
543 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
544 | - * |
|
545 | - * @param string $appId |
|
546 | - * @return string|false |
|
547 | - */ |
|
548 | - public static function getAppWebPath($appId) { |
|
549 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
550 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
551 | - } |
|
552 | - return false; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * get the last version of the app from appinfo/info.xml |
|
557 | - * |
|
558 | - * @param string $appId |
|
559 | - * @param bool $useCache |
|
560 | - * @return string |
|
561 | - */ |
|
562 | - public static function getAppVersion($appId, $useCache = true) { |
|
563 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
564 | - return self::$appVersion[$appId]; |
|
565 | - } |
|
566 | - |
|
567 | - $file = self::getAppPath($appId); |
|
568 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
569 | - return self::$appVersion[$appId]; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * get app's version based on it's path |
|
574 | - * |
|
575 | - * @param string $path |
|
576 | - * @return string |
|
577 | - */ |
|
578 | - public static function getAppVersionByPath($path) { |
|
579 | - $infoFile = $path . '/appinfo/info.xml'; |
|
580 | - $appData = self::getAppInfo($infoFile, true); |
|
581 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Read all app metadata from the info.xml file |
|
587 | - * |
|
588 | - * @param string $appId id of the app or the path of the info.xml file |
|
589 | - * @param bool $path |
|
590 | - * @param string $lang |
|
591 | - * @return array|null |
|
592 | - * @note all data is read from info.xml, not just pre-defined fields |
|
593 | - */ |
|
594 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
595 | - if ($path) { |
|
596 | - $file = $appId; |
|
597 | - } else { |
|
598 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
599 | - return self::$appInfo[$appId]; |
|
600 | - } |
|
601 | - $appPath = self::getAppPath($appId); |
|
602 | - if($appPath === false) { |
|
603 | - return null; |
|
604 | - } |
|
605 | - $file = $appPath . '/appinfo/info.xml'; |
|
606 | - } |
|
607 | - |
|
608 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
609 | - $data = $parser->parse($file); |
|
610 | - |
|
611 | - if (is_array($data)) { |
|
612 | - $data = OC_App::parseAppInfo($data, $lang); |
|
613 | - } |
|
614 | - if(isset($data['ocsid'])) { |
|
615 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
616 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
617 | - $data['ocsid'] = $storedId; |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - if ($lang === null) { |
|
622 | - self::$appInfo[$appId] = $data; |
|
623 | - } |
|
624 | - |
|
625 | - return $data; |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Returns the navigation |
|
630 | - * |
|
631 | - * @return array |
|
632 | - * |
|
633 | - * This function returns an array containing all entries added. The |
|
634 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
635 | - * given for each app the following keys exist: |
|
636 | - * - active: boolean, signals if the user is on this navigation entry |
|
637 | - */ |
|
638 | - public static function getNavigation() { |
|
639 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
640 | - return self::proceedNavigation($entries); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Returns the Settings Navigation |
|
645 | - * |
|
646 | - * @return string[] |
|
647 | - * |
|
648 | - * This function returns an array containing all settings pages added. The |
|
649 | - * entries are sorted by the key 'order' ascending. |
|
650 | - */ |
|
651 | - public static function getSettingsNavigation() { |
|
652 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
653 | - return self::proceedNavigation($entries); |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * get the id of loaded app |
|
658 | - * |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public static function getCurrentApp() { |
|
662 | - $request = \OC::$server->getRequest(); |
|
663 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
664 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
665 | - if (empty($topFolder)) { |
|
666 | - $path_info = $request->getPathInfo(); |
|
667 | - if ($path_info) { |
|
668 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
669 | - } |
|
670 | - } |
|
671 | - if ($topFolder == 'apps') { |
|
672 | - $length = strlen($topFolder); |
|
673 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
674 | - } else { |
|
675 | - return $topFolder; |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * @param string $type |
|
681 | - * @return array |
|
682 | - */ |
|
683 | - public static function getForms($type) { |
|
684 | - $forms = array(); |
|
685 | - switch ($type) { |
|
686 | - case 'admin': |
|
687 | - $source = self::$adminForms; |
|
688 | - break; |
|
689 | - case 'personal': |
|
690 | - $source = self::$personalForms; |
|
691 | - break; |
|
692 | - default: |
|
693 | - return array(); |
|
694 | - } |
|
695 | - foreach ($source as $form) { |
|
696 | - $forms[] = include $form; |
|
697 | - } |
|
698 | - return $forms; |
|
699 | - } |
|
700 | - |
|
701 | - /** |
|
702 | - * register an admin form to be shown |
|
703 | - * |
|
704 | - * @param string $app |
|
705 | - * @param string $page |
|
706 | - */ |
|
707 | - public static function registerAdmin($app, $page) { |
|
708 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * register a personal form to be shown |
|
713 | - * @param string $app |
|
714 | - * @param string $page |
|
715 | - */ |
|
716 | - public static function registerPersonal($app, $page) { |
|
717 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * @param array $entry |
|
722 | - */ |
|
723 | - public static function registerLogIn(array $entry) { |
|
724 | - self::$altLogin[] = $entry; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * @return array |
|
729 | - */ |
|
730 | - public static function getAlternativeLogIns() { |
|
731 | - return self::$altLogin; |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * get a list of all apps in the apps folder |
|
736 | - * |
|
737 | - * @return array an array of app names (string IDs) |
|
738 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
739 | - */ |
|
740 | - public static function getAllApps() { |
|
741 | - |
|
742 | - $apps = array(); |
|
743 | - |
|
744 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
745 | - if (!is_readable($apps_dir['path'])) { |
|
746 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
747 | - continue; |
|
748 | - } |
|
749 | - $dh = opendir($apps_dir['path']); |
|
750 | - |
|
751 | - if (is_resource($dh)) { |
|
752 | - while (($file = readdir($dh)) !== false) { |
|
753 | - |
|
754 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
755 | - |
|
756 | - $apps[] = $file; |
|
757 | - } |
|
758 | - } |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - return $apps; |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * List all apps, this is used in apps.php |
|
767 | - * |
|
768 | - * @return array |
|
769 | - */ |
|
770 | - public function listAllApps() { |
|
771 | - $installedApps = OC_App::getAllApps(); |
|
772 | - |
|
773 | - $appManager = \OC::$server->getAppManager(); |
|
774 | - //we don't want to show configuration for these |
|
775 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
776 | - $appList = array(); |
|
777 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
778 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
779 | - |
|
780 | - foreach ($installedApps as $app) { |
|
781 | - if (array_search($app, $blacklist) === false) { |
|
782 | - |
|
783 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
784 | - if (!is_array($info)) { |
|
785 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
786 | - continue; |
|
787 | - } |
|
788 | - |
|
789 | - if (!isset($info['name'])) { |
|
790 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
791 | - continue; |
|
792 | - } |
|
793 | - |
|
794 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
795 | - $info['groups'] = null; |
|
796 | - if ($enabled === 'yes') { |
|
797 | - $active = true; |
|
798 | - } else if ($enabled === 'no') { |
|
799 | - $active = false; |
|
800 | - } else { |
|
801 | - $active = true; |
|
802 | - $info['groups'] = $enabled; |
|
803 | - } |
|
804 | - |
|
805 | - $info['active'] = $active; |
|
806 | - |
|
807 | - if ($appManager->isShipped($app)) { |
|
808 | - $info['internal'] = true; |
|
809 | - $info['level'] = self::officialApp; |
|
810 | - $info['removable'] = false; |
|
811 | - } else { |
|
812 | - $info['internal'] = false; |
|
813 | - $info['removable'] = true; |
|
814 | - } |
|
815 | - |
|
816 | - $appPath = self::getAppPath($app); |
|
817 | - if($appPath !== false) { |
|
818 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
819 | - if (file_exists($appIcon)) { |
|
820 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
821 | - $info['previewAsIcon'] = true; |
|
822 | - } else { |
|
823 | - $appIcon = $appPath . '/img/app.svg'; |
|
824 | - if (file_exists($appIcon)) { |
|
825 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
826 | - $info['previewAsIcon'] = true; |
|
827 | - } |
|
828 | - } |
|
829 | - } |
|
830 | - // fix documentation |
|
831 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
832 | - foreach ($info['documentation'] as $key => $url) { |
|
833 | - // If it is not an absolute URL we assume it is a key |
|
834 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
835 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
836 | - $url = $urlGenerator->linkToDocs($url); |
|
837 | - } |
|
838 | - |
|
839 | - $info['documentation'][$key] = $url; |
|
840 | - } |
|
841 | - } |
|
842 | - |
|
843 | - $info['version'] = OC_App::getAppVersion($app); |
|
844 | - $appList[] = $info; |
|
845 | - } |
|
846 | - } |
|
847 | - |
|
848 | - return $appList; |
|
849 | - } |
|
850 | - |
|
851 | - /** |
|
852 | - * Returns the internal app ID or false |
|
853 | - * @param string $ocsID |
|
854 | - * @return string|false |
|
855 | - */ |
|
856 | - public static function getInternalAppIdByOcs($ocsID) { |
|
857 | - if(is_numeric($ocsID)) { |
|
858 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
859 | - if(array_search($ocsID, $idArray)) { |
|
860 | - return array_search($ocsID, $idArray); |
|
861 | - } |
|
862 | - } |
|
863 | - return false; |
|
864 | - } |
|
865 | - |
|
866 | - public static function shouldUpgrade($app) { |
|
867 | - $versions = self::getAppVersions(); |
|
868 | - $currentVersion = OC_App::getAppVersion($app); |
|
869 | - if ($currentVersion && isset($versions[$app])) { |
|
870 | - $installedVersion = $versions[$app]; |
|
871 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
872 | - return true; |
|
873 | - } |
|
874 | - } |
|
875 | - return false; |
|
876 | - } |
|
877 | - |
|
878 | - /** |
|
879 | - * Adjust the number of version parts of $version1 to match |
|
880 | - * the number of version parts of $version2. |
|
881 | - * |
|
882 | - * @param string $version1 version to adjust |
|
883 | - * @param string $version2 version to take the number of parts from |
|
884 | - * @return string shortened $version1 |
|
885 | - */ |
|
886 | - private static function adjustVersionParts($version1, $version2) { |
|
887 | - $version1 = explode('.', $version1); |
|
888 | - $version2 = explode('.', $version2); |
|
889 | - // reduce $version1 to match the number of parts in $version2 |
|
890 | - while (count($version1) > count($version2)) { |
|
891 | - array_pop($version1); |
|
892 | - } |
|
893 | - // if $version1 does not have enough parts, add some |
|
894 | - while (count($version1) < count($version2)) { |
|
895 | - $version1[] = '0'; |
|
896 | - } |
|
897 | - return implode('.', $version1); |
|
898 | - } |
|
899 | - |
|
900 | - /** |
|
901 | - * Check whether the current ownCloud version matches the given |
|
902 | - * application's version requirements. |
|
903 | - * |
|
904 | - * The comparison is made based on the number of parts that the |
|
905 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
906 | - * app info version is expecting version 6.0, the comparison is |
|
907 | - * made on the first two parts of the ownCloud version. |
|
908 | - * This means that it's possible to specify "requiremin" => 6 |
|
909 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
910 | - * |
|
911 | - * @param string $ocVersion ownCloud version to check against |
|
912 | - * @param array $appInfo app info (from xml) |
|
913 | - * |
|
914 | - * @return boolean true if compatible, otherwise false |
|
915 | - */ |
|
916 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
917 | - $requireMin = ''; |
|
918 | - $requireMax = ''; |
|
919 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
920 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
921 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
922 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
923 | - } else if (isset($appInfo['requiremin'])) { |
|
924 | - $requireMin = $appInfo['requiremin']; |
|
925 | - } else if (isset($appInfo['require'])) { |
|
926 | - $requireMin = $appInfo['require']; |
|
927 | - } |
|
928 | - |
|
929 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
930 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
931 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
932 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
933 | - } else if (isset($appInfo['requiremax'])) { |
|
934 | - $requireMax = $appInfo['requiremax']; |
|
935 | - } |
|
936 | - |
|
937 | - if (is_array($ocVersion)) { |
|
938 | - $ocVersion = implode('.', $ocVersion); |
|
939 | - } |
|
940 | - |
|
941 | - if (!empty($requireMin) |
|
942 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
943 | - ) { |
|
944 | - |
|
945 | - return false; |
|
946 | - } |
|
947 | - |
|
948 | - if (!empty($requireMax) |
|
949 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
950 | - ) { |
|
951 | - return false; |
|
952 | - } |
|
953 | - |
|
954 | - return true; |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * get the installed version of all apps |
|
959 | - */ |
|
960 | - public static function getAppVersions() { |
|
961 | - static $versions; |
|
962 | - |
|
963 | - if(!$versions) { |
|
964 | - $appConfig = \OC::$server->getAppConfig(); |
|
965 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
966 | - } |
|
967 | - return $versions; |
|
968 | - } |
|
969 | - |
|
970 | - /** |
|
971 | - * @param string $app |
|
972 | - * @param \OCP\IConfig $config |
|
973 | - * @param \OCP\IL10N $l |
|
974 | - * @return bool |
|
975 | - * |
|
976 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
977 | - * @throws Exception if no app-name was specified |
|
978 | - */ |
|
979 | - public function installApp($app, |
|
980 | - \OCP\IConfig $config, |
|
981 | - \OCP\IL10N $l) { |
|
982 | - if ($app !== false) { |
|
983 | - // check if the app is compatible with this version of ownCloud |
|
984 | - $info = self::getAppInfo($app); |
|
985 | - if(!is_array($info)) { |
|
986 | - throw new \Exception( |
|
987 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
988 | - [$info['name']] |
|
989 | - ) |
|
990 | - ); |
|
991 | - } |
|
992 | - |
|
993 | - $version = \OCP\Util::getVersion(); |
|
994 | - if (!self::isAppCompatible($version, $info)) { |
|
995 | - throw new \Exception( |
|
996 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
997 | - array($info['name']) |
|
998 | - ) |
|
999 | - ); |
|
1000 | - } |
|
1001 | - |
|
1002 | - // check for required dependencies |
|
1003 | - self::checkAppDependencies($config, $l, $info); |
|
1004 | - |
|
1005 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1006 | - if (isset($appData['id'])) { |
|
1007 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1008 | - } |
|
1009 | - |
|
1010 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1011 | - $appPath = self::getAppPath($app); |
|
1012 | - self::registerAutoloading($app, $appPath); |
|
1013 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1014 | - } |
|
1015 | - |
|
1016 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1017 | - } else { |
|
1018 | - if(empty($appName) ) { |
|
1019 | - throw new \Exception($l->t("No app name specified")); |
|
1020 | - } else { |
|
1021 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - return $app; |
|
1026 | - } |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * update the database for the app and call the update script |
|
1030 | - * |
|
1031 | - * @param string $appId |
|
1032 | - * @return bool |
|
1033 | - */ |
|
1034 | - public static function updateApp($appId) { |
|
1035 | - $appPath = self::getAppPath($appId); |
|
1036 | - if($appPath === false) { |
|
1037 | - return false; |
|
1038 | - } |
|
1039 | - self::registerAutoloading($appId, $appPath); |
|
1040 | - |
|
1041 | - $appData = self::getAppInfo($appId); |
|
1042 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1043 | - |
|
1044 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1045 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1046 | - } else { |
|
1047 | - $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
1048 | - $ms->migrate(); |
|
1049 | - } |
|
1050 | - |
|
1051 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1052 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1053 | - unset(self::$appVersion[$appId]); |
|
1054 | - |
|
1055 | - // run upgrade code |
|
1056 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1057 | - self::loadApp($appId); |
|
1058 | - include $appPath . '/appinfo/update.php'; |
|
1059 | - } |
|
1060 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1061 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1062 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1063 | - } |
|
1064 | - |
|
1065 | - //set remote/public handlers |
|
1066 | - if (array_key_exists('ocsid', $appData)) { |
|
1067 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1068 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1069 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1070 | - } |
|
1071 | - foreach ($appData['remote'] as $name => $path) { |
|
1072 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1073 | - } |
|
1074 | - foreach ($appData['public'] as $name => $path) { |
|
1075 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1076 | - } |
|
1077 | - |
|
1078 | - self::setAppTypes($appId); |
|
1079 | - |
|
1080 | - $version = \OC_App::getAppVersion($appId); |
|
1081 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1082 | - |
|
1083 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1084 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1085 | - )); |
|
1086 | - |
|
1087 | - return true; |
|
1088 | - } |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * @param string $appId |
|
1092 | - * @param string[] $steps |
|
1093 | - * @throws \OC\NeedsUpdateException |
|
1094 | - */ |
|
1095 | - public static function executeRepairSteps($appId, array $steps) { |
|
1096 | - if (empty($steps)) { |
|
1097 | - return; |
|
1098 | - } |
|
1099 | - // load the app |
|
1100 | - self::loadApp($appId); |
|
1101 | - |
|
1102 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1103 | - |
|
1104 | - // load the steps |
|
1105 | - $r = new Repair([], $dispatcher); |
|
1106 | - foreach ($steps as $step) { |
|
1107 | - try { |
|
1108 | - $r->addStep($step); |
|
1109 | - } catch (Exception $ex) { |
|
1110 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1111 | - \OC::$server->getLogger()->logException($ex); |
|
1112 | - } |
|
1113 | - } |
|
1114 | - // run the steps |
|
1115 | - $r->run(); |
|
1116 | - } |
|
1117 | - |
|
1118 | - public static function setupBackgroundJobs(array $jobs) { |
|
1119 | - $queue = \OC::$server->getJobList(); |
|
1120 | - foreach ($jobs as $job) { |
|
1121 | - $queue->add($job); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * @param string $appId |
|
1127 | - * @param string[] $steps |
|
1128 | - */ |
|
1129 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1130 | - $queue = \OC::$server->getJobList(); |
|
1131 | - foreach ($steps as $step) { |
|
1132 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1133 | - 'app' => $appId, |
|
1134 | - 'step' => $step]); |
|
1135 | - } |
|
1136 | - } |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * @param string $appId |
|
1140 | - * @return \OC\Files\View|false |
|
1141 | - */ |
|
1142 | - public static function getStorage($appId) { |
|
1143 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
1144 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1145 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1146 | - if (!$view->file_exists($appId)) { |
|
1147 | - $view->mkdir($appId); |
|
1148 | - } |
|
1149 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1150 | - } else { |
|
1151 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1152 | - return false; |
|
1153 | - } |
|
1154 | - } else { |
|
1155 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1156 | - return false; |
|
1157 | - } |
|
1158 | - } |
|
1159 | - |
|
1160 | - protected static function findBestL10NOption($options, $lang) { |
|
1161 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1162 | - |
|
1163 | - $lang = strtolower($lang); |
|
1164 | - $similarLang = $lang; |
|
1165 | - if (strpos($similarLang, '_')) { |
|
1166 | - // For "de_DE" we want to find "de" and the other way around |
|
1167 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1168 | - } |
|
1169 | - |
|
1170 | - foreach ($options as $option) { |
|
1171 | - if (is_array($option)) { |
|
1172 | - if ($fallback === false) { |
|
1173 | - $fallback = $option['@value']; |
|
1174 | - } |
|
1175 | - |
|
1176 | - if (!isset($option['@attributes']['lang'])) { |
|
1177 | - continue; |
|
1178 | - } |
|
1179 | - |
|
1180 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1181 | - if ($attributeLang === $lang) { |
|
1182 | - return $option['@value']; |
|
1183 | - } |
|
1184 | - |
|
1185 | - if ($attributeLang === $similarLang) { |
|
1186 | - $similarLangFallback = $option['@value']; |
|
1187 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1188 | - if ($similarLangFallback === false) { |
|
1189 | - $similarLangFallback = $option['@value']; |
|
1190 | - } |
|
1191 | - } |
|
1192 | - } else { |
|
1193 | - $englishFallback = $option; |
|
1194 | - } |
|
1195 | - } |
|
1196 | - |
|
1197 | - if ($similarLangFallback !== false) { |
|
1198 | - return $similarLangFallback; |
|
1199 | - } else if ($englishFallback !== false) { |
|
1200 | - return $englishFallback; |
|
1201 | - } |
|
1202 | - return (string) $fallback; |
|
1203 | - } |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * parses the app data array and enhanced the 'description' value |
|
1207 | - * |
|
1208 | - * @param array $data the app data |
|
1209 | - * @param string $lang |
|
1210 | - * @return array improved app data |
|
1211 | - */ |
|
1212 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1213 | - |
|
1214 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1215 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1216 | - } |
|
1217 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1218 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1219 | - } |
|
1220 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1221 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1222 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1223 | - $data['description'] = trim($data['description']); |
|
1224 | - } else { |
|
1225 | - $data['description'] = ''; |
|
1226 | - } |
|
1227 | - |
|
1228 | - return $data; |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * @param \OCP\IConfig $config |
|
1233 | - * @param \OCP\IL10N $l |
|
1234 | - * @param array $info |
|
1235 | - * @throws \Exception |
|
1236 | - */ |
|
1237 | - public static function checkAppDependencies($config, $l, $info) { |
|
1238 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1239 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1240 | - if (!empty($missing)) { |
|
1241 | - $missingMsg = implode(PHP_EOL, $missing); |
|
1242 | - throw new \Exception( |
|
1243 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1244 | - [$info['name'], $missingMsg] |
|
1245 | - ) |
|
1246 | - ); |
|
1247 | - } |
|
1248 | - } |
|
64 | + static private $appVersion = []; |
|
65 | + static private $adminForms = array(); |
|
66 | + static private $personalForms = array(); |
|
67 | + static private $appInfo = array(); |
|
68 | + static private $appTypes = array(); |
|
69 | + static private $loadedApps = array(); |
|
70 | + static private $altLogin = array(); |
|
71 | + static private $alreadyRegistered = []; |
|
72 | + const officialApp = 200; |
|
73 | + |
|
74 | + /** |
|
75 | + * clean the appId |
|
76 | + * |
|
77 | + * @param string|boolean $app AppId that needs to be cleaned |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function cleanAppId($app) { |
|
81 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check if an app is loaded |
|
86 | + * |
|
87 | + * @param string $app |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public static function isAppLoaded($app) { |
|
91 | + return in_array($app, self::$loadedApps, true); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * loads all apps |
|
96 | + * |
|
97 | + * @param string[] | string | null $types |
|
98 | + * @return bool |
|
99 | + * |
|
100 | + * This function walks through the ownCloud directory and loads all apps |
|
101 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | + * exists. |
|
103 | + * |
|
104 | + * if $types is set, only apps of those types will be loaded |
|
105 | + */ |
|
106 | + public static function loadApps($types = null) { |
|
107 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + // Load the enabled apps here |
|
111 | + $apps = self::getEnabledApps(); |
|
112 | + |
|
113 | + // Add each apps' folder as allowed class path |
|
114 | + foreach($apps as $app) { |
|
115 | + $path = self::getAppPath($app); |
|
116 | + if($path !== false) { |
|
117 | + self::registerAutoloading($app, $path); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + // prevent app.php from printing output |
|
122 | + ob_start(); |
|
123 | + foreach ($apps as $app) { |
|
124 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | + self::loadApp($app); |
|
126 | + } |
|
127 | + } |
|
128 | + ob_end_clean(); |
|
129 | + |
|
130 | + return true; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * load a single app |
|
135 | + * |
|
136 | + * @param string $app |
|
137 | + */ |
|
138 | + public static function loadApp($app) { |
|
139 | + self::$loadedApps[] = $app; |
|
140 | + $appPath = self::getAppPath($app); |
|
141 | + if($appPath === false) { |
|
142 | + return; |
|
143 | + } |
|
144 | + |
|
145 | + // in case someone calls loadApp() directly |
|
146 | + self::registerAutoloading($app, $appPath); |
|
147 | + |
|
148 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | + self::requireAppFile($app); |
|
151 | + if (self::isType($app, array('authentication'))) { |
|
152 | + // since authentication apps affect the "is app enabled for group" check, |
|
153 | + // the enabled apps cache needs to be cleared to make sure that the |
|
154 | + // next time getEnableApps() is called it will also include apps that were |
|
155 | + // enabled for groups |
|
156 | + self::$enabledAppsCache = array(); |
|
157 | + } |
|
158 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
159 | + } |
|
160 | + |
|
161 | + $info = self::getAppInfo($app); |
|
162 | + if (!empty($info['activity']['filters'])) { |
|
163 | + foreach ($info['activity']['filters'] as $filter) { |
|
164 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
165 | + } |
|
166 | + } |
|
167 | + if (!empty($info['activity']['settings'])) { |
|
168 | + foreach ($info['activity']['settings'] as $setting) { |
|
169 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
170 | + } |
|
171 | + } |
|
172 | + if (!empty($info['activity']['providers'])) { |
|
173 | + foreach ($info['activity']['providers'] as $provider) { |
|
174 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
175 | + } |
|
176 | + } |
|
177 | + if (!empty($info['collaboration']['collaborators']['searchPlugins'])) { |
|
178 | + foreach ($info['collaboration']['collaborators']['searchPlugins'] as $plugin) { |
|
179 | + \OC::$server->getCollaboratorSearch()->registerPlugin($plugin); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @internal |
|
186 | + * @param string $app |
|
187 | + * @param string $path |
|
188 | + */ |
|
189 | + public static function registerAutoloading($app, $path) { |
|
190 | + $key = $app . '-' . $path; |
|
191 | + if(isset(self::$alreadyRegistered[$key])) { |
|
192 | + return; |
|
193 | + } |
|
194 | + self::$alreadyRegistered[$key] = true; |
|
195 | + // Register on PSR-4 composer autoloader |
|
196 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
197 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
198 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
199 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
200 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
201 | + } |
|
202 | + |
|
203 | + // Register on legacy autoloader |
|
204 | + \OC::$loader->addValidRoot($path); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Load app.php from the given app |
|
209 | + * |
|
210 | + * @param string $app app name |
|
211 | + */ |
|
212 | + private static function requireAppFile($app) { |
|
213 | + try { |
|
214 | + // encapsulated here to avoid variable scope conflicts |
|
215 | + require_once $app . '/appinfo/app.php'; |
|
216 | + } catch (Error $ex) { |
|
217 | + \OC::$server->getLogger()->logException($ex); |
|
218 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
219 | + if (!in_array($app, $blacklist)) { |
|
220 | + self::disable($app); |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * check if an app is of a specific type |
|
227 | + * |
|
228 | + * @param string $app |
|
229 | + * @param string|array $types |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public static function isType($app, $types) { |
|
233 | + if (is_string($types)) { |
|
234 | + $types = array($types); |
|
235 | + } |
|
236 | + $appTypes = self::getAppTypes($app); |
|
237 | + foreach ($types as $type) { |
|
238 | + if (array_search($type, $appTypes) !== false) { |
|
239 | + return true; |
|
240 | + } |
|
241 | + } |
|
242 | + return false; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * get the types of an app |
|
247 | + * |
|
248 | + * @param string $app |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + private static function getAppTypes($app) { |
|
252 | + //load the cache |
|
253 | + if (count(self::$appTypes) == 0) { |
|
254 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
255 | + } |
|
256 | + |
|
257 | + if (isset(self::$appTypes[$app])) { |
|
258 | + return explode(',', self::$appTypes[$app]); |
|
259 | + } else { |
|
260 | + return array(); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * read app types from info.xml and cache them in the database |
|
266 | + */ |
|
267 | + public static function setAppTypes($app) { |
|
268 | + $appData = self::getAppInfo($app); |
|
269 | + if(!is_array($appData)) { |
|
270 | + return; |
|
271 | + } |
|
272 | + |
|
273 | + if (isset($appData['types'])) { |
|
274 | + $appTypes = implode(',', $appData['types']); |
|
275 | + } else { |
|
276 | + $appTypes = ''; |
|
277 | + $appData['types'] = []; |
|
278 | + } |
|
279 | + |
|
280 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
281 | + |
|
282 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
283 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
284 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
285 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * get all enabled apps |
|
292 | + */ |
|
293 | + protected static $enabledAppsCache = array(); |
|
294 | + |
|
295 | + /** |
|
296 | + * Returns apps enabled for the current user. |
|
297 | + * |
|
298 | + * @param bool $forceRefresh whether to refresh the cache |
|
299 | + * @param bool $all whether to return apps for all users, not only the |
|
300 | + * currently logged in one |
|
301 | + * @return string[] |
|
302 | + */ |
|
303 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
304 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
305 | + return array(); |
|
306 | + } |
|
307 | + // in incognito mode or when logged out, $user will be false, |
|
308 | + // which is also the case during an upgrade |
|
309 | + $appManager = \OC::$server->getAppManager(); |
|
310 | + if ($all) { |
|
311 | + $user = null; |
|
312 | + } else { |
|
313 | + $user = \OC::$server->getUserSession()->getUser(); |
|
314 | + } |
|
315 | + |
|
316 | + if (is_null($user)) { |
|
317 | + $apps = $appManager->getInstalledApps(); |
|
318 | + } else { |
|
319 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
320 | + } |
|
321 | + $apps = array_filter($apps, function ($app) { |
|
322 | + return $app !== 'files';//we add this manually |
|
323 | + }); |
|
324 | + sort($apps); |
|
325 | + array_unshift($apps, 'files'); |
|
326 | + return $apps; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * checks whether or not an app is enabled |
|
331 | + * |
|
332 | + * @param string $app app |
|
333 | + * @return bool |
|
334 | + * |
|
335 | + * This function checks whether or not an app is enabled. |
|
336 | + */ |
|
337 | + public static function isEnabled($app) { |
|
338 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * enables an app |
|
343 | + * |
|
344 | + * @param string $appId |
|
345 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
346 | + * @throws \Exception |
|
347 | + * @return void |
|
348 | + * |
|
349 | + * This function set an app as enabled in appconfig. |
|
350 | + */ |
|
351 | + public function enable($appId, |
|
352 | + $groups = null) { |
|
353 | + self::$enabledAppsCache = []; // flush |
|
354 | + |
|
355 | + // Check if app is already downloaded |
|
356 | + $installer = new Installer( |
|
357 | + \OC::$server->getAppFetcher(), |
|
358 | + \OC::$server->getHTTPClientService(), |
|
359 | + \OC::$server->getTempManager(), |
|
360 | + \OC::$server->getLogger(), |
|
361 | + \OC::$server->getConfig() |
|
362 | + ); |
|
363 | + $isDownloaded = $installer->isDownloaded($appId); |
|
364 | + |
|
365 | + if(!$isDownloaded) { |
|
366 | + $installer->downloadApp($appId); |
|
367 | + } |
|
368 | + |
|
369 | + $installer->installApp($appId); |
|
370 | + |
|
371 | + $appManager = \OC::$server->getAppManager(); |
|
372 | + if (!is_null($groups)) { |
|
373 | + $groupManager = \OC::$server->getGroupManager(); |
|
374 | + $groupsList = []; |
|
375 | + foreach ($groups as $group) { |
|
376 | + $groupItem = $groupManager->get($group); |
|
377 | + if ($groupItem instanceof \OCP\IGroup) { |
|
378 | + $groupsList[] = $groupManager->get($group); |
|
379 | + } |
|
380 | + } |
|
381 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
382 | + } else { |
|
383 | + $appManager->enableApp($appId); |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * @param string $app |
|
389 | + * @return bool |
|
390 | + */ |
|
391 | + public static function removeApp($app) { |
|
392 | + if (\OC::$server->getAppManager()->isShipped($app)) { |
|
393 | + return false; |
|
394 | + } |
|
395 | + |
|
396 | + $installer = new Installer( |
|
397 | + \OC::$server->getAppFetcher(), |
|
398 | + \OC::$server->getHTTPClientService(), |
|
399 | + \OC::$server->getTempManager(), |
|
400 | + \OC::$server->getLogger(), |
|
401 | + \OC::$server->getConfig() |
|
402 | + ); |
|
403 | + return $installer->removeApp($app); |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * This function set an app as disabled in appconfig. |
|
408 | + * |
|
409 | + * @param string $app app |
|
410 | + * @throws Exception |
|
411 | + */ |
|
412 | + public static function disable($app) { |
|
413 | + // flush |
|
414 | + self::$enabledAppsCache = array(); |
|
415 | + |
|
416 | + // run uninstall steps |
|
417 | + $appData = OC_App::getAppInfo($app); |
|
418 | + if (!is_null($appData)) { |
|
419 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
420 | + } |
|
421 | + |
|
422 | + // emit disable hook - needed anymore ? |
|
423 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
424 | + |
|
425 | + // finally disable it |
|
426 | + $appManager = \OC::$server->getAppManager(); |
|
427 | + $appManager->disableApp($app); |
|
428 | + } |
|
429 | + |
|
430 | + // This is private as well. It simply works, so don't ask for more details |
|
431 | + private static function proceedNavigation($list) { |
|
432 | + usort($list, function($a, $b) { |
|
433 | + if (isset($a['order']) && isset($b['order'])) { |
|
434 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
435 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
436 | + return isset($a['order']) ? -1 : 1; |
|
437 | + } else { |
|
438 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
439 | + } |
|
440 | + }); |
|
441 | + |
|
442 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
443 | + foreach ($list as $index => &$navEntry) { |
|
444 | + if ($navEntry['id'] == $activeApp) { |
|
445 | + $navEntry['active'] = true; |
|
446 | + } else { |
|
447 | + $navEntry['active'] = false; |
|
448 | + } |
|
449 | + } |
|
450 | + unset($navEntry); |
|
451 | + |
|
452 | + return $list; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Get the path where to install apps |
|
457 | + * |
|
458 | + * @return string|false |
|
459 | + */ |
|
460 | + public static function getInstallPath() { |
|
461 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
462 | + return false; |
|
463 | + } |
|
464 | + |
|
465 | + foreach (OC::$APPSROOTS as $dir) { |
|
466 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
467 | + return $dir['path']; |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
472 | + return null; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * search for an app in all app-directories |
|
478 | + * |
|
479 | + * @param string $appId |
|
480 | + * @return false|string |
|
481 | + */ |
|
482 | + public static function findAppInDirectories($appId) { |
|
483 | + $sanitizedAppId = self::cleanAppId($appId); |
|
484 | + if($sanitizedAppId !== $appId) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + static $app_dir = array(); |
|
488 | + |
|
489 | + if (isset($app_dir[$appId])) { |
|
490 | + return $app_dir[$appId]; |
|
491 | + } |
|
492 | + |
|
493 | + $possibleApps = array(); |
|
494 | + foreach (OC::$APPSROOTS as $dir) { |
|
495 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
496 | + $possibleApps[] = $dir; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + if (empty($possibleApps)) { |
|
501 | + return false; |
|
502 | + } elseif (count($possibleApps) === 1) { |
|
503 | + $dir = array_shift($possibleApps); |
|
504 | + $app_dir[$appId] = $dir; |
|
505 | + return $dir; |
|
506 | + } else { |
|
507 | + $versionToLoad = array(); |
|
508 | + foreach ($possibleApps as $possibleApp) { |
|
509 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
510 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
511 | + $versionToLoad = array( |
|
512 | + 'dir' => $possibleApp, |
|
513 | + 'version' => $version, |
|
514 | + ); |
|
515 | + } |
|
516 | + } |
|
517 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
518 | + return $versionToLoad['dir']; |
|
519 | + //TODO - write test |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Get the directory for the given app. |
|
525 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
526 | + * |
|
527 | + * @param string $appId |
|
528 | + * @return string|false |
|
529 | + */ |
|
530 | + public static function getAppPath($appId) { |
|
531 | + if ($appId === null || trim($appId) === '') { |
|
532 | + return false; |
|
533 | + } |
|
534 | + |
|
535 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
536 | + return $dir['path'] . '/' . $appId; |
|
537 | + } |
|
538 | + return false; |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Get the path for the given app on the access |
|
543 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
544 | + * |
|
545 | + * @param string $appId |
|
546 | + * @return string|false |
|
547 | + */ |
|
548 | + public static function getAppWebPath($appId) { |
|
549 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
550 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
551 | + } |
|
552 | + return false; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * get the last version of the app from appinfo/info.xml |
|
557 | + * |
|
558 | + * @param string $appId |
|
559 | + * @param bool $useCache |
|
560 | + * @return string |
|
561 | + */ |
|
562 | + public static function getAppVersion($appId, $useCache = true) { |
|
563 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
564 | + return self::$appVersion[$appId]; |
|
565 | + } |
|
566 | + |
|
567 | + $file = self::getAppPath($appId); |
|
568 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
569 | + return self::$appVersion[$appId]; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * get app's version based on it's path |
|
574 | + * |
|
575 | + * @param string $path |
|
576 | + * @return string |
|
577 | + */ |
|
578 | + public static function getAppVersionByPath($path) { |
|
579 | + $infoFile = $path . '/appinfo/info.xml'; |
|
580 | + $appData = self::getAppInfo($infoFile, true); |
|
581 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Read all app metadata from the info.xml file |
|
587 | + * |
|
588 | + * @param string $appId id of the app or the path of the info.xml file |
|
589 | + * @param bool $path |
|
590 | + * @param string $lang |
|
591 | + * @return array|null |
|
592 | + * @note all data is read from info.xml, not just pre-defined fields |
|
593 | + */ |
|
594 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
595 | + if ($path) { |
|
596 | + $file = $appId; |
|
597 | + } else { |
|
598 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
599 | + return self::$appInfo[$appId]; |
|
600 | + } |
|
601 | + $appPath = self::getAppPath($appId); |
|
602 | + if($appPath === false) { |
|
603 | + return null; |
|
604 | + } |
|
605 | + $file = $appPath . '/appinfo/info.xml'; |
|
606 | + } |
|
607 | + |
|
608 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
609 | + $data = $parser->parse($file); |
|
610 | + |
|
611 | + if (is_array($data)) { |
|
612 | + $data = OC_App::parseAppInfo($data, $lang); |
|
613 | + } |
|
614 | + if(isset($data['ocsid'])) { |
|
615 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
616 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
617 | + $data['ocsid'] = $storedId; |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + if ($lang === null) { |
|
622 | + self::$appInfo[$appId] = $data; |
|
623 | + } |
|
624 | + |
|
625 | + return $data; |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Returns the navigation |
|
630 | + * |
|
631 | + * @return array |
|
632 | + * |
|
633 | + * This function returns an array containing all entries added. The |
|
634 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
635 | + * given for each app the following keys exist: |
|
636 | + * - active: boolean, signals if the user is on this navigation entry |
|
637 | + */ |
|
638 | + public static function getNavigation() { |
|
639 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
640 | + return self::proceedNavigation($entries); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Returns the Settings Navigation |
|
645 | + * |
|
646 | + * @return string[] |
|
647 | + * |
|
648 | + * This function returns an array containing all settings pages added. The |
|
649 | + * entries are sorted by the key 'order' ascending. |
|
650 | + */ |
|
651 | + public static function getSettingsNavigation() { |
|
652 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
653 | + return self::proceedNavigation($entries); |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * get the id of loaded app |
|
658 | + * |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public static function getCurrentApp() { |
|
662 | + $request = \OC::$server->getRequest(); |
|
663 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
664 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
665 | + if (empty($topFolder)) { |
|
666 | + $path_info = $request->getPathInfo(); |
|
667 | + if ($path_info) { |
|
668 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
669 | + } |
|
670 | + } |
|
671 | + if ($topFolder == 'apps') { |
|
672 | + $length = strlen($topFolder); |
|
673 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
674 | + } else { |
|
675 | + return $topFolder; |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * @param string $type |
|
681 | + * @return array |
|
682 | + */ |
|
683 | + public static function getForms($type) { |
|
684 | + $forms = array(); |
|
685 | + switch ($type) { |
|
686 | + case 'admin': |
|
687 | + $source = self::$adminForms; |
|
688 | + break; |
|
689 | + case 'personal': |
|
690 | + $source = self::$personalForms; |
|
691 | + break; |
|
692 | + default: |
|
693 | + return array(); |
|
694 | + } |
|
695 | + foreach ($source as $form) { |
|
696 | + $forms[] = include $form; |
|
697 | + } |
|
698 | + return $forms; |
|
699 | + } |
|
700 | + |
|
701 | + /** |
|
702 | + * register an admin form to be shown |
|
703 | + * |
|
704 | + * @param string $app |
|
705 | + * @param string $page |
|
706 | + */ |
|
707 | + public static function registerAdmin($app, $page) { |
|
708 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * register a personal form to be shown |
|
713 | + * @param string $app |
|
714 | + * @param string $page |
|
715 | + */ |
|
716 | + public static function registerPersonal($app, $page) { |
|
717 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * @param array $entry |
|
722 | + */ |
|
723 | + public static function registerLogIn(array $entry) { |
|
724 | + self::$altLogin[] = $entry; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * @return array |
|
729 | + */ |
|
730 | + public static function getAlternativeLogIns() { |
|
731 | + return self::$altLogin; |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * get a list of all apps in the apps folder |
|
736 | + * |
|
737 | + * @return array an array of app names (string IDs) |
|
738 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
739 | + */ |
|
740 | + public static function getAllApps() { |
|
741 | + |
|
742 | + $apps = array(); |
|
743 | + |
|
744 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
745 | + if (!is_readable($apps_dir['path'])) { |
|
746 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
747 | + continue; |
|
748 | + } |
|
749 | + $dh = opendir($apps_dir['path']); |
|
750 | + |
|
751 | + if (is_resource($dh)) { |
|
752 | + while (($file = readdir($dh)) !== false) { |
|
753 | + |
|
754 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
755 | + |
|
756 | + $apps[] = $file; |
|
757 | + } |
|
758 | + } |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + return $apps; |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * List all apps, this is used in apps.php |
|
767 | + * |
|
768 | + * @return array |
|
769 | + */ |
|
770 | + public function listAllApps() { |
|
771 | + $installedApps = OC_App::getAllApps(); |
|
772 | + |
|
773 | + $appManager = \OC::$server->getAppManager(); |
|
774 | + //we don't want to show configuration for these |
|
775 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
776 | + $appList = array(); |
|
777 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
778 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
779 | + |
|
780 | + foreach ($installedApps as $app) { |
|
781 | + if (array_search($app, $blacklist) === false) { |
|
782 | + |
|
783 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
784 | + if (!is_array($info)) { |
|
785 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
786 | + continue; |
|
787 | + } |
|
788 | + |
|
789 | + if (!isset($info['name'])) { |
|
790 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
791 | + continue; |
|
792 | + } |
|
793 | + |
|
794 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
795 | + $info['groups'] = null; |
|
796 | + if ($enabled === 'yes') { |
|
797 | + $active = true; |
|
798 | + } else if ($enabled === 'no') { |
|
799 | + $active = false; |
|
800 | + } else { |
|
801 | + $active = true; |
|
802 | + $info['groups'] = $enabled; |
|
803 | + } |
|
804 | + |
|
805 | + $info['active'] = $active; |
|
806 | + |
|
807 | + if ($appManager->isShipped($app)) { |
|
808 | + $info['internal'] = true; |
|
809 | + $info['level'] = self::officialApp; |
|
810 | + $info['removable'] = false; |
|
811 | + } else { |
|
812 | + $info['internal'] = false; |
|
813 | + $info['removable'] = true; |
|
814 | + } |
|
815 | + |
|
816 | + $appPath = self::getAppPath($app); |
|
817 | + if($appPath !== false) { |
|
818 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
819 | + if (file_exists($appIcon)) { |
|
820 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
821 | + $info['previewAsIcon'] = true; |
|
822 | + } else { |
|
823 | + $appIcon = $appPath . '/img/app.svg'; |
|
824 | + if (file_exists($appIcon)) { |
|
825 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
826 | + $info['previewAsIcon'] = true; |
|
827 | + } |
|
828 | + } |
|
829 | + } |
|
830 | + // fix documentation |
|
831 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
832 | + foreach ($info['documentation'] as $key => $url) { |
|
833 | + // If it is not an absolute URL we assume it is a key |
|
834 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
835 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
836 | + $url = $urlGenerator->linkToDocs($url); |
|
837 | + } |
|
838 | + |
|
839 | + $info['documentation'][$key] = $url; |
|
840 | + } |
|
841 | + } |
|
842 | + |
|
843 | + $info['version'] = OC_App::getAppVersion($app); |
|
844 | + $appList[] = $info; |
|
845 | + } |
|
846 | + } |
|
847 | + |
|
848 | + return $appList; |
|
849 | + } |
|
850 | + |
|
851 | + /** |
|
852 | + * Returns the internal app ID or false |
|
853 | + * @param string $ocsID |
|
854 | + * @return string|false |
|
855 | + */ |
|
856 | + public static function getInternalAppIdByOcs($ocsID) { |
|
857 | + if(is_numeric($ocsID)) { |
|
858 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
859 | + if(array_search($ocsID, $idArray)) { |
|
860 | + return array_search($ocsID, $idArray); |
|
861 | + } |
|
862 | + } |
|
863 | + return false; |
|
864 | + } |
|
865 | + |
|
866 | + public static function shouldUpgrade($app) { |
|
867 | + $versions = self::getAppVersions(); |
|
868 | + $currentVersion = OC_App::getAppVersion($app); |
|
869 | + if ($currentVersion && isset($versions[$app])) { |
|
870 | + $installedVersion = $versions[$app]; |
|
871 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
872 | + return true; |
|
873 | + } |
|
874 | + } |
|
875 | + return false; |
|
876 | + } |
|
877 | + |
|
878 | + /** |
|
879 | + * Adjust the number of version parts of $version1 to match |
|
880 | + * the number of version parts of $version2. |
|
881 | + * |
|
882 | + * @param string $version1 version to adjust |
|
883 | + * @param string $version2 version to take the number of parts from |
|
884 | + * @return string shortened $version1 |
|
885 | + */ |
|
886 | + private static function adjustVersionParts($version1, $version2) { |
|
887 | + $version1 = explode('.', $version1); |
|
888 | + $version2 = explode('.', $version2); |
|
889 | + // reduce $version1 to match the number of parts in $version2 |
|
890 | + while (count($version1) > count($version2)) { |
|
891 | + array_pop($version1); |
|
892 | + } |
|
893 | + // if $version1 does not have enough parts, add some |
|
894 | + while (count($version1) < count($version2)) { |
|
895 | + $version1[] = '0'; |
|
896 | + } |
|
897 | + return implode('.', $version1); |
|
898 | + } |
|
899 | + |
|
900 | + /** |
|
901 | + * Check whether the current ownCloud version matches the given |
|
902 | + * application's version requirements. |
|
903 | + * |
|
904 | + * The comparison is made based on the number of parts that the |
|
905 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
906 | + * app info version is expecting version 6.0, the comparison is |
|
907 | + * made on the first two parts of the ownCloud version. |
|
908 | + * This means that it's possible to specify "requiremin" => 6 |
|
909 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
910 | + * |
|
911 | + * @param string $ocVersion ownCloud version to check against |
|
912 | + * @param array $appInfo app info (from xml) |
|
913 | + * |
|
914 | + * @return boolean true if compatible, otherwise false |
|
915 | + */ |
|
916 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
917 | + $requireMin = ''; |
|
918 | + $requireMax = ''; |
|
919 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
920 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
921 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
922 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
923 | + } else if (isset($appInfo['requiremin'])) { |
|
924 | + $requireMin = $appInfo['requiremin']; |
|
925 | + } else if (isset($appInfo['require'])) { |
|
926 | + $requireMin = $appInfo['require']; |
|
927 | + } |
|
928 | + |
|
929 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
930 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
931 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
932 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
933 | + } else if (isset($appInfo['requiremax'])) { |
|
934 | + $requireMax = $appInfo['requiremax']; |
|
935 | + } |
|
936 | + |
|
937 | + if (is_array($ocVersion)) { |
|
938 | + $ocVersion = implode('.', $ocVersion); |
|
939 | + } |
|
940 | + |
|
941 | + if (!empty($requireMin) |
|
942 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
943 | + ) { |
|
944 | + |
|
945 | + return false; |
|
946 | + } |
|
947 | + |
|
948 | + if (!empty($requireMax) |
|
949 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
950 | + ) { |
|
951 | + return false; |
|
952 | + } |
|
953 | + |
|
954 | + return true; |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * get the installed version of all apps |
|
959 | + */ |
|
960 | + public static function getAppVersions() { |
|
961 | + static $versions; |
|
962 | + |
|
963 | + if(!$versions) { |
|
964 | + $appConfig = \OC::$server->getAppConfig(); |
|
965 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
966 | + } |
|
967 | + return $versions; |
|
968 | + } |
|
969 | + |
|
970 | + /** |
|
971 | + * @param string $app |
|
972 | + * @param \OCP\IConfig $config |
|
973 | + * @param \OCP\IL10N $l |
|
974 | + * @return bool |
|
975 | + * |
|
976 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
977 | + * @throws Exception if no app-name was specified |
|
978 | + */ |
|
979 | + public function installApp($app, |
|
980 | + \OCP\IConfig $config, |
|
981 | + \OCP\IL10N $l) { |
|
982 | + if ($app !== false) { |
|
983 | + // check if the app is compatible with this version of ownCloud |
|
984 | + $info = self::getAppInfo($app); |
|
985 | + if(!is_array($info)) { |
|
986 | + throw new \Exception( |
|
987 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
988 | + [$info['name']] |
|
989 | + ) |
|
990 | + ); |
|
991 | + } |
|
992 | + |
|
993 | + $version = \OCP\Util::getVersion(); |
|
994 | + if (!self::isAppCompatible($version, $info)) { |
|
995 | + throw new \Exception( |
|
996 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
997 | + array($info['name']) |
|
998 | + ) |
|
999 | + ); |
|
1000 | + } |
|
1001 | + |
|
1002 | + // check for required dependencies |
|
1003 | + self::checkAppDependencies($config, $l, $info); |
|
1004 | + |
|
1005 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1006 | + if (isset($appData['id'])) { |
|
1007 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1008 | + } |
|
1009 | + |
|
1010 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1011 | + $appPath = self::getAppPath($app); |
|
1012 | + self::registerAutoloading($app, $appPath); |
|
1013 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1014 | + } |
|
1015 | + |
|
1016 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1017 | + } else { |
|
1018 | + if(empty($appName) ) { |
|
1019 | + throw new \Exception($l->t("No app name specified")); |
|
1020 | + } else { |
|
1021 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + return $app; |
|
1026 | + } |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * update the database for the app and call the update script |
|
1030 | + * |
|
1031 | + * @param string $appId |
|
1032 | + * @return bool |
|
1033 | + */ |
|
1034 | + public static function updateApp($appId) { |
|
1035 | + $appPath = self::getAppPath($appId); |
|
1036 | + if($appPath === false) { |
|
1037 | + return false; |
|
1038 | + } |
|
1039 | + self::registerAutoloading($appId, $appPath); |
|
1040 | + |
|
1041 | + $appData = self::getAppInfo($appId); |
|
1042 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1043 | + |
|
1044 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1045 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1046 | + } else { |
|
1047 | + $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
1048 | + $ms->migrate(); |
|
1049 | + } |
|
1050 | + |
|
1051 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1052 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1053 | + unset(self::$appVersion[$appId]); |
|
1054 | + |
|
1055 | + // run upgrade code |
|
1056 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1057 | + self::loadApp($appId); |
|
1058 | + include $appPath . '/appinfo/update.php'; |
|
1059 | + } |
|
1060 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1061 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1062 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1063 | + } |
|
1064 | + |
|
1065 | + //set remote/public handlers |
|
1066 | + if (array_key_exists('ocsid', $appData)) { |
|
1067 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1068 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1069 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1070 | + } |
|
1071 | + foreach ($appData['remote'] as $name => $path) { |
|
1072 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1073 | + } |
|
1074 | + foreach ($appData['public'] as $name => $path) { |
|
1075 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1076 | + } |
|
1077 | + |
|
1078 | + self::setAppTypes($appId); |
|
1079 | + |
|
1080 | + $version = \OC_App::getAppVersion($appId); |
|
1081 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1082 | + |
|
1083 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1084 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1085 | + )); |
|
1086 | + |
|
1087 | + return true; |
|
1088 | + } |
|
1089 | + |
|
1090 | + /** |
|
1091 | + * @param string $appId |
|
1092 | + * @param string[] $steps |
|
1093 | + * @throws \OC\NeedsUpdateException |
|
1094 | + */ |
|
1095 | + public static function executeRepairSteps($appId, array $steps) { |
|
1096 | + if (empty($steps)) { |
|
1097 | + return; |
|
1098 | + } |
|
1099 | + // load the app |
|
1100 | + self::loadApp($appId); |
|
1101 | + |
|
1102 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1103 | + |
|
1104 | + // load the steps |
|
1105 | + $r = new Repair([], $dispatcher); |
|
1106 | + foreach ($steps as $step) { |
|
1107 | + try { |
|
1108 | + $r->addStep($step); |
|
1109 | + } catch (Exception $ex) { |
|
1110 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1111 | + \OC::$server->getLogger()->logException($ex); |
|
1112 | + } |
|
1113 | + } |
|
1114 | + // run the steps |
|
1115 | + $r->run(); |
|
1116 | + } |
|
1117 | + |
|
1118 | + public static function setupBackgroundJobs(array $jobs) { |
|
1119 | + $queue = \OC::$server->getJobList(); |
|
1120 | + foreach ($jobs as $job) { |
|
1121 | + $queue->add($job); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * @param string $appId |
|
1127 | + * @param string[] $steps |
|
1128 | + */ |
|
1129 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1130 | + $queue = \OC::$server->getJobList(); |
|
1131 | + foreach ($steps as $step) { |
|
1132 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1133 | + 'app' => $appId, |
|
1134 | + 'step' => $step]); |
|
1135 | + } |
|
1136 | + } |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * @param string $appId |
|
1140 | + * @return \OC\Files\View|false |
|
1141 | + */ |
|
1142 | + public static function getStorage($appId) { |
|
1143 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
1144 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1145 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1146 | + if (!$view->file_exists($appId)) { |
|
1147 | + $view->mkdir($appId); |
|
1148 | + } |
|
1149 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1150 | + } else { |
|
1151 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1152 | + return false; |
|
1153 | + } |
|
1154 | + } else { |
|
1155 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1156 | + return false; |
|
1157 | + } |
|
1158 | + } |
|
1159 | + |
|
1160 | + protected static function findBestL10NOption($options, $lang) { |
|
1161 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1162 | + |
|
1163 | + $lang = strtolower($lang); |
|
1164 | + $similarLang = $lang; |
|
1165 | + if (strpos($similarLang, '_')) { |
|
1166 | + // For "de_DE" we want to find "de" and the other way around |
|
1167 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1168 | + } |
|
1169 | + |
|
1170 | + foreach ($options as $option) { |
|
1171 | + if (is_array($option)) { |
|
1172 | + if ($fallback === false) { |
|
1173 | + $fallback = $option['@value']; |
|
1174 | + } |
|
1175 | + |
|
1176 | + if (!isset($option['@attributes']['lang'])) { |
|
1177 | + continue; |
|
1178 | + } |
|
1179 | + |
|
1180 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1181 | + if ($attributeLang === $lang) { |
|
1182 | + return $option['@value']; |
|
1183 | + } |
|
1184 | + |
|
1185 | + if ($attributeLang === $similarLang) { |
|
1186 | + $similarLangFallback = $option['@value']; |
|
1187 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1188 | + if ($similarLangFallback === false) { |
|
1189 | + $similarLangFallback = $option['@value']; |
|
1190 | + } |
|
1191 | + } |
|
1192 | + } else { |
|
1193 | + $englishFallback = $option; |
|
1194 | + } |
|
1195 | + } |
|
1196 | + |
|
1197 | + if ($similarLangFallback !== false) { |
|
1198 | + return $similarLangFallback; |
|
1199 | + } else if ($englishFallback !== false) { |
|
1200 | + return $englishFallback; |
|
1201 | + } |
|
1202 | + return (string) $fallback; |
|
1203 | + } |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * parses the app data array and enhanced the 'description' value |
|
1207 | + * |
|
1208 | + * @param array $data the app data |
|
1209 | + * @param string $lang |
|
1210 | + * @return array improved app data |
|
1211 | + */ |
|
1212 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1213 | + |
|
1214 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1215 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1216 | + } |
|
1217 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1218 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1219 | + } |
|
1220 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1221 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1222 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1223 | + $data['description'] = trim($data['description']); |
|
1224 | + } else { |
|
1225 | + $data['description'] = ''; |
|
1226 | + } |
|
1227 | + |
|
1228 | + return $data; |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * @param \OCP\IConfig $config |
|
1233 | + * @param \OCP\IL10N $l |
|
1234 | + * @param array $info |
|
1235 | + * @throws \Exception |
|
1236 | + */ |
|
1237 | + public static function checkAppDependencies($config, $l, $info) { |
|
1238 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1239 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1240 | + if (!empty($missing)) { |
|
1241 | + $missingMsg = implode(PHP_EOL, $missing); |
|
1242 | + throw new \Exception( |
|
1243 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1244 | + [$info['name'], $missingMsg] |
|
1245 | + ) |
|
1246 | + ); |
|
1247 | + } |
|
1248 | + } |
|
1249 | 1249 | } |
@@ -30,44 +30,44 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | class SearchResultType { |
33 | - /** @var string */ |
|
34 | - protected $label; |
|
33 | + /** @var string */ |
|
34 | + protected $label; |
|
35 | 35 | |
36 | - /** |
|
37 | - * SearchResultType constructor. |
|
38 | - * |
|
39 | - * @param string $label |
|
40 | - * @since 13.0.0 |
|
41 | - */ |
|
42 | - public function __construct($label) { |
|
43 | - $this->label = $this->getValidatedType($label); |
|
44 | - } |
|
36 | + /** |
|
37 | + * SearchResultType constructor. |
|
38 | + * |
|
39 | + * @param string $label |
|
40 | + * @since 13.0.0 |
|
41 | + */ |
|
42 | + public function __construct($label) { |
|
43 | + $this->label = $this->getValidatedType($label); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - * @since 13.0.0 |
|
49 | - */ |
|
50 | - public function getLabel() { |
|
51 | - return $this->label; |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + * @since 13.0.0 |
|
49 | + */ |
|
50 | + public function getLabel() { |
|
51 | + return $this->label; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param $type |
|
56 | - * @return string |
|
57 | - * @throws \InvalidArgumentException |
|
58 | - * @since 13.0.0 |
|
59 | - */ |
|
60 | - protected function getValidatedType($type) { |
|
61 | - $type = trim(strval($type)); |
|
54 | + /** |
|
55 | + * @param $type |
|
56 | + * @return string |
|
57 | + * @throws \InvalidArgumentException |
|
58 | + * @since 13.0.0 |
|
59 | + */ |
|
60 | + protected function getValidatedType($type) { |
|
61 | + $type = trim(strval($type)); |
|
62 | 62 | |
63 | - if($type === '') { |
|
64 | - throw new \InvalidArgumentException('Type must not be empty'); |
|
65 | - } |
|
63 | + if($type === '') { |
|
64 | + throw new \InvalidArgumentException('Type must not be empty'); |
|
65 | + } |
|
66 | 66 | |
67 | - if($type === 'exact') { |
|
68 | - throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
69 | - } |
|
67 | + if($type === 'exact') { |
|
68 | + throw new \InvalidArgumentException('Provided type is a reserved word'); |
|
69 | + } |
|
70 | 70 | |
71 | - return $type; |
|
72 | - } |
|
71 | + return $type; |
|
72 | + } |
|
73 | 73 | } |
@@ -29,58 +29,58 @@ |
||
29 | 29 | |
30 | 30 | class SearchResult implements ISearchResult { |
31 | 31 | |
32 | - protected $result = [ |
|
33 | - 'exact' => [], |
|
34 | - ]; |
|
32 | + protected $result = [ |
|
33 | + 'exact' => [], |
|
34 | + ]; |
|
35 | 35 | |
36 | - protected $exactIdMatches = []; |
|
36 | + protected $exactIdMatches = []; |
|
37 | 37 | |
38 | - public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | - $type = $type->getLabel(); |
|
40 | - if(!isset($this->result[$type])) { |
|
41 | - $this->result[$type] = []; |
|
42 | - $this->result['exact'][$type] = []; |
|
43 | - } |
|
38 | + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | + $type = $type->getLabel(); |
|
40 | + if(!isset($this->result[$type])) { |
|
41 | + $this->result[$type] = []; |
|
42 | + $this->result['exact'][$type] = []; |
|
43 | + } |
|
44 | 44 | |
45 | - $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | - if(is_array($exactMatches)) { |
|
47 | - $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | - } |
|
49 | - } |
|
45 | + $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | + if(is_array($exactMatches)) { |
|
47 | + $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - public function markExactIdMatch(SearchResultType $type) { |
|
52 | - $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | - } |
|
51 | + public function markExactIdMatch(SearchResultType $type) { |
|
52 | + $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | + } |
|
54 | 54 | |
55 | - public function hasExactIdMatch(SearchResultType$type) { |
|
56 | - return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | - } |
|
55 | + public function hasExactIdMatch(SearchResultType$type) { |
|
56 | + return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | + } |
|
58 | 58 | |
59 | - public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | - $type = $type->getLabel(); |
|
61 | - if(!isset($this->result[$type])) { |
|
62 | - return false; |
|
63 | - } |
|
59 | + public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | + $type = $type->getLabel(); |
|
61 | + if(!isset($this->result[$type])) { |
|
62 | + return false; |
|
63 | + } |
|
64 | 64 | |
65 | - $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | - foreach($resultArrays as $resultArray) { |
|
67 | - if ($resultArray['value']['shareWith'] === $collaboratorId) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - } |
|
65 | + $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | + foreach($resultArrays as $resultArray) { |
|
67 | + if ($resultArray['value']['shareWith'] === $collaboratorId) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - return false; |
|
73 | - } |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - public function asArray() { |
|
76 | - return $this->result; |
|
77 | - } |
|
75 | + public function asArray() { |
|
76 | + return $this->result; |
|
77 | + } |
|
78 | 78 | |
79 | - public function unsetResult(SearchResultType $type) { |
|
80 | - $type = $type->getLabel(); |
|
81 | - $this->result[$type] = []; |
|
82 | - if(isset($this->result['exact'][$type])) { |
|
83 | - $this->result['exact'][$type] = []; |
|
84 | - } |
|
85 | - } |
|
79 | + public function unsetResult(SearchResultType $type) { |
|
80 | + $type = $type->getLabel(); |
|
81 | + $this->result[$type] = []; |
|
82 | + if(isset($this->result['exact'][$type])) { |
|
83 | + $this->result['exact'][$type] = []; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |