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