@@ -36,232 +36,232 @@ |
||
| 36 | 36 | |
| 37 | 37 | class BackgroundJob extends TimedJob { |
| 38 | 38 | |
| 39 | - protected $connectionNotifications = [3, 7, 14, 30]; |
|
| 40 | - |
|
| 41 | - /** @var IConfig */ |
|
| 42 | - protected $config; |
|
| 43 | - |
|
| 44 | - /** @var IManager */ |
|
| 45 | - protected $notificationManager; |
|
| 46 | - |
|
| 47 | - /** @var IGroupManager */ |
|
| 48 | - protected $groupManager; |
|
| 49 | - |
|
| 50 | - /** @var IAppManager */ |
|
| 51 | - protected $appManager; |
|
| 52 | - |
|
| 53 | - /** @var IClientService */ |
|
| 54 | - protected $client; |
|
| 55 | - |
|
| 56 | - /** @var Installer */ |
|
| 57 | - protected $installer; |
|
| 58 | - |
|
| 59 | - /** @var string[] */ |
|
| 60 | - protected $users; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * NotificationBackgroundJob constructor. |
|
| 64 | - * |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param IManager $notificationManager |
|
| 67 | - * @param IGroupManager $groupManager |
|
| 68 | - * @param IAppManager $appManager |
|
| 69 | - * @param IClientService $client |
|
| 70 | - * @param Installer $installer |
|
| 71 | - */ |
|
| 72 | - public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { |
|
| 73 | - // Run once a day |
|
| 74 | - $this->setInterval(60 * 60 * 24); |
|
| 75 | - |
|
| 76 | - $this->config = $config; |
|
| 77 | - $this->notificationManager = $notificationManager; |
|
| 78 | - $this->groupManager = $groupManager; |
|
| 79 | - $this->appManager = $appManager; |
|
| 80 | - $this->client = $client; |
|
| 81 | - $this->installer = $installer; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - protected function run($argument) { |
|
| 85 | - $this->checkCoreUpdate(); |
|
| 86 | - $this->checkAppUpdates(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Check for ownCloud update |
|
| 91 | - */ |
|
| 92 | - protected function checkCoreUpdate() { |
|
| 93 | - if (in_array($this->getChannel(), ['daily', 'git'], true)) { |
|
| 94 | - // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $updater = $this->createVersionCheck(); |
|
| 99 | - |
|
| 100 | - $status = $updater->check(); |
|
| 101 | - if ($status === false) { |
|
| 102 | - $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 103 | - $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); |
|
| 104 | - |
|
| 105 | - if (in_array($errors, $this->connectionNotifications, true)) { |
|
| 106 | - $this->sendErrorNotifications($errors); |
|
| 107 | - } |
|
| 108 | - } else if (is_array($status)) { |
|
| 109 | - $this->config->setAppValue('updatenotification', 'update_check_errors', 0); |
|
| 110 | - $this->clearErrorNotifications(); |
|
| 111 | - |
|
| 112 | - if (isset($status['version'])) { |
|
| 113 | - $this->createNotifications('core', $status['version'], $status['versionstring']); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Send a message to the admin when the update server could not be reached |
|
| 120 | - * @param int $numDays |
|
| 121 | - */ |
|
| 122 | - protected function sendErrorNotifications($numDays) { |
|
| 123 | - $this->clearErrorNotifications(); |
|
| 124 | - |
|
| 125 | - $notification = $this->notificationManager->createNotification(); |
|
| 126 | - try { |
|
| 127 | - $notification->setApp('updatenotification') |
|
| 128 | - ->setDateTime(new \DateTime()) |
|
| 129 | - ->setObject('updatenotification', 'error') |
|
| 130 | - ->setSubject('connection_error', ['days' => $numDays]); |
|
| 131 | - |
|
| 132 | - foreach ($this->getUsersToNotify() as $uid) { |
|
| 133 | - $notification->setUser($uid); |
|
| 134 | - $this->notificationManager->notify($notification); |
|
| 135 | - } |
|
| 136 | - } catch (\InvalidArgumentException $e) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Remove error notifications again |
|
| 143 | - */ |
|
| 144 | - protected function clearErrorNotifications() { |
|
| 145 | - $notification = $this->notificationManager->createNotification(); |
|
| 146 | - try { |
|
| 147 | - $notification->setApp('updatenotification') |
|
| 148 | - ->setSubject('connection_error') |
|
| 149 | - ->setObject('updatenotification', 'error'); |
|
| 150 | - } catch (\InvalidArgumentException $e) { |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - $this->notificationManager->markProcessed($notification); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Check all installed apps for updates |
|
| 158 | - */ |
|
| 159 | - protected function checkAppUpdates() { |
|
| 160 | - $apps = $this->appManager->getInstalledApps(); |
|
| 161 | - foreach ($apps as $app) { |
|
| 162 | - $update = $this->isUpdateAvailable($app); |
|
| 163 | - if ($update !== false) { |
|
| 164 | - $this->createNotifications($app, $update); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Create notifications for this app version |
|
| 171 | - * |
|
| 172 | - * @param string $app |
|
| 173 | - * @param string $version |
|
| 174 | - * @param string $visibleVersion |
|
| 175 | - */ |
|
| 176 | - protected function createNotifications($app, $version, $visibleVersion = '') { |
|
| 177 | - $lastNotification = $this->config->getAppValue('updatenotification', $app, false); |
|
| 178 | - if ($lastNotification === $version) { |
|
| 179 | - // We already notified about this update |
|
| 180 | - return; |
|
| 181 | - } else if ($lastNotification !== false) { |
|
| 182 | - // Delete old updates |
|
| 183 | - $this->deleteOutdatedNotifications($app, $lastNotification); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - $notification = $this->notificationManager->createNotification(); |
|
| 188 | - $notification->setApp('updatenotification') |
|
| 189 | - ->setDateTime(new \DateTime()) |
|
| 190 | - ->setObject($app, $version); |
|
| 191 | - |
|
| 192 | - if ($visibleVersion !== '') { |
|
| 193 | - $notification->setSubject('update_available', ['version' => $visibleVersion]); |
|
| 194 | - } else { |
|
| 195 | - $notification->setSubject('update_available'); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - foreach ($this->getUsersToNotify() as $uid) { |
|
| 199 | - $notification->setUser($uid); |
|
| 200 | - $this->notificationManager->notify($notification); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $this->config->setAppValue('updatenotification', $app, $version); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @return string[] |
|
| 208 | - */ |
|
| 209 | - protected function getUsersToNotify() { |
|
| 210 | - if ($this->users !== null) { |
|
| 211 | - return $this->users; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 215 | - $this->users = []; |
|
| 216 | - foreach ($notifyGroups as $group) { |
|
| 217 | - $groupToNotify = $this->groupManager->get($group); |
|
| 218 | - if ($groupToNotify instanceof IGroup) { |
|
| 219 | - foreach ($groupToNotify->getUsers() as $user) { |
|
| 220 | - $this->users[$user->getUID()] = true; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $this->users = array_keys($this->users); |
|
| 226 | - |
|
| 227 | - return $this->users; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Delete notifications for old updates |
|
| 232 | - * |
|
| 233 | - * @param string $app |
|
| 234 | - * @param string $version |
|
| 235 | - */ |
|
| 236 | - protected function deleteOutdatedNotifications($app, $version) { |
|
| 237 | - $notification = $this->notificationManager->createNotification(); |
|
| 238 | - $notification->setApp('updatenotification') |
|
| 239 | - ->setObject($app, $version); |
|
| 240 | - $this->notificationManager->markProcessed($notification); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @return VersionCheck |
|
| 245 | - */ |
|
| 246 | - protected function createVersionCheck() { |
|
| 247 | - return new VersionCheck( |
|
| 248 | - $this->client, |
|
| 249 | - $this->config |
|
| 250 | - ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - protected function getChannel() { |
|
| 257 | - return \OC_Util::getChannel(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @param string $app |
|
| 262 | - * @return string|false |
|
| 263 | - */ |
|
| 264 | - protected function isUpdateAvailable($app) { |
|
| 265 | - return $this->installer->isUpdateAvailable($app); |
|
| 266 | - } |
|
| 39 | + protected $connectionNotifications = [3, 7, 14, 30]; |
|
| 40 | + |
|
| 41 | + /** @var IConfig */ |
|
| 42 | + protected $config; |
|
| 43 | + |
|
| 44 | + /** @var IManager */ |
|
| 45 | + protected $notificationManager; |
|
| 46 | + |
|
| 47 | + /** @var IGroupManager */ |
|
| 48 | + protected $groupManager; |
|
| 49 | + |
|
| 50 | + /** @var IAppManager */ |
|
| 51 | + protected $appManager; |
|
| 52 | + |
|
| 53 | + /** @var IClientService */ |
|
| 54 | + protected $client; |
|
| 55 | + |
|
| 56 | + /** @var Installer */ |
|
| 57 | + protected $installer; |
|
| 58 | + |
|
| 59 | + /** @var string[] */ |
|
| 60 | + protected $users; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * NotificationBackgroundJob constructor. |
|
| 64 | + * |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param IManager $notificationManager |
|
| 67 | + * @param IGroupManager $groupManager |
|
| 68 | + * @param IAppManager $appManager |
|
| 69 | + * @param IClientService $client |
|
| 70 | + * @param Installer $installer |
|
| 71 | + */ |
|
| 72 | + public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { |
|
| 73 | + // Run once a day |
|
| 74 | + $this->setInterval(60 * 60 * 24); |
|
| 75 | + |
|
| 76 | + $this->config = $config; |
|
| 77 | + $this->notificationManager = $notificationManager; |
|
| 78 | + $this->groupManager = $groupManager; |
|
| 79 | + $this->appManager = $appManager; |
|
| 80 | + $this->client = $client; |
|
| 81 | + $this->installer = $installer; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + protected function run($argument) { |
|
| 85 | + $this->checkCoreUpdate(); |
|
| 86 | + $this->checkAppUpdates(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Check for ownCloud update |
|
| 91 | + */ |
|
| 92 | + protected function checkCoreUpdate() { |
|
| 93 | + if (in_array($this->getChannel(), ['daily', 'git'], true)) { |
|
| 94 | + // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $updater = $this->createVersionCheck(); |
|
| 99 | + |
|
| 100 | + $status = $updater->check(); |
|
| 101 | + if ($status === false) { |
|
| 102 | + $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 103 | + $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); |
|
| 104 | + |
|
| 105 | + if (in_array($errors, $this->connectionNotifications, true)) { |
|
| 106 | + $this->sendErrorNotifications($errors); |
|
| 107 | + } |
|
| 108 | + } else if (is_array($status)) { |
|
| 109 | + $this->config->setAppValue('updatenotification', 'update_check_errors', 0); |
|
| 110 | + $this->clearErrorNotifications(); |
|
| 111 | + |
|
| 112 | + if (isset($status['version'])) { |
|
| 113 | + $this->createNotifications('core', $status['version'], $status['versionstring']); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Send a message to the admin when the update server could not be reached |
|
| 120 | + * @param int $numDays |
|
| 121 | + */ |
|
| 122 | + protected function sendErrorNotifications($numDays) { |
|
| 123 | + $this->clearErrorNotifications(); |
|
| 124 | + |
|
| 125 | + $notification = $this->notificationManager->createNotification(); |
|
| 126 | + try { |
|
| 127 | + $notification->setApp('updatenotification') |
|
| 128 | + ->setDateTime(new \DateTime()) |
|
| 129 | + ->setObject('updatenotification', 'error') |
|
| 130 | + ->setSubject('connection_error', ['days' => $numDays]); |
|
| 131 | + |
|
| 132 | + foreach ($this->getUsersToNotify() as $uid) { |
|
| 133 | + $notification->setUser($uid); |
|
| 134 | + $this->notificationManager->notify($notification); |
|
| 135 | + } |
|
| 136 | + } catch (\InvalidArgumentException $e) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Remove error notifications again |
|
| 143 | + */ |
|
| 144 | + protected function clearErrorNotifications() { |
|
| 145 | + $notification = $this->notificationManager->createNotification(); |
|
| 146 | + try { |
|
| 147 | + $notification->setApp('updatenotification') |
|
| 148 | + ->setSubject('connection_error') |
|
| 149 | + ->setObject('updatenotification', 'error'); |
|
| 150 | + } catch (\InvalidArgumentException $e) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + $this->notificationManager->markProcessed($notification); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Check all installed apps for updates |
|
| 158 | + */ |
|
| 159 | + protected function checkAppUpdates() { |
|
| 160 | + $apps = $this->appManager->getInstalledApps(); |
|
| 161 | + foreach ($apps as $app) { |
|
| 162 | + $update = $this->isUpdateAvailable($app); |
|
| 163 | + if ($update !== false) { |
|
| 164 | + $this->createNotifications($app, $update); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Create notifications for this app version |
|
| 171 | + * |
|
| 172 | + * @param string $app |
|
| 173 | + * @param string $version |
|
| 174 | + * @param string $visibleVersion |
|
| 175 | + */ |
|
| 176 | + protected function createNotifications($app, $version, $visibleVersion = '') { |
|
| 177 | + $lastNotification = $this->config->getAppValue('updatenotification', $app, false); |
|
| 178 | + if ($lastNotification === $version) { |
|
| 179 | + // We already notified about this update |
|
| 180 | + return; |
|
| 181 | + } else if ($lastNotification !== false) { |
|
| 182 | + // Delete old updates |
|
| 183 | + $this->deleteOutdatedNotifications($app, $lastNotification); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + $notification = $this->notificationManager->createNotification(); |
|
| 188 | + $notification->setApp('updatenotification') |
|
| 189 | + ->setDateTime(new \DateTime()) |
|
| 190 | + ->setObject($app, $version); |
|
| 191 | + |
|
| 192 | + if ($visibleVersion !== '') { |
|
| 193 | + $notification->setSubject('update_available', ['version' => $visibleVersion]); |
|
| 194 | + } else { |
|
| 195 | + $notification->setSubject('update_available'); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + foreach ($this->getUsersToNotify() as $uid) { |
|
| 199 | + $notification->setUser($uid); |
|
| 200 | + $this->notificationManager->notify($notification); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $this->config->setAppValue('updatenotification', $app, $version); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @return string[] |
|
| 208 | + */ |
|
| 209 | + protected function getUsersToNotify() { |
|
| 210 | + if ($this->users !== null) { |
|
| 211 | + return $this->users; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 215 | + $this->users = []; |
|
| 216 | + foreach ($notifyGroups as $group) { |
|
| 217 | + $groupToNotify = $this->groupManager->get($group); |
|
| 218 | + if ($groupToNotify instanceof IGroup) { |
|
| 219 | + foreach ($groupToNotify->getUsers() as $user) { |
|
| 220 | + $this->users[$user->getUID()] = true; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $this->users = array_keys($this->users); |
|
| 226 | + |
|
| 227 | + return $this->users; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Delete notifications for old updates |
|
| 232 | + * |
|
| 233 | + * @param string $app |
|
| 234 | + * @param string $version |
|
| 235 | + */ |
|
| 236 | + protected function deleteOutdatedNotifications($app, $version) { |
|
| 237 | + $notification = $this->notificationManager->createNotification(); |
|
| 238 | + $notification->setApp('updatenotification') |
|
| 239 | + ->setObject($app, $version); |
|
| 240 | + $this->notificationManager->markProcessed($notification); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @return VersionCheck |
|
| 245 | + */ |
|
| 246 | + protected function createVersionCheck() { |
|
| 247 | + return new VersionCheck( |
|
| 248 | + $this->client, |
|
| 249 | + $this->config |
|
| 250 | + ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + protected function getChannel() { |
|
| 257 | + return \OC_Util::getChannel(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @param string $app |
|
| 262 | + * @return string|false |
|
| 263 | + */ |
|
| 264 | + protected function isUpdateAvailable($app) { |
|
| 265 | + return $this->installer->isUpdateAvailable($app); |
|
| 266 | + } |
|
| 267 | 267 | } |
@@ -53,415 +53,415 @@ |
||
| 53 | 53 | * @package OC\Settings\Controller |
| 54 | 54 | */ |
| 55 | 55 | class AppSettingsController extends Controller { |
| 56 | - const CAT_ENABLED = 0; |
|
| 57 | - const CAT_DISABLED = 1; |
|
| 58 | - const CAT_ALL_INSTALLED = 2; |
|
| 59 | - const CAT_APP_BUNDLES = 3; |
|
| 60 | - const CAT_UPDATES = 4; |
|
| 61 | - |
|
| 62 | - /** @var \OCP\IL10N */ |
|
| 63 | - private $l10n; |
|
| 64 | - /** @var IConfig */ |
|
| 65 | - private $config; |
|
| 66 | - /** @var INavigationManager */ |
|
| 67 | - private $navigationManager; |
|
| 68 | - /** @var IAppManager */ |
|
| 69 | - private $appManager; |
|
| 70 | - /** @var CategoryFetcher */ |
|
| 71 | - private $categoryFetcher; |
|
| 72 | - /** @var AppFetcher */ |
|
| 73 | - private $appFetcher; |
|
| 74 | - /** @var IFactory */ |
|
| 75 | - private $l10nFactory; |
|
| 76 | - /** @var BundleFetcher */ |
|
| 77 | - private $bundleFetcher; |
|
| 78 | - /** @var Installer */ |
|
| 79 | - private $installer; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $appName |
|
| 83 | - * @param IRequest $request |
|
| 84 | - * @param IL10N $l10n |
|
| 85 | - * @param IConfig $config |
|
| 86 | - * @param INavigationManager $navigationManager |
|
| 87 | - * @param IAppManager $appManager |
|
| 88 | - * @param CategoryFetcher $categoryFetcher |
|
| 89 | - * @param AppFetcher $appFetcher |
|
| 90 | - * @param IFactory $l10nFactory |
|
| 91 | - * @param BundleFetcher $bundleFetcher |
|
| 92 | - * @param Installer $installer |
|
| 93 | - */ |
|
| 94 | - public function __construct($appName, |
|
| 95 | - IRequest $request, |
|
| 96 | - IL10N $l10n, |
|
| 97 | - IConfig $config, |
|
| 98 | - INavigationManager $navigationManager, |
|
| 99 | - IAppManager $appManager, |
|
| 100 | - CategoryFetcher $categoryFetcher, |
|
| 101 | - AppFetcher $appFetcher, |
|
| 102 | - IFactory $l10nFactory, |
|
| 103 | - BundleFetcher $bundleFetcher, |
|
| 104 | - Installer $installer) { |
|
| 105 | - parent::__construct($appName, $request); |
|
| 106 | - $this->l10n = $l10n; |
|
| 107 | - $this->config = $config; |
|
| 108 | - $this->navigationManager = $navigationManager; |
|
| 109 | - $this->appManager = $appManager; |
|
| 110 | - $this->categoryFetcher = $categoryFetcher; |
|
| 111 | - $this->appFetcher = $appFetcher; |
|
| 112 | - $this->l10nFactory = $l10nFactory; |
|
| 113 | - $this->bundleFetcher = $bundleFetcher; |
|
| 114 | - $this->installer = $installer; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @NoCSRFRequired |
|
| 119 | - * |
|
| 120 | - * @param string $category |
|
| 121 | - * @return TemplateResponse |
|
| 122 | - */ |
|
| 123 | - public function viewApps($category = '') { |
|
| 124 | - if ($category === '') { |
|
| 125 | - $category = 'installed'; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $params = []; |
|
| 129 | - $params['category'] = $category; |
|
| 130 | - $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true; |
|
| 131 | - $this->navigationManager->setActiveEntry('core_apps'); |
|
| 132 | - |
|
| 133 | - $templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user'); |
|
| 134 | - $policy = new ContentSecurityPolicy(); |
|
| 135 | - $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com'); |
|
| 136 | - $templateResponse->setContentSecurityPolicy($policy); |
|
| 137 | - |
|
| 138 | - return $templateResponse; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - private function getAllCategories() { |
|
| 142 | - $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
|
| 143 | - |
|
| 144 | - $updateCount = count($this->getAppsWithUpdates()); |
|
| 145 | - $formattedCategories = [ |
|
| 146 | - ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], |
|
| 147 | - ['id' => self::CAT_UPDATES, 'ident' => 'updates', 'displayName' => (string)$this->l10n->t('Updates'), 'counter' => $updateCount], |
|
| 148 | - ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], |
|
| 149 | - ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], |
|
| 150 | - ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], |
|
| 151 | - ]; |
|
| 152 | - $categories = $this->categoryFetcher->get(); |
|
| 153 | - foreach($categories as $category) { |
|
| 154 | - $formattedCategories[] = [ |
|
| 155 | - 'id' => $category['id'], |
|
| 156 | - 'ident' => $category['id'], |
|
| 157 | - 'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'], |
|
| 158 | - ]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $formattedCategories; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Get all available categories |
|
| 166 | - * |
|
| 167 | - * @return JSONResponse |
|
| 168 | - */ |
|
| 169 | - public function listCategories() { |
|
| 170 | - return new JSONResponse($this->getAllCategories()); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Get all apps for a category |
|
| 175 | - * |
|
| 176 | - * @param string $requestedCategory |
|
| 177 | - * @return array |
|
| 178 | - */ |
|
| 179 | - private function getAppsForCategory($requestedCategory) { |
|
| 180 | - $versionParser = new VersionParser(); |
|
| 181 | - $formattedApps = []; |
|
| 182 | - $apps = $this->appFetcher->get(); |
|
| 183 | - foreach($apps as $app) { |
|
| 184 | - if (isset($app['isFeatured'])) { |
|
| 185 | - $app['featured'] = $app['isFeatured']; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Skip all apps not in the requested category |
|
| 189 | - $isInCategory = false; |
|
| 190 | - foreach($app['categories'] as $category) { |
|
| 191 | - if($category === $requestedCategory) { |
|
| 192 | - $isInCategory = true; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - if(!$isInCategory) { |
|
| 196 | - continue; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
|
| 200 | - $nextCloudVersionDependencies = []; |
|
| 201 | - if($nextCloudVersion->getMinimumVersion() !== '') { |
|
| 202 | - $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
|
| 203 | - } |
|
| 204 | - if($nextCloudVersion->getMaximumVersion() !== '') { |
|
| 205 | - $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
|
| 206 | - } |
|
| 207 | - $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
|
| 208 | - $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
|
| 209 | - $phpDependencies = []; |
|
| 210 | - if($phpVersion->getMinimumVersion() !== '') { |
|
| 211 | - $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
|
| 212 | - } |
|
| 213 | - if($phpVersion->getMaximumVersion() !== '') { |
|
| 214 | - $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
|
| 215 | - } |
|
| 216 | - if(isset($app['releases'][0]['minIntSize'])) { |
|
| 217 | - $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
|
| 218 | - } |
|
| 219 | - $authors = ''; |
|
| 220 | - foreach($app['authors'] as $key => $author) { |
|
| 221 | - $authors .= $author['name']; |
|
| 222 | - if($key !== count($app['authors']) - 1) { |
|
| 223 | - $authors .= ', '; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
|
| 228 | - $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
|
| 229 | - $groups = null; |
|
| 230 | - if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
| 231 | - $groups = $enabledValue; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $currentVersion = ''; |
|
| 235 | - if($this->appManager->isInstalled($app['id'])) { |
|
| 236 | - $currentVersion = \OC_App::getAppVersion($app['id']); |
|
| 237 | - } else { |
|
| 238 | - $currentLanguage = $app['releases'][0]['version']; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $formattedApps[] = [ |
|
| 242 | - 'id' => $app['id'], |
|
| 243 | - 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
|
| 244 | - 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
|
| 245 | - 'license' => $app['releases'][0]['licenses'], |
|
| 246 | - 'author' => $authors, |
|
| 247 | - 'shipped' => false, |
|
| 248 | - 'version' => $currentVersion, |
|
| 249 | - 'default_enable' => '', |
|
| 250 | - 'types' => [], |
|
| 251 | - 'documentation' => [ |
|
| 252 | - 'admin' => $app['adminDocs'], |
|
| 253 | - 'user' => $app['userDocs'], |
|
| 254 | - 'developer' => $app['developerDocs'] |
|
| 255 | - ], |
|
| 256 | - 'website' => $app['website'], |
|
| 257 | - 'bugs' => $app['issueTracker'], |
|
| 258 | - 'detailpage' => $app['website'], |
|
| 259 | - 'dependencies' => array_merge( |
|
| 260 | - $nextCloudVersionDependencies, |
|
| 261 | - $phpDependencies |
|
| 262 | - ), |
|
| 263 | - 'level' => ($app['featured'] === true) ? 200 : 100, |
|
| 264 | - 'missingMaxOwnCloudVersion' => false, |
|
| 265 | - 'missingMinOwnCloudVersion' => false, |
|
| 266 | - 'canInstall' => true, |
|
| 267 | - 'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
|
| 268 | - 'score' => $app['ratingOverall'], |
|
| 269 | - 'ratingNumOverall' => $app['ratingNumOverall'], |
|
| 270 | - 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false, |
|
| 271 | - 'removable' => $existsLocally, |
|
| 272 | - 'active' => $this->appManager->isEnabledForUser($app['id']), |
|
| 273 | - 'needsDownload' => !$existsLocally, |
|
| 274 | - 'groups' => $groups, |
|
| 275 | - 'fromAppStore' => true, |
|
| 276 | - ]; |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 280 | - if($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
| 281 | - $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $formattedApps; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - private function getAppsWithUpdates() { |
|
| 289 | - $appClass = new \OC_App(); |
|
| 290 | - $apps = $appClass->listAllApps(); |
|
| 291 | - foreach($apps as $key => $app) { |
|
| 292 | - $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 293 | - if($newVersion !== false) { |
|
| 294 | - $apps[$key]['update'] = $newVersion; |
|
| 295 | - } else { |
|
| 296 | - unset($apps[$key]); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - usort($apps, function ($a, $b) { |
|
| 300 | - $a = (string)$a['name']; |
|
| 301 | - $b = (string)$b['name']; |
|
| 302 | - if ($a === $b) { |
|
| 303 | - return 0; |
|
| 304 | - } |
|
| 305 | - return ($a < $b) ? -1 : 1; |
|
| 306 | - }); |
|
| 307 | - return $apps; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Get all available apps in a category |
|
| 312 | - * |
|
| 313 | - * @param string $category |
|
| 314 | - * @return JSONResponse |
|
| 315 | - */ |
|
| 316 | - public function listApps($category = '') { |
|
| 317 | - $appClass = new \OC_App(); |
|
| 318 | - |
|
| 319 | - switch ($category) { |
|
| 320 | - // installed apps |
|
| 321 | - case 'installed': |
|
| 322 | - $apps = $appClass->listAllApps(); |
|
| 323 | - |
|
| 324 | - foreach($apps as $key => $app) { |
|
| 325 | - $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 326 | - $apps[$key]['update'] = $newVersion; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - usort($apps, function ($a, $b) { |
|
| 330 | - $a = (string)$a['name']; |
|
| 331 | - $b = (string)$b['name']; |
|
| 332 | - if ($a === $b) { |
|
| 333 | - return 0; |
|
| 334 | - } |
|
| 335 | - return ($a < $b) ? -1 : 1; |
|
| 336 | - }); |
|
| 337 | - break; |
|
| 338 | - // updates |
|
| 339 | - case 'updates': |
|
| 340 | - $apps = $this->getAppsWithUpdates(); |
|
| 341 | - break; |
|
| 342 | - // enabled apps |
|
| 343 | - case 'enabled': |
|
| 344 | - $apps = $appClass->listAllApps(); |
|
| 345 | - $apps = array_filter($apps, function ($app) { |
|
| 346 | - return $app['active']; |
|
| 347 | - }); |
|
| 348 | - |
|
| 349 | - foreach($apps as $key => $app) { |
|
| 350 | - $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 351 | - $apps[$key]['update'] = $newVersion; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - usort($apps, function ($a, $b) { |
|
| 355 | - $a = (string)$a['name']; |
|
| 356 | - $b = (string)$b['name']; |
|
| 357 | - if ($a === $b) { |
|
| 358 | - return 0; |
|
| 359 | - } |
|
| 360 | - return ($a < $b) ? -1 : 1; |
|
| 361 | - }); |
|
| 362 | - break; |
|
| 363 | - // disabled apps |
|
| 364 | - case 'disabled': |
|
| 365 | - $apps = $appClass->listAllApps(); |
|
| 366 | - $apps = array_filter($apps, function ($app) { |
|
| 367 | - return !$app['active']; |
|
| 368 | - }); |
|
| 369 | - |
|
| 370 | - $apps = array_map(function ($app) { |
|
| 371 | - $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 372 | - if ($newVersion !== false) { |
|
| 373 | - $app['update'] = $newVersion; |
|
| 374 | - } |
|
| 375 | - return $app; |
|
| 376 | - }, $apps); |
|
| 377 | - |
|
| 378 | - usort($apps, function ($a, $b) { |
|
| 379 | - $a = (string)$a['name']; |
|
| 380 | - $b = (string)$b['name']; |
|
| 381 | - if ($a === $b) { |
|
| 382 | - return 0; |
|
| 383 | - } |
|
| 384 | - return ($a < $b) ? -1 : 1; |
|
| 385 | - }); |
|
| 386 | - break; |
|
| 387 | - case 'app-bundles': |
|
| 388 | - $bundles = $this->bundleFetcher->getBundles(); |
|
| 389 | - $apps = []; |
|
| 390 | - foreach($bundles as $bundle) { |
|
| 391 | - $newCategory = true; |
|
| 392 | - $allApps = $appClass->listAllApps(); |
|
| 393 | - $categories = $this->getAllCategories(); |
|
| 394 | - foreach($categories as $singleCategory) { |
|
| 395 | - $newApps = $this->getAppsForCategory($singleCategory['id']); |
|
| 396 | - foreach($allApps as $app) { |
|
| 397 | - foreach($newApps as $key => $newApp) { |
|
| 398 | - if($app['id'] === $newApp['id']) { |
|
| 399 | - unset($newApps[$key]); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - $allApps = array_merge($allApps, $newApps); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - foreach($bundle->getAppIdentifiers() as $identifier) { |
|
| 407 | - foreach($allApps as $app) { |
|
| 408 | - if($app['id'] === $identifier) { |
|
| 409 | - if($newCategory) { |
|
| 410 | - $app['newCategory'] = true; |
|
| 411 | - $app['categoryName'] = $bundle->getName(); |
|
| 412 | - } |
|
| 413 | - $app['bundleId'] = $bundle->getIdentifier(); |
|
| 414 | - $newCategory = false; |
|
| 415 | - $apps[] = $app; |
|
| 416 | - continue; |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - break; |
|
| 422 | - default: |
|
| 423 | - $apps = $this->getAppsForCategory($category); |
|
| 424 | - |
|
| 425 | - // sort by score |
|
| 426 | - usort($apps, function ($a, $b) { |
|
| 427 | - $a = (int)$a['score']; |
|
| 428 | - $b = (int)$b['score']; |
|
| 429 | - if ($a === $b) { |
|
| 430 | - return 0; |
|
| 431 | - } |
|
| 432 | - return ($a > $b) ? -1 : 1; |
|
| 433 | - }); |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // fix groups to be an array |
|
| 438 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n); |
|
| 439 | - $apps = array_map(function($app) use ($dependencyAnalyzer) { |
|
| 440 | - |
|
| 441 | - // fix groups |
|
| 442 | - $groups = array(); |
|
| 443 | - if (is_string($app['groups'])) { |
|
| 444 | - $groups = json_decode($app['groups']); |
|
| 445 | - } |
|
| 446 | - $app['groups'] = $groups; |
|
| 447 | - $app['canUnInstall'] = !$app['active'] && $app['removable']; |
|
| 448 | - |
|
| 449 | - // fix licence vs license |
|
| 450 | - if (isset($app['license']) && !isset($app['licence'])) { |
|
| 451 | - $app['licence'] = $app['license']; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // analyse dependencies |
|
| 455 | - $missing = $dependencyAnalyzer->analyze($app); |
|
| 456 | - $app['canInstall'] = empty($missing); |
|
| 457 | - $app['missingDependencies'] = $missing; |
|
| 458 | - |
|
| 459 | - $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']); |
|
| 460 | - $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']); |
|
| 461 | - |
|
| 462 | - return $app; |
|
| 463 | - }, $apps); |
|
| 464 | - |
|
| 465 | - return new JSONResponse(['apps' => $apps, 'status' => 'success']); |
|
| 466 | - } |
|
| 56 | + const CAT_ENABLED = 0; |
|
| 57 | + const CAT_DISABLED = 1; |
|
| 58 | + const CAT_ALL_INSTALLED = 2; |
|
| 59 | + const CAT_APP_BUNDLES = 3; |
|
| 60 | + const CAT_UPDATES = 4; |
|
| 61 | + |
|
| 62 | + /** @var \OCP\IL10N */ |
|
| 63 | + private $l10n; |
|
| 64 | + /** @var IConfig */ |
|
| 65 | + private $config; |
|
| 66 | + /** @var INavigationManager */ |
|
| 67 | + private $navigationManager; |
|
| 68 | + /** @var IAppManager */ |
|
| 69 | + private $appManager; |
|
| 70 | + /** @var CategoryFetcher */ |
|
| 71 | + private $categoryFetcher; |
|
| 72 | + /** @var AppFetcher */ |
|
| 73 | + private $appFetcher; |
|
| 74 | + /** @var IFactory */ |
|
| 75 | + private $l10nFactory; |
|
| 76 | + /** @var BundleFetcher */ |
|
| 77 | + private $bundleFetcher; |
|
| 78 | + /** @var Installer */ |
|
| 79 | + private $installer; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $appName |
|
| 83 | + * @param IRequest $request |
|
| 84 | + * @param IL10N $l10n |
|
| 85 | + * @param IConfig $config |
|
| 86 | + * @param INavigationManager $navigationManager |
|
| 87 | + * @param IAppManager $appManager |
|
| 88 | + * @param CategoryFetcher $categoryFetcher |
|
| 89 | + * @param AppFetcher $appFetcher |
|
| 90 | + * @param IFactory $l10nFactory |
|
| 91 | + * @param BundleFetcher $bundleFetcher |
|
| 92 | + * @param Installer $installer |
|
| 93 | + */ |
|
| 94 | + public function __construct($appName, |
|
| 95 | + IRequest $request, |
|
| 96 | + IL10N $l10n, |
|
| 97 | + IConfig $config, |
|
| 98 | + INavigationManager $navigationManager, |
|
| 99 | + IAppManager $appManager, |
|
| 100 | + CategoryFetcher $categoryFetcher, |
|
| 101 | + AppFetcher $appFetcher, |
|
| 102 | + IFactory $l10nFactory, |
|
| 103 | + BundleFetcher $bundleFetcher, |
|
| 104 | + Installer $installer) { |
|
| 105 | + parent::__construct($appName, $request); |
|
| 106 | + $this->l10n = $l10n; |
|
| 107 | + $this->config = $config; |
|
| 108 | + $this->navigationManager = $navigationManager; |
|
| 109 | + $this->appManager = $appManager; |
|
| 110 | + $this->categoryFetcher = $categoryFetcher; |
|
| 111 | + $this->appFetcher = $appFetcher; |
|
| 112 | + $this->l10nFactory = $l10nFactory; |
|
| 113 | + $this->bundleFetcher = $bundleFetcher; |
|
| 114 | + $this->installer = $installer; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @NoCSRFRequired |
|
| 119 | + * |
|
| 120 | + * @param string $category |
|
| 121 | + * @return TemplateResponse |
|
| 122 | + */ |
|
| 123 | + public function viewApps($category = '') { |
|
| 124 | + if ($category === '') { |
|
| 125 | + $category = 'installed'; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $params = []; |
|
| 129 | + $params['category'] = $category; |
|
| 130 | + $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true; |
|
| 131 | + $this->navigationManager->setActiveEntry('core_apps'); |
|
| 132 | + |
|
| 133 | + $templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user'); |
|
| 134 | + $policy = new ContentSecurityPolicy(); |
|
| 135 | + $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com'); |
|
| 136 | + $templateResponse->setContentSecurityPolicy($policy); |
|
| 137 | + |
|
| 138 | + return $templateResponse; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + private function getAllCategories() { |
|
| 142 | + $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); |
|
| 143 | + |
|
| 144 | + $updateCount = count($this->getAppsWithUpdates()); |
|
| 145 | + $formattedCategories = [ |
|
| 146 | + ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], |
|
| 147 | + ['id' => self::CAT_UPDATES, 'ident' => 'updates', 'displayName' => (string)$this->l10n->t('Updates'), 'counter' => $updateCount], |
|
| 148 | + ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], |
|
| 149 | + ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], |
|
| 150 | + ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], |
|
| 151 | + ]; |
|
| 152 | + $categories = $this->categoryFetcher->get(); |
|
| 153 | + foreach($categories as $category) { |
|
| 154 | + $formattedCategories[] = [ |
|
| 155 | + 'id' => $category['id'], |
|
| 156 | + 'ident' => $category['id'], |
|
| 157 | + 'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'], |
|
| 158 | + ]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $formattedCategories; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Get all available categories |
|
| 166 | + * |
|
| 167 | + * @return JSONResponse |
|
| 168 | + */ |
|
| 169 | + public function listCategories() { |
|
| 170 | + return new JSONResponse($this->getAllCategories()); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Get all apps for a category |
|
| 175 | + * |
|
| 176 | + * @param string $requestedCategory |
|
| 177 | + * @return array |
|
| 178 | + */ |
|
| 179 | + private function getAppsForCategory($requestedCategory) { |
|
| 180 | + $versionParser = new VersionParser(); |
|
| 181 | + $formattedApps = []; |
|
| 182 | + $apps = $this->appFetcher->get(); |
|
| 183 | + foreach($apps as $app) { |
|
| 184 | + if (isset($app['isFeatured'])) { |
|
| 185 | + $app['featured'] = $app['isFeatured']; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Skip all apps not in the requested category |
|
| 189 | + $isInCategory = false; |
|
| 190 | + foreach($app['categories'] as $category) { |
|
| 191 | + if($category === $requestedCategory) { |
|
| 192 | + $isInCategory = true; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + if(!$isInCategory) { |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
|
| 200 | + $nextCloudVersionDependencies = []; |
|
| 201 | + if($nextCloudVersion->getMinimumVersion() !== '') { |
|
| 202 | + $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
|
| 203 | + } |
|
| 204 | + if($nextCloudVersion->getMaximumVersion() !== '') { |
|
| 205 | + $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
|
| 206 | + } |
|
| 207 | + $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
|
| 208 | + $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
|
| 209 | + $phpDependencies = []; |
|
| 210 | + if($phpVersion->getMinimumVersion() !== '') { |
|
| 211 | + $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
|
| 212 | + } |
|
| 213 | + if($phpVersion->getMaximumVersion() !== '') { |
|
| 214 | + $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
|
| 215 | + } |
|
| 216 | + if(isset($app['releases'][0]['minIntSize'])) { |
|
| 217 | + $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
|
| 218 | + } |
|
| 219 | + $authors = ''; |
|
| 220 | + foreach($app['authors'] as $key => $author) { |
|
| 221 | + $authors .= $author['name']; |
|
| 222 | + if($key !== count($app['authors']) - 1) { |
|
| 223 | + $authors .= ', '; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
|
| 228 | + $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
|
| 229 | + $groups = null; |
|
| 230 | + if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
| 231 | + $groups = $enabledValue; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $currentVersion = ''; |
|
| 235 | + if($this->appManager->isInstalled($app['id'])) { |
|
| 236 | + $currentVersion = \OC_App::getAppVersion($app['id']); |
|
| 237 | + } else { |
|
| 238 | + $currentLanguage = $app['releases'][0]['version']; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $formattedApps[] = [ |
|
| 242 | + 'id' => $app['id'], |
|
| 243 | + 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
|
| 244 | + 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
|
| 245 | + 'license' => $app['releases'][0]['licenses'], |
|
| 246 | + 'author' => $authors, |
|
| 247 | + 'shipped' => false, |
|
| 248 | + 'version' => $currentVersion, |
|
| 249 | + 'default_enable' => '', |
|
| 250 | + 'types' => [], |
|
| 251 | + 'documentation' => [ |
|
| 252 | + 'admin' => $app['adminDocs'], |
|
| 253 | + 'user' => $app['userDocs'], |
|
| 254 | + 'developer' => $app['developerDocs'] |
|
| 255 | + ], |
|
| 256 | + 'website' => $app['website'], |
|
| 257 | + 'bugs' => $app['issueTracker'], |
|
| 258 | + 'detailpage' => $app['website'], |
|
| 259 | + 'dependencies' => array_merge( |
|
| 260 | + $nextCloudVersionDependencies, |
|
| 261 | + $phpDependencies |
|
| 262 | + ), |
|
| 263 | + 'level' => ($app['featured'] === true) ? 200 : 100, |
|
| 264 | + 'missingMaxOwnCloudVersion' => false, |
|
| 265 | + 'missingMinOwnCloudVersion' => false, |
|
| 266 | + 'canInstall' => true, |
|
| 267 | + 'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
|
| 268 | + 'score' => $app['ratingOverall'], |
|
| 269 | + 'ratingNumOverall' => $app['ratingNumOverall'], |
|
| 270 | + 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false, |
|
| 271 | + 'removable' => $existsLocally, |
|
| 272 | + 'active' => $this->appManager->isEnabledForUser($app['id']), |
|
| 273 | + 'needsDownload' => !$existsLocally, |
|
| 274 | + 'groups' => $groups, |
|
| 275 | + 'fromAppStore' => true, |
|
| 276 | + ]; |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 280 | + if($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
| 281 | + $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $formattedApps; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + private function getAppsWithUpdates() { |
|
| 289 | + $appClass = new \OC_App(); |
|
| 290 | + $apps = $appClass->listAllApps(); |
|
| 291 | + foreach($apps as $key => $app) { |
|
| 292 | + $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 293 | + if($newVersion !== false) { |
|
| 294 | + $apps[$key]['update'] = $newVersion; |
|
| 295 | + } else { |
|
| 296 | + unset($apps[$key]); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + usort($apps, function ($a, $b) { |
|
| 300 | + $a = (string)$a['name']; |
|
| 301 | + $b = (string)$b['name']; |
|
| 302 | + if ($a === $b) { |
|
| 303 | + return 0; |
|
| 304 | + } |
|
| 305 | + return ($a < $b) ? -1 : 1; |
|
| 306 | + }); |
|
| 307 | + return $apps; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Get all available apps in a category |
|
| 312 | + * |
|
| 313 | + * @param string $category |
|
| 314 | + * @return JSONResponse |
|
| 315 | + */ |
|
| 316 | + public function listApps($category = '') { |
|
| 317 | + $appClass = new \OC_App(); |
|
| 318 | + |
|
| 319 | + switch ($category) { |
|
| 320 | + // installed apps |
|
| 321 | + case 'installed': |
|
| 322 | + $apps = $appClass->listAllApps(); |
|
| 323 | + |
|
| 324 | + foreach($apps as $key => $app) { |
|
| 325 | + $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 326 | + $apps[$key]['update'] = $newVersion; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + usort($apps, function ($a, $b) { |
|
| 330 | + $a = (string)$a['name']; |
|
| 331 | + $b = (string)$b['name']; |
|
| 332 | + if ($a === $b) { |
|
| 333 | + return 0; |
|
| 334 | + } |
|
| 335 | + return ($a < $b) ? -1 : 1; |
|
| 336 | + }); |
|
| 337 | + break; |
|
| 338 | + // updates |
|
| 339 | + case 'updates': |
|
| 340 | + $apps = $this->getAppsWithUpdates(); |
|
| 341 | + break; |
|
| 342 | + // enabled apps |
|
| 343 | + case 'enabled': |
|
| 344 | + $apps = $appClass->listAllApps(); |
|
| 345 | + $apps = array_filter($apps, function ($app) { |
|
| 346 | + return $app['active']; |
|
| 347 | + }); |
|
| 348 | + |
|
| 349 | + foreach($apps as $key => $app) { |
|
| 350 | + $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 351 | + $apps[$key]['update'] = $newVersion; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + usort($apps, function ($a, $b) { |
|
| 355 | + $a = (string)$a['name']; |
|
| 356 | + $b = (string)$b['name']; |
|
| 357 | + if ($a === $b) { |
|
| 358 | + return 0; |
|
| 359 | + } |
|
| 360 | + return ($a < $b) ? -1 : 1; |
|
| 361 | + }); |
|
| 362 | + break; |
|
| 363 | + // disabled apps |
|
| 364 | + case 'disabled': |
|
| 365 | + $apps = $appClass->listAllApps(); |
|
| 366 | + $apps = array_filter($apps, function ($app) { |
|
| 367 | + return !$app['active']; |
|
| 368 | + }); |
|
| 369 | + |
|
| 370 | + $apps = array_map(function ($app) { |
|
| 371 | + $newVersion = $this->installer->isUpdateAvailable($app['id']); |
|
| 372 | + if ($newVersion !== false) { |
|
| 373 | + $app['update'] = $newVersion; |
|
| 374 | + } |
|
| 375 | + return $app; |
|
| 376 | + }, $apps); |
|
| 377 | + |
|
| 378 | + usort($apps, function ($a, $b) { |
|
| 379 | + $a = (string)$a['name']; |
|
| 380 | + $b = (string)$b['name']; |
|
| 381 | + if ($a === $b) { |
|
| 382 | + return 0; |
|
| 383 | + } |
|
| 384 | + return ($a < $b) ? -1 : 1; |
|
| 385 | + }); |
|
| 386 | + break; |
|
| 387 | + case 'app-bundles': |
|
| 388 | + $bundles = $this->bundleFetcher->getBundles(); |
|
| 389 | + $apps = []; |
|
| 390 | + foreach($bundles as $bundle) { |
|
| 391 | + $newCategory = true; |
|
| 392 | + $allApps = $appClass->listAllApps(); |
|
| 393 | + $categories = $this->getAllCategories(); |
|
| 394 | + foreach($categories as $singleCategory) { |
|
| 395 | + $newApps = $this->getAppsForCategory($singleCategory['id']); |
|
| 396 | + foreach($allApps as $app) { |
|
| 397 | + foreach($newApps as $key => $newApp) { |
|
| 398 | + if($app['id'] === $newApp['id']) { |
|
| 399 | + unset($newApps[$key]); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + $allApps = array_merge($allApps, $newApps); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + foreach($bundle->getAppIdentifiers() as $identifier) { |
|
| 407 | + foreach($allApps as $app) { |
|
| 408 | + if($app['id'] === $identifier) { |
|
| 409 | + if($newCategory) { |
|
| 410 | + $app['newCategory'] = true; |
|
| 411 | + $app['categoryName'] = $bundle->getName(); |
|
| 412 | + } |
|
| 413 | + $app['bundleId'] = $bundle->getIdentifier(); |
|
| 414 | + $newCategory = false; |
|
| 415 | + $apps[] = $app; |
|
| 416 | + continue; |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + break; |
|
| 422 | + default: |
|
| 423 | + $apps = $this->getAppsForCategory($category); |
|
| 424 | + |
|
| 425 | + // sort by score |
|
| 426 | + usort($apps, function ($a, $b) { |
|
| 427 | + $a = (int)$a['score']; |
|
| 428 | + $b = (int)$b['score']; |
|
| 429 | + if ($a === $b) { |
|
| 430 | + return 0; |
|
| 431 | + } |
|
| 432 | + return ($a > $b) ? -1 : 1; |
|
| 433 | + }); |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // fix groups to be an array |
|
| 438 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n); |
|
| 439 | + $apps = array_map(function($app) use ($dependencyAnalyzer) { |
|
| 440 | + |
|
| 441 | + // fix groups |
|
| 442 | + $groups = array(); |
|
| 443 | + if (is_string($app['groups'])) { |
|
| 444 | + $groups = json_decode($app['groups']); |
|
| 445 | + } |
|
| 446 | + $app['groups'] = $groups; |
|
| 447 | + $app['canUnInstall'] = !$app['active'] && $app['removable']; |
|
| 448 | + |
|
| 449 | + // fix licence vs license |
|
| 450 | + if (isset($app['license']) && !isset($app['licence'])) { |
|
| 451 | + $app['licence'] = $app['license']; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // analyse dependencies |
|
| 455 | + $missing = $dependencyAnalyzer->analyze($app); |
|
| 456 | + $app['canInstall'] = empty($missing); |
|
| 457 | + $app['missingDependencies'] = $missing; |
|
| 458 | + |
|
| 459 | + $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']); |
|
| 460 | + $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']); |
|
| 461 | + |
|
| 462 | + return $app; |
|
| 463 | + }, $apps); |
|
| 464 | + |
|
| 465 | + return new JSONResponse(['apps' => $apps, 'status' => 'success']); |
|
| 466 | + } |
|
| 467 | 467 | } |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | $updateCount = count($this->getAppsWithUpdates()); |
| 145 | 145 | $formattedCategories = [ |
| 146 | - ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')], |
|
| 147 | - ['id' => self::CAT_UPDATES, 'ident' => 'updates', 'displayName' => (string)$this->l10n->t('Updates'), 'counter' => $updateCount], |
|
| 148 | - ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')], |
|
| 149 | - ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')], |
|
| 150 | - ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string)$this->l10n->t('App bundles')], |
|
| 146 | + ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string) $this->l10n->t('Your apps')], |
|
| 147 | + ['id' => self::CAT_UPDATES, 'ident' => 'updates', 'displayName' => (string) $this->l10n->t('Updates'), 'counter' => $updateCount], |
|
| 148 | + ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string) $this->l10n->t('Enabled apps')], |
|
| 149 | + ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string) $this->l10n->t('Disabled apps')], |
|
| 150 | + ['id' => self::CAT_APP_BUNDLES, 'ident' => 'app-bundles', 'displayName' => (string) $this->l10n->t('App bundles')], |
|
| 151 | 151 | ]; |
| 152 | 152 | $categories = $this->categoryFetcher->get(); |
| 153 | - foreach($categories as $category) { |
|
| 153 | + foreach ($categories as $category) { |
|
| 154 | 154 | $formattedCategories[] = [ |
| 155 | 155 | 'id' => $category['id'], |
| 156 | 156 | 'ident' => $category['id'], |
@@ -180,46 +180,46 @@ discard block |
||
| 180 | 180 | $versionParser = new VersionParser(); |
| 181 | 181 | $formattedApps = []; |
| 182 | 182 | $apps = $this->appFetcher->get(); |
| 183 | - foreach($apps as $app) { |
|
| 183 | + foreach ($apps as $app) { |
|
| 184 | 184 | if (isset($app['isFeatured'])) { |
| 185 | 185 | $app['featured'] = $app['isFeatured']; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Skip all apps not in the requested category |
| 189 | 189 | $isInCategory = false; |
| 190 | - foreach($app['categories'] as $category) { |
|
| 191 | - if($category === $requestedCategory) { |
|
| 190 | + foreach ($app['categories'] as $category) { |
|
| 191 | + if ($category === $requestedCategory) { |
|
| 192 | 192 | $isInCategory = true; |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | - if(!$isInCategory) { |
|
| 195 | + if (!$isInCategory) { |
|
| 196 | 196 | continue; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
| 200 | 200 | $nextCloudVersionDependencies = []; |
| 201 | - if($nextCloudVersion->getMinimumVersion() !== '') { |
|
| 201 | + if ($nextCloudVersion->getMinimumVersion() !== '') { |
|
| 202 | 202 | $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
| 203 | 203 | } |
| 204 | - if($nextCloudVersion->getMaximumVersion() !== '') { |
|
| 204 | + if ($nextCloudVersion->getMaximumVersion() !== '') { |
|
| 205 | 205 | $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
| 206 | 206 | } |
| 207 | 207 | $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
| 208 | 208 | $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
| 209 | 209 | $phpDependencies = []; |
| 210 | - if($phpVersion->getMinimumVersion() !== '') { |
|
| 210 | + if ($phpVersion->getMinimumVersion() !== '') { |
|
| 211 | 211 | $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
| 212 | 212 | } |
| 213 | - if($phpVersion->getMaximumVersion() !== '') { |
|
| 213 | + if ($phpVersion->getMaximumVersion() !== '') { |
|
| 214 | 214 | $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
| 215 | 215 | } |
| 216 | - if(isset($app['releases'][0]['minIntSize'])) { |
|
| 216 | + if (isset($app['releases'][0]['minIntSize'])) { |
|
| 217 | 217 | $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
| 218 | 218 | } |
| 219 | 219 | $authors = ''; |
| 220 | - foreach($app['authors'] as $key => $author) { |
|
| 220 | + foreach ($app['authors'] as $key => $author) { |
|
| 221 | 221 | $authors .= $author['name']; |
| 222 | - if($key !== count($app['authors']) - 1) { |
|
| 222 | + if ($key !== count($app['authors']) - 1) { |
|
| 223 | 223 | $authors .= ', '; |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
| 228 | 228 | $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
| 229 | 229 | $groups = null; |
| 230 | - if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
| 230 | + if ($enabledValue !== 'no' && $enabledValue !== 'yes') { |
|
| 231 | 231 | $groups = $enabledValue; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | $currentVersion = ''; |
| 235 | - if($this->appManager->isInstalled($app['id'])) { |
|
| 235 | + if ($this->appManager->isInstalled($app['id'])) { |
|
| 236 | 236 | $currentVersion = \OC_App::getAppVersion($app['id']); |
| 237 | 237 | } else { |
| 238 | 238 | $currentLanguage = $app['releases'][0]['version']; |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | |
| 279 | 279 | $newVersion = $this->installer->isUpdateAvailable($app['id']); |
| 280 | - if($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
| 281 | - $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
|
| 280 | + if ($newVersion && $this->appManager->isInstalled($app['id'])) { |
|
| 281 | + $formattedApps[count($formattedApps) - 1]['update'] = $newVersion; |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | private function getAppsWithUpdates() { |
| 289 | 289 | $appClass = new \OC_App(); |
| 290 | 290 | $apps = $appClass->listAllApps(); |
| 291 | - foreach($apps as $key => $app) { |
|
| 291 | + foreach ($apps as $key => $app) { |
|
| 292 | 292 | $newVersion = $this->installer->isUpdateAvailable($app['id']); |
| 293 | - if($newVersion !== false) { |
|
| 293 | + if ($newVersion !== false) { |
|
| 294 | 294 | $apps[$key]['update'] = $newVersion; |
| 295 | 295 | } else { |
| 296 | 296 | unset($apps[$key]); |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | - usort($apps, function ($a, $b) { |
|
| 300 | - $a = (string)$a['name']; |
|
| 301 | - $b = (string)$b['name']; |
|
| 299 | + usort($apps, function($a, $b) { |
|
| 300 | + $a = (string) $a['name']; |
|
| 301 | + $b = (string) $b['name']; |
|
| 302 | 302 | if ($a === $b) { |
| 303 | 303 | return 0; |
| 304 | 304 | } |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | case 'installed': |
| 322 | 322 | $apps = $appClass->listAllApps(); |
| 323 | 323 | |
| 324 | - foreach($apps as $key => $app) { |
|
| 324 | + foreach ($apps as $key => $app) { |
|
| 325 | 325 | $newVersion = $this->installer->isUpdateAvailable($app['id']); |
| 326 | 326 | $apps[$key]['update'] = $newVersion; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - usort($apps, function ($a, $b) { |
|
| 330 | - $a = (string)$a['name']; |
|
| 331 | - $b = (string)$b['name']; |
|
| 329 | + usort($apps, function($a, $b) { |
|
| 330 | + $a = (string) $a['name']; |
|
| 331 | + $b = (string) $b['name']; |
|
| 332 | 332 | if ($a === $b) { |
| 333 | 333 | return 0; |
| 334 | 334 | } |
@@ -342,18 +342,18 @@ discard block |
||
| 342 | 342 | // enabled apps |
| 343 | 343 | case 'enabled': |
| 344 | 344 | $apps = $appClass->listAllApps(); |
| 345 | - $apps = array_filter($apps, function ($app) { |
|
| 345 | + $apps = array_filter($apps, function($app) { |
|
| 346 | 346 | return $app['active']; |
| 347 | 347 | }); |
| 348 | 348 | |
| 349 | - foreach($apps as $key => $app) { |
|
| 349 | + foreach ($apps as $key => $app) { |
|
| 350 | 350 | $newVersion = $this->installer->isUpdateAvailable($app['id']); |
| 351 | 351 | $apps[$key]['update'] = $newVersion; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - usort($apps, function ($a, $b) { |
|
| 355 | - $a = (string)$a['name']; |
|
| 356 | - $b = (string)$b['name']; |
|
| 354 | + usort($apps, function($a, $b) { |
|
| 355 | + $a = (string) $a['name']; |
|
| 356 | + $b = (string) $b['name']; |
|
| 357 | 357 | if ($a === $b) { |
| 358 | 358 | return 0; |
| 359 | 359 | } |
@@ -363,11 +363,11 @@ discard block |
||
| 363 | 363 | // disabled apps |
| 364 | 364 | case 'disabled': |
| 365 | 365 | $apps = $appClass->listAllApps(); |
| 366 | - $apps = array_filter($apps, function ($app) { |
|
| 366 | + $apps = array_filter($apps, function($app) { |
|
| 367 | 367 | return !$app['active']; |
| 368 | 368 | }); |
| 369 | 369 | |
| 370 | - $apps = array_map(function ($app) { |
|
| 370 | + $apps = array_map(function($app) { |
|
| 371 | 371 | $newVersion = $this->installer->isUpdateAvailable($app['id']); |
| 372 | 372 | if ($newVersion !== false) { |
| 373 | 373 | $app['update'] = $newVersion; |
@@ -375,9 +375,9 @@ discard block |
||
| 375 | 375 | return $app; |
| 376 | 376 | }, $apps); |
| 377 | 377 | |
| 378 | - usort($apps, function ($a, $b) { |
|
| 379 | - $a = (string)$a['name']; |
|
| 380 | - $b = (string)$b['name']; |
|
| 378 | + usort($apps, function($a, $b) { |
|
| 379 | + $a = (string) $a['name']; |
|
| 380 | + $b = (string) $b['name']; |
|
| 381 | 381 | if ($a === $b) { |
| 382 | 382 | return 0; |
| 383 | 383 | } |
@@ -387,15 +387,15 @@ discard block |
||
| 387 | 387 | case 'app-bundles': |
| 388 | 388 | $bundles = $this->bundleFetcher->getBundles(); |
| 389 | 389 | $apps = []; |
| 390 | - foreach($bundles as $bundle) { |
|
| 390 | + foreach ($bundles as $bundle) { |
|
| 391 | 391 | $newCategory = true; |
| 392 | 392 | $allApps = $appClass->listAllApps(); |
| 393 | 393 | $categories = $this->getAllCategories(); |
| 394 | - foreach($categories as $singleCategory) { |
|
| 394 | + foreach ($categories as $singleCategory) { |
|
| 395 | 395 | $newApps = $this->getAppsForCategory($singleCategory['id']); |
| 396 | - foreach($allApps as $app) { |
|
| 397 | - foreach($newApps as $key => $newApp) { |
|
| 398 | - if($app['id'] === $newApp['id']) { |
|
| 396 | + foreach ($allApps as $app) { |
|
| 397 | + foreach ($newApps as $key => $newApp) { |
|
| 398 | + if ($app['id'] === $newApp['id']) { |
|
| 399 | 399 | unset($newApps[$key]); |
| 400 | 400 | } |
| 401 | 401 | } |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | $allApps = array_merge($allApps, $newApps); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - foreach($bundle->getAppIdentifiers() as $identifier) { |
|
| 407 | - foreach($allApps as $app) { |
|
| 408 | - if($app['id'] === $identifier) { |
|
| 409 | - if($newCategory) { |
|
| 406 | + foreach ($bundle->getAppIdentifiers() as $identifier) { |
|
| 407 | + foreach ($allApps as $app) { |
|
| 408 | + if ($app['id'] === $identifier) { |
|
| 409 | + if ($newCategory) { |
|
| 410 | 410 | $app['newCategory'] = true; |
| 411 | 411 | $app['categoryName'] = $bundle->getName(); |
| 412 | 412 | } |
@@ -423,9 +423,9 @@ discard block |
||
| 423 | 423 | $apps = $this->getAppsForCategory($category); |
| 424 | 424 | |
| 425 | 425 | // sort by score |
| 426 | - usort($apps, function ($a, $b) { |
|
| 427 | - $a = (int)$a['score']; |
|
| 428 | - $b = (int)$b['score']; |
|
| 426 | + usort($apps, function($a, $b) { |
|
| 427 | + $a = (int) $a['score']; |
|
| 428 | + $b = (int) $b['score']; |
|
| 429 | 429 | if ($a === $b) { |
| 430 | 430 | return 0; |
| 431 | 431 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 32 | 32 | |
| 33 | 33 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
| 34 | - @set_time_limit(0); |
|
| 34 | + @set_time_limit(0); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | require_once '../../lib/base.php'; |
@@ -45,191 +45,191 @@ discard block |
||
| 45 | 45 | $eventSource->send('success', (string)$l->t('Preparing update')); |
| 46 | 46 | |
| 47 | 47 | class FeedBackHandler { |
| 48 | - /** @var integer */ |
|
| 49 | - private $progressStateMax = 100; |
|
| 50 | - /** @var integer */ |
|
| 51 | - private $progressStateStep = 0; |
|
| 52 | - /** @var string */ |
|
| 53 | - private $currentStep; |
|
| 54 | - /** @var \OCP\IEventSource */ |
|
| 55 | - private $eventSource; |
|
| 56 | - /** @var \OCP\IL10N */ |
|
| 57 | - private $l10n; |
|
| 58 | - |
|
| 59 | - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
| 60 | - $this->eventSource = $eventSource; |
|
| 61 | - $this->l10n = $l10n; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function handleRepairFeedback($event) { |
|
| 65 | - if (!$event instanceof GenericEvent) { |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - switch ($event->getSubject()) { |
|
| 70 | - case '\OC\Repair::startProgress': |
|
| 71 | - $this->progressStateMax = $event->getArgument(0); |
|
| 72 | - $this->progressStateStep = 0; |
|
| 73 | - $this->currentStep = $event->getArgument(1); |
|
| 74 | - break; |
|
| 75 | - case '\OC\Repair::advance': |
|
| 76 | - $this->progressStateStep += $event->getArgument(0); |
|
| 77 | - $desc = $event->getArgument(1); |
|
| 78 | - if (empty($desc)) { |
|
| 79 | - $desc = $this->currentStep; |
|
| 80 | - } |
|
| 81 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
| 82 | - break; |
|
| 83 | - case '\OC\Repair::finishProgress': |
|
| 84 | - $this->progressStateMax = $this->progressStateStep; |
|
| 85 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
| 86 | - break; |
|
| 87 | - case '\OC\Repair::step': |
|
| 88 | - break; |
|
| 89 | - case '\OC\Repair::info': |
|
| 90 | - break; |
|
| 91 | - case '\OC\Repair::warning': |
|
| 92 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0)); |
|
| 93 | - break; |
|
| 94 | - case '\OC\Repair::error': |
|
| 95 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0)); |
|
| 96 | - break; |
|
| 97 | - } |
|
| 98 | - } |
|
| 48 | + /** @var integer */ |
|
| 49 | + private $progressStateMax = 100; |
|
| 50 | + /** @var integer */ |
|
| 51 | + private $progressStateStep = 0; |
|
| 52 | + /** @var string */ |
|
| 53 | + private $currentStep; |
|
| 54 | + /** @var \OCP\IEventSource */ |
|
| 55 | + private $eventSource; |
|
| 56 | + /** @var \OCP\IL10N */ |
|
| 57 | + private $l10n; |
|
| 58 | + |
|
| 59 | + public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
| 60 | + $this->eventSource = $eventSource; |
|
| 61 | + $this->l10n = $l10n; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function handleRepairFeedback($event) { |
|
| 65 | + if (!$event instanceof GenericEvent) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + switch ($event->getSubject()) { |
|
| 70 | + case '\OC\Repair::startProgress': |
|
| 71 | + $this->progressStateMax = $event->getArgument(0); |
|
| 72 | + $this->progressStateStep = 0; |
|
| 73 | + $this->currentStep = $event->getArgument(1); |
|
| 74 | + break; |
|
| 75 | + case '\OC\Repair::advance': |
|
| 76 | + $this->progressStateStep += $event->getArgument(0); |
|
| 77 | + $desc = $event->getArgument(1); |
|
| 78 | + if (empty($desc)) { |
|
| 79 | + $desc = $this->currentStep; |
|
| 80 | + } |
|
| 81 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
| 82 | + break; |
|
| 83 | + case '\OC\Repair::finishProgress': |
|
| 84 | + $this->progressStateMax = $this->progressStateStep; |
|
| 85 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
| 86 | + break; |
|
| 87 | + case '\OC\Repair::step': |
|
| 88 | + break; |
|
| 89 | + case '\OC\Repair::info': |
|
| 90 | + break; |
|
| 91 | + case '\OC\Repair::warning': |
|
| 92 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0)); |
|
| 93 | + break; |
|
| 94 | + case '\OC\Repair::error': |
|
| 95 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0)); |
|
| 96 | + break; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | if (OC::checkUpgrade(false)) { |
| 102 | 102 | |
| 103 | - $config = \OC::$server->getSystemConfig(); |
|
| 104 | - if ($config->getValue('upgrade.disable-web', false)) { |
|
| 105 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
| 106 | - $eventSource->close(); |
|
| 107 | - exit(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // if a user is currently logged in, their session must be ignored to |
|
| 111 | - // avoid side effects |
|
| 112 | - \OC_User::setIncognitoMode(true); |
|
| 113 | - |
|
| 114 | - $logger = \OC::$server->getLogger(); |
|
| 115 | - $config = \OC::$server->getConfig(); |
|
| 116 | - $updater = new \OC\Updater( |
|
| 117 | - $config, |
|
| 118 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 119 | - $logger, |
|
| 120 | - \OC::$server->query(\OC\Installer::class) |
|
| 121 | - ); |
|
| 122 | - $incompatibleApps = []; |
|
| 123 | - $disabledThirdPartyApps = []; |
|
| 124 | - |
|
| 125 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 126 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
| 127 | - if ($event instanceof GenericEvent) { |
|
| 128 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 129 | - } |
|
| 130 | - }); |
|
| 131 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
| 132 | - if ($event instanceof GenericEvent) { |
|
| 133 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 134 | - } |
|
| 135 | - }); |
|
| 136 | - $feedBack = new FeedBackHandler($eventSource, $l); |
|
| 137 | - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 138 | - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
| 139 | - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 140 | - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
| 141 | - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
| 142 | - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
| 143 | - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
| 144 | - |
|
| 145 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
| 146 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
| 147 | - }); |
|
| 148 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
| 149 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
| 150 | - }); |
|
| 151 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
| 152 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
| 153 | - }); |
|
| 154 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) { |
|
| 155 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
| 156 | - }); |
|
| 157 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
| 158 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
| 159 | - }); |
|
| 160 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) { |
|
| 161 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
| 162 | - }); |
|
| 163 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
| 164 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
| 165 | - }); |
|
| 166 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
| 167 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
| 168 | - }); |
|
| 169 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
| 170 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
| 171 | - }); |
|
| 172 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 173 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
| 174 | - }); |
|
| 175 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 176 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
| 177 | - }); |
|
| 178 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
| 179 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
| 180 | - }); |
|
| 181 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
| 182 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
| 183 | - }); |
|
| 184 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
| 185 | - $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version))); |
|
| 186 | - }); |
|
| 187 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
| 188 | - $incompatibleApps[]= $app; |
|
| 189 | - }); |
|
| 190 | - $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) { |
|
| 191 | - $disabledThirdPartyApps[]= $app; |
|
| 192 | - }); |
|
| 193 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
| 194 | - $eventSource->send('failure', $message); |
|
| 195 | - $eventSource->close(); |
|
| 196 | - $config->setSystemValue('maintenance', false); |
|
| 197 | - }); |
|
| 198 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
| 199 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
| 200 | - }); |
|
| 201 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
| 202 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
| 203 | - }); |
|
| 204 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) { |
|
| 205 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
| 206 | - }); |
|
| 207 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) { |
|
| 208 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
| 209 | - }); |
|
| 210 | - |
|
| 211 | - try { |
|
| 212 | - $updater->upgrade(); |
|
| 213 | - } catch (\Exception $e) { |
|
| 214 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
| 215 | - $eventSource->close(); |
|
| 216 | - exit(); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $disabledApps = []; |
|
| 220 | - foreach ($disabledThirdPartyApps as $app) { |
|
| 221 | - $disabledApps[$app] = (string) $l->t('%s (3rdparty)', [$app]); |
|
| 222 | - } |
|
| 223 | - foreach ($incompatibleApps as $app) { |
|
| 224 | - $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if (!empty($disabledApps)) { |
|
| 228 | - $eventSource->send('notice', |
|
| 229 | - (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
| 230 | - } |
|
| 103 | + $config = \OC::$server->getSystemConfig(); |
|
| 104 | + if ($config->getValue('upgrade.disable-web', false)) { |
|
| 105 | + $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
| 106 | + $eventSource->close(); |
|
| 107 | + exit(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // if a user is currently logged in, their session must be ignored to |
|
| 111 | + // avoid side effects |
|
| 112 | + \OC_User::setIncognitoMode(true); |
|
| 113 | + |
|
| 114 | + $logger = \OC::$server->getLogger(); |
|
| 115 | + $config = \OC::$server->getConfig(); |
|
| 116 | + $updater = new \OC\Updater( |
|
| 117 | + $config, |
|
| 118 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 119 | + $logger, |
|
| 120 | + \OC::$server->query(\OC\Installer::class) |
|
| 121 | + ); |
|
| 122 | + $incompatibleApps = []; |
|
| 123 | + $disabledThirdPartyApps = []; |
|
| 124 | + |
|
| 125 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 126 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
| 127 | + if ($event instanceof GenericEvent) { |
|
| 128 | + $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 129 | + } |
|
| 130 | + }); |
|
| 131 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
| 132 | + if ($event instanceof GenericEvent) { |
|
| 133 | + $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
| 134 | + } |
|
| 135 | + }); |
|
| 136 | + $feedBack = new FeedBackHandler($eventSource, $l); |
|
| 137 | + $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 138 | + $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
| 139 | + $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
| 140 | + $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
| 141 | + $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
| 142 | + $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
| 143 | + $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
| 144 | + |
|
| 145 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
| 146 | + $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
| 147 | + }); |
|
| 148 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
| 149 | + $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
| 150 | + }); |
|
| 151 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
| 152 | + $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
| 153 | + }); |
|
| 154 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) { |
|
| 155 | + $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
| 156 | + }); |
|
| 157 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
| 158 | + $eventSource->send('success', (string)$l->t('Updated database')); |
|
| 159 | + }); |
|
| 160 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) { |
|
| 161 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
| 162 | + }); |
|
| 163 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
| 164 | + $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
| 165 | + }); |
|
| 166 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
| 167 | + $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
| 168 | + }); |
|
| 169 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
| 170 | + $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
| 171 | + }); |
|
| 172 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 173 | + $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
| 174 | + }); |
|
| 175 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
| 176 | + $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
| 177 | + }); |
|
| 178 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
| 179 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
| 180 | + }); |
|
| 181 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
| 182 | + $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
| 183 | + }); |
|
| 184 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
| 185 | + $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version))); |
|
| 186 | + }); |
|
| 187 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
| 188 | + $incompatibleApps[]= $app; |
|
| 189 | + }); |
|
| 190 | + $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) { |
|
| 191 | + $disabledThirdPartyApps[]= $app; |
|
| 192 | + }); |
|
| 193 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
| 194 | + $eventSource->send('failure', $message); |
|
| 195 | + $eventSource->close(); |
|
| 196 | + $config->setSystemValue('maintenance', false); |
|
| 197 | + }); |
|
| 198 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
| 199 | + $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
| 200 | + }); |
|
| 201 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { |
|
| 202 | + $eventSource->send('success', (string)$l->t('Reset log level')); |
|
| 203 | + }); |
|
| 204 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) { |
|
| 205 | + $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
| 206 | + }); |
|
| 207 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) { |
|
| 208 | + $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
| 209 | + }); |
|
| 210 | + |
|
| 211 | + try { |
|
| 212 | + $updater->upgrade(); |
|
| 213 | + } catch (\Exception $e) { |
|
| 214 | + $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
| 215 | + $eventSource->close(); |
|
| 216 | + exit(); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $disabledApps = []; |
|
| 220 | + foreach ($disabledThirdPartyApps as $app) { |
|
| 221 | + $disabledApps[$app] = (string) $l->t('%s (3rdparty)', [$app]); |
|
| 222 | + } |
|
| 223 | + foreach ($incompatibleApps as $app) { |
|
| 224 | + $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if (!empty($disabledApps)) { |
|
| 228 | + $eventSource->send('notice', |
|
| 229 | + (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
| 230 | + } |
|
| 231 | 231 | } else { |
| 232 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
| 232 | + $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $eventSource->send('done', ''); |
@@ -43,162 +43,162 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Install extends Command { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var SystemConfig |
|
| 48 | - */ |
|
| 49 | - private $config; |
|
| 50 | - |
|
| 51 | - public function __construct(SystemConfig $config) { |
|
| 52 | - parent::__construct(); |
|
| 53 | - $this->config = $config; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - protected function configure() { |
|
| 57 | - $this |
|
| 58 | - ->setName('maintenance:install') |
|
| 59 | - ->setDescription('install Nextcloud') |
|
| 60 | - ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite') |
|
| 61 | - ->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database') |
|
| 62 | - ->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost') |
|
| 63 | - ->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on') |
|
| 64 | - ->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database') |
|
| 65 | - ->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null) |
|
| 66 | - ->addOption('database-table-prefix', null, InputOption::VALUE_OPTIONAL, 'Prefix for all tables (default: oc_)', null) |
|
| 67 | - ->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null) |
|
| 68 | - ->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin') |
|
| 69 | - ->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account') |
|
| 70 | - ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data"); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 74 | - |
|
| 75 | - // validate the environment |
|
| 76 | - $server = \OC::$server; |
|
| 77 | - $setupHelper = new Setup( |
|
| 78 | - $this->config, |
|
| 79 | - $server->getIniWrapper(), |
|
| 80 | - $server->getL10N('lib'), |
|
| 81 | - $server->query(Defaults::class), |
|
| 82 | - $server->getLogger(), |
|
| 83 | - $server->getSecureRandom(), |
|
| 84 | - \OC::$server->query(Installer::class) |
|
| 85 | - ); |
|
| 86 | - $sysInfo = $setupHelper->getSystemInfo(true); |
|
| 87 | - $errors = $sysInfo['errors']; |
|
| 88 | - if (count($errors) > 0) { |
|
| 89 | - $this->printErrors($output, $errors); |
|
| 90 | - |
|
| 91 | - // ignore the OS X setup warning |
|
| 92 | - if(count($errors) !== 1 || |
|
| 93 | - (string)($errors[0]['error']) !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') { |
|
| 94 | - return 1; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // validate user input |
|
| 99 | - $options = $this->validateInput($input, $output, array_keys($sysInfo['databases'])); |
|
| 100 | - |
|
| 101 | - // perform installation |
|
| 102 | - $errors = $setupHelper->install($options); |
|
| 103 | - if (count($errors) > 0) { |
|
| 104 | - $this->printErrors($output, $errors); |
|
| 105 | - return 1; |
|
| 106 | - } |
|
| 107 | - $output->writeln("Nextcloud was successfully installed"); |
|
| 108 | - return 0; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param InputInterface $input |
|
| 113 | - * @param OutputInterface $output |
|
| 114 | - * @param string[] $supportedDatabases |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) { |
|
| 118 | - $db = strtolower($input->getOption('database')); |
|
| 119 | - |
|
| 120 | - if (!in_array($db, $supportedDatabases)) { |
|
| 121 | - throw new InvalidArgumentException("Database <$db> is not supported."); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $dbUser = $input->getOption('database-user'); |
|
| 125 | - $dbPass = $input->getOption('database-pass'); |
|
| 126 | - $dbName = $input->getOption('database-name'); |
|
| 127 | - $dbPort = $input->getOption('database-port'); |
|
| 128 | - if ($db === 'oci') { |
|
| 129 | - // an empty hostname needs to be read from the raw parameters |
|
| 130 | - $dbHost = $input->getParameterOption('--database-host', ''); |
|
| 131 | - } else { |
|
| 132 | - $dbHost = $input->getOption('database-host'); |
|
| 133 | - } |
|
| 134 | - $dbTablePrefix = 'oc_'; |
|
| 135 | - if ($input->hasParameterOption('--database-table-prefix')) { |
|
| 136 | - $dbTablePrefix = (string) $input->getOption('database-table-prefix'); |
|
| 137 | - $dbTablePrefix = trim($dbTablePrefix); |
|
| 138 | - } |
|
| 139 | - if ($input->hasParameterOption('--database-pass')) { |
|
| 140 | - $dbPass = (string) $input->getOption('database-pass'); |
|
| 141 | - } |
|
| 142 | - $adminLogin = $input->getOption('admin-user'); |
|
| 143 | - $adminPassword = $input->getOption('admin-pass'); |
|
| 144 | - $dataDir = $input->getOption('data-dir'); |
|
| 145 | - |
|
| 146 | - if ($db !== 'sqlite') { |
|
| 147 | - if (is_null($dbUser)) { |
|
| 148 | - throw new InvalidArgumentException("Database user not provided."); |
|
| 149 | - } |
|
| 150 | - if (is_null($dbName)) { |
|
| 151 | - throw new InvalidArgumentException("Database name not provided."); |
|
| 152 | - } |
|
| 153 | - if (is_null($dbPass)) { |
|
| 154 | - /** @var QuestionHelper $helper */ |
|
| 155 | - $helper = $this->getHelper('question'); |
|
| 156 | - $question = new Question('What is the password to access the database with user <'.$dbUser.'>?'); |
|
| 157 | - $question->setHidden(true); |
|
| 158 | - $question->setHiddenFallback(false); |
|
| 159 | - $dbPass = $helper->ask($input, $output, $question); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (is_null($adminPassword)) { |
|
| 164 | - /** @var QuestionHelper $helper */ |
|
| 165 | - $helper = $this->getHelper('question'); |
|
| 166 | - $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?'); |
|
| 167 | - $question->setHidden(true); |
|
| 168 | - $question->setHiddenFallback(false); |
|
| 169 | - $adminPassword = $helper->ask($input, $output, $question); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $options = [ |
|
| 173 | - 'dbtype' => $db, |
|
| 174 | - 'dbuser' => $dbUser, |
|
| 175 | - 'dbpass' => $dbPass, |
|
| 176 | - 'dbname' => $dbName, |
|
| 177 | - 'dbhost' => $dbHost, |
|
| 178 | - 'dbport' => $dbPort, |
|
| 179 | - 'dbtableprefix' => $dbTablePrefix, |
|
| 180 | - 'adminlogin' => $adminLogin, |
|
| 181 | - 'adminpass' => $adminPassword, |
|
| 182 | - 'directory' => $dataDir |
|
| 183 | - ]; |
|
| 184 | - if ($db === 'oci') { |
|
| 185 | - $options['dbtablespace'] = $input->getParameterOption('--database-table-space', ''); |
|
| 186 | - } |
|
| 187 | - return $options; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param OutputInterface $output |
|
| 192 | - * @param $errors |
|
| 193 | - */ |
|
| 194 | - protected function printErrors(OutputInterface $output, $errors) { |
|
| 195 | - foreach ($errors as $error) { |
|
| 196 | - if (is_array($error)) { |
|
| 197 | - $output->writeln('<error>' . (string)$error['error'] . '</error>'); |
|
| 198 | - $output->writeln('<info> -> ' . (string)$error['hint'] . '</info>'); |
|
| 199 | - } else { |
|
| 200 | - $output->writeln('<error>' . (string)$error . '</error>'); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 46 | + /** |
|
| 47 | + * @var SystemConfig |
|
| 48 | + */ |
|
| 49 | + private $config; |
|
| 50 | + |
|
| 51 | + public function __construct(SystemConfig $config) { |
|
| 52 | + parent::__construct(); |
|
| 53 | + $this->config = $config; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + protected function configure() { |
|
| 57 | + $this |
|
| 58 | + ->setName('maintenance:install') |
|
| 59 | + ->setDescription('install Nextcloud') |
|
| 60 | + ->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite') |
|
| 61 | + ->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database') |
|
| 62 | + ->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost') |
|
| 63 | + ->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on') |
|
| 64 | + ->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database') |
|
| 65 | + ->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null) |
|
| 66 | + ->addOption('database-table-prefix', null, InputOption::VALUE_OPTIONAL, 'Prefix for all tables (default: oc_)', null) |
|
| 67 | + ->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null) |
|
| 68 | + ->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin') |
|
| 69 | + ->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account') |
|
| 70 | + ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data"); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 74 | + |
|
| 75 | + // validate the environment |
|
| 76 | + $server = \OC::$server; |
|
| 77 | + $setupHelper = new Setup( |
|
| 78 | + $this->config, |
|
| 79 | + $server->getIniWrapper(), |
|
| 80 | + $server->getL10N('lib'), |
|
| 81 | + $server->query(Defaults::class), |
|
| 82 | + $server->getLogger(), |
|
| 83 | + $server->getSecureRandom(), |
|
| 84 | + \OC::$server->query(Installer::class) |
|
| 85 | + ); |
|
| 86 | + $sysInfo = $setupHelper->getSystemInfo(true); |
|
| 87 | + $errors = $sysInfo['errors']; |
|
| 88 | + if (count($errors) > 0) { |
|
| 89 | + $this->printErrors($output, $errors); |
|
| 90 | + |
|
| 91 | + // ignore the OS X setup warning |
|
| 92 | + if(count($errors) !== 1 || |
|
| 93 | + (string)($errors[0]['error']) !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') { |
|
| 94 | + return 1; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // validate user input |
|
| 99 | + $options = $this->validateInput($input, $output, array_keys($sysInfo['databases'])); |
|
| 100 | + |
|
| 101 | + // perform installation |
|
| 102 | + $errors = $setupHelper->install($options); |
|
| 103 | + if (count($errors) > 0) { |
|
| 104 | + $this->printErrors($output, $errors); |
|
| 105 | + return 1; |
|
| 106 | + } |
|
| 107 | + $output->writeln("Nextcloud was successfully installed"); |
|
| 108 | + return 0; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param InputInterface $input |
|
| 113 | + * @param OutputInterface $output |
|
| 114 | + * @param string[] $supportedDatabases |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) { |
|
| 118 | + $db = strtolower($input->getOption('database')); |
|
| 119 | + |
|
| 120 | + if (!in_array($db, $supportedDatabases)) { |
|
| 121 | + throw new InvalidArgumentException("Database <$db> is not supported."); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $dbUser = $input->getOption('database-user'); |
|
| 125 | + $dbPass = $input->getOption('database-pass'); |
|
| 126 | + $dbName = $input->getOption('database-name'); |
|
| 127 | + $dbPort = $input->getOption('database-port'); |
|
| 128 | + if ($db === 'oci') { |
|
| 129 | + // an empty hostname needs to be read from the raw parameters |
|
| 130 | + $dbHost = $input->getParameterOption('--database-host', ''); |
|
| 131 | + } else { |
|
| 132 | + $dbHost = $input->getOption('database-host'); |
|
| 133 | + } |
|
| 134 | + $dbTablePrefix = 'oc_'; |
|
| 135 | + if ($input->hasParameterOption('--database-table-prefix')) { |
|
| 136 | + $dbTablePrefix = (string) $input->getOption('database-table-prefix'); |
|
| 137 | + $dbTablePrefix = trim($dbTablePrefix); |
|
| 138 | + } |
|
| 139 | + if ($input->hasParameterOption('--database-pass')) { |
|
| 140 | + $dbPass = (string) $input->getOption('database-pass'); |
|
| 141 | + } |
|
| 142 | + $adminLogin = $input->getOption('admin-user'); |
|
| 143 | + $adminPassword = $input->getOption('admin-pass'); |
|
| 144 | + $dataDir = $input->getOption('data-dir'); |
|
| 145 | + |
|
| 146 | + if ($db !== 'sqlite') { |
|
| 147 | + if (is_null($dbUser)) { |
|
| 148 | + throw new InvalidArgumentException("Database user not provided."); |
|
| 149 | + } |
|
| 150 | + if (is_null($dbName)) { |
|
| 151 | + throw new InvalidArgumentException("Database name not provided."); |
|
| 152 | + } |
|
| 153 | + if (is_null($dbPass)) { |
|
| 154 | + /** @var QuestionHelper $helper */ |
|
| 155 | + $helper = $this->getHelper('question'); |
|
| 156 | + $question = new Question('What is the password to access the database with user <'.$dbUser.'>?'); |
|
| 157 | + $question->setHidden(true); |
|
| 158 | + $question->setHiddenFallback(false); |
|
| 159 | + $dbPass = $helper->ask($input, $output, $question); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (is_null($adminPassword)) { |
|
| 164 | + /** @var QuestionHelper $helper */ |
|
| 165 | + $helper = $this->getHelper('question'); |
|
| 166 | + $question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?'); |
|
| 167 | + $question->setHidden(true); |
|
| 168 | + $question->setHiddenFallback(false); |
|
| 169 | + $adminPassword = $helper->ask($input, $output, $question); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $options = [ |
|
| 173 | + 'dbtype' => $db, |
|
| 174 | + 'dbuser' => $dbUser, |
|
| 175 | + 'dbpass' => $dbPass, |
|
| 176 | + 'dbname' => $dbName, |
|
| 177 | + 'dbhost' => $dbHost, |
|
| 178 | + 'dbport' => $dbPort, |
|
| 179 | + 'dbtableprefix' => $dbTablePrefix, |
|
| 180 | + 'adminlogin' => $adminLogin, |
|
| 181 | + 'adminpass' => $adminPassword, |
|
| 182 | + 'directory' => $dataDir |
|
| 183 | + ]; |
|
| 184 | + if ($db === 'oci') { |
|
| 185 | + $options['dbtablespace'] = $input->getParameterOption('--database-table-space', ''); |
|
| 186 | + } |
|
| 187 | + return $options; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param OutputInterface $output |
|
| 192 | + * @param $errors |
|
| 193 | + */ |
|
| 194 | + protected function printErrors(OutputInterface $output, $errors) { |
|
| 195 | + foreach ($errors as $error) { |
|
| 196 | + if (is_array($error)) { |
|
| 197 | + $output->writeln('<error>' . (string)$error['error'] . '</error>'); |
|
| 198 | + $output->writeln('<info> -> ' . (string)$error['hint'] . '</info>'); |
|
| 199 | + } else { |
|
| 200 | + $output->writeln('<error>' . (string)$error . '</error>'); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -30,42 +30,42 @@ |
||
| 30 | 30 | |
| 31 | 31 | class Install extends Command { |
| 32 | 32 | |
| 33 | - protected function configure() { |
|
| 34 | - $this |
|
| 35 | - ->setName('app:install') |
|
| 36 | - ->setDescription('install an app') |
|
| 37 | - ->addArgument( |
|
| 38 | - 'app-id', |
|
| 39 | - InputArgument::REQUIRED, |
|
| 40 | - 'install the specified app' |
|
| 41 | - ) |
|
| 42 | - ; |
|
| 43 | - } |
|
| 33 | + protected function configure() { |
|
| 34 | + $this |
|
| 35 | + ->setName('app:install') |
|
| 36 | + ->setDescription('install an app') |
|
| 37 | + ->addArgument( |
|
| 38 | + 'app-id', |
|
| 39 | + InputArgument::REQUIRED, |
|
| 40 | + 'install the specified app' |
|
| 41 | + ) |
|
| 42 | + ; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 46 | - $appId = $input->getArgument('app-id'); |
|
| 45 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 46 | + $appId = $input->getArgument('app-id'); |
|
| 47 | 47 | |
| 48 | - if (\OC_App::getAppPath($appId)) { |
|
| 49 | - $output->writeln($appId . ' already installed'); |
|
| 50 | - return 1; |
|
| 51 | - } |
|
| 48 | + if (\OC_App::getAppPath($appId)) { |
|
| 49 | + $output->writeln($appId . ' already installed'); |
|
| 50 | + return 1; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - try { |
|
| 54 | - $installer = \OC::$server->query(Installer::class); |
|
| 55 | - $installer->downloadApp($appId); |
|
| 56 | - $result = $installer->installApp($appId); |
|
| 57 | - } catch(\Exception $e) { |
|
| 58 | - $output->writeln('Error: ' . $e->getMessage()); |
|
| 59 | - return 1; |
|
| 60 | - } |
|
| 53 | + try { |
|
| 54 | + $installer = \OC::$server->query(Installer::class); |
|
| 55 | + $installer->downloadApp($appId); |
|
| 56 | + $result = $installer->installApp($appId); |
|
| 57 | + } catch(\Exception $e) { |
|
| 58 | + $output->writeln('Error: ' . $e->getMessage()); |
|
| 59 | + return 1; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if($result === false) { |
|
| 63 | - $output->writeln($appId . ' couldn\'t be installed'); |
|
| 64 | - return 1; |
|
| 65 | - } |
|
| 62 | + if($result === false) { |
|
| 63 | + $output->writeln($appId . ' couldn\'t be installed'); |
|
| 64 | + return 1; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $output->writeln($appId . ' installed'); |
|
| 67 | + $output->writeln($appId . ' installed'); |
|
| 68 | 68 | |
| 69 | - return 0; |
|
| 70 | - } |
|
| 69 | + return 0; |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $appId = $input->getArgument('app-id'); |
| 47 | 47 | |
| 48 | 48 | if (\OC_App::getAppPath($appId)) { |
| 49 | - $output->writeln($appId . ' already installed'); |
|
| 49 | + $output->writeln($appId.' already installed'); |
|
| 50 | 50 | return 1; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | $installer = \OC::$server->query(Installer::class); |
| 55 | 55 | $installer->downloadApp($appId); |
| 56 | 56 | $result = $installer->installApp($appId); |
| 57 | - } catch(\Exception $e) { |
|
| 58 | - $output->writeln('Error: ' . $e->getMessage()); |
|
| 57 | + } catch (\Exception $e) { |
|
| 58 | + $output->writeln('Error: '.$e->getMessage()); |
|
| 59 | 59 | return 1; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if($result === false) { |
|
| 63 | - $output->writeln($appId . ' couldn\'t be installed'); |
|
| 62 | + if ($result === false) { |
|
| 63 | + $output->writeln($appId.' couldn\'t be installed'); |
|
| 64 | 64 | return 1; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $output->writeln($appId . ' installed'); |
|
| 67 | + $output->writeln($appId.' installed'); |
|
| 68 | 68 | |
| 69 | 69 | return 0; |
| 70 | 70 | } |
@@ -48,263 +48,263 @@ |
||
| 48 | 48 | |
| 49 | 49 | class Upgrade extends Command { |
| 50 | 50 | |
| 51 | - const ERROR_SUCCESS = 0; |
|
| 52 | - const ERROR_NOT_INSTALLED = 1; |
|
| 53 | - const ERROR_MAINTENANCE_MODE = 2; |
|
| 54 | - const ERROR_UP_TO_DATE = 0; |
|
| 55 | - const ERROR_INVALID_ARGUMENTS = 4; |
|
| 56 | - const ERROR_FAILURE = 5; |
|
| 51 | + const ERROR_SUCCESS = 0; |
|
| 52 | + const ERROR_NOT_INSTALLED = 1; |
|
| 53 | + const ERROR_MAINTENANCE_MODE = 2; |
|
| 54 | + const ERROR_UP_TO_DATE = 0; |
|
| 55 | + const ERROR_INVALID_ARGUMENTS = 4; |
|
| 56 | + const ERROR_FAILURE = 5; |
|
| 57 | 57 | |
| 58 | - /** @var IConfig */ |
|
| 59 | - private $config; |
|
| 58 | + /** @var IConfig */ |
|
| 59 | + private $config; |
|
| 60 | 60 | |
| 61 | - /** @var ILogger */ |
|
| 62 | - private $logger; |
|
| 61 | + /** @var ILogger */ |
|
| 62 | + private $logger; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param ILogger $logger |
|
| 67 | - * @param Installer $installer |
|
| 68 | - */ |
|
| 69 | - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
| 70 | - parent::__construct(); |
|
| 71 | - $this->config = $config; |
|
| 72 | - $this->logger = $logger; |
|
| 73 | - $this->installer = $installer; |
|
| 74 | - } |
|
| 64 | + /** |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param ILogger $logger |
|
| 67 | + * @param Installer $installer |
|
| 68 | + */ |
|
| 69 | + public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
| 70 | + parent::__construct(); |
|
| 71 | + $this->config = $config; |
|
| 72 | + $this->logger = $logger; |
|
| 73 | + $this->installer = $installer; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - protected function configure() { |
|
| 77 | - $this |
|
| 78 | - ->setName('upgrade') |
|
| 79 | - ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.') |
|
| 80 | - ->addOption( |
|
| 81 | - '--no-app-disable', |
|
| 82 | - null, |
|
| 83 | - InputOption::VALUE_NONE, |
|
| 84 | - 'skips the disable of third party apps' |
|
| 85 | - ); |
|
| 86 | - } |
|
| 76 | + protected function configure() { |
|
| 77 | + $this |
|
| 78 | + ->setName('upgrade') |
|
| 79 | + ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.') |
|
| 80 | + ->addOption( |
|
| 81 | + '--no-app-disable', |
|
| 82 | + null, |
|
| 83 | + InputOption::VALUE_NONE, |
|
| 84 | + 'skips the disable of third party apps' |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Execute the upgrade command |
|
| 90 | - * |
|
| 91 | - * @param InputInterface $input input interface |
|
| 92 | - * @param OutputInterface $output output interface |
|
| 93 | - */ |
|
| 94 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 88 | + /** |
|
| 89 | + * Execute the upgrade command |
|
| 90 | + * |
|
| 91 | + * @param InputInterface $input input interface |
|
| 92 | + * @param OutputInterface $output output interface |
|
| 93 | + */ |
|
| 94 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 95 | 95 | |
| 96 | - if(\OC::checkUpgrade(false)) { |
|
| 97 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 98 | - // Prepend each line with a little timestamp |
|
| 99 | - $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
| 100 | - $output->setFormatter($timestampFormatter); |
|
| 101 | - } |
|
| 96 | + if(\OC::checkUpgrade(false)) { |
|
| 97 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 98 | + // Prepend each line with a little timestamp |
|
| 99 | + $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
| 100 | + $output->setFormatter($timestampFormatter); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - $self = $this; |
|
| 104 | - $updater = new Updater( |
|
| 105 | - $this->config, |
|
| 106 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 107 | - $this->logger, |
|
| 108 | - $this->installer |
|
| 109 | - ); |
|
| 103 | + $self = $this; |
|
| 104 | + $updater = new Updater( |
|
| 105 | + $this->config, |
|
| 106 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 107 | + $this->logger, |
|
| 108 | + $this->installer |
|
| 109 | + ); |
|
| 110 | 110 | |
| 111 | - if ($input->getOption('no-app-disable')) { |
|
| 112 | - $updater->setSkip3rdPartyAppsDisable(true); |
|
| 113 | - } |
|
| 114 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 115 | - $progress = new ProgressBar($output); |
|
| 116 | - $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
| 117 | - $listener = function($event) use ($progress, $output) { |
|
| 118 | - if ($event instanceof GenericEvent) { |
|
| 119 | - $message = $event->getSubject(); |
|
| 120 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 121 | - $output->writeln(' Checking table ' . $message); |
|
| 122 | - } else { |
|
| 123 | - if (strlen($message) > 60) { |
|
| 124 | - $message = substr($message, 0, 57) . '...'; |
|
| 125 | - } |
|
| 126 | - $progress->setMessage($message); |
|
| 127 | - if ($event[0] === 1) { |
|
| 128 | - $output->writeln(''); |
|
| 129 | - $progress->start($event[1]); |
|
| 130 | - } |
|
| 131 | - $progress->setProgress($event[0]); |
|
| 132 | - if ($event[0] === $event[1]) { |
|
| 133 | - $progress->setMessage('Done'); |
|
| 134 | - $progress->finish(); |
|
| 135 | - $output->writeln(''); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - }; |
|
| 140 | - $repairListener = function($event) use ($progress, $output) { |
|
| 141 | - if (!$event instanceof GenericEvent) { |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - switch ($event->getSubject()) { |
|
| 145 | - case '\OC\Repair::startProgress': |
|
| 146 | - $progress->setMessage('Starting ...'); |
|
| 147 | - $output->writeln($event->getArgument(1)); |
|
| 148 | - $output->writeln(''); |
|
| 149 | - $progress->start($event->getArgument(0)); |
|
| 150 | - break; |
|
| 151 | - case '\OC\Repair::advance': |
|
| 152 | - $desc = $event->getArgument(1); |
|
| 153 | - if (!empty($desc)) { |
|
| 154 | - $progress->setMessage($desc); |
|
| 155 | - } |
|
| 156 | - $progress->advance($event->getArgument(0)); |
|
| 111 | + if ($input->getOption('no-app-disable')) { |
|
| 112 | + $updater->setSkip3rdPartyAppsDisable(true); |
|
| 113 | + } |
|
| 114 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 115 | + $progress = new ProgressBar($output); |
|
| 116 | + $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
| 117 | + $listener = function($event) use ($progress, $output) { |
|
| 118 | + if ($event instanceof GenericEvent) { |
|
| 119 | + $message = $event->getSubject(); |
|
| 120 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 121 | + $output->writeln(' Checking table ' . $message); |
|
| 122 | + } else { |
|
| 123 | + if (strlen($message) > 60) { |
|
| 124 | + $message = substr($message, 0, 57) . '...'; |
|
| 125 | + } |
|
| 126 | + $progress->setMessage($message); |
|
| 127 | + if ($event[0] === 1) { |
|
| 128 | + $output->writeln(''); |
|
| 129 | + $progress->start($event[1]); |
|
| 130 | + } |
|
| 131 | + $progress->setProgress($event[0]); |
|
| 132 | + if ($event[0] === $event[1]) { |
|
| 133 | + $progress->setMessage('Done'); |
|
| 134 | + $progress->finish(); |
|
| 135 | + $output->writeln(''); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + }; |
|
| 140 | + $repairListener = function($event) use ($progress, $output) { |
|
| 141 | + if (!$event instanceof GenericEvent) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + switch ($event->getSubject()) { |
|
| 145 | + case '\OC\Repair::startProgress': |
|
| 146 | + $progress->setMessage('Starting ...'); |
|
| 147 | + $output->writeln($event->getArgument(1)); |
|
| 148 | + $output->writeln(''); |
|
| 149 | + $progress->start($event->getArgument(0)); |
|
| 150 | + break; |
|
| 151 | + case '\OC\Repair::advance': |
|
| 152 | + $desc = $event->getArgument(1); |
|
| 153 | + if (!empty($desc)) { |
|
| 154 | + $progress->setMessage($desc); |
|
| 155 | + } |
|
| 156 | + $progress->advance($event->getArgument(0)); |
|
| 157 | 157 | |
| 158 | - break; |
|
| 159 | - case '\OC\Repair::finishProgress': |
|
| 160 | - $progress->setMessage('Done'); |
|
| 161 | - $progress->finish(); |
|
| 162 | - $output->writeln(''); |
|
| 163 | - break; |
|
| 164 | - case '\OC\Repair::step': |
|
| 165 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 166 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
| 167 | - } |
|
| 168 | - break; |
|
| 169 | - case '\OC\Repair::info': |
|
| 170 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 171 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
| 172 | - } |
|
| 173 | - break; |
|
| 174 | - case '\OC\Repair::warning': |
|
| 175 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
| 176 | - break; |
|
| 177 | - case '\OC\Repair::error': |
|
| 178 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
| 179 | - break; |
|
| 180 | - } |
|
| 181 | - }; |
|
| 158 | + break; |
|
| 159 | + case '\OC\Repair::finishProgress': |
|
| 160 | + $progress->setMessage('Done'); |
|
| 161 | + $progress->finish(); |
|
| 162 | + $output->writeln(''); |
|
| 163 | + break; |
|
| 164 | + case '\OC\Repair::step': |
|
| 165 | + if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 166 | + $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
| 167 | + } |
|
| 168 | + break; |
|
| 169 | + case '\OC\Repair::info': |
|
| 170 | + if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
| 171 | + $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
| 172 | + } |
|
| 173 | + break; |
|
| 174 | + case '\OC\Repair::warning': |
|
| 175 | + $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
| 176 | + break; |
|
| 177 | + case '\OC\Repair::error': |
|
| 178 | + $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
| 179 | + break; |
|
| 180 | + } |
|
| 181 | + }; |
|
| 182 | 182 | |
| 183 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
| 184 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
| 185 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 186 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 187 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 188 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 189 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 190 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 191 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 183 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
| 184 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
| 185 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 186 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 187 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 188 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 189 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 190 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 191 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { |
|
| 195 | - $output->writeln('<info>Turned on maintenance mode</info>'); |
|
| 196 | - }); |
|
| 197 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) { |
|
| 198 | - $output->writeln('<info>Turned off maintenance mode</info>'); |
|
| 199 | - }); |
|
| 200 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) { |
|
| 201 | - $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
| 202 | - }); |
|
| 203 | - $updater->listen('\OC\Updater', 'updateEnd', |
|
| 204 | - function ($success) use($output, $self) { |
|
| 205 | - if ($success) { |
|
| 206 | - $message = "<info>Update successful</info>"; |
|
| 207 | - } else { |
|
| 208 | - $message = "<error>Update failed</error>"; |
|
| 209 | - } |
|
| 210 | - $output->writeln($message); |
|
| 211 | - }); |
|
| 212 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) { |
|
| 213 | - $output->writeln('<info>Updating database schema</info>'); |
|
| 214 | - }); |
|
| 215 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { |
|
| 216 | - $output->writeln('<info>Updated database</info>'); |
|
| 217 | - }); |
|
| 218 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) { |
|
| 219 | - $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
|
| 220 | - }); |
|
| 221 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) { |
|
| 222 | - $output->writeln('<info>Checked database schema update</info>'); |
|
| 223 | - }); |
|
| 224 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) { |
|
| 225 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
| 226 | - }); |
|
| 227 | - $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($output) { |
|
| 228 | - $output->writeln('<comment>Disabled 3rd-party app: ' . $app . '</comment>'); |
|
| 229 | - }); |
|
| 230 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) { |
|
| 231 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
| 232 | - }); |
|
| 233 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) { |
|
| 234 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
| 235 | - }); |
|
| 236 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) { |
|
| 237 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
| 238 | - }); |
|
| 239 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
| 240 | - $output->writeln('<info>Checking updates of apps</info>'); |
|
| 241 | - }); |
|
| 242 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
| 243 | - $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
| 244 | - }); |
|
| 245 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
| 246 | - $output->writeln('<info>Checked database schema update for apps</info>'); |
|
| 247 | - }); |
|
| 248 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
| 249 | - $output->writeln("<info>Updating <$app> ...</info>"); |
|
| 250 | - }); |
|
| 251 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
| 252 | - $output->writeln("<info>Updated <$app> to $version</info>"); |
|
| 253 | - }); |
|
| 254 | - $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { |
|
| 255 | - $output->writeln("<error>$message</error>"); |
|
| 256 | - }); |
|
| 257 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
| 258 | - $output->writeln("<info>Set log level to debug</info>"); |
|
| 259 | - }); |
|
| 260 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
| 261 | - $output->writeln("<info>Reset log level</info>"); |
|
| 262 | - }); |
|
| 263 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) { |
|
| 264 | - $output->writeln("<info>Starting code integrity check...</info>"); |
|
| 265 | - }); |
|
| 266 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) { |
|
| 267 | - $output->writeln("<info>Finished code integrity check</info>"); |
|
| 268 | - }); |
|
| 194 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { |
|
| 195 | + $output->writeln('<info>Turned on maintenance mode</info>'); |
|
| 196 | + }); |
|
| 197 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) { |
|
| 198 | + $output->writeln('<info>Turned off maintenance mode</info>'); |
|
| 199 | + }); |
|
| 200 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) { |
|
| 201 | + $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
| 202 | + }); |
|
| 203 | + $updater->listen('\OC\Updater', 'updateEnd', |
|
| 204 | + function ($success) use($output, $self) { |
|
| 205 | + if ($success) { |
|
| 206 | + $message = "<info>Update successful</info>"; |
|
| 207 | + } else { |
|
| 208 | + $message = "<error>Update failed</error>"; |
|
| 209 | + } |
|
| 210 | + $output->writeln($message); |
|
| 211 | + }); |
|
| 212 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) { |
|
| 213 | + $output->writeln('<info>Updating database schema</info>'); |
|
| 214 | + }); |
|
| 215 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { |
|
| 216 | + $output->writeln('<info>Updated database</info>'); |
|
| 217 | + }); |
|
| 218 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) { |
|
| 219 | + $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
|
| 220 | + }); |
|
| 221 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) { |
|
| 222 | + $output->writeln('<info>Checked database schema update</info>'); |
|
| 223 | + }); |
|
| 224 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) { |
|
| 225 | + $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
| 226 | + }); |
|
| 227 | + $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($output) { |
|
| 228 | + $output->writeln('<comment>Disabled 3rd-party app: ' . $app . '</comment>'); |
|
| 229 | + }); |
|
| 230 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) { |
|
| 231 | + $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
| 232 | + }); |
|
| 233 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) { |
|
| 234 | + $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
| 235 | + }); |
|
| 236 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) { |
|
| 237 | + $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
| 238 | + }); |
|
| 239 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
| 240 | + $output->writeln('<info>Checking updates of apps</info>'); |
|
| 241 | + }); |
|
| 242 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
| 243 | + $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
| 244 | + }); |
|
| 245 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
| 246 | + $output->writeln('<info>Checked database schema update for apps</info>'); |
|
| 247 | + }); |
|
| 248 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
| 249 | + $output->writeln("<info>Updating <$app> ...</info>"); |
|
| 250 | + }); |
|
| 251 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
| 252 | + $output->writeln("<info>Updated <$app> to $version</info>"); |
|
| 253 | + }); |
|
| 254 | + $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { |
|
| 255 | + $output->writeln("<error>$message</error>"); |
|
| 256 | + }); |
|
| 257 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
| 258 | + $output->writeln("<info>Set log level to debug</info>"); |
|
| 259 | + }); |
|
| 260 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) { |
|
| 261 | + $output->writeln("<info>Reset log level</info>"); |
|
| 262 | + }); |
|
| 263 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) { |
|
| 264 | + $output->writeln("<info>Starting code integrity check...</info>"); |
|
| 265 | + }); |
|
| 266 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) { |
|
| 267 | + $output->writeln("<info>Finished code integrity check</info>"); |
|
| 268 | + }); |
|
| 269 | 269 | |
| 270 | - $success = $updater->upgrade(); |
|
| 270 | + $success = $updater->upgrade(); |
|
| 271 | 271 | |
| 272 | - $this->postUpgradeCheck($input, $output); |
|
| 272 | + $this->postUpgradeCheck($input, $output); |
|
| 273 | 273 | |
| 274 | - if(!$success) { |
|
| 275 | - return self::ERROR_FAILURE; |
|
| 276 | - } |
|
| 274 | + if(!$success) { |
|
| 275 | + return self::ERROR_FAILURE; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - return self::ERROR_SUCCESS; |
|
| 279 | - } else if($this->config->getSystemValue('maintenance', false)) { |
|
| 280 | - //Possible scenario: Nextcloud core is updated but an app failed |
|
| 281 | - $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
|
| 282 | - $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
| 283 | - . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
| 284 | - . 'upgrade procedure, remove the "maintenance mode" from ' |
|
| 285 | - . 'config.php and call this script again.</comment>' |
|
| 286 | - , true); |
|
| 287 | - return self::ERROR_MAINTENANCE_MODE; |
|
| 288 | - } else { |
|
| 289 | - $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
| 290 | - return self::ERROR_UP_TO_DATE; |
|
| 291 | - } |
|
| 292 | - } |
|
| 278 | + return self::ERROR_SUCCESS; |
|
| 279 | + } else if($this->config->getSystemValue('maintenance', false)) { |
|
| 280 | + //Possible scenario: Nextcloud core is updated but an app failed |
|
| 281 | + $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
|
| 282 | + $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
| 283 | + . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
| 284 | + . 'upgrade procedure, remove the "maintenance mode" from ' |
|
| 285 | + . 'config.php and call this script again.</comment>' |
|
| 286 | + , true); |
|
| 287 | + return self::ERROR_MAINTENANCE_MODE; |
|
| 288 | + } else { |
|
| 289 | + $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
| 290 | + return self::ERROR_UP_TO_DATE; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * Perform a post upgrade check (specific to the command line tool) |
|
| 296 | - * |
|
| 297 | - * @param InputInterface $input input interface |
|
| 298 | - * @param OutputInterface $output output interface |
|
| 299 | - */ |
|
| 300 | - protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
| 301 | - $trustedDomains = $this->config->getSystemValue('trusted_domains', array()); |
|
| 302 | - if (empty($trustedDomains)) { |
|
| 303 | - $output->write( |
|
| 304 | - '<warning>The setting "trusted_domains" could not be ' . |
|
| 305 | - 'set automatically by the upgrade script, ' . |
|
| 306 | - 'please set it manually</warning>' |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - } |
|
| 294 | + /** |
|
| 295 | + * Perform a post upgrade check (specific to the command line tool) |
|
| 296 | + * |
|
| 297 | + * @param InputInterface $input input interface |
|
| 298 | + * @param OutputInterface $output output interface |
|
| 299 | + */ |
|
| 300 | + protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
| 301 | + $trustedDomains = $this->config->getSystemValue('trusted_domains', array()); |
|
| 302 | + if (empty($trustedDomains)) { |
|
| 303 | + $output->write( |
|
| 304 | + '<warning>The setting "trusted_domains" could not be ' . |
|
| 305 | + 'set automatically by the upgrade script, ' . |
|
| 306 | + 'please set it manually</warning>' |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | 310 | } |
@@ -65,1445 +65,1445 @@ |
||
| 65 | 65 | use OCP\IUser; |
| 66 | 66 | |
| 67 | 67 | class OC_Util { |
| 68 | - public static $scripts = array(); |
|
| 69 | - public static $styles = array(); |
|
| 70 | - public static $headers = array(); |
|
| 71 | - private static $rootMounted = false; |
|
| 72 | - private static $fsSetup = false; |
|
| 73 | - |
|
| 74 | - /** @var array Local cache of version.php */ |
|
| 75 | - private static $versionCache = null; |
|
| 76 | - |
|
| 77 | - protected static function getAppManager() { |
|
| 78 | - return \OC::$server->getAppManager(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - private static function initLocalStorageRootFS() { |
|
| 82 | - // mount local file backend as root |
|
| 83 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 84 | - //first set up the local "root" storage |
|
| 85 | - \OC\Files\Filesystem::initMountManager(); |
|
| 86 | - if (!self::$rootMounted) { |
|
| 87 | - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 88 | - self::$rootMounted = true; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * mounting an object storage as the root fs will in essence remove the |
|
| 94 | - * necessity of a data folder being present. |
|
| 95 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 96 | - * |
|
| 97 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 98 | - * @suppress PhanDeprecatedFunction |
|
| 99 | - */ |
|
| 100 | - private static function initObjectStoreRootFS($config) { |
|
| 101 | - // check misconfiguration |
|
| 102 | - if (empty($config['class'])) { |
|
| 103 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 104 | - } |
|
| 105 | - if (!isset($config['arguments'])) { |
|
| 106 | - $config['arguments'] = array(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // instantiate object store implementation |
|
| 110 | - $name = $config['class']; |
|
| 111 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 112 | - $segments = explode('\\', $name); |
|
| 113 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 114 | - } |
|
| 115 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 116 | - // mount with plain / root object store implementation |
|
| 117 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 118 | - |
|
| 119 | - // mount object storage as root |
|
| 120 | - \OC\Files\Filesystem::initMountManager(); |
|
| 121 | - if (!self::$rootMounted) { |
|
| 122 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 123 | - self::$rootMounted = true; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * mounting an object storage as the root fs will in essence remove the |
|
| 129 | - * necessity of a data folder being present. |
|
| 130 | - * |
|
| 131 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 132 | - * @suppress PhanDeprecatedFunction |
|
| 133 | - */ |
|
| 134 | - private static function initObjectStoreMultibucketRootFS($config) { |
|
| 135 | - // check misconfiguration |
|
| 136 | - if (empty($config['class'])) { |
|
| 137 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 138 | - } |
|
| 139 | - if (!isset($config['arguments'])) { |
|
| 140 | - $config['arguments'] = array(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // instantiate object store implementation |
|
| 144 | - $name = $config['class']; |
|
| 145 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 146 | - $segments = explode('\\', $name); |
|
| 147 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - if (!isset($config['arguments']['bucket'])) { |
|
| 151 | - $config['arguments']['bucket'] = ''; |
|
| 152 | - } |
|
| 153 | - // put the root FS always in first bucket for multibucket configuration |
|
| 154 | - $config['arguments']['bucket'] .= '0'; |
|
| 155 | - |
|
| 156 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 157 | - // mount with plain / root object store implementation |
|
| 158 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 159 | - |
|
| 160 | - // mount object storage as root |
|
| 161 | - \OC\Files\Filesystem::initMountManager(); |
|
| 162 | - if (!self::$rootMounted) { |
|
| 163 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 164 | - self::$rootMounted = true; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Can be set up |
|
| 170 | - * |
|
| 171 | - * @param string $user |
|
| 172 | - * @return boolean |
|
| 173 | - * @description configure the initial filesystem based on the configuration |
|
| 174 | - * @suppress PhanDeprecatedFunction |
|
| 175 | - * @suppress PhanAccessMethodInternal |
|
| 176 | - */ |
|
| 177 | - public static function setupFS($user = '') { |
|
| 178 | - //setting up the filesystem twice can only lead to trouble |
|
| 179 | - if (self::$fsSetup) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 184 | - |
|
| 185 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 186 | - if ($user === null) { |
|
| 187 | - $user = ''; |
|
| 188 | - } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 189 | - $user = OC_User::getUser(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 193 | - OC_App::loadApps(array('filesystem')); |
|
| 194 | - |
|
| 195 | - // the filesystem will finish when $user is not empty, |
|
| 196 | - // mark fs setup here to avoid doing the setup from loading |
|
| 197 | - // OC_Filesystem |
|
| 198 | - if ($user != '') { |
|
| 199 | - self::$fsSetup = true; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - \OC\Files\Filesystem::initMountManager(); |
|
| 203 | - |
|
| 204 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 205 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 207 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 208 | - $storage->setMountOptions($mount->getOptions()); |
|
| 209 | - } |
|
| 210 | - return $storage; |
|
| 211 | - }); |
|
| 212 | - |
|
| 213 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 214 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 215 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 216 | - 'storage' => $storage, |
|
| 217 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 218 | - ]); |
|
| 219 | - } |
|
| 220 | - return $storage; |
|
| 221 | - }); |
|
| 222 | - |
|
| 223 | - // install storage availability wrapper, before most other wrappers |
|
| 224 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 225 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 226 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 227 | - } |
|
| 228 | - return $storage; |
|
| 229 | - }); |
|
| 230 | - |
|
| 231 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 232 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 233 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 234 | - } |
|
| 235 | - return $storage; |
|
| 236 | - }); |
|
| 237 | - |
|
| 238 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 239 | - // set up quota for home storages, even for other users |
|
| 240 | - // which can happen when using sharing |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @var \OC\Files\Storage\Storage $storage |
|
| 244 | - */ |
|
| 245 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 246 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 247 | - ) { |
|
| 248 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 249 | - if (is_object($storage->getUser())) { |
|
| 250 | - $user = $storage->getUser()->getUID(); |
|
| 251 | - $quota = OC_Util::getUserQuota($user); |
|
| 252 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 253 | - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $storage; |
|
| 259 | - }); |
|
| 260 | - |
|
| 261 | - OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 262 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 263 | - |
|
| 264 | - //check if we are using an object storage |
|
| 265 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 266 | - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 267 | - |
|
| 268 | - // use the same order as in ObjectHomeMountProvider |
|
| 269 | - if (isset($objectStoreMultibucket)) { |
|
| 270 | - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 271 | - } elseif (isset($objectStore)) { |
|
| 272 | - self::initObjectStoreRootFS($objectStore); |
|
| 273 | - } else { |
|
| 274 | - self::initLocalStorageRootFS(); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - if ($user != '' && !OCP\User::userExists($user)) { |
|
| 278 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - //if we aren't logged in, there is no use to set up the filesystem |
|
| 283 | - if ($user != "") { |
|
| 284 | - |
|
| 285 | - $userDir = '/' . $user . '/files'; |
|
| 286 | - |
|
| 287 | - //jail the user into his "home" directory |
|
| 288 | - \OC\Files\Filesystem::init($user, $userDir); |
|
| 289 | - |
|
| 290 | - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 291 | - } |
|
| 292 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 293 | - return true; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * check if a password is required for each public link |
|
| 298 | - * |
|
| 299 | - * @return boolean |
|
| 300 | - * @suppress PhanDeprecatedFunction |
|
| 301 | - */ |
|
| 302 | - public static function isPublicLinkPasswordRequired() { |
|
| 303 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 304 | - $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 305 | - return ($enforcePassword === 'yes') ? true : false; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * check if sharing is disabled for the current user |
|
| 310 | - * @param IConfig $config |
|
| 311 | - * @param IGroupManager $groupManager |
|
| 312 | - * @param IUser|null $user |
|
| 313 | - * @return bool |
|
| 314 | - */ |
|
| 315 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 316 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 317 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 318 | - $excludedGroups = json_decode($groupsList); |
|
| 319 | - if (is_null($excludedGroups)) { |
|
| 320 | - $excludedGroups = explode(',', $groupsList); |
|
| 321 | - $newValue = json_encode($excludedGroups); |
|
| 322 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 323 | - } |
|
| 324 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 325 | - if (!empty($usersGroups)) { |
|
| 326 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 327 | - // if the user is only in groups which are disabled for sharing then |
|
| 328 | - // sharing is also disabled for the user |
|
| 329 | - if (empty($remainingGroups)) { |
|
| 330 | - return true; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * check if share API enforces a default expire date |
|
| 339 | - * |
|
| 340 | - * @return boolean |
|
| 341 | - * @suppress PhanDeprecatedFunction |
|
| 342 | - */ |
|
| 343 | - public static function isDefaultExpireDateEnforced() { |
|
| 344 | - $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 345 | - $enforceDefaultExpireDate = false; |
|
| 346 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 347 | - $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 348 | - $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $enforceDefaultExpireDate; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Get the quota of a user |
|
| 356 | - * |
|
| 357 | - * @param string $userId |
|
| 358 | - * @return float Quota bytes |
|
| 359 | - */ |
|
| 360 | - public static function getUserQuota($userId) { |
|
| 361 | - $user = \OC::$server->getUserManager()->get($userId); |
|
| 362 | - if (is_null($user)) { |
|
| 363 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 364 | - } |
|
| 365 | - $userQuota = $user->getQuota(); |
|
| 366 | - if($userQuota === 'none') { |
|
| 367 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 368 | - } |
|
| 369 | - return OC_Helper::computerFileSize($userQuota); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * copies the skeleton to the users /files |
|
| 374 | - * |
|
| 375 | - * @param String $userId |
|
| 376 | - * @param \OCP\Files\Folder $userDirectory |
|
| 377 | - * @throws \RuntimeException |
|
| 378 | - * @suppress PhanDeprecatedFunction |
|
| 379 | - */ |
|
| 380 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 381 | - |
|
| 382 | - $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 383 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 384 | - |
|
| 385 | - if ($instanceId === null) { |
|
| 386 | - throw new \RuntimeException('no instance id!'); |
|
| 387 | - } |
|
| 388 | - $appdata = 'appdata_' . $instanceId; |
|
| 389 | - if ($userId === $appdata) { |
|
| 390 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (!empty($skeletonDirectory)) { |
|
| 394 | - \OCP\Util::writeLog( |
|
| 395 | - 'files_skeleton', |
|
| 396 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 397 | - \OCP\Util::DEBUG |
|
| 398 | - ); |
|
| 399 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 400 | - // update the file cache |
|
| 401 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * copies a directory recursively by using streams |
|
| 407 | - * |
|
| 408 | - * @param string $source |
|
| 409 | - * @param \OCP\Files\Folder $target |
|
| 410 | - * @return void |
|
| 411 | - */ |
|
| 412 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 413 | - $logger = \OC::$server->getLogger(); |
|
| 414 | - |
|
| 415 | - // Verify if folder exists |
|
| 416 | - $dir = opendir($source); |
|
| 417 | - if($dir === false) { |
|
| 418 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 419 | - return; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - // Copy the files |
|
| 423 | - while (false !== ($file = readdir($dir))) { |
|
| 424 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 425 | - if (is_dir($source . '/' . $file)) { |
|
| 426 | - $child = $target->newFolder($file); |
|
| 427 | - self::copyr($source . '/' . $file, $child); |
|
| 428 | - } else { |
|
| 429 | - $child = $target->newFile($file); |
|
| 430 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 431 | - if($sourceStream === false) { |
|
| 432 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 433 | - closedir($dir); |
|
| 434 | - return; |
|
| 435 | - } |
|
| 436 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - closedir($dir); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * @return void |
|
| 445 | - * @suppress PhanUndeclaredMethod |
|
| 446 | - */ |
|
| 447 | - public static function tearDownFS() { |
|
| 448 | - \OC\Files\Filesystem::tearDown(); |
|
| 449 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 450 | - self::$fsSetup = false; |
|
| 451 | - self::$rootMounted = false; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * get the current installed version of ownCloud |
|
| 456 | - * |
|
| 457 | - * @return array |
|
| 458 | - */ |
|
| 459 | - public static function getVersion() { |
|
| 460 | - OC_Util::loadVersion(); |
|
| 461 | - return self::$versionCache['OC_Version']; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * get the current installed version string of ownCloud |
|
| 466 | - * |
|
| 467 | - * @return string |
|
| 468 | - */ |
|
| 469 | - public static function getVersionString() { |
|
| 470 | - OC_Util::loadVersion(); |
|
| 471 | - return self::$versionCache['OC_VersionString']; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * @deprecated the value is of no use anymore |
|
| 476 | - * @return string |
|
| 477 | - */ |
|
| 478 | - public static function getEditionString() { |
|
| 479 | - return ''; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @description get the update channel of the current installed of ownCloud. |
|
| 484 | - * @return string |
|
| 485 | - */ |
|
| 486 | - public static function getChannel() { |
|
| 487 | - OC_Util::loadVersion(); |
|
| 488 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @description get the build number of the current installed of ownCloud. |
|
| 493 | - * @return string |
|
| 494 | - */ |
|
| 495 | - public static function getBuild() { |
|
| 496 | - OC_Util::loadVersion(); |
|
| 497 | - return self::$versionCache['OC_Build']; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @description load the version.php into the session as cache |
|
| 502 | - * @suppress PhanUndeclaredVariable |
|
| 503 | - */ |
|
| 504 | - private static function loadVersion() { |
|
| 505 | - if (self::$versionCache !== null) { |
|
| 506 | - return; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 510 | - require OC::$SERVERROOT . '/version.php'; |
|
| 511 | - /** @var $timestamp int */ |
|
| 512 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 513 | - /** @var $OC_Version string */ |
|
| 514 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 515 | - /** @var $OC_VersionString string */ |
|
| 516 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 517 | - /** @var $OC_Build string */ |
|
| 518 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 519 | - |
|
| 520 | - /** @var $OC_Channel string */ |
|
| 521 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 526 | - * |
|
| 527 | - * @param string $application application to get the files from |
|
| 528 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 529 | - * @param string $file the file inside of the above folder |
|
| 530 | - * @return string the path |
|
| 531 | - */ |
|
| 532 | - private static function generatePath($application, $directory, $file) { |
|
| 533 | - if (is_null($file)) { |
|
| 534 | - $file = $application; |
|
| 535 | - $application = ""; |
|
| 536 | - } |
|
| 537 | - if (!empty($application)) { |
|
| 538 | - return "$application/$directory/$file"; |
|
| 539 | - } else { |
|
| 540 | - return "$directory/$file"; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * add a javascript file |
|
| 546 | - * |
|
| 547 | - * @param string $application application id |
|
| 548 | - * @param string|null $file filename |
|
| 549 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 550 | - * @return void |
|
| 551 | - */ |
|
| 552 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 553 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 554 | - |
|
| 555 | - // core js files need separate handling |
|
| 556 | - if ($application !== 'core' && $file !== null) { |
|
| 557 | - self::addTranslations ( $application ); |
|
| 558 | - } |
|
| 559 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * add a javascript file from the vendor sub folder |
|
| 564 | - * |
|
| 565 | - * @param string $application application id |
|
| 566 | - * @param string|null $file filename |
|
| 567 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 568 | - * @return void |
|
| 569 | - */ |
|
| 570 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 571 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 572 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * add a translation JS file |
|
| 577 | - * |
|
| 578 | - * @param string $application application id |
|
| 579 | - * @param string|null $languageCode language code, defaults to the current language |
|
| 580 | - * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 581 | - */ |
|
| 582 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 583 | - if (is_null($languageCode)) { |
|
| 584 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 585 | - } |
|
| 586 | - if (!empty($application)) { |
|
| 587 | - $path = "$application/l10n/$languageCode"; |
|
| 588 | - } else { |
|
| 589 | - $path = "l10n/$languageCode"; |
|
| 590 | - } |
|
| 591 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * add a css file |
|
| 596 | - * |
|
| 597 | - * @param string $application application id |
|
| 598 | - * @param string|null $file filename |
|
| 599 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 603 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 604 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * add a css file from the vendor sub folder |
|
| 609 | - * |
|
| 610 | - * @param string $application application id |
|
| 611 | - * @param string|null $file filename |
|
| 612 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 613 | - * @return void |
|
| 614 | - */ |
|
| 615 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 616 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 617 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * add an external resource css/js file |
|
| 622 | - * |
|
| 623 | - * @param string $application application id |
|
| 624 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 625 | - * @param string $path |
|
| 626 | - * @param string $type (script or style) |
|
| 627 | - * @return void |
|
| 628 | - */ |
|
| 629 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 630 | - |
|
| 631 | - if ($type === "style") { |
|
| 632 | - if (!in_array($path, self::$styles)) { |
|
| 633 | - if ($prepend === true) { |
|
| 634 | - array_unshift ( self::$styles, $path ); |
|
| 635 | - } else { |
|
| 636 | - self::$styles[] = $path; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - } elseif ($type === "script") { |
|
| 640 | - if (!in_array($path, self::$scripts)) { |
|
| 641 | - if ($prepend === true) { |
|
| 642 | - array_unshift ( self::$scripts, $path ); |
|
| 643 | - } else { |
|
| 644 | - self::$scripts [] = $path; |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * Add a custom element to the header |
|
| 652 | - * If $text is null then the element will be written as empty element. |
|
| 653 | - * So use "" to get a closing tag. |
|
| 654 | - * @param string $tag tag name of the element |
|
| 655 | - * @param array $attributes array of attributes for the element |
|
| 656 | - * @param string $text the text content for the element |
|
| 657 | - */ |
|
| 658 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 659 | - self::$headers[] = array( |
|
| 660 | - 'tag' => $tag, |
|
| 661 | - 'attributes' => $attributes, |
|
| 662 | - 'text' => $text |
|
| 663 | - ); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * formats a timestamp in the "right" way |
|
| 668 | - * |
|
| 669 | - * @param int $timestamp |
|
| 670 | - * @param bool $dateOnly option to omit time from the result |
|
| 671 | - * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 672 | - * @return string timestamp |
|
| 673 | - * |
|
| 674 | - * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 675 | - */ |
|
| 676 | - public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 677 | - if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 678 | - $timeZone = new \DateTimeZone($timeZone); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** @var \OC\DateTimeFormatter $formatter */ |
|
| 682 | - $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 683 | - if ($dateOnly) { |
|
| 684 | - return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 685 | - } |
|
| 686 | - return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * check if the current server configuration is suitable for ownCloud |
|
| 691 | - * |
|
| 692 | - * @param \OC\SystemConfig $config |
|
| 693 | - * @return array arrays with error messages and hints |
|
| 694 | - */ |
|
| 695 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 696 | - $l = \OC::$server->getL10N('lib'); |
|
| 697 | - $errors = array(); |
|
| 698 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 699 | - |
|
| 700 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 701 | - // this check needs to be done every time |
|
| 702 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 706 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 707 | - return $errors; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - $webServerRestart = false; |
|
| 711 | - $setup = new \OC\Setup( |
|
| 712 | - $config, |
|
| 713 | - \OC::$server->getIniWrapper(), |
|
| 714 | - \OC::$server->getL10N('lib'), |
|
| 715 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 716 | - \OC::$server->getLogger(), |
|
| 717 | - \OC::$server->getSecureRandom(), |
|
| 718 | - \OC::$server->query(\OC\Installer::class) |
|
| 719 | - ); |
|
| 720 | - |
|
| 721 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 722 | - |
|
| 723 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 724 | - if (empty($availableDatabases)) { |
|
| 725 | - $errors[] = array( |
|
| 726 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 727 | - 'hint' => '' //TODO: sane hint |
|
| 728 | - ); |
|
| 729 | - $webServerRestart = true; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - // Check if config folder is writable. |
|
| 733 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 734 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 735 | - $errors[] = array( |
|
| 736 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
| 737 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 738 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 739 | - ); |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Check if there is a writable install folder. |
|
| 744 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 745 | - if (OC_App::getInstallPath() === null |
|
| 746 | - || !is_writable(OC_App::getInstallPath()) |
|
| 747 | - || !is_readable(OC_App::getInstallPath()) |
|
| 748 | - ) { |
|
| 749 | - $errors[] = array( |
|
| 750 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 751 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 752 | - . ' or disabling the appstore in the config file. See %s', |
|
| 753 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 754 | - ); |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - // Create root dir. |
|
| 758 | - if ($config->getValue('installed', false)) { |
|
| 759 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 760 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 761 | - if ($success) { |
|
| 762 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 763 | - } else { |
|
| 764 | - $errors[] = [ |
|
| 765 | - 'error' => $l->t('Cannot create "data" directory'), |
|
| 766 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 767 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 768 | - ]; |
|
| 769 | - } |
|
| 770 | - } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 771 | - //common hint for all file permissions error messages |
|
| 772 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 773 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 774 | - $errors[] = [ |
|
| 775 | - 'error' => 'Your data directory is not writable', |
|
| 776 | - 'hint' => $permissionsHint |
|
| 777 | - ]; |
|
| 778 | - } else { |
|
| 779 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 784 | - $errors[] = array( |
|
| 785 | - 'error' => $l->t('Setting locale to %s failed', |
|
| 786 | - array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 787 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 788 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 789 | - ); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - // Contains the dependencies that should be checked against |
|
| 793 | - // classes = class_exists |
|
| 794 | - // functions = function_exists |
|
| 795 | - // defined = defined |
|
| 796 | - // ini = ini_get |
|
| 797 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 798 | - // When adding new checks always verify that they pass on Travis as well |
|
| 799 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 800 | - $dependencies = array( |
|
| 801 | - 'classes' => array( |
|
| 802 | - 'ZipArchive' => 'zip', |
|
| 803 | - 'DOMDocument' => 'dom', |
|
| 804 | - 'XMLWriter' => 'XMLWriter', |
|
| 805 | - 'XMLReader' => 'XMLReader', |
|
| 806 | - ), |
|
| 807 | - 'functions' => [ |
|
| 808 | - 'xml_parser_create' => 'libxml', |
|
| 809 | - 'mb_strcut' => 'mb multibyte', |
|
| 810 | - 'ctype_digit' => 'ctype', |
|
| 811 | - 'json_encode' => 'JSON', |
|
| 812 | - 'gd_info' => 'GD', |
|
| 813 | - 'gzencode' => 'zlib', |
|
| 814 | - 'iconv' => 'iconv', |
|
| 815 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 816 | - 'hash' => 'HASH Message Digest Framework', |
|
| 817 | - 'curl_init' => 'cURL', |
|
| 818 | - 'openssl_verify' => 'OpenSSL', |
|
| 819 | - ], |
|
| 820 | - 'defined' => array( |
|
| 821 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 822 | - ), |
|
| 823 | - 'ini' => [ |
|
| 824 | - 'default_charset' => 'UTF-8', |
|
| 825 | - ], |
|
| 826 | - ); |
|
| 827 | - $missingDependencies = array(); |
|
| 828 | - $invalidIniSettings = []; |
|
| 829 | - $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 833 | - * and prevents installation. Once HHVM is more compatible with our |
|
| 834 | - * approach to check for these values we should re-enable those |
|
| 835 | - * checks. |
|
| 836 | - */ |
|
| 837 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 838 | - if (!self::runningOnHhvm()) { |
|
| 839 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 840 | - if (!class_exists($class)) { |
|
| 841 | - $missingDependencies[] = $module; |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 845 | - if (!function_exists($function)) { |
|
| 846 | - $missingDependencies[] = $module; |
|
| 847 | - } |
|
| 848 | - } |
|
| 849 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 850 | - if (!defined($defined)) { |
|
| 851 | - $missingDependencies[] = $module; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 855 | - if (is_bool($expected)) { |
|
| 856 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 857 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - if (is_int($expected)) { |
|
| 861 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 862 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - if (is_string($expected)) { |
|
| 866 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 867 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - foreach($missingDependencies as $missingDependency) { |
|
| 874 | - $errors[] = array( |
|
| 875 | - 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 876 | - 'hint' => $moduleHint |
|
| 877 | - ); |
|
| 878 | - $webServerRestart = true; |
|
| 879 | - } |
|
| 880 | - foreach($invalidIniSettings as $setting) { |
|
| 881 | - if(is_bool($setting[1])) { |
|
| 882 | - $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 883 | - } |
|
| 884 | - $errors[] = [ |
|
| 885 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 886 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 887 | - ]; |
|
| 888 | - $webServerRestart = true; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 893 | - * module is installed as it will return null if the checking setting is |
|
| 894 | - * not available and thus a check on the boolean value fails. |
|
| 895 | - * |
|
| 896 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 897 | - * check somehow in the long-term. |
|
| 898 | - */ |
|
| 899 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 900 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 901 | - $errors[] = array( |
|
| 902 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 903 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 904 | - ); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - if(function_exists('xml_parser_create') && |
|
| 908 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 909 | - $version = LIBXML_LOADED_VERSION; |
|
| 910 | - $major = floor($version/10000); |
|
| 911 | - $version -= ($major * 10000); |
|
| 912 | - $minor = floor($version/100); |
|
| 913 | - $version -= ($minor * 100); |
|
| 914 | - $patch = $version; |
|
| 915 | - $errors[] = array( |
|
| 916 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 917 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 918 | - ); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - if (!self::isAnnotationsWorking()) { |
|
| 922 | - $errors[] = array( |
|
| 923 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 924 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 925 | - ); |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 929 | - $errors[] = array( |
|
| 930 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 931 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 932 | - ); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 936 | - |
|
| 937 | - // Cache the result of this function |
|
| 938 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 939 | - |
|
| 940 | - return $errors; |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * Check the database version |
|
| 945 | - * |
|
| 946 | - * @return array errors array |
|
| 947 | - */ |
|
| 948 | - public static function checkDatabaseVersion() { |
|
| 949 | - $l = \OC::$server->getL10N('lib'); |
|
| 950 | - $errors = array(); |
|
| 951 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 952 | - if ($dbType === 'pgsql') { |
|
| 953 | - // check PostgreSQL version |
|
| 954 | - try { |
|
| 955 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 956 | - $data = $result->fetchRow(); |
|
| 957 | - if (isset($data['server_version'])) { |
|
| 958 | - $version = $data['server_version']; |
|
| 959 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 960 | - $errors[] = array( |
|
| 961 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 962 | - 'hint' => $l->t('Please upgrade your database version') |
|
| 963 | - ); |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 967 | - $logger = \OC::$server->getLogger(); |
|
| 968 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 969 | - $logger->logException($e); |
|
| 970 | - } |
|
| 971 | - } |
|
| 972 | - return $errors; |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - /** |
|
| 976 | - * Check for correct file permissions of data directory |
|
| 977 | - * |
|
| 978 | - * @param string $dataDirectory |
|
| 979 | - * @return array arrays with error messages and hints |
|
| 980 | - */ |
|
| 981 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 982 | - $l = \OC::$server->getL10N('lib'); |
|
| 983 | - $errors = array(); |
|
| 984 | - $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 985 | - . ' cannot be listed by other users.'); |
|
| 986 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 987 | - if (substr($perms, -1) !== '0') { |
|
| 988 | - chmod($dataDirectory, 0770); |
|
| 989 | - clearstatcache(); |
|
| 990 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 991 | - if ($perms[2] !== '0') { |
|
| 992 | - $errors[] = [ |
|
| 993 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
| 994 | - 'hint' => $permissionsModHint |
|
| 995 | - ]; |
|
| 996 | - } |
|
| 997 | - } |
|
| 998 | - return $errors; |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * Check that the data directory exists and is valid by |
|
| 1003 | - * checking the existence of the ".ocdata" file. |
|
| 1004 | - * |
|
| 1005 | - * @param string $dataDirectory data directory path |
|
| 1006 | - * @return array errors found |
|
| 1007 | - */ |
|
| 1008 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 1009 | - $l = \OC::$server->getL10N('lib'); |
|
| 1010 | - $errors = []; |
|
| 1011 | - if ($dataDirectory[0] !== '/') { |
|
| 1012 | - $errors[] = [ |
|
| 1013 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 1014 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 1015 | - ]; |
|
| 1016 | - } |
|
| 1017 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1018 | - $errors[] = [ |
|
| 1019 | - 'error' => $l->t('Your data directory is invalid'), |
|
| 1020 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1021 | - ' in the root of the data directory.') |
|
| 1022 | - ]; |
|
| 1023 | - } |
|
| 1024 | - return $errors; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * Check if the user is logged in, redirects to home if not. With |
|
| 1029 | - * redirect URL parameter to the request URI. |
|
| 1030 | - * |
|
| 1031 | - * @return void |
|
| 1032 | - */ |
|
| 1033 | - public static function checkLoggedIn() { |
|
| 1034 | - // Check if we are a user |
|
| 1035 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1036 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1037 | - 'core.login.showLoginForm', |
|
| 1038 | - [ |
|
| 1039 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1040 | - ] |
|
| 1041 | - ) |
|
| 1042 | - ); |
|
| 1043 | - exit(); |
|
| 1044 | - } |
|
| 1045 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1046 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1047 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1048 | - exit(); |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * Check if the user is a admin, redirects to home if not |
|
| 1054 | - * |
|
| 1055 | - * @return void |
|
| 1056 | - */ |
|
| 1057 | - public static function checkAdminUser() { |
|
| 1058 | - OC_Util::checkLoggedIn(); |
|
| 1059 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1060 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1061 | - exit(); |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Check if the user is a subadmin, redirects to home if not |
|
| 1067 | - * |
|
| 1068 | - * @return null|boolean $groups where the current user is subadmin |
|
| 1069 | - */ |
|
| 1070 | - public static function checkSubAdminUser() { |
|
| 1071 | - OC_Util::checkLoggedIn(); |
|
| 1072 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1073 | - $isSubAdmin = false; |
|
| 1074 | - if($userObject !== null) { |
|
| 1075 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - if (!$isSubAdmin) { |
|
| 1079 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1080 | - exit(); |
|
| 1081 | - } |
|
| 1082 | - return true; |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Returns the URL of the default page |
|
| 1087 | - * based on the system configuration and |
|
| 1088 | - * the apps visible for the current user |
|
| 1089 | - * |
|
| 1090 | - * @return string URL |
|
| 1091 | - * @suppress PhanDeprecatedFunction |
|
| 1092 | - */ |
|
| 1093 | - public static function getDefaultPageUrl() { |
|
| 1094 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1095 | - // Deny the redirect if the URL contains a @ |
|
| 1096 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1097 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1098 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1099 | - } else { |
|
| 1100 | - $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1101 | - if ($defaultPage) { |
|
| 1102 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1103 | - } else { |
|
| 1104 | - $appId = 'files'; |
|
| 1105 | - $config = \OC::$server->getConfig(); |
|
| 1106 | - $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'files')); |
|
| 1107 | - // find the first app that is enabled for the current user |
|
| 1108 | - foreach ($defaultApps as $defaultApp) { |
|
| 1109 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1110 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1111 | - $appId = $defaultApp; |
|
| 1112 | - break; |
|
| 1113 | - } |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1117 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1118 | - } else { |
|
| 1119 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1120 | - } |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - return $location; |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - /** |
|
| 1127 | - * Redirect to the user default page |
|
| 1128 | - * |
|
| 1129 | - * @return void |
|
| 1130 | - */ |
|
| 1131 | - public static function redirectToDefaultPage() { |
|
| 1132 | - $location = self::getDefaultPageUrl(); |
|
| 1133 | - header('Location: ' . $location); |
|
| 1134 | - exit(); |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * get an id unique for this instance |
|
| 1139 | - * |
|
| 1140 | - * @return string |
|
| 1141 | - */ |
|
| 1142 | - public static function getInstanceId() { |
|
| 1143 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1144 | - if (is_null($id)) { |
|
| 1145 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1146 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1147 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1148 | - } |
|
| 1149 | - return $id; |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * Public function to sanitize HTML |
|
| 1154 | - * |
|
| 1155 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1156 | - * string or array of strings before displaying it on a web page. |
|
| 1157 | - * |
|
| 1158 | - * @param string|array $value |
|
| 1159 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1160 | - */ |
|
| 1161 | - public static function sanitizeHTML($value) { |
|
| 1162 | - if (is_array($value)) { |
|
| 1163 | - $value = array_map(function($value) { |
|
| 1164 | - return self::sanitizeHTML($value); |
|
| 1165 | - }, $value); |
|
| 1166 | - } else { |
|
| 1167 | - // Specify encoding for PHP<5.4 |
|
| 1168 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1169 | - } |
|
| 1170 | - return $value; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - /** |
|
| 1174 | - * Public function to encode url parameters |
|
| 1175 | - * |
|
| 1176 | - * This function is used to encode path to file before output. |
|
| 1177 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1178 | - * Character '/' is preserved as is. |
|
| 1179 | - * |
|
| 1180 | - * @param string $component part of URI to encode |
|
| 1181 | - * @return string |
|
| 1182 | - */ |
|
| 1183 | - public static function encodePath($component) { |
|
| 1184 | - $encoded = rawurlencode($component); |
|
| 1185 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1186 | - return $encoded; |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - |
|
| 1190 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1191 | - // php dev server does not support htaccess |
|
| 1192 | - if (php_sapi_name() === 'cli-server') { |
|
| 1193 | - return false; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - // testdata |
|
| 1197 | - $fileName = '/htaccesstest.txt'; |
|
| 1198 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1199 | - |
|
| 1200 | - // creating a test file |
|
| 1201 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1202 | - |
|
| 1203 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1204 | - return false; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - $fp = @fopen($testFile, 'w'); |
|
| 1208 | - if (!$fp) { |
|
| 1209 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1210 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1211 | - } |
|
| 1212 | - fwrite($fp, $testContent); |
|
| 1213 | - fclose($fp); |
|
| 1214 | - |
|
| 1215 | - return $testContent; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Check if the .htaccess file is working |
|
| 1220 | - * @param \OCP\IConfig $config |
|
| 1221 | - * @return bool |
|
| 1222 | - * @throws Exception |
|
| 1223 | - * @throws \OC\HintException If the test file can't get written. |
|
| 1224 | - */ |
|
| 1225 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1226 | - |
|
| 1227 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1228 | - return true; |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1232 | - if ($testContent === false) { |
|
| 1233 | - return false; |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - $fileName = '/htaccesstest.txt'; |
|
| 1237 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1238 | - |
|
| 1239 | - // accessing the file via http |
|
| 1240 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1241 | - try { |
|
| 1242 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1243 | - } catch (\Exception $e) { |
|
| 1244 | - $content = false; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - // cleanup |
|
| 1248 | - @unlink($testFile); |
|
| 1249 | - |
|
| 1250 | - /* |
|
| 68 | + public static $scripts = array(); |
|
| 69 | + public static $styles = array(); |
|
| 70 | + public static $headers = array(); |
|
| 71 | + private static $rootMounted = false; |
|
| 72 | + private static $fsSetup = false; |
|
| 73 | + |
|
| 74 | + /** @var array Local cache of version.php */ |
|
| 75 | + private static $versionCache = null; |
|
| 76 | + |
|
| 77 | + protected static function getAppManager() { |
|
| 78 | + return \OC::$server->getAppManager(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + private static function initLocalStorageRootFS() { |
|
| 82 | + // mount local file backend as root |
|
| 83 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 84 | + //first set up the local "root" storage |
|
| 85 | + \OC\Files\Filesystem::initMountManager(); |
|
| 86 | + if (!self::$rootMounted) { |
|
| 87 | + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 88 | + self::$rootMounted = true; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * mounting an object storage as the root fs will in essence remove the |
|
| 94 | + * necessity of a data folder being present. |
|
| 95 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 96 | + * |
|
| 97 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 98 | + * @suppress PhanDeprecatedFunction |
|
| 99 | + */ |
|
| 100 | + private static function initObjectStoreRootFS($config) { |
|
| 101 | + // check misconfiguration |
|
| 102 | + if (empty($config['class'])) { |
|
| 103 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 104 | + } |
|
| 105 | + if (!isset($config['arguments'])) { |
|
| 106 | + $config['arguments'] = array(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // instantiate object store implementation |
|
| 110 | + $name = $config['class']; |
|
| 111 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 112 | + $segments = explode('\\', $name); |
|
| 113 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 114 | + } |
|
| 115 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 116 | + // mount with plain / root object store implementation |
|
| 117 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 118 | + |
|
| 119 | + // mount object storage as root |
|
| 120 | + \OC\Files\Filesystem::initMountManager(); |
|
| 121 | + if (!self::$rootMounted) { |
|
| 122 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 123 | + self::$rootMounted = true; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * mounting an object storage as the root fs will in essence remove the |
|
| 129 | + * necessity of a data folder being present. |
|
| 130 | + * |
|
| 131 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 132 | + * @suppress PhanDeprecatedFunction |
|
| 133 | + */ |
|
| 134 | + private static function initObjectStoreMultibucketRootFS($config) { |
|
| 135 | + // check misconfiguration |
|
| 136 | + if (empty($config['class'])) { |
|
| 137 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 138 | + } |
|
| 139 | + if (!isset($config['arguments'])) { |
|
| 140 | + $config['arguments'] = array(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // instantiate object store implementation |
|
| 144 | + $name = $config['class']; |
|
| 145 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 146 | + $segments = explode('\\', $name); |
|
| 147 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + if (!isset($config['arguments']['bucket'])) { |
|
| 151 | + $config['arguments']['bucket'] = ''; |
|
| 152 | + } |
|
| 153 | + // put the root FS always in first bucket for multibucket configuration |
|
| 154 | + $config['arguments']['bucket'] .= '0'; |
|
| 155 | + |
|
| 156 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 157 | + // mount with plain / root object store implementation |
|
| 158 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 159 | + |
|
| 160 | + // mount object storage as root |
|
| 161 | + \OC\Files\Filesystem::initMountManager(); |
|
| 162 | + if (!self::$rootMounted) { |
|
| 163 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 164 | + self::$rootMounted = true; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Can be set up |
|
| 170 | + * |
|
| 171 | + * @param string $user |
|
| 172 | + * @return boolean |
|
| 173 | + * @description configure the initial filesystem based on the configuration |
|
| 174 | + * @suppress PhanDeprecatedFunction |
|
| 175 | + * @suppress PhanAccessMethodInternal |
|
| 176 | + */ |
|
| 177 | + public static function setupFS($user = '') { |
|
| 178 | + //setting up the filesystem twice can only lead to trouble |
|
| 179 | + if (self::$fsSetup) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 184 | + |
|
| 185 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 186 | + if ($user === null) { |
|
| 187 | + $user = ''; |
|
| 188 | + } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 189 | + $user = OC_User::getUser(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 193 | + OC_App::loadApps(array('filesystem')); |
|
| 194 | + |
|
| 195 | + // the filesystem will finish when $user is not empty, |
|
| 196 | + // mark fs setup here to avoid doing the setup from loading |
|
| 197 | + // OC_Filesystem |
|
| 198 | + if ($user != '') { |
|
| 199 | + self::$fsSetup = true; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + \OC\Files\Filesystem::initMountManager(); |
|
| 203 | + |
|
| 204 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 205 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 207 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 208 | + $storage->setMountOptions($mount->getOptions()); |
|
| 209 | + } |
|
| 210 | + return $storage; |
|
| 211 | + }); |
|
| 212 | + |
|
| 213 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 214 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 215 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 216 | + 'storage' => $storage, |
|
| 217 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 218 | + ]); |
|
| 219 | + } |
|
| 220 | + return $storage; |
|
| 221 | + }); |
|
| 222 | + |
|
| 223 | + // install storage availability wrapper, before most other wrappers |
|
| 224 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 225 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 226 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 227 | + } |
|
| 228 | + return $storage; |
|
| 229 | + }); |
|
| 230 | + |
|
| 231 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 232 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 233 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 234 | + } |
|
| 235 | + return $storage; |
|
| 236 | + }); |
|
| 237 | + |
|
| 238 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 239 | + // set up quota for home storages, even for other users |
|
| 240 | + // which can happen when using sharing |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @var \OC\Files\Storage\Storage $storage |
|
| 244 | + */ |
|
| 245 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 246 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 247 | + ) { |
|
| 248 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 249 | + if (is_object($storage->getUser())) { |
|
| 250 | + $user = $storage->getUser()->getUID(); |
|
| 251 | + $quota = OC_Util::getUserQuota($user); |
|
| 252 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 253 | + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $storage; |
|
| 259 | + }); |
|
| 260 | + |
|
| 261 | + OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 262 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 263 | + |
|
| 264 | + //check if we are using an object storage |
|
| 265 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 266 | + $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 267 | + |
|
| 268 | + // use the same order as in ObjectHomeMountProvider |
|
| 269 | + if (isset($objectStoreMultibucket)) { |
|
| 270 | + self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 271 | + } elseif (isset($objectStore)) { |
|
| 272 | + self::initObjectStoreRootFS($objectStore); |
|
| 273 | + } else { |
|
| 274 | + self::initLocalStorageRootFS(); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + if ($user != '' && !OCP\User::userExists($user)) { |
|
| 278 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + //if we aren't logged in, there is no use to set up the filesystem |
|
| 283 | + if ($user != "") { |
|
| 284 | + |
|
| 285 | + $userDir = '/' . $user . '/files'; |
|
| 286 | + |
|
| 287 | + //jail the user into his "home" directory |
|
| 288 | + \OC\Files\Filesystem::init($user, $userDir); |
|
| 289 | + |
|
| 290 | + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 291 | + } |
|
| 292 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 293 | + return true; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * check if a password is required for each public link |
|
| 298 | + * |
|
| 299 | + * @return boolean |
|
| 300 | + * @suppress PhanDeprecatedFunction |
|
| 301 | + */ |
|
| 302 | + public static function isPublicLinkPasswordRequired() { |
|
| 303 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 304 | + $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 305 | + return ($enforcePassword === 'yes') ? true : false; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * check if sharing is disabled for the current user |
|
| 310 | + * @param IConfig $config |
|
| 311 | + * @param IGroupManager $groupManager |
|
| 312 | + * @param IUser|null $user |
|
| 313 | + * @return bool |
|
| 314 | + */ |
|
| 315 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 316 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 317 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 318 | + $excludedGroups = json_decode($groupsList); |
|
| 319 | + if (is_null($excludedGroups)) { |
|
| 320 | + $excludedGroups = explode(',', $groupsList); |
|
| 321 | + $newValue = json_encode($excludedGroups); |
|
| 322 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 323 | + } |
|
| 324 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 325 | + if (!empty($usersGroups)) { |
|
| 326 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 327 | + // if the user is only in groups which are disabled for sharing then |
|
| 328 | + // sharing is also disabled for the user |
|
| 329 | + if (empty($remainingGroups)) { |
|
| 330 | + return true; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * check if share API enforces a default expire date |
|
| 339 | + * |
|
| 340 | + * @return boolean |
|
| 341 | + * @suppress PhanDeprecatedFunction |
|
| 342 | + */ |
|
| 343 | + public static function isDefaultExpireDateEnforced() { |
|
| 344 | + $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 345 | + $enforceDefaultExpireDate = false; |
|
| 346 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 347 | + $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 348 | + $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $enforceDefaultExpireDate; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Get the quota of a user |
|
| 356 | + * |
|
| 357 | + * @param string $userId |
|
| 358 | + * @return float Quota bytes |
|
| 359 | + */ |
|
| 360 | + public static function getUserQuota($userId) { |
|
| 361 | + $user = \OC::$server->getUserManager()->get($userId); |
|
| 362 | + if (is_null($user)) { |
|
| 363 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 364 | + } |
|
| 365 | + $userQuota = $user->getQuota(); |
|
| 366 | + if($userQuota === 'none') { |
|
| 367 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 368 | + } |
|
| 369 | + return OC_Helper::computerFileSize($userQuota); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * copies the skeleton to the users /files |
|
| 374 | + * |
|
| 375 | + * @param String $userId |
|
| 376 | + * @param \OCP\Files\Folder $userDirectory |
|
| 377 | + * @throws \RuntimeException |
|
| 378 | + * @suppress PhanDeprecatedFunction |
|
| 379 | + */ |
|
| 380 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 381 | + |
|
| 382 | + $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 383 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 384 | + |
|
| 385 | + if ($instanceId === null) { |
|
| 386 | + throw new \RuntimeException('no instance id!'); |
|
| 387 | + } |
|
| 388 | + $appdata = 'appdata_' . $instanceId; |
|
| 389 | + if ($userId === $appdata) { |
|
| 390 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (!empty($skeletonDirectory)) { |
|
| 394 | + \OCP\Util::writeLog( |
|
| 395 | + 'files_skeleton', |
|
| 396 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 397 | + \OCP\Util::DEBUG |
|
| 398 | + ); |
|
| 399 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 400 | + // update the file cache |
|
| 401 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * copies a directory recursively by using streams |
|
| 407 | + * |
|
| 408 | + * @param string $source |
|
| 409 | + * @param \OCP\Files\Folder $target |
|
| 410 | + * @return void |
|
| 411 | + */ |
|
| 412 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 413 | + $logger = \OC::$server->getLogger(); |
|
| 414 | + |
|
| 415 | + // Verify if folder exists |
|
| 416 | + $dir = opendir($source); |
|
| 417 | + if($dir === false) { |
|
| 418 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 419 | + return; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + // Copy the files |
|
| 423 | + while (false !== ($file = readdir($dir))) { |
|
| 424 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 425 | + if (is_dir($source . '/' . $file)) { |
|
| 426 | + $child = $target->newFolder($file); |
|
| 427 | + self::copyr($source . '/' . $file, $child); |
|
| 428 | + } else { |
|
| 429 | + $child = $target->newFile($file); |
|
| 430 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 431 | + if($sourceStream === false) { |
|
| 432 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 433 | + closedir($dir); |
|
| 434 | + return; |
|
| 435 | + } |
|
| 436 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + closedir($dir); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * @return void |
|
| 445 | + * @suppress PhanUndeclaredMethod |
|
| 446 | + */ |
|
| 447 | + public static function tearDownFS() { |
|
| 448 | + \OC\Files\Filesystem::tearDown(); |
|
| 449 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 450 | + self::$fsSetup = false; |
|
| 451 | + self::$rootMounted = false; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * get the current installed version of ownCloud |
|
| 456 | + * |
|
| 457 | + * @return array |
|
| 458 | + */ |
|
| 459 | + public static function getVersion() { |
|
| 460 | + OC_Util::loadVersion(); |
|
| 461 | + return self::$versionCache['OC_Version']; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * get the current installed version string of ownCloud |
|
| 466 | + * |
|
| 467 | + * @return string |
|
| 468 | + */ |
|
| 469 | + public static function getVersionString() { |
|
| 470 | + OC_Util::loadVersion(); |
|
| 471 | + return self::$versionCache['OC_VersionString']; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * @deprecated the value is of no use anymore |
|
| 476 | + * @return string |
|
| 477 | + */ |
|
| 478 | + public static function getEditionString() { |
|
| 479 | + return ''; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @description get the update channel of the current installed of ownCloud. |
|
| 484 | + * @return string |
|
| 485 | + */ |
|
| 486 | + public static function getChannel() { |
|
| 487 | + OC_Util::loadVersion(); |
|
| 488 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @description get the build number of the current installed of ownCloud. |
|
| 493 | + * @return string |
|
| 494 | + */ |
|
| 495 | + public static function getBuild() { |
|
| 496 | + OC_Util::loadVersion(); |
|
| 497 | + return self::$versionCache['OC_Build']; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @description load the version.php into the session as cache |
|
| 502 | + * @suppress PhanUndeclaredVariable |
|
| 503 | + */ |
|
| 504 | + private static function loadVersion() { |
|
| 505 | + if (self::$versionCache !== null) { |
|
| 506 | + return; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 510 | + require OC::$SERVERROOT . '/version.php'; |
|
| 511 | + /** @var $timestamp int */ |
|
| 512 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 513 | + /** @var $OC_Version string */ |
|
| 514 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 515 | + /** @var $OC_VersionString string */ |
|
| 516 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 517 | + /** @var $OC_Build string */ |
|
| 518 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 519 | + |
|
| 520 | + /** @var $OC_Channel string */ |
|
| 521 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 526 | + * |
|
| 527 | + * @param string $application application to get the files from |
|
| 528 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 529 | + * @param string $file the file inside of the above folder |
|
| 530 | + * @return string the path |
|
| 531 | + */ |
|
| 532 | + private static function generatePath($application, $directory, $file) { |
|
| 533 | + if (is_null($file)) { |
|
| 534 | + $file = $application; |
|
| 535 | + $application = ""; |
|
| 536 | + } |
|
| 537 | + if (!empty($application)) { |
|
| 538 | + return "$application/$directory/$file"; |
|
| 539 | + } else { |
|
| 540 | + return "$directory/$file"; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * add a javascript file |
|
| 546 | + * |
|
| 547 | + * @param string $application application id |
|
| 548 | + * @param string|null $file filename |
|
| 549 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 550 | + * @return void |
|
| 551 | + */ |
|
| 552 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 553 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 554 | + |
|
| 555 | + // core js files need separate handling |
|
| 556 | + if ($application !== 'core' && $file !== null) { |
|
| 557 | + self::addTranslations ( $application ); |
|
| 558 | + } |
|
| 559 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * add a javascript file from the vendor sub folder |
|
| 564 | + * |
|
| 565 | + * @param string $application application id |
|
| 566 | + * @param string|null $file filename |
|
| 567 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 568 | + * @return void |
|
| 569 | + */ |
|
| 570 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 571 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 572 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * add a translation JS file |
|
| 577 | + * |
|
| 578 | + * @param string $application application id |
|
| 579 | + * @param string|null $languageCode language code, defaults to the current language |
|
| 580 | + * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 581 | + */ |
|
| 582 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 583 | + if (is_null($languageCode)) { |
|
| 584 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 585 | + } |
|
| 586 | + if (!empty($application)) { |
|
| 587 | + $path = "$application/l10n/$languageCode"; |
|
| 588 | + } else { |
|
| 589 | + $path = "l10n/$languageCode"; |
|
| 590 | + } |
|
| 591 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * add a css file |
|
| 596 | + * |
|
| 597 | + * @param string $application application id |
|
| 598 | + * @param string|null $file filename |
|
| 599 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 603 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 604 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * add a css file from the vendor sub folder |
|
| 609 | + * |
|
| 610 | + * @param string $application application id |
|
| 611 | + * @param string|null $file filename |
|
| 612 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 613 | + * @return void |
|
| 614 | + */ |
|
| 615 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 616 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 617 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * add an external resource css/js file |
|
| 622 | + * |
|
| 623 | + * @param string $application application id |
|
| 624 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 625 | + * @param string $path |
|
| 626 | + * @param string $type (script or style) |
|
| 627 | + * @return void |
|
| 628 | + */ |
|
| 629 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 630 | + |
|
| 631 | + if ($type === "style") { |
|
| 632 | + if (!in_array($path, self::$styles)) { |
|
| 633 | + if ($prepend === true) { |
|
| 634 | + array_unshift ( self::$styles, $path ); |
|
| 635 | + } else { |
|
| 636 | + self::$styles[] = $path; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + } elseif ($type === "script") { |
|
| 640 | + if (!in_array($path, self::$scripts)) { |
|
| 641 | + if ($prepend === true) { |
|
| 642 | + array_unshift ( self::$scripts, $path ); |
|
| 643 | + } else { |
|
| 644 | + self::$scripts [] = $path; |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * Add a custom element to the header |
|
| 652 | + * If $text is null then the element will be written as empty element. |
|
| 653 | + * So use "" to get a closing tag. |
|
| 654 | + * @param string $tag tag name of the element |
|
| 655 | + * @param array $attributes array of attributes for the element |
|
| 656 | + * @param string $text the text content for the element |
|
| 657 | + */ |
|
| 658 | + public static function addHeader($tag, $attributes, $text=null) { |
|
| 659 | + self::$headers[] = array( |
|
| 660 | + 'tag' => $tag, |
|
| 661 | + 'attributes' => $attributes, |
|
| 662 | + 'text' => $text |
|
| 663 | + ); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * formats a timestamp in the "right" way |
|
| 668 | + * |
|
| 669 | + * @param int $timestamp |
|
| 670 | + * @param bool $dateOnly option to omit time from the result |
|
| 671 | + * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 672 | + * @return string timestamp |
|
| 673 | + * |
|
| 674 | + * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 675 | + */ |
|
| 676 | + public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 677 | + if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 678 | + $timeZone = new \DateTimeZone($timeZone); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** @var \OC\DateTimeFormatter $formatter */ |
|
| 682 | + $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 683 | + if ($dateOnly) { |
|
| 684 | + return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 685 | + } |
|
| 686 | + return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * check if the current server configuration is suitable for ownCloud |
|
| 691 | + * |
|
| 692 | + * @param \OC\SystemConfig $config |
|
| 693 | + * @return array arrays with error messages and hints |
|
| 694 | + */ |
|
| 695 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 696 | + $l = \OC::$server->getL10N('lib'); |
|
| 697 | + $errors = array(); |
|
| 698 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 699 | + |
|
| 700 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 701 | + // this check needs to be done every time |
|
| 702 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 706 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 707 | + return $errors; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + $webServerRestart = false; |
|
| 711 | + $setup = new \OC\Setup( |
|
| 712 | + $config, |
|
| 713 | + \OC::$server->getIniWrapper(), |
|
| 714 | + \OC::$server->getL10N('lib'), |
|
| 715 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 716 | + \OC::$server->getLogger(), |
|
| 717 | + \OC::$server->getSecureRandom(), |
|
| 718 | + \OC::$server->query(\OC\Installer::class) |
|
| 719 | + ); |
|
| 720 | + |
|
| 721 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 722 | + |
|
| 723 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 724 | + if (empty($availableDatabases)) { |
|
| 725 | + $errors[] = array( |
|
| 726 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 727 | + 'hint' => '' //TODO: sane hint |
|
| 728 | + ); |
|
| 729 | + $webServerRestart = true; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + // Check if config folder is writable. |
|
| 733 | + if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 734 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 735 | + $errors[] = array( |
|
| 736 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
| 737 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 738 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 739 | + ); |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Check if there is a writable install folder. |
|
| 744 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 745 | + if (OC_App::getInstallPath() === null |
|
| 746 | + || !is_writable(OC_App::getInstallPath()) |
|
| 747 | + || !is_readable(OC_App::getInstallPath()) |
|
| 748 | + ) { |
|
| 749 | + $errors[] = array( |
|
| 750 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 751 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 752 | + . ' or disabling the appstore in the config file. See %s', |
|
| 753 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 754 | + ); |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + // Create root dir. |
|
| 758 | + if ($config->getValue('installed', false)) { |
|
| 759 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 760 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 761 | + if ($success) { |
|
| 762 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 763 | + } else { |
|
| 764 | + $errors[] = [ |
|
| 765 | + 'error' => $l->t('Cannot create "data" directory'), |
|
| 766 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 767 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 768 | + ]; |
|
| 769 | + } |
|
| 770 | + } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 771 | + //common hint for all file permissions error messages |
|
| 772 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 773 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 774 | + $errors[] = [ |
|
| 775 | + 'error' => 'Your data directory is not writable', |
|
| 776 | + 'hint' => $permissionsHint |
|
| 777 | + ]; |
|
| 778 | + } else { |
|
| 779 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 784 | + $errors[] = array( |
|
| 785 | + 'error' => $l->t('Setting locale to %s failed', |
|
| 786 | + array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 787 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 788 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 789 | + ); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + // Contains the dependencies that should be checked against |
|
| 793 | + // classes = class_exists |
|
| 794 | + // functions = function_exists |
|
| 795 | + // defined = defined |
|
| 796 | + // ini = ini_get |
|
| 797 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 798 | + // When adding new checks always verify that they pass on Travis as well |
|
| 799 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 800 | + $dependencies = array( |
|
| 801 | + 'classes' => array( |
|
| 802 | + 'ZipArchive' => 'zip', |
|
| 803 | + 'DOMDocument' => 'dom', |
|
| 804 | + 'XMLWriter' => 'XMLWriter', |
|
| 805 | + 'XMLReader' => 'XMLReader', |
|
| 806 | + ), |
|
| 807 | + 'functions' => [ |
|
| 808 | + 'xml_parser_create' => 'libxml', |
|
| 809 | + 'mb_strcut' => 'mb multibyte', |
|
| 810 | + 'ctype_digit' => 'ctype', |
|
| 811 | + 'json_encode' => 'JSON', |
|
| 812 | + 'gd_info' => 'GD', |
|
| 813 | + 'gzencode' => 'zlib', |
|
| 814 | + 'iconv' => 'iconv', |
|
| 815 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 816 | + 'hash' => 'HASH Message Digest Framework', |
|
| 817 | + 'curl_init' => 'cURL', |
|
| 818 | + 'openssl_verify' => 'OpenSSL', |
|
| 819 | + ], |
|
| 820 | + 'defined' => array( |
|
| 821 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 822 | + ), |
|
| 823 | + 'ini' => [ |
|
| 824 | + 'default_charset' => 'UTF-8', |
|
| 825 | + ], |
|
| 826 | + ); |
|
| 827 | + $missingDependencies = array(); |
|
| 828 | + $invalidIniSettings = []; |
|
| 829 | + $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 833 | + * and prevents installation. Once HHVM is more compatible with our |
|
| 834 | + * approach to check for these values we should re-enable those |
|
| 835 | + * checks. |
|
| 836 | + */ |
|
| 837 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 838 | + if (!self::runningOnHhvm()) { |
|
| 839 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 840 | + if (!class_exists($class)) { |
|
| 841 | + $missingDependencies[] = $module; |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 845 | + if (!function_exists($function)) { |
|
| 846 | + $missingDependencies[] = $module; |
|
| 847 | + } |
|
| 848 | + } |
|
| 849 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 850 | + if (!defined($defined)) { |
|
| 851 | + $missingDependencies[] = $module; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 855 | + if (is_bool($expected)) { |
|
| 856 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 857 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + if (is_int($expected)) { |
|
| 861 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 862 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + if (is_string($expected)) { |
|
| 866 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 867 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + foreach($missingDependencies as $missingDependency) { |
|
| 874 | + $errors[] = array( |
|
| 875 | + 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 876 | + 'hint' => $moduleHint |
|
| 877 | + ); |
|
| 878 | + $webServerRestart = true; |
|
| 879 | + } |
|
| 880 | + foreach($invalidIniSettings as $setting) { |
|
| 881 | + if(is_bool($setting[1])) { |
|
| 882 | + $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 883 | + } |
|
| 884 | + $errors[] = [ |
|
| 885 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 886 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 887 | + ]; |
|
| 888 | + $webServerRestart = true; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 893 | + * module is installed as it will return null if the checking setting is |
|
| 894 | + * not available and thus a check on the boolean value fails. |
|
| 895 | + * |
|
| 896 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 897 | + * check somehow in the long-term. |
|
| 898 | + */ |
|
| 899 | + if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 900 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 901 | + $errors[] = array( |
|
| 902 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 903 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 904 | + ); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + if(function_exists('xml_parser_create') && |
|
| 908 | + LIBXML_LOADED_VERSION < 20700 ) { |
|
| 909 | + $version = LIBXML_LOADED_VERSION; |
|
| 910 | + $major = floor($version/10000); |
|
| 911 | + $version -= ($major * 10000); |
|
| 912 | + $minor = floor($version/100); |
|
| 913 | + $version -= ($minor * 100); |
|
| 914 | + $patch = $version; |
|
| 915 | + $errors[] = array( |
|
| 916 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 917 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 918 | + ); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + if (!self::isAnnotationsWorking()) { |
|
| 922 | + $errors[] = array( |
|
| 923 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 924 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 925 | + ); |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 929 | + $errors[] = array( |
|
| 930 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 931 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 932 | + ); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 936 | + |
|
| 937 | + // Cache the result of this function |
|
| 938 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 939 | + |
|
| 940 | + return $errors; |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * Check the database version |
|
| 945 | + * |
|
| 946 | + * @return array errors array |
|
| 947 | + */ |
|
| 948 | + public static function checkDatabaseVersion() { |
|
| 949 | + $l = \OC::$server->getL10N('lib'); |
|
| 950 | + $errors = array(); |
|
| 951 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 952 | + if ($dbType === 'pgsql') { |
|
| 953 | + // check PostgreSQL version |
|
| 954 | + try { |
|
| 955 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 956 | + $data = $result->fetchRow(); |
|
| 957 | + if (isset($data['server_version'])) { |
|
| 958 | + $version = $data['server_version']; |
|
| 959 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 960 | + $errors[] = array( |
|
| 961 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 962 | + 'hint' => $l->t('Please upgrade your database version') |
|
| 963 | + ); |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 967 | + $logger = \OC::$server->getLogger(); |
|
| 968 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 969 | + $logger->logException($e); |
|
| 970 | + } |
|
| 971 | + } |
|
| 972 | + return $errors; |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + /** |
|
| 976 | + * Check for correct file permissions of data directory |
|
| 977 | + * |
|
| 978 | + * @param string $dataDirectory |
|
| 979 | + * @return array arrays with error messages and hints |
|
| 980 | + */ |
|
| 981 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 982 | + $l = \OC::$server->getL10N('lib'); |
|
| 983 | + $errors = array(); |
|
| 984 | + $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 985 | + . ' cannot be listed by other users.'); |
|
| 986 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 987 | + if (substr($perms, -1) !== '0') { |
|
| 988 | + chmod($dataDirectory, 0770); |
|
| 989 | + clearstatcache(); |
|
| 990 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 991 | + if ($perms[2] !== '0') { |
|
| 992 | + $errors[] = [ |
|
| 993 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
| 994 | + 'hint' => $permissionsModHint |
|
| 995 | + ]; |
|
| 996 | + } |
|
| 997 | + } |
|
| 998 | + return $errors; |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * Check that the data directory exists and is valid by |
|
| 1003 | + * checking the existence of the ".ocdata" file. |
|
| 1004 | + * |
|
| 1005 | + * @param string $dataDirectory data directory path |
|
| 1006 | + * @return array errors found |
|
| 1007 | + */ |
|
| 1008 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 1009 | + $l = \OC::$server->getL10N('lib'); |
|
| 1010 | + $errors = []; |
|
| 1011 | + if ($dataDirectory[0] !== '/') { |
|
| 1012 | + $errors[] = [ |
|
| 1013 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 1014 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 1015 | + ]; |
|
| 1016 | + } |
|
| 1017 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1018 | + $errors[] = [ |
|
| 1019 | + 'error' => $l->t('Your data directory is invalid'), |
|
| 1020 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1021 | + ' in the root of the data directory.') |
|
| 1022 | + ]; |
|
| 1023 | + } |
|
| 1024 | + return $errors; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * Check if the user is logged in, redirects to home if not. With |
|
| 1029 | + * redirect URL parameter to the request URI. |
|
| 1030 | + * |
|
| 1031 | + * @return void |
|
| 1032 | + */ |
|
| 1033 | + public static function checkLoggedIn() { |
|
| 1034 | + // Check if we are a user |
|
| 1035 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1036 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1037 | + 'core.login.showLoginForm', |
|
| 1038 | + [ |
|
| 1039 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1040 | + ] |
|
| 1041 | + ) |
|
| 1042 | + ); |
|
| 1043 | + exit(); |
|
| 1044 | + } |
|
| 1045 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1046 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1047 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1048 | + exit(); |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * Check if the user is a admin, redirects to home if not |
|
| 1054 | + * |
|
| 1055 | + * @return void |
|
| 1056 | + */ |
|
| 1057 | + public static function checkAdminUser() { |
|
| 1058 | + OC_Util::checkLoggedIn(); |
|
| 1059 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1060 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1061 | + exit(); |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Check if the user is a subadmin, redirects to home if not |
|
| 1067 | + * |
|
| 1068 | + * @return null|boolean $groups where the current user is subadmin |
|
| 1069 | + */ |
|
| 1070 | + public static function checkSubAdminUser() { |
|
| 1071 | + OC_Util::checkLoggedIn(); |
|
| 1072 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1073 | + $isSubAdmin = false; |
|
| 1074 | + if($userObject !== null) { |
|
| 1075 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + if (!$isSubAdmin) { |
|
| 1079 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1080 | + exit(); |
|
| 1081 | + } |
|
| 1082 | + return true; |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Returns the URL of the default page |
|
| 1087 | + * based on the system configuration and |
|
| 1088 | + * the apps visible for the current user |
|
| 1089 | + * |
|
| 1090 | + * @return string URL |
|
| 1091 | + * @suppress PhanDeprecatedFunction |
|
| 1092 | + */ |
|
| 1093 | + public static function getDefaultPageUrl() { |
|
| 1094 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1095 | + // Deny the redirect if the URL contains a @ |
|
| 1096 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1097 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1098 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1099 | + } else { |
|
| 1100 | + $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1101 | + if ($defaultPage) { |
|
| 1102 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1103 | + } else { |
|
| 1104 | + $appId = 'files'; |
|
| 1105 | + $config = \OC::$server->getConfig(); |
|
| 1106 | + $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'files')); |
|
| 1107 | + // find the first app that is enabled for the current user |
|
| 1108 | + foreach ($defaultApps as $defaultApp) { |
|
| 1109 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1110 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1111 | + $appId = $defaultApp; |
|
| 1112 | + break; |
|
| 1113 | + } |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1117 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1118 | + } else { |
|
| 1119 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1120 | + } |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + return $location; |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + /** |
|
| 1127 | + * Redirect to the user default page |
|
| 1128 | + * |
|
| 1129 | + * @return void |
|
| 1130 | + */ |
|
| 1131 | + public static function redirectToDefaultPage() { |
|
| 1132 | + $location = self::getDefaultPageUrl(); |
|
| 1133 | + header('Location: ' . $location); |
|
| 1134 | + exit(); |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * get an id unique for this instance |
|
| 1139 | + * |
|
| 1140 | + * @return string |
|
| 1141 | + */ |
|
| 1142 | + public static function getInstanceId() { |
|
| 1143 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1144 | + if (is_null($id)) { |
|
| 1145 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1146 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1147 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1148 | + } |
|
| 1149 | + return $id; |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Public function to sanitize HTML |
|
| 1154 | + * |
|
| 1155 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1156 | + * string or array of strings before displaying it on a web page. |
|
| 1157 | + * |
|
| 1158 | + * @param string|array $value |
|
| 1159 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1160 | + */ |
|
| 1161 | + public static function sanitizeHTML($value) { |
|
| 1162 | + if (is_array($value)) { |
|
| 1163 | + $value = array_map(function($value) { |
|
| 1164 | + return self::sanitizeHTML($value); |
|
| 1165 | + }, $value); |
|
| 1166 | + } else { |
|
| 1167 | + // Specify encoding for PHP<5.4 |
|
| 1168 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1169 | + } |
|
| 1170 | + return $value; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + /** |
|
| 1174 | + * Public function to encode url parameters |
|
| 1175 | + * |
|
| 1176 | + * This function is used to encode path to file before output. |
|
| 1177 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1178 | + * Character '/' is preserved as is. |
|
| 1179 | + * |
|
| 1180 | + * @param string $component part of URI to encode |
|
| 1181 | + * @return string |
|
| 1182 | + */ |
|
| 1183 | + public static function encodePath($component) { |
|
| 1184 | + $encoded = rawurlencode($component); |
|
| 1185 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1186 | + return $encoded; |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + |
|
| 1190 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1191 | + // php dev server does not support htaccess |
|
| 1192 | + if (php_sapi_name() === 'cli-server') { |
|
| 1193 | + return false; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + // testdata |
|
| 1197 | + $fileName = '/htaccesstest.txt'; |
|
| 1198 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1199 | + |
|
| 1200 | + // creating a test file |
|
| 1201 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1202 | + |
|
| 1203 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1204 | + return false; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + $fp = @fopen($testFile, 'w'); |
|
| 1208 | + if (!$fp) { |
|
| 1209 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1210 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1211 | + } |
|
| 1212 | + fwrite($fp, $testContent); |
|
| 1213 | + fclose($fp); |
|
| 1214 | + |
|
| 1215 | + return $testContent; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Check if the .htaccess file is working |
|
| 1220 | + * @param \OCP\IConfig $config |
|
| 1221 | + * @return bool |
|
| 1222 | + * @throws Exception |
|
| 1223 | + * @throws \OC\HintException If the test file can't get written. |
|
| 1224 | + */ |
|
| 1225 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1226 | + |
|
| 1227 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1228 | + return true; |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1232 | + if ($testContent === false) { |
|
| 1233 | + return false; |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + $fileName = '/htaccesstest.txt'; |
|
| 1237 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1238 | + |
|
| 1239 | + // accessing the file via http |
|
| 1240 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1241 | + try { |
|
| 1242 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1243 | + } catch (\Exception $e) { |
|
| 1244 | + $content = false; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + // cleanup |
|
| 1248 | + @unlink($testFile); |
|
| 1249 | + |
|
| 1250 | + /* |
|
| 1251 | 1251 | * If the content is not equal to test content our .htaccess |
| 1252 | 1252 | * is working as required |
| 1253 | 1253 | */ |
| 1254 | - return $content !== $testContent; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - /** |
|
| 1258 | - * Check if the setlocal call does not work. This can happen if the right |
|
| 1259 | - * local packages are not available on the server. |
|
| 1260 | - * |
|
| 1261 | - * @return bool |
|
| 1262 | - */ |
|
| 1263 | - public static function isSetLocaleWorking() { |
|
| 1264 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1265 | - if ('' === basename('§')) { |
|
| 1266 | - return false; |
|
| 1267 | - } |
|
| 1268 | - return true; |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * Check if it's possible to get the inline annotations |
|
| 1273 | - * |
|
| 1274 | - * @return bool |
|
| 1275 | - */ |
|
| 1276 | - public static function isAnnotationsWorking() { |
|
| 1277 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1278 | - $docs = $reflection->getDocComment(); |
|
| 1279 | - |
|
| 1280 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - /** |
|
| 1284 | - * Check if the PHP module fileinfo is loaded. |
|
| 1285 | - * |
|
| 1286 | - * @return bool |
|
| 1287 | - */ |
|
| 1288 | - public static function fileInfoLoaded() { |
|
| 1289 | - return function_exists('finfo_open'); |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - /** |
|
| 1293 | - * clear all levels of output buffering |
|
| 1294 | - * |
|
| 1295 | - * @return void |
|
| 1296 | - */ |
|
| 1297 | - public static function obEnd() { |
|
| 1298 | - while (ob_get_level()) { |
|
| 1299 | - ob_end_clean(); |
|
| 1300 | - } |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * Checks whether the server is running on Mac OS X |
|
| 1305 | - * |
|
| 1306 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1307 | - */ |
|
| 1308 | - public static function runningOnMac() { |
|
| 1309 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * Checks whether server is running on HHVM |
|
| 1314 | - * |
|
| 1315 | - * @return bool True if running on HHVM, false otherwise |
|
| 1316 | - */ |
|
| 1317 | - public static function runningOnHhvm() { |
|
| 1318 | - return defined('HHVM_VERSION'); |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1323 | - * theme exists and take that one |
|
| 1324 | - * |
|
| 1325 | - * @return string the theme |
|
| 1326 | - */ |
|
| 1327 | - public static function getTheme() { |
|
| 1328 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1329 | - |
|
| 1330 | - if ($theme === '') { |
|
| 1331 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1332 | - $theme = 'default'; |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - return $theme; |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Clear a single file from the opcode cache |
|
| 1341 | - * This is useful for writing to the config file |
|
| 1342 | - * in case the opcode cache does not re-validate files |
|
| 1343 | - * Returns true if successful, false if unsuccessful: |
|
| 1344 | - * caller should fall back on clearing the entire cache |
|
| 1345 | - * with clearOpcodeCache() if unsuccessful |
|
| 1346 | - * |
|
| 1347 | - * @param string $path the path of the file to clear from the cache |
|
| 1348 | - * @return bool true if underlying function returns true, otherwise false |
|
| 1349 | - */ |
|
| 1350 | - public static function deleteFromOpcodeCache($path) { |
|
| 1351 | - $ret = false; |
|
| 1352 | - if ($path) { |
|
| 1353 | - // APC >= 3.1.1 |
|
| 1354 | - if (function_exists('apc_delete_file')) { |
|
| 1355 | - $ret = @apc_delete_file($path); |
|
| 1356 | - } |
|
| 1357 | - // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1358 | - if (function_exists('opcache_invalidate')) { |
|
| 1359 | - $ret = opcache_invalidate($path); |
|
| 1360 | - } |
|
| 1361 | - } |
|
| 1362 | - return $ret; |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * Clear the opcode cache if one exists |
|
| 1367 | - * This is necessary for writing to the config file |
|
| 1368 | - * in case the opcode cache does not re-validate files |
|
| 1369 | - * |
|
| 1370 | - * @return void |
|
| 1371 | - * @suppress PhanDeprecatedFunction |
|
| 1372 | - * @suppress PhanUndeclaredConstant |
|
| 1373 | - */ |
|
| 1374 | - public static function clearOpcodeCache() { |
|
| 1375 | - // APC |
|
| 1376 | - if (function_exists('apc_clear_cache')) { |
|
| 1377 | - apc_clear_cache(); |
|
| 1378 | - } |
|
| 1379 | - // Zend Opcache |
|
| 1380 | - if (function_exists('accelerator_reset')) { |
|
| 1381 | - accelerator_reset(); |
|
| 1382 | - } |
|
| 1383 | - // XCache |
|
| 1384 | - if (function_exists('xcache_clear_cache')) { |
|
| 1385 | - if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1386 | - \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1387 | - } else { |
|
| 1388 | - @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1389 | - } |
|
| 1390 | - } |
|
| 1391 | - // Opcache (PHP >= 5.5) |
|
| 1392 | - if (function_exists('opcache_reset')) { |
|
| 1393 | - opcache_reset(); |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Normalize a unicode string |
|
| 1399 | - * |
|
| 1400 | - * @param string $value a not normalized string |
|
| 1401 | - * @return bool|string |
|
| 1402 | - */ |
|
| 1403 | - public static function normalizeUnicode($value) { |
|
| 1404 | - if(Normalizer::isNormalized($value)) { |
|
| 1405 | - return $value; |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1409 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1410 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1411 | - return $value; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - return $normalizedValue; |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * A human readable string is generated based on version and build number |
|
| 1419 | - * |
|
| 1420 | - * @return string |
|
| 1421 | - */ |
|
| 1422 | - public static function getHumanVersion() { |
|
| 1423 | - $version = OC_Util::getVersionString(); |
|
| 1424 | - $build = OC_Util::getBuild(); |
|
| 1425 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1426 | - $version .= ' Build:' . $build; |
|
| 1427 | - } |
|
| 1428 | - return $version; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - /** |
|
| 1432 | - * Returns whether the given file name is valid |
|
| 1433 | - * |
|
| 1434 | - * @param string $file file name to check |
|
| 1435 | - * @return bool true if the file name is valid, false otherwise |
|
| 1436 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1437 | - */ |
|
| 1438 | - public static function isValidFileName($file) { |
|
| 1439 | - $trimmed = trim($file); |
|
| 1440 | - if ($trimmed === '') { |
|
| 1441 | - return false; |
|
| 1442 | - } |
|
| 1443 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1444 | - return false; |
|
| 1445 | - } |
|
| 1446 | - |
|
| 1447 | - // detect part files |
|
| 1448 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1449 | - return false; |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - foreach (str_split($trimmed) as $char) { |
|
| 1453 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1454 | - return false; |
|
| 1455 | - } |
|
| 1456 | - } |
|
| 1457 | - return true; |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - /** |
|
| 1461 | - * Check whether the instance needs to perform an upgrade, |
|
| 1462 | - * either when the core version is higher or any app requires |
|
| 1463 | - * an upgrade. |
|
| 1464 | - * |
|
| 1465 | - * @param \OC\SystemConfig $config |
|
| 1466 | - * @return bool whether the core or any app needs an upgrade |
|
| 1467 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1468 | - */ |
|
| 1469 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1470 | - if ($config->getValue('installed', false)) { |
|
| 1471 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1472 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1473 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1474 | - if ($versionDiff > 0) { |
|
| 1475 | - return true; |
|
| 1476 | - } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1477 | - // downgrade with debug |
|
| 1478 | - $installedMajor = explode('.', $installedVersion); |
|
| 1479 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1480 | - $currentMajor = explode('.', $currentVersion); |
|
| 1481 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1482 | - if ($installedMajor === $currentMajor) { |
|
| 1483 | - // Same major, allow downgrade for developers |
|
| 1484 | - return true; |
|
| 1485 | - } else { |
|
| 1486 | - // downgrade attempt, throw exception |
|
| 1487 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1488 | - } |
|
| 1489 | - } else if ($versionDiff < 0) { |
|
| 1490 | - // downgrade attempt, throw exception |
|
| 1491 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - // also check for upgrades for apps (independently from the user) |
|
| 1495 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1496 | - $shouldUpgrade = false; |
|
| 1497 | - foreach ($apps as $app) { |
|
| 1498 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1499 | - $shouldUpgrade = true; |
|
| 1500 | - break; |
|
| 1501 | - } |
|
| 1502 | - } |
|
| 1503 | - return $shouldUpgrade; |
|
| 1504 | - } else { |
|
| 1505 | - return false; |
|
| 1506 | - } |
|
| 1507 | - } |
|
| 1254 | + return $content !== $testContent; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + /** |
|
| 1258 | + * Check if the setlocal call does not work. This can happen if the right |
|
| 1259 | + * local packages are not available on the server. |
|
| 1260 | + * |
|
| 1261 | + * @return bool |
|
| 1262 | + */ |
|
| 1263 | + public static function isSetLocaleWorking() { |
|
| 1264 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1265 | + if ('' === basename('§')) { |
|
| 1266 | + return false; |
|
| 1267 | + } |
|
| 1268 | + return true; |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * Check if it's possible to get the inline annotations |
|
| 1273 | + * |
|
| 1274 | + * @return bool |
|
| 1275 | + */ |
|
| 1276 | + public static function isAnnotationsWorking() { |
|
| 1277 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1278 | + $docs = $reflection->getDocComment(); |
|
| 1279 | + |
|
| 1280 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + /** |
|
| 1284 | + * Check if the PHP module fileinfo is loaded. |
|
| 1285 | + * |
|
| 1286 | + * @return bool |
|
| 1287 | + */ |
|
| 1288 | + public static function fileInfoLoaded() { |
|
| 1289 | + return function_exists('finfo_open'); |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + /** |
|
| 1293 | + * clear all levels of output buffering |
|
| 1294 | + * |
|
| 1295 | + * @return void |
|
| 1296 | + */ |
|
| 1297 | + public static function obEnd() { |
|
| 1298 | + while (ob_get_level()) { |
|
| 1299 | + ob_end_clean(); |
|
| 1300 | + } |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * Checks whether the server is running on Mac OS X |
|
| 1305 | + * |
|
| 1306 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1307 | + */ |
|
| 1308 | + public static function runningOnMac() { |
|
| 1309 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * Checks whether server is running on HHVM |
|
| 1314 | + * |
|
| 1315 | + * @return bool True if running on HHVM, false otherwise |
|
| 1316 | + */ |
|
| 1317 | + public static function runningOnHhvm() { |
|
| 1318 | + return defined('HHVM_VERSION'); |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1323 | + * theme exists and take that one |
|
| 1324 | + * |
|
| 1325 | + * @return string the theme |
|
| 1326 | + */ |
|
| 1327 | + public static function getTheme() { |
|
| 1328 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1329 | + |
|
| 1330 | + if ($theme === '') { |
|
| 1331 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1332 | + $theme = 'default'; |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + return $theme; |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Clear a single file from the opcode cache |
|
| 1341 | + * This is useful for writing to the config file |
|
| 1342 | + * in case the opcode cache does not re-validate files |
|
| 1343 | + * Returns true if successful, false if unsuccessful: |
|
| 1344 | + * caller should fall back on clearing the entire cache |
|
| 1345 | + * with clearOpcodeCache() if unsuccessful |
|
| 1346 | + * |
|
| 1347 | + * @param string $path the path of the file to clear from the cache |
|
| 1348 | + * @return bool true if underlying function returns true, otherwise false |
|
| 1349 | + */ |
|
| 1350 | + public static function deleteFromOpcodeCache($path) { |
|
| 1351 | + $ret = false; |
|
| 1352 | + if ($path) { |
|
| 1353 | + // APC >= 3.1.1 |
|
| 1354 | + if (function_exists('apc_delete_file')) { |
|
| 1355 | + $ret = @apc_delete_file($path); |
|
| 1356 | + } |
|
| 1357 | + // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1358 | + if (function_exists('opcache_invalidate')) { |
|
| 1359 | + $ret = opcache_invalidate($path); |
|
| 1360 | + } |
|
| 1361 | + } |
|
| 1362 | + return $ret; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * Clear the opcode cache if one exists |
|
| 1367 | + * This is necessary for writing to the config file |
|
| 1368 | + * in case the opcode cache does not re-validate files |
|
| 1369 | + * |
|
| 1370 | + * @return void |
|
| 1371 | + * @suppress PhanDeprecatedFunction |
|
| 1372 | + * @suppress PhanUndeclaredConstant |
|
| 1373 | + */ |
|
| 1374 | + public static function clearOpcodeCache() { |
|
| 1375 | + // APC |
|
| 1376 | + if (function_exists('apc_clear_cache')) { |
|
| 1377 | + apc_clear_cache(); |
|
| 1378 | + } |
|
| 1379 | + // Zend Opcache |
|
| 1380 | + if (function_exists('accelerator_reset')) { |
|
| 1381 | + accelerator_reset(); |
|
| 1382 | + } |
|
| 1383 | + // XCache |
|
| 1384 | + if (function_exists('xcache_clear_cache')) { |
|
| 1385 | + if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1386 | + \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1387 | + } else { |
|
| 1388 | + @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | + // Opcache (PHP >= 5.5) |
|
| 1392 | + if (function_exists('opcache_reset')) { |
|
| 1393 | + opcache_reset(); |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Normalize a unicode string |
|
| 1399 | + * |
|
| 1400 | + * @param string $value a not normalized string |
|
| 1401 | + * @return bool|string |
|
| 1402 | + */ |
|
| 1403 | + public static function normalizeUnicode($value) { |
|
| 1404 | + if(Normalizer::isNormalized($value)) { |
|
| 1405 | + return $value; |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1409 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1410 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1411 | + return $value; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + return $normalizedValue; |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * A human readable string is generated based on version and build number |
|
| 1419 | + * |
|
| 1420 | + * @return string |
|
| 1421 | + */ |
|
| 1422 | + public static function getHumanVersion() { |
|
| 1423 | + $version = OC_Util::getVersionString(); |
|
| 1424 | + $build = OC_Util::getBuild(); |
|
| 1425 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1426 | + $version .= ' Build:' . $build; |
|
| 1427 | + } |
|
| 1428 | + return $version; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + /** |
|
| 1432 | + * Returns whether the given file name is valid |
|
| 1433 | + * |
|
| 1434 | + * @param string $file file name to check |
|
| 1435 | + * @return bool true if the file name is valid, false otherwise |
|
| 1436 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1437 | + */ |
|
| 1438 | + public static function isValidFileName($file) { |
|
| 1439 | + $trimmed = trim($file); |
|
| 1440 | + if ($trimmed === '') { |
|
| 1441 | + return false; |
|
| 1442 | + } |
|
| 1443 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1444 | + return false; |
|
| 1445 | + } |
|
| 1446 | + |
|
| 1447 | + // detect part files |
|
| 1448 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1449 | + return false; |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + foreach (str_split($trimmed) as $char) { |
|
| 1453 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1454 | + return false; |
|
| 1455 | + } |
|
| 1456 | + } |
|
| 1457 | + return true; |
|
| 1458 | + } |
|
| 1459 | + |
|
| 1460 | + /** |
|
| 1461 | + * Check whether the instance needs to perform an upgrade, |
|
| 1462 | + * either when the core version is higher or any app requires |
|
| 1463 | + * an upgrade. |
|
| 1464 | + * |
|
| 1465 | + * @param \OC\SystemConfig $config |
|
| 1466 | + * @return bool whether the core or any app needs an upgrade |
|
| 1467 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1468 | + */ |
|
| 1469 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1470 | + if ($config->getValue('installed', false)) { |
|
| 1471 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1472 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1473 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1474 | + if ($versionDiff > 0) { |
|
| 1475 | + return true; |
|
| 1476 | + } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1477 | + // downgrade with debug |
|
| 1478 | + $installedMajor = explode('.', $installedVersion); |
|
| 1479 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1480 | + $currentMajor = explode('.', $currentVersion); |
|
| 1481 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1482 | + if ($installedMajor === $currentMajor) { |
|
| 1483 | + // Same major, allow downgrade for developers |
|
| 1484 | + return true; |
|
| 1485 | + } else { |
|
| 1486 | + // downgrade attempt, throw exception |
|
| 1487 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1488 | + } |
|
| 1489 | + } else if ($versionDiff < 0) { |
|
| 1490 | + // downgrade attempt, throw exception |
|
| 1491 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + // also check for upgrades for apps (independently from the user) |
|
| 1495 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1496 | + $shouldUpgrade = false; |
|
| 1497 | + foreach ($apps as $app) { |
|
| 1498 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1499 | + $shouldUpgrade = true; |
|
| 1500 | + break; |
|
| 1501 | + } |
|
| 1502 | + } |
|
| 1503 | + return $shouldUpgrade; |
|
| 1504 | + } else { |
|
| 1505 | + return false; |
|
| 1506 | + } |
|
| 1507 | + } |
|
| 1508 | 1508 | |
| 1509 | 1509 | } |
@@ -63,1184 +63,1184 @@ |
||
| 63 | 63 | * upgrading and removing apps. |
| 64 | 64 | */ |
| 65 | 65 | class OC_App { |
| 66 | - static private $appVersion = []; |
|
| 67 | - static private $adminForms = array(); |
|
| 68 | - static private $personalForms = array(); |
|
| 69 | - static private $appInfo = array(); |
|
| 70 | - static private $appTypes = array(); |
|
| 71 | - static private $loadedApps = array(); |
|
| 72 | - static private $altLogin = array(); |
|
| 73 | - static private $alreadyRegistered = []; |
|
| 74 | - const officialApp = 200; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * clean the appId |
|
| 78 | - * |
|
| 79 | - * @param string|boolean $app AppId that needs to be cleaned |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public static function cleanAppId($app) { |
|
| 83 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Check if an app is loaded |
|
| 88 | - * |
|
| 89 | - * @param string $app |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public static function isAppLoaded($app) { |
|
| 93 | - return in_array($app, self::$loadedApps, true); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * loads all apps |
|
| 98 | - * |
|
| 99 | - * @param string[] | string | null $types |
|
| 100 | - * @return bool |
|
| 101 | - * |
|
| 102 | - * This function walks through the ownCloud directory and loads all apps |
|
| 103 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
| 104 | - * exists. |
|
| 105 | - * |
|
| 106 | - * if $types is set, only apps of those types will be loaded |
|
| 107 | - */ |
|
| 108 | - public static function loadApps($types = null) { |
|
| 109 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 110 | - return false; |
|
| 111 | - } |
|
| 112 | - // Load the enabled apps here |
|
| 113 | - $apps = self::getEnabledApps(); |
|
| 114 | - |
|
| 115 | - // Add each apps' folder as allowed class path |
|
| 116 | - foreach($apps as $app) { |
|
| 117 | - $path = self::getAppPath($app); |
|
| 118 | - if($path !== false) { |
|
| 119 | - self::registerAutoloading($app, $path); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // prevent app.php from printing output |
|
| 124 | - ob_start(); |
|
| 125 | - foreach ($apps as $app) { |
|
| 126 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
| 127 | - self::loadApp($app); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - ob_end_clean(); |
|
| 131 | - |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * load a single app |
|
| 137 | - * |
|
| 138 | - * @param string $app |
|
| 139 | - */ |
|
| 140 | - public static function loadApp($app) { |
|
| 141 | - self::$loadedApps[] = $app; |
|
| 142 | - $appPath = self::getAppPath($app); |
|
| 143 | - if($appPath === false) { |
|
| 144 | - return; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // in case someone calls loadApp() directly |
|
| 148 | - self::registerAutoloading($app, $appPath); |
|
| 149 | - |
|
| 150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
| 151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 152 | - self::requireAppFile($app); |
|
| 153 | - if (self::isType($app, array('authentication'))) { |
|
| 154 | - // since authentication apps affect the "is app enabled for group" check, |
|
| 155 | - // the enabled apps cache needs to be cleared to make sure that the |
|
| 156 | - // next time getEnableApps() is called it will also include apps that were |
|
| 157 | - // enabled for groups |
|
| 158 | - self::$enabledAppsCache = array(); |
|
| 159 | - } |
|
| 160 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $info = self::getAppInfo($app); |
|
| 164 | - if (!empty($info['activity']['filters'])) { |
|
| 165 | - foreach ($info['activity']['filters'] as $filter) { |
|
| 166 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - if (!empty($info['activity']['settings'])) { |
|
| 170 | - foreach ($info['activity']['settings'] as $setting) { |
|
| 171 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - if (!empty($info['activity']['providers'])) { |
|
| 175 | - foreach ($info['activity']['providers'] as $provider) { |
|
| 176 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - if (!empty($info['collaboration']['plugins'])) { |
|
| 180 | - // deal with one or many plugin entries |
|
| 181 | - $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
| 182 | - [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
| 183 | - foreach ($plugins as $plugin) { |
|
| 184 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 185 | - $pluginInfo = [ |
|
| 186 | - 'shareType' => $plugin['@attributes']['share-type'], |
|
| 187 | - 'class' => $plugin['@value'], |
|
| 188 | - ]; |
|
| 189 | - \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
| 190 | - } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
| 191 | - \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @internal |
|
| 199 | - * @param string $app |
|
| 200 | - * @param string $path |
|
| 201 | - */ |
|
| 202 | - public static function registerAutoloading($app, $path) { |
|
| 203 | - $key = $app . '-' . $path; |
|
| 204 | - if(isset(self::$alreadyRegistered[$key])) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - self::$alreadyRegistered[$key] = true; |
|
| 209 | - |
|
| 210 | - // Register on PSR-4 composer autoloader |
|
| 211 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
| 212 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
| 213 | - |
|
| 214 | - if (file_exists($path . '/composer/autoload.php')) { |
|
| 215 | - require_once $path . '/composer/autoload.php'; |
|
| 216 | - } else { |
|
| 217 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 218 | - // Register on legacy autoloader |
|
| 219 | - \OC::$loader->addValidRoot($path); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // Register Test namespace only when testing |
|
| 223 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
| 224 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Load app.php from the given app |
|
| 230 | - * |
|
| 231 | - * @param string $app app name |
|
| 232 | - */ |
|
| 233 | - private static function requireAppFile($app) { |
|
| 234 | - try { |
|
| 235 | - // encapsulated here to avoid variable scope conflicts |
|
| 236 | - require_once $app . '/appinfo/app.php'; |
|
| 237 | - } catch (Error $ex) { |
|
| 238 | - \OC::$server->getLogger()->logException($ex); |
|
| 239 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
| 240 | - if (!in_array($app, $blacklist)) { |
|
| 241 | - self::disable($app); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * check if an app is of a specific type |
|
| 248 | - * |
|
| 249 | - * @param string $app |
|
| 250 | - * @param string|array $types |
|
| 251 | - * @return bool |
|
| 252 | - */ |
|
| 253 | - public static function isType($app, $types) { |
|
| 254 | - if (is_string($types)) { |
|
| 255 | - $types = array($types); |
|
| 256 | - } |
|
| 257 | - $appTypes = self::getAppTypes($app); |
|
| 258 | - foreach ($types as $type) { |
|
| 259 | - if (array_search($type, $appTypes) !== false) { |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * get the types of an app |
|
| 268 | - * |
|
| 269 | - * @param string $app |
|
| 270 | - * @return array |
|
| 271 | - */ |
|
| 272 | - private static function getAppTypes($app) { |
|
| 273 | - //load the cache |
|
| 274 | - if (count(self::$appTypes) == 0) { |
|
| 275 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - if (isset(self::$appTypes[$app])) { |
|
| 279 | - return explode(',', self::$appTypes[$app]); |
|
| 280 | - } else { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * read app types from info.xml and cache them in the database |
|
| 287 | - */ |
|
| 288 | - public static function setAppTypes($app) { |
|
| 289 | - $appData = self::getAppInfo($app); |
|
| 290 | - if(!is_array($appData)) { |
|
| 291 | - return; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (isset($appData['types'])) { |
|
| 295 | - $appTypes = implode(',', $appData['types']); |
|
| 296 | - } else { |
|
| 297 | - $appTypes = ''; |
|
| 298 | - $appData['types'] = []; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
| 302 | - |
|
| 303 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
| 304 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
| 305 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
| 306 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * get all enabled apps |
|
| 313 | - */ |
|
| 314 | - protected static $enabledAppsCache = array(); |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Returns apps enabled for the current user. |
|
| 318 | - * |
|
| 319 | - * @param bool $forceRefresh whether to refresh the cache |
|
| 320 | - * @param bool $all whether to return apps for all users, not only the |
|
| 321 | - * currently logged in one |
|
| 322 | - * @return string[] |
|
| 323 | - */ |
|
| 324 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
| 325 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 326 | - return array(); |
|
| 327 | - } |
|
| 328 | - // in incognito mode or when logged out, $user will be false, |
|
| 329 | - // which is also the case during an upgrade |
|
| 330 | - $appManager = \OC::$server->getAppManager(); |
|
| 331 | - if ($all) { |
|
| 332 | - $user = null; |
|
| 333 | - } else { |
|
| 334 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if (is_null($user)) { |
|
| 338 | - $apps = $appManager->getInstalledApps(); |
|
| 339 | - } else { |
|
| 340 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
| 341 | - } |
|
| 342 | - $apps = array_filter($apps, function ($app) { |
|
| 343 | - return $app !== 'files';//we add this manually |
|
| 344 | - }); |
|
| 345 | - sort($apps); |
|
| 346 | - array_unshift($apps, 'files'); |
|
| 347 | - return $apps; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * checks whether or not an app is enabled |
|
| 352 | - * |
|
| 353 | - * @param string $app app |
|
| 354 | - * @return bool |
|
| 355 | - * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
| 356 | - * |
|
| 357 | - * This function checks whether or not an app is enabled. |
|
| 358 | - */ |
|
| 359 | - public static function isEnabled($app) { |
|
| 360 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * enables an app |
|
| 365 | - * |
|
| 366 | - * @param string $appId |
|
| 367 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
| 368 | - * @throws \Exception |
|
| 369 | - * @return void |
|
| 370 | - * |
|
| 371 | - * This function set an app as enabled in appconfig. |
|
| 372 | - */ |
|
| 373 | - public function enable($appId, |
|
| 374 | - $groups = null) { |
|
| 375 | - self::$enabledAppsCache = []; // flush |
|
| 376 | - |
|
| 377 | - // Check if app is already downloaded |
|
| 378 | - $installer = \OC::$server->query(Installer::class); |
|
| 379 | - $isDownloaded = $installer->isDownloaded($appId); |
|
| 380 | - |
|
| 381 | - if(!$isDownloaded) { |
|
| 382 | - $installer->downloadApp($appId); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - $installer->installApp($appId); |
|
| 386 | - |
|
| 387 | - $appManager = \OC::$server->getAppManager(); |
|
| 388 | - if (!is_null($groups)) { |
|
| 389 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 390 | - $groupsList = []; |
|
| 391 | - foreach ($groups as $group) { |
|
| 392 | - $groupItem = $groupManager->get($group); |
|
| 393 | - if ($groupItem instanceof \OCP\IGroup) { |
|
| 394 | - $groupsList[] = $groupManager->get($group); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
| 398 | - } else { |
|
| 399 | - $appManager->enableApp($appId); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @param string $app |
|
| 405 | - * @return bool |
|
| 406 | - */ |
|
| 407 | - public static function removeApp($app) { |
|
| 408 | - if (\OC::$server->getAppManager()->isShipped($app)) { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $installer = \OC::$server->query(Installer::class); |
|
| 413 | - return $installer->removeApp($app); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * This function set an app as disabled in appconfig. |
|
| 418 | - * |
|
| 419 | - * @param string $app app |
|
| 420 | - * @throws Exception |
|
| 421 | - */ |
|
| 422 | - public static function disable($app) { |
|
| 423 | - // flush |
|
| 424 | - self::$enabledAppsCache = array(); |
|
| 425 | - |
|
| 426 | - // run uninstall steps |
|
| 427 | - $appData = OC_App::getAppInfo($app); |
|
| 428 | - if (!is_null($appData)) { |
|
| 429 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // emit disable hook - needed anymore ? |
|
| 433 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
| 434 | - |
|
| 435 | - // finally disable it |
|
| 436 | - $appManager = \OC::$server->getAppManager(); |
|
| 437 | - $appManager->disableApp($app); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // This is private as well. It simply works, so don't ask for more details |
|
| 441 | - private static function proceedNavigation($list) { |
|
| 442 | - usort($list, function($a, $b) { |
|
| 443 | - if (isset($a['order']) && isset($b['order'])) { |
|
| 444 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 445 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
| 446 | - return isset($a['order']) ? -1 : 1; |
|
| 447 | - } else { |
|
| 448 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 449 | - } |
|
| 450 | - }); |
|
| 451 | - |
|
| 452 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
| 453 | - foreach ($list as $index => &$navEntry) { |
|
| 454 | - if ($navEntry['id'] == $activeApp) { |
|
| 455 | - $navEntry['active'] = true; |
|
| 456 | - } else { |
|
| 457 | - $navEntry['active'] = false; |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - unset($navEntry); |
|
| 461 | - |
|
| 462 | - return $list; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Get the path where to install apps |
|
| 467 | - * |
|
| 468 | - * @return string|false |
|
| 469 | - */ |
|
| 470 | - public static function getInstallPath() { |
|
| 471 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - foreach (OC::$APPSROOTS as $dir) { |
|
| 476 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
| 477 | - return $dir['path']; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
| 482 | - return null; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * search for an app in all app-directories |
|
| 488 | - * |
|
| 489 | - * @param string $appId |
|
| 490 | - * @return false|string |
|
| 491 | - */ |
|
| 492 | - public static function findAppInDirectories($appId) { |
|
| 493 | - $sanitizedAppId = self::cleanAppId($appId); |
|
| 494 | - if($sanitizedAppId !== $appId) { |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - static $app_dir = array(); |
|
| 498 | - |
|
| 499 | - if (isset($app_dir[$appId])) { |
|
| 500 | - return $app_dir[$appId]; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $possibleApps = array(); |
|
| 504 | - foreach (OC::$APPSROOTS as $dir) { |
|
| 505 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 506 | - $possibleApps[] = $dir; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if (empty($possibleApps)) { |
|
| 511 | - return false; |
|
| 512 | - } elseif (count($possibleApps) === 1) { |
|
| 513 | - $dir = array_shift($possibleApps); |
|
| 514 | - $app_dir[$appId] = $dir; |
|
| 515 | - return $dir; |
|
| 516 | - } else { |
|
| 517 | - $versionToLoad = array(); |
|
| 518 | - foreach ($possibleApps as $possibleApp) { |
|
| 519 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
| 520 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
| 521 | - $versionToLoad = array( |
|
| 522 | - 'dir' => $possibleApp, |
|
| 523 | - 'version' => $version, |
|
| 524 | - ); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
| 528 | - return $versionToLoad['dir']; |
|
| 529 | - //TODO - write test |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Get the directory for the given app. |
|
| 535 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 536 | - * |
|
| 537 | - * @param string $appId |
|
| 538 | - * @return string|false |
|
| 539 | - */ |
|
| 540 | - public static function getAppPath($appId) { |
|
| 541 | - if ($appId === null || trim($appId) === '') { |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 546 | - return $dir['path'] . '/' . $appId; |
|
| 547 | - } |
|
| 548 | - return false; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Get the path for the given app on the access |
|
| 553 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 554 | - * |
|
| 555 | - * @param string $appId |
|
| 556 | - * @return string|false |
|
| 557 | - */ |
|
| 558 | - public static function getAppWebPath($appId) { |
|
| 559 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 560 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 561 | - } |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * get the last version of the app from appinfo/info.xml |
|
| 567 | - * |
|
| 568 | - * @param string $appId |
|
| 569 | - * @param bool $useCache |
|
| 570 | - * @return string |
|
| 571 | - */ |
|
| 572 | - public static function getAppVersion($appId, $useCache = true) { |
|
| 573 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
| 574 | - return self::$appVersion[$appId]; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $file = self::getAppPath($appId); |
|
| 578 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
| 579 | - return self::$appVersion[$appId]; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * get app's version based on it's path |
|
| 584 | - * |
|
| 585 | - * @param string $path |
|
| 586 | - * @return string |
|
| 587 | - */ |
|
| 588 | - public static function getAppVersionByPath($path) { |
|
| 589 | - $infoFile = $path . '/appinfo/info.xml'; |
|
| 590 | - $appData = self::getAppInfo($infoFile, true); |
|
| 591 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Read all app metadata from the info.xml file |
|
| 597 | - * |
|
| 598 | - * @param string $appId id of the app or the path of the info.xml file |
|
| 599 | - * @param bool $path |
|
| 600 | - * @param string $lang |
|
| 601 | - * @return array|null |
|
| 602 | - * @note all data is read from info.xml, not just pre-defined fields |
|
| 603 | - */ |
|
| 604 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
| 605 | - if ($path) { |
|
| 606 | - $file = $appId; |
|
| 607 | - } else { |
|
| 608 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
| 609 | - return self::$appInfo[$appId]; |
|
| 610 | - } |
|
| 611 | - $appPath = self::getAppPath($appId); |
|
| 612 | - if($appPath === false) { |
|
| 613 | - return null; |
|
| 614 | - } |
|
| 615 | - $file = $appPath . '/appinfo/info.xml'; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
|
| 619 | - $data = $parser->parse($file); |
|
| 620 | - |
|
| 621 | - if (is_array($data)) { |
|
| 622 | - $data = OC_App::parseAppInfo($data, $lang); |
|
| 623 | - } |
|
| 624 | - if(isset($data['ocsid'])) { |
|
| 625 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
| 626 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 627 | - $data['ocsid'] = $storedId; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ($lang === null) { |
|
| 632 | - self::$appInfo[$appId] = $data; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - return $data; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Returns the navigation |
|
| 640 | - * |
|
| 641 | - * @return array |
|
| 642 | - * |
|
| 643 | - * This function returns an array containing all entries added. The |
|
| 644 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
| 645 | - * given for each app the following keys exist: |
|
| 646 | - * - active: boolean, signals if the user is on this navigation entry |
|
| 647 | - */ |
|
| 648 | - public static function getNavigation() { |
|
| 649 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
| 650 | - return self::proceedNavigation($entries); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Returns the Settings Navigation |
|
| 655 | - * |
|
| 656 | - * @return string[] |
|
| 657 | - * |
|
| 658 | - * This function returns an array containing all settings pages added. The |
|
| 659 | - * entries are sorted by the key 'order' ascending. |
|
| 660 | - */ |
|
| 661 | - public static function getSettingsNavigation() { |
|
| 662 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
| 663 | - return self::proceedNavigation($entries); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * get the id of loaded app |
|
| 668 | - * |
|
| 669 | - * @return string |
|
| 670 | - */ |
|
| 671 | - public static function getCurrentApp() { |
|
| 672 | - $request = \OC::$server->getRequest(); |
|
| 673 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
| 674 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
| 675 | - if (empty($topFolder)) { |
|
| 676 | - $path_info = $request->getPathInfo(); |
|
| 677 | - if ($path_info) { |
|
| 678 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - if ($topFolder == 'apps') { |
|
| 682 | - $length = strlen($topFolder); |
|
| 683 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
| 684 | - } else { |
|
| 685 | - return $topFolder; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * @param string $type |
|
| 691 | - * @return array |
|
| 692 | - */ |
|
| 693 | - public static function getForms($type) { |
|
| 694 | - $forms = array(); |
|
| 695 | - switch ($type) { |
|
| 696 | - case 'admin': |
|
| 697 | - $source = self::$adminForms; |
|
| 698 | - break; |
|
| 699 | - case 'personal': |
|
| 700 | - $source = self::$personalForms; |
|
| 701 | - break; |
|
| 702 | - default: |
|
| 703 | - return array(); |
|
| 704 | - } |
|
| 705 | - foreach ($source as $form) { |
|
| 706 | - $forms[] = include $form; |
|
| 707 | - } |
|
| 708 | - return $forms; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * register an admin form to be shown |
|
| 713 | - * |
|
| 714 | - * @param string $app |
|
| 715 | - * @param string $page |
|
| 716 | - */ |
|
| 717 | - public static function registerAdmin($app, $page) { |
|
| 718 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * register a personal form to be shown |
|
| 723 | - * @param string $app |
|
| 724 | - * @param string $page |
|
| 725 | - */ |
|
| 726 | - public static function registerPersonal($app, $page) { |
|
| 727 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * @param array $entry |
|
| 732 | - */ |
|
| 733 | - public static function registerLogIn(array $entry) { |
|
| 734 | - self::$altLogin[] = $entry; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * @return array |
|
| 739 | - */ |
|
| 740 | - public static function getAlternativeLogIns() { |
|
| 741 | - return self::$altLogin; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * get a list of all apps in the apps folder |
|
| 746 | - * |
|
| 747 | - * @return array an array of app names (string IDs) |
|
| 748 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
| 749 | - */ |
|
| 750 | - public static function getAllApps() { |
|
| 751 | - |
|
| 752 | - $apps = array(); |
|
| 753 | - |
|
| 754 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
| 755 | - if (!is_readable($apps_dir['path'])) { |
|
| 756 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 757 | - continue; |
|
| 758 | - } |
|
| 759 | - $dh = opendir($apps_dir['path']); |
|
| 760 | - |
|
| 761 | - if (is_resource($dh)) { |
|
| 762 | - while (($file = readdir($dh)) !== false) { |
|
| 763 | - |
|
| 764 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 765 | - |
|
| 766 | - $apps[] = $file; |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - $apps = array_unique($apps); |
|
| 773 | - |
|
| 774 | - return $apps; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * List all apps, this is used in apps.php |
|
| 779 | - * |
|
| 780 | - * @return array |
|
| 781 | - */ |
|
| 782 | - public function listAllApps() { |
|
| 783 | - $installedApps = OC_App::getAllApps(); |
|
| 784 | - |
|
| 785 | - $appManager = \OC::$server->getAppManager(); |
|
| 786 | - //we don't want to show configuration for these |
|
| 787 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
| 788 | - $appList = array(); |
|
| 789 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
| 790 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 791 | - |
|
| 792 | - foreach ($installedApps as $app) { |
|
| 793 | - if (array_search($app, $blacklist) === false) { |
|
| 794 | - |
|
| 795 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
| 796 | - if (!is_array($info)) { |
|
| 797 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 798 | - continue; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - if (!isset($info['name'])) { |
|
| 802 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 803 | - continue; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
| 807 | - $info['groups'] = null; |
|
| 808 | - if ($enabled === 'yes') { |
|
| 809 | - $active = true; |
|
| 810 | - } else if ($enabled === 'no') { |
|
| 811 | - $active = false; |
|
| 812 | - } else { |
|
| 813 | - $active = true; |
|
| 814 | - $info['groups'] = $enabled; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $info['active'] = $active; |
|
| 818 | - |
|
| 819 | - if ($appManager->isShipped($app)) { |
|
| 820 | - $info['internal'] = true; |
|
| 821 | - $info['level'] = self::officialApp; |
|
| 822 | - $info['removable'] = false; |
|
| 823 | - } else { |
|
| 824 | - $info['internal'] = false; |
|
| 825 | - $info['removable'] = true; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - $appPath = self::getAppPath($app); |
|
| 829 | - if($appPath !== false) { |
|
| 830 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 831 | - if (file_exists($appIcon)) { |
|
| 832 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
| 833 | - $info['previewAsIcon'] = true; |
|
| 834 | - } else { |
|
| 835 | - $appIcon = $appPath . '/img/app.svg'; |
|
| 836 | - if (file_exists($appIcon)) { |
|
| 837 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
| 838 | - $info['previewAsIcon'] = true; |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - // fix documentation |
|
| 843 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
| 844 | - foreach ($info['documentation'] as $key => $url) { |
|
| 845 | - // If it is not an absolute URL we assume it is a key |
|
| 846 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
| 847 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
| 848 | - $url = $urlGenerator->linkToDocs($url); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - $info['documentation'][$key] = $url; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - $info['version'] = OC_App::getAppVersion($app); |
|
| 856 | - $appList[] = $info; |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - return $appList; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - public static function shouldUpgrade($app) { |
|
| 864 | - $versions = self::getAppVersions(); |
|
| 865 | - $currentVersion = OC_App::getAppVersion($app); |
|
| 866 | - if ($currentVersion && isset($versions[$app])) { |
|
| 867 | - $installedVersion = $versions[$app]; |
|
| 868 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
| 869 | - return true; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - return false; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Adjust the number of version parts of $version1 to match |
|
| 877 | - * the number of version parts of $version2. |
|
| 878 | - * |
|
| 879 | - * @param string $version1 version to adjust |
|
| 880 | - * @param string $version2 version to take the number of parts from |
|
| 881 | - * @return string shortened $version1 |
|
| 882 | - */ |
|
| 883 | - private static function adjustVersionParts($version1, $version2) { |
|
| 884 | - $version1 = explode('.', $version1); |
|
| 885 | - $version2 = explode('.', $version2); |
|
| 886 | - // reduce $version1 to match the number of parts in $version2 |
|
| 887 | - while (count($version1) > count($version2)) { |
|
| 888 | - array_pop($version1); |
|
| 889 | - } |
|
| 890 | - // if $version1 does not have enough parts, add some |
|
| 891 | - while (count($version1) < count($version2)) { |
|
| 892 | - $version1[] = '0'; |
|
| 893 | - } |
|
| 894 | - return implode('.', $version1); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Check whether the current ownCloud version matches the given |
|
| 899 | - * application's version requirements. |
|
| 900 | - * |
|
| 901 | - * The comparison is made based on the number of parts that the |
|
| 902 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
| 903 | - * app info version is expecting version 6.0, the comparison is |
|
| 904 | - * made on the first two parts of the ownCloud version. |
|
| 905 | - * This means that it's possible to specify "requiremin" => 6 |
|
| 906 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
| 907 | - * |
|
| 908 | - * @param string $ocVersion ownCloud version to check against |
|
| 909 | - * @param array $appInfo app info (from xml) |
|
| 910 | - * |
|
| 911 | - * @return boolean true if compatible, otherwise false |
|
| 912 | - */ |
|
| 913 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
| 914 | - $requireMin = ''; |
|
| 915 | - $requireMax = ''; |
|
| 916 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 917 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
| 918 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 919 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
| 920 | - } else if (isset($appInfo['requiremin'])) { |
|
| 921 | - $requireMin = $appInfo['requiremin']; |
|
| 922 | - } else if (isset($appInfo['require'])) { |
|
| 923 | - $requireMin = $appInfo['require']; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 927 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
| 928 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 929 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
| 930 | - } else if (isset($appInfo['requiremax'])) { |
|
| 931 | - $requireMax = $appInfo['requiremax']; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - if (is_array($ocVersion)) { |
|
| 935 | - $ocVersion = implode('.', $ocVersion); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - if (!empty($requireMin) |
|
| 939 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
| 940 | - ) { |
|
| 941 | - |
|
| 942 | - return false; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - if (!empty($requireMax) |
|
| 946 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
| 947 | - ) { |
|
| 948 | - return false; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return true; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * get the installed version of all apps |
|
| 956 | - */ |
|
| 957 | - public static function getAppVersions() { |
|
| 958 | - static $versions; |
|
| 959 | - |
|
| 960 | - if(!$versions) { |
|
| 961 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 962 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
| 963 | - } |
|
| 964 | - return $versions; |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * @param string $app |
|
| 969 | - * @param \OCP\IConfig $config |
|
| 970 | - * @param \OCP\IL10N $l |
|
| 971 | - * @return bool |
|
| 972 | - * |
|
| 973 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
| 974 | - * @throws Exception if no app-name was specified |
|
| 975 | - */ |
|
| 976 | - public function installApp($app, |
|
| 977 | - \OCP\IConfig $config, |
|
| 978 | - \OCP\IL10N $l) { |
|
| 979 | - if ($app !== false) { |
|
| 980 | - // check if the app is compatible with this version of ownCloud |
|
| 981 | - $info = self::getAppInfo($app); |
|
| 982 | - if(!is_array($info)) { |
|
| 983 | - throw new \Exception( |
|
| 984 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 985 | - [$info['name']] |
|
| 986 | - ) |
|
| 987 | - ); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - $version = \OCP\Util::getVersion(); |
|
| 991 | - if (!self::isAppCompatible($version, $info)) { |
|
| 992 | - throw new \Exception( |
|
| 993 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 994 | - array($info['name']) |
|
| 995 | - ) |
|
| 996 | - ); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - // check for required dependencies |
|
| 1000 | - self::checkAppDependencies($config, $l, $info); |
|
| 1001 | - |
|
| 1002 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
| 1003 | - if (isset($appData['id'])) { |
|
| 1004 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1008 | - $appPath = self::getAppPath($app); |
|
| 1009 | - self::registerAutoloading($app, $appPath); |
|
| 1010 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
| 1014 | - } else { |
|
| 1015 | - if(empty($appName) ) { |
|
| 1016 | - throw new \Exception($l->t("No app name specified")); |
|
| 1017 | - } else { |
|
| 1018 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - return $app; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * update the database for the app and call the update script |
|
| 1027 | - * |
|
| 1028 | - * @param string $appId |
|
| 1029 | - * @return bool |
|
| 1030 | - */ |
|
| 1031 | - public static function updateApp($appId) { |
|
| 1032 | - $appPath = self::getAppPath($appId); |
|
| 1033 | - if($appPath === false) { |
|
| 1034 | - return false; |
|
| 1035 | - } |
|
| 1036 | - self::registerAutoloading($appId, $appPath); |
|
| 1037 | - |
|
| 1038 | - $appData = self::getAppInfo($appId); |
|
| 1039 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
| 1040 | - |
|
| 1041 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1042 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1043 | - } else { |
|
| 1044 | - $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
| 1045 | - $ms->migrate(); |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
| 1049 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
| 1050 | - unset(self::$appVersion[$appId]); |
|
| 1051 | - |
|
| 1052 | - // run upgrade code |
|
| 1053 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1054 | - self::loadApp($appId); |
|
| 1055 | - include $appPath . '/appinfo/update.php'; |
|
| 1056 | - } |
|
| 1057 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
| 1058 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1059 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - //set remote/public handlers |
|
| 1063 | - if (array_key_exists('ocsid', $appData)) { |
|
| 1064 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
| 1065 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1066 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
| 1067 | - } |
|
| 1068 | - foreach ($appData['remote'] as $name => $path) { |
|
| 1069 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1070 | - } |
|
| 1071 | - foreach ($appData['public'] as $name => $path) { |
|
| 1072 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - self::setAppTypes($appId); |
|
| 1076 | - |
|
| 1077 | - $version = \OC_App::getAppVersion($appId); |
|
| 1078 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
| 1079 | - |
|
| 1080 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
| 1081 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
| 1082 | - )); |
|
| 1083 | - |
|
| 1084 | - return true; |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * @param string $appId |
|
| 1089 | - * @param string[] $steps |
|
| 1090 | - * @throws \OC\NeedsUpdateException |
|
| 1091 | - */ |
|
| 1092 | - public static function executeRepairSteps($appId, array $steps) { |
|
| 1093 | - if (empty($steps)) { |
|
| 1094 | - return; |
|
| 1095 | - } |
|
| 1096 | - // load the app |
|
| 1097 | - self::loadApp($appId); |
|
| 1098 | - |
|
| 1099 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
| 1100 | - |
|
| 1101 | - // load the steps |
|
| 1102 | - $r = new Repair([], $dispatcher); |
|
| 1103 | - foreach ($steps as $step) { |
|
| 1104 | - try { |
|
| 1105 | - $r->addStep($step); |
|
| 1106 | - } catch (Exception $ex) { |
|
| 1107 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
| 1108 | - \OC::$server->getLogger()->logException($ex); |
|
| 1109 | - } |
|
| 1110 | - } |
|
| 1111 | - // run the steps |
|
| 1112 | - $r->run(); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - public static function setupBackgroundJobs(array $jobs) { |
|
| 1116 | - $queue = \OC::$server->getJobList(); |
|
| 1117 | - foreach ($jobs as $job) { |
|
| 1118 | - $queue->add($job); |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - /** |
|
| 1123 | - * @param string $appId |
|
| 1124 | - * @param string[] $steps |
|
| 1125 | - */ |
|
| 1126 | - private static function setupLiveMigrations($appId, array $steps) { |
|
| 1127 | - $queue = \OC::$server->getJobList(); |
|
| 1128 | - foreach ($steps as $step) { |
|
| 1129 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
| 1130 | - 'app' => $appId, |
|
| 1131 | - 'step' => $step]); |
|
| 1132 | - } |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * @param string $appId |
|
| 1137 | - * @return \OC\Files\View|false |
|
| 1138 | - */ |
|
| 1139 | - public static function getStorage($appId) { |
|
| 1140 | - if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
| 1141 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1142 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1143 | - if (!$view->file_exists($appId)) { |
|
| 1144 | - $view->mkdir($appId); |
|
| 1145 | - } |
|
| 1146 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1147 | - } else { |
|
| 1148 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1149 | - return false; |
|
| 1150 | - } |
|
| 1151 | - } else { |
|
| 1152 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1153 | - return false; |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - protected static function findBestL10NOption($options, $lang) { |
|
| 1158 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
| 1159 | - |
|
| 1160 | - $lang = strtolower($lang); |
|
| 1161 | - $similarLang = $lang; |
|
| 1162 | - if (strpos($similarLang, '_')) { |
|
| 1163 | - // For "de_DE" we want to find "de" and the other way around |
|
| 1164 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - foreach ($options as $option) { |
|
| 1168 | - if (is_array($option)) { |
|
| 1169 | - if ($fallback === false) { |
|
| 1170 | - $fallback = $option['@value']; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - if (!isset($option['@attributes']['lang'])) { |
|
| 1174 | - continue; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 1178 | - if ($attributeLang === $lang) { |
|
| 1179 | - return $option['@value']; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - if ($attributeLang === $similarLang) { |
|
| 1183 | - $similarLangFallback = $option['@value']; |
|
| 1184 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1185 | - if ($similarLangFallback === false) { |
|
| 1186 | - $similarLangFallback = $option['@value']; |
|
| 1187 | - } |
|
| 1188 | - } |
|
| 1189 | - } else { |
|
| 1190 | - $englishFallback = $option; |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - if ($similarLangFallback !== false) { |
|
| 1195 | - return $similarLangFallback; |
|
| 1196 | - } else if ($englishFallback !== false) { |
|
| 1197 | - return $englishFallback; |
|
| 1198 | - } |
|
| 1199 | - return (string) $fallback; |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * parses the app data array and enhanced the 'description' value |
|
| 1204 | - * |
|
| 1205 | - * @param array $data the app data |
|
| 1206 | - * @param string $lang |
|
| 1207 | - * @return array improved app data |
|
| 1208 | - */ |
|
| 1209 | - public static function parseAppInfo(array $data, $lang = null) { |
|
| 1210 | - |
|
| 1211 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
| 1212 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
| 1213 | - } |
|
| 1214 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
| 1215 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
| 1216 | - } |
|
| 1217 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
| 1218 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
| 1219 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
| 1220 | - $data['description'] = trim($data['description']); |
|
| 1221 | - } else { |
|
| 1222 | - $data['description'] = ''; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return $data; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - /** |
|
| 1229 | - * @param \OCP\IConfig $config |
|
| 1230 | - * @param \OCP\IL10N $l |
|
| 1231 | - * @param array $info |
|
| 1232 | - * @throws \Exception |
|
| 1233 | - */ |
|
| 1234 | - public static function checkAppDependencies($config, $l, $info) { |
|
| 1235 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
| 1236 | - $missing = $dependencyAnalyzer->analyze($info); |
|
| 1237 | - if (!empty($missing)) { |
|
| 1238 | - $missingMsg = implode(PHP_EOL, $missing); |
|
| 1239 | - throw new \Exception( |
|
| 1240 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
| 1241 | - [$info['name'], $missingMsg] |
|
| 1242 | - ) |
|
| 1243 | - ); |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 66 | + static private $appVersion = []; |
|
| 67 | + static private $adminForms = array(); |
|
| 68 | + static private $personalForms = array(); |
|
| 69 | + static private $appInfo = array(); |
|
| 70 | + static private $appTypes = array(); |
|
| 71 | + static private $loadedApps = array(); |
|
| 72 | + static private $altLogin = array(); |
|
| 73 | + static private $alreadyRegistered = []; |
|
| 74 | + const officialApp = 200; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * clean the appId |
|
| 78 | + * |
|
| 79 | + * @param string|boolean $app AppId that needs to be cleaned |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public static function cleanAppId($app) { |
|
| 83 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Check if an app is loaded |
|
| 88 | + * |
|
| 89 | + * @param string $app |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public static function isAppLoaded($app) { |
|
| 93 | + return in_array($app, self::$loadedApps, true); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * loads all apps |
|
| 98 | + * |
|
| 99 | + * @param string[] | string | null $types |
|
| 100 | + * @return bool |
|
| 101 | + * |
|
| 102 | + * This function walks through the ownCloud directory and loads all apps |
|
| 103 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
| 104 | + * exists. |
|
| 105 | + * |
|
| 106 | + * if $types is set, only apps of those types will be loaded |
|
| 107 | + */ |
|
| 108 | + public static function loadApps($types = null) { |
|
| 109 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 110 | + return false; |
|
| 111 | + } |
|
| 112 | + // Load the enabled apps here |
|
| 113 | + $apps = self::getEnabledApps(); |
|
| 114 | + |
|
| 115 | + // Add each apps' folder as allowed class path |
|
| 116 | + foreach($apps as $app) { |
|
| 117 | + $path = self::getAppPath($app); |
|
| 118 | + if($path !== false) { |
|
| 119 | + self::registerAutoloading($app, $path); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // prevent app.php from printing output |
|
| 124 | + ob_start(); |
|
| 125 | + foreach ($apps as $app) { |
|
| 126 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
| 127 | + self::loadApp($app); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + ob_end_clean(); |
|
| 131 | + |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * load a single app |
|
| 137 | + * |
|
| 138 | + * @param string $app |
|
| 139 | + */ |
|
| 140 | + public static function loadApp($app) { |
|
| 141 | + self::$loadedApps[] = $app; |
|
| 142 | + $appPath = self::getAppPath($app); |
|
| 143 | + if($appPath === false) { |
|
| 144 | + return; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // in case someone calls loadApp() directly |
|
| 148 | + self::registerAutoloading($app, $appPath); |
|
| 149 | + |
|
| 150 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
| 151 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 152 | + self::requireAppFile($app); |
|
| 153 | + if (self::isType($app, array('authentication'))) { |
|
| 154 | + // since authentication apps affect the "is app enabled for group" check, |
|
| 155 | + // the enabled apps cache needs to be cleared to make sure that the |
|
| 156 | + // next time getEnableApps() is called it will also include apps that were |
|
| 157 | + // enabled for groups |
|
| 158 | + self::$enabledAppsCache = array(); |
|
| 159 | + } |
|
| 160 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $info = self::getAppInfo($app); |
|
| 164 | + if (!empty($info['activity']['filters'])) { |
|
| 165 | + foreach ($info['activity']['filters'] as $filter) { |
|
| 166 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + if (!empty($info['activity']['settings'])) { |
|
| 170 | + foreach ($info['activity']['settings'] as $setting) { |
|
| 171 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + if (!empty($info['activity']['providers'])) { |
|
| 175 | + foreach ($info['activity']['providers'] as $provider) { |
|
| 176 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + if (!empty($info['collaboration']['plugins'])) { |
|
| 180 | + // deal with one or many plugin entries |
|
| 181 | + $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
| 182 | + [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
| 183 | + foreach ($plugins as $plugin) { |
|
| 184 | + if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 185 | + $pluginInfo = [ |
|
| 186 | + 'shareType' => $plugin['@attributes']['share-type'], |
|
| 187 | + 'class' => $plugin['@value'], |
|
| 188 | + ]; |
|
| 189 | + \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
| 190 | + } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
| 191 | + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @internal |
|
| 199 | + * @param string $app |
|
| 200 | + * @param string $path |
|
| 201 | + */ |
|
| 202 | + public static function registerAutoloading($app, $path) { |
|
| 203 | + $key = $app . '-' . $path; |
|
| 204 | + if(isset(self::$alreadyRegistered[$key])) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + self::$alreadyRegistered[$key] = true; |
|
| 209 | + |
|
| 210 | + // Register on PSR-4 composer autoloader |
|
| 211 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
| 212 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
| 213 | + |
|
| 214 | + if (file_exists($path . '/composer/autoload.php')) { |
|
| 215 | + require_once $path . '/composer/autoload.php'; |
|
| 216 | + } else { |
|
| 217 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 218 | + // Register on legacy autoloader |
|
| 219 | + \OC::$loader->addValidRoot($path); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // Register Test namespace only when testing |
|
| 223 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
| 224 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Load app.php from the given app |
|
| 230 | + * |
|
| 231 | + * @param string $app app name |
|
| 232 | + */ |
|
| 233 | + private static function requireAppFile($app) { |
|
| 234 | + try { |
|
| 235 | + // encapsulated here to avoid variable scope conflicts |
|
| 236 | + require_once $app . '/appinfo/app.php'; |
|
| 237 | + } catch (Error $ex) { |
|
| 238 | + \OC::$server->getLogger()->logException($ex); |
|
| 239 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
| 240 | + if (!in_array($app, $blacklist)) { |
|
| 241 | + self::disable($app); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * check if an app is of a specific type |
|
| 248 | + * |
|
| 249 | + * @param string $app |
|
| 250 | + * @param string|array $types |
|
| 251 | + * @return bool |
|
| 252 | + */ |
|
| 253 | + public static function isType($app, $types) { |
|
| 254 | + if (is_string($types)) { |
|
| 255 | + $types = array($types); |
|
| 256 | + } |
|
| 257 | + $appTypes = self::getAppTypes($app); |
|
| 258 | + foreach ($types as $type) { |
|
| 259 | + if (array_search($type, $appTypes) !== false) { |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * get the types of an app |
|
| 268 | + * |
|
| 269 | + * @param string $app |
|
| 270 | + * @return array |
|
| 271 | + */ |
|
| 272 | + private static function getAppTypes($app) { |
|
| 273 | + //load the cache |
|
| 274 | + if (count(self::$appTypes) == 0) { |
|
| 275 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + if (isset(self::$appTypes[$app])) { |
|
| 279 | + return explode(',', self::$appTypes[$app]); |
|
| 280 | + } else { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * read app types from info.xml and cache them in the database |
|
| 287 | + */ |
|
| 288 | + public static function setAppTypes($app) { |
|
| 289 | + $appData = self::getAppInfo($app); |
|
| 290 | + if(!is_array($appData)) { |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (isset($appData['types'])) { |
|
| 295 | + $appTypes = implode(',', $appData['types']); |
|
| 296 | + } else { |
|
| 297 | + $appTypes = ''; |
|
| 298 | + $appData['types'] = []; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
| 302 | + |
|
| 303 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
| 304 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
| 305 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
| 306 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * get all enabled apps |
|
| 313 | + */ |
|
| 314 | + protected static $enabledAppsCache = array(); |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Returns apps enabled for the current user. |
|
| 318 | + * |
|
| 319 | + * @param bool $forceRefresh whether to refresh the cache |
|
| 320 | + * @param bool $all whether to return apps for all users, not only the |
|
| 321 | + * currently logged in one |
|
| 322 | + * @return string[] |
|
| 323 | + */ |
|
| 324 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
| 325 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 326 | + return array(); |
|
| 327 | + } |
|
| 328 | + // in incognito mode or when logged out, $user will be false, |
|
| 329 | + // which is also the case during an upgrade |
|
| 330 | + $appManager = \OC::$server->getAppManager(); |
|
| 331 | + if ($all) { |
|
| 332 | + $user = null; |
|
| 333 | + } else { |
|
| 334 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if (is_null($user)) { |
|
| 338 | + $apps = $appManager->getInstalledApps(); |
|
| 339 | + } else { |
|
| 340 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
| 341 | + } |
|
| 342 | + $apps = array_filter($apps, function ($app) { |
|
| 343 | + return $app !== 'files';//we add this manually |
|
| 344 | + }); |
|
| 345 | + sort($apps); |
|
| 346 | + array_unshift($apps, 'files'); |
|
| 347 | + return $apps; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * checks whether or not an app is enabled |
|
| 352 | + * |
|
| 353 | + * @param string $app app |
|
| 354 | + * @return bool |
|
| 355 | + * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
| 356 | + * |
|
| 357 | + * This function checks whether or not an app is enabled. |
|
| 358 | + */ |
|
| 359 | + public static function isEnabled($app) { |
|
| 360 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * enables an app |
|
| 365 | + * |
|
| 366 | + * @param string $appId |
|
| 367 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
| 368 | + * @throws \Exception |
|
| 369 | + * @return void |
|
| 370 | + * |
|
| 371 | + * This function set an app as enabled in appconfig. |
|
| 372 | + */ |
|
| 373 | + public function enable($appId, |
|
| 374 | + $groups = null) { |
|
| 375 | + self::$enabledAppsCache = []; // flush |
|
| 376 | + |
|
| 377 | + // Check if app is already downloaded |
|
| 378 | + $installer = \OC::$server->query(Installer::class); |
|
| 379 | + $isDownloaded = $installer->isDownloaded($appId); |
|
| 380 | + |
|
| 381 | + if(!$isDownloaded) { |
|
| 382 | + $installer->downloadApp($appId); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + $installer->installApp($appId); |
|
| 386 | + |
|
| 387 | + $appManager = \OC::$server->getAppManager(); |
|
| 388 | + if (!is_null($groups)) { |
|
| 389 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 390 | + $groupsList = []; |
|
| 391 | + foreach ($groups as $group) { |
|
| 392 | + $groupItem = $groupManager->get($group); |
|
| 393 | + if ($groupItem instanceof \OCP\IGroup) { |
|
| 394 | + $groupsList[] = $groupManager->get($group); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
| 398 | + } else { |
|
| 399 | + $appManager->enableApp($appId); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @param string $app |
|
| 405 | + * @return bool |
|
| 406 | + */ |
|
| 407 | + public static function removeApp($app) { |
|
| 408 | + if (\OC::$server->getAppManager()->isShipped($app)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $installer = \OC::$server->query(Installer::class); |
|
| 413 | + return $installer->removeApp($app); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * This function set an app as disabled in appconfig. |
|
| 418 | + * |
|
| 419 | + * @param string $app app |
|
| 420 | + * @throws Exception |
|
| 421 | + */ |
|
| 422 | + public static function disable($app) { |
|
| 423 | + // flush |
|
| 424 | + self::$enabledAppsCache = array(); |
|
| 425 | + |
|
| 426 | + // run uninstall steps |
|
| 427 | + $appData = OC_App::getAppInfo($app); |
|
| 428 | + if (!is_null($appData)) { |
|
| 429 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // emit disable hook - needed anymore ? |
|
| 433 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
| 434 | + |
|
| 435 | + // finally disable it |
|
| 436 | + $appManager = \OC::$server->getAppManager(); |
|
| 437 | + $appManager->disableApp($app); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // This is private as well. It simply works, so don't ask for more details |
|
| 441 | + private static function proceedNavigation($list) { |
|
| 442 | + usort($list, function($a, $b) { |
|
| 443 | + if (isset($a['order']) && isset($b['order'])) { |
|
| 444 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 445 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
| 446 | + return isset($a['order']) ? -1 : 1; |
|
| 447 | + } else { |
|
| 448 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 449 | + } |
|
| 450 | + }); |
|
| 451 | + |
|
| 452 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
| 453 | + foreach ($list as $index => &$navEntry) { |
|
| 454 | + if ($navEntry['id'] == $activeApp) { |
|
| 455 | + $navEntry['active'] = true; |
|
| 456 | + } else { |
|
| 457 | + $navEntry['active'] = false; |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + unset($navEntry); |
|
| 461 | + |
|
| 462 | + return $list; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Get the path where to install apps |
|
| 467 | + * |
|
| 468 | + * @return string|false |
|
| 469 | + */ |
|
| 470 | + public static function getInstallPath() { |
|
| 471 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + foreach (OC::$APPSROOTS as $dir) { |
|
| 476 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
| 477 | + return $dir['path']; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
| 482 | + return null; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * search for an app in all app-directories |
|
| 488 | + * |
|
| 489 | + * @param string $appId |
|
| 490 | + * @return false|string |
|
| 491 | + */ |
|
| 492 | + public static function findAppInDirectories($appId) { |
|
| 493 | + $sanitizedAppId = self::cleanAppId($appId); |
|
| 494 | + if($sanitizedAppId !== $appId) { |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + static $app_dir = array(); |
|
| 498 | + |
|
| 499 | + if (isset($app_dir[$appId])) { |
|
| 500 | + return $app_dir[$appId]; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $possibleApps = array(); |
|
| 504 | + foreach (OC::$APPSROOTS as $dir) { |
|
| 505 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 506 | + $possibleApps[] = $dir; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if (empty($possibleApps)) { |
|
| 511 | + return false; |
|
| 512 | + } elseif (count($possibleApps) === 1) { |
|
| 513 | + $dir = array_shift($possibleApps); |
|
| 514 | + $app_dir[$appId] = $dir; |
|
| 515 | + return $dir; |
|
| 516 | + } else { |
|
| 517 | + $versionToLoad = array(); |
|
| 518 | + foreach ($possibleApps as $possibleApp) { |
|
| 519 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
| 520 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
| 521 | + $versionToLoad = array( |
|
| 522 | + 'dir' => $possibleApp, |
|
| 523 | + 'version' => $version, |
|
| 524 | + ); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
| 528 | + return $versionToLoad['dir']; |
|
| 529 | + //TODO - write test |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Get the directory for the given app. |
|
| 535 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 536 | + * |
|
| 537 | + * @param string $appId |
|
| 538 | + * @return string|false |
|
| 539 | + */ |
|
| 540 | + public static function getAppPath($appId) { |
|
| 541 | + if ($appId === null || trim($appId) === '') { |
|
| 542 | + return false; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 546 | + return $dir['path'] . '/' . $appId; |
|
| 547 | + } |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Get the path for the given app on the access |
|
| 553 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
| 554 | + * |
|
| 555 | + * @param string $appId |
|
| 556 | + * @return string|false |
|
| 557 | + */ |
|
| 558 | + public static function getAppWebPath($appId) { |
|
| 559 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
| 560 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 561 | + } |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * get the last version of the app from appinfo/info.xml |
|
| 567 | + * |
|
| 568 | + * @param string $appId |
|
| 569 | + * @param bool $useCache |
|
| 570 | + * @return string |
|
| 571 | + */ |
|
| 572 | + public static function getAppVersion($appId, $useCache = true) { |
|
| 573 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
| 574 | + return self::$appVersion[$appId]; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $file = self::getAppPath($appId); |
|
| 578 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
| 579 | + return self::$appVersion[$appId]; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * get app's version based on it's path |
|
| 584 | + * |
|
| 585 | + * @param string $path |
|
| 586 | + * @return string |
|
| 587 | + */ |
|
| 588 | + public static function getAppVersionByPath($path) { |
|
| 589 | + $infoFile = $path . '/appinfo/info.xml'; |
|
| 590 | + $appData = self::getAppInfo($infoFile, true); |
|
| 591 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Read all app metadata from the info.xml file |
|
| 597 | + * |
|
| 598 | + * @param string $appId id of the app or the path of the info.xml file |
|
| 599 | + * @param bool $path |
|
| 600 | + * @param string $lang |
|
| 601 | + * @return array|null |
|
| 602 | + * @note all data is read from info.xml, not just pre-defined fields |
|
| 603 | + */ |
|
| 604 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
| 605 | + if ($path) { |
|
| 606 | + $file = $appId; |
|
| 607 | + } else { |
|
| 608 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
| 609 | + return self::$appInfo[$appId]; |
|
| 610 | + } |
|
| 611 | + $appPath = self::getAppPath($appId); |
|
| 612 | + if($appPath === false) { |
|
| 613 | + return null; |
|
| 614 | + } |
|
| 615 | + $file = $appPath . '/appinfo/info.xml'; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
|
| 619 | + $data = $parser->parse($file); |
|
| 620 | + |
|
| 621 | + if (is_array($data)) { |
|
| 622 | + $data = OC_App::parseAppInfo($data, $lang); |
|
| 623 | + } |
|
| 624 | + if(isset($data['ocsid'])) { |
|
| 625 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
| 626 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 627 | + $data['ocsid'] = $storedId; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ($lang === null) { |
|
| 632 | + self::$appInfo[$appId] = $data; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + return $data; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Returns the navigation |
|
| 640 | + * |
|
| 641 | + * @return array |
|
| 642 | + * |
|
| 643 | + * This function returns an array containing all entries added. The |
|
| 644 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
| 645 | + * given for each app the following keys exist: |
|
| 646 | + * - active: boolean, signals if the user is on this navigation entry |
|
| 647 | + */ |
|
| 648 | + public static function getNavigation() { |
|
| 649 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
| 650 | + return self::proceedNavigation($entries); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Returns the Settings Navigation |
|
| 655 | + * |
|
| 656 | + * @return string[] |
|
| 657 | + * |
|
| 658 | + * This function returns an array containing all settings pages added. The |
|
| 659 | + * entries are sorted by the key 'order' ascending. |
|
| 660 | + */ |
|
| 661 | + public static function getSettingsNavigation() { |
|
| 662 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
| 663 | + return self::proceedNavigation($entries); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * get the id of loaded app |
|
| 668 | + * |
|
| 669 | + * @return string |
|
| 670 | + */ |
|
| 671 | + public static function getCurrentApp() { |
|
| 672 | + $request = \OC::$server->getRequest(); |
|
| 673 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
| 674 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
| 675 | + if (empty($topFolder)) { |
|
| 676 | + $path_info = $request->getPathInfo(); |
|
| 677 | + if ($path_info) { |
|
| 678 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + if ($topFolder == 'apps') { |
|
| 682 | + $length = strlen($topFolder); |
|
| 683 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
| 684 | + } else { |
|
| 685 | + return $topFolder; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * @param string $type |
|
| 691 | + * @return array |
|
| 692 | + */ |
|
| 693 | + public static function getForms($type) { |
|
| 694 | + $forms = array(); |
|
| 695 | + switch ($type) { |
|
| 696 | + case 'admin': |
|
| 697 | + $source = self::$adminForms; |
|
| 698 | + break; |
|
| 699 | + case 'personal': |
|
| 700 | + $source = self::$personalForms; |
|
| 701 | + break; |
|
| 702 | + default: |
|
| 703 | + return array(); |
|
| 704 | + } |
|
| 705 | + foreach ($source as $form) { |
|
| 706 | + $forms[] = include $form; |
|
| 707 | + } |
|
| 708 | + return $forms; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * register an admin form to be shown |
|
| 713 | + * |
|
| 714 | + * @param string $app |
|
| 715 | + * @param string $page |
|
| 716 | + */ |
|
| 717 | + public static function registerAdmin($app, $page) { |
|
| 718 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * register a personal form to be shown |
|
| 723 | + * @param string $app |
|
| 724 | + * @param string $page |
|
| 725 | + */ |
|
| 726 | + public static function registerPersonal($app, $page) { |
|
| 727 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * @param array $entry |
|
| 732 | + */ |
|
| 733 | + public static function registerLogIn(array $entry) { |
|
| 734 | + self::$altLogin[] = $entry; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * @return array |
|
| 739 | + */ |
|
| 740 | + public static function getAlternativeLogIns() { |
|
| 741 | + return self::$altLogin; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * get a list of all apps in the apps folder |
|
| 746 | + * |
|
| 747 | + * @return array an array of app names (string IDs) |
|
| 748 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
| 749 | + */ |
|
| 750 | + public static function getAllApps() { |
|
| 751 | + |
|
| 752 | + $apps = array(); |
|
| 753 | + |
|
| 754 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
| 755 | + if (!is_readable($apps_dir['path'])) { |
|
| 756 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 757 | + continue; |
|
| 758 | + } |
|
| 759 | + $dh = opendir($apps_dir['path']); |
|
| 760 | + |
|
| 761 | + if (is_resource($dh)) { |
|
| 762 | + while (($file = readdir($dh)) !== false) { |
|
| 763 | + |
|
| 764 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 765 | + |
|
| 766 | + $apps[] = $file; |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + $apps = array_unique($apps); |
|
| 773 | + |
|
| 774 | + return $apps; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * List all apps, this is used in apps.php |
|
| 779 | + * |
|
| 780 | + * @return array |
|
| 781 | + */ |
|
| 782 | + public function listAllApps() { |
|
| 783 | + $installedApps = OC_App::getAllApps(); |
|
| 784 | + |
|
| 785 | + $appManager = \OC::$server->getAppManager(); |
|
| 786 | + //we don't want to show configuration for these |
|
| 787 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
| 788 | + $appList = array(); |
|
| 789 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
| 790 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 791 | + |
|
| 792 | + foreach ($installedApps as $app) { |
|
| 793 | + if (array_search($app, $blacklist) === false) { |
|
| 794 | + |
|
| 795 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
| 796 | + if (!is_array($info)) { |
|
| 797 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 798 | + continue; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + if (!isset($info['name'])) { |
|
| 802 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
| 807 | + $info['groups'] = null; |
|
| 808 | + if ($enabled === 'yes') { |
|
| 809 | + $active = true; |
|
| 810 | + } else if ($enabled === 'no') { |
|
| 811 | + $active = false; |
|
| 812 | + } else { |
|
| 813 | + $active = true; |
|
| 814 | + $info['groups'] = $enabled; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $info['active'] = $active; |
|
| 818 | + |
|
| 819 | + if ($appManager->isShipped($app)) { |
|
| 820 | + $info['internal'] = true; |
|
| 821 | + $info['level'] = self::officialApp; |
|
| 822 | + $info['removable'] = false; |
|
| 823 | + } else { |
|
| 824 | + $info['internal'] = false; |
|
| 825 | + $info['removable'] = true; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + $appPath = self::getAppPath($app); |
|
| 829 | + if($appPath !== false) { |
|
| 830 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 831 | + if (file_exists($appIcon)) { |
|
| 832 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
| 833 | + $info['previewAsIcon'] = true; |
|
| 834 | + } else { |
|
| 835 | + $appIcon = $appPath . '/img/app.svg'; |
|
| 836 | + if (file_exists($appIcon)) { |
|
| 837 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
| 838 | + $info['previewAsIcon'] = true; |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + // fix documentation |
|
| 843 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
| 844 | + foreach ($info['documentation'] as $key => $url) { |
|
| 845 | + // If it is not an absolute URL we assume it is a key |
|
| 846 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
| 847 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
| 848 | + $url = $urlGenerator->linkToDocs($url); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + $info['documentation'][$key] = $url; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + $info['version'] = OC_App::getAppVersion($app); |
|
| 856 | + $appList[] = $info; |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + return $appList; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + public static function shouldUpgrade($app) { |
|
| 864 | + $versions = self::getAppVersions(); |
|
| 865 | + $currentVersion = OC_App::getAppVersion($app); |
|
| 866 | + if ($currentVersion && isset($versions[$app])) { |
|
| 867 | + $installedVersion = $versions[$app]; |
|
| 868 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
| 869 | + return true; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + return false; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Adjust the number of version parts of $version1 to match |
|
| 877 | + * the number of version parts of $version2. |
|
| 878 | + * |
|
| 879 | + * @param string $version1 version to adjust |
|
| 880 | + * @param string $version2 version to take the number of parts from |
|
| 881 | + * @return string shortened $version1 |
|
| 882 | + */ |
|
| 883 | + private static function adjustVersionParts($version1, $version2) { |
|
| 884 | + $version1 = explode('.', $version1); |
|
| 885 | + $version2 = explode('.', $version2); |
|
| 886 | + // reduce $version1 to match the number of parts in $version2 |
|
| 887 | + while (count($version1) > count($version2)) { |
|
| 888 | + array_pop($version1); |
|
| 889 | + } |
|
| 890 | + // if $version1 does not have enough parts, add some |
|
| 891 | + while (count($version1) < count($version2)) { |
|
| 892 | + $version1[] = '0'; |
|
| 893 | + } |
|
| 894 | + return implode('.', $version1); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Check whether the current ownCloud version matches the given |
|
| 899 | + * application's version requirements. |
|
| 900 | + * |
|
| 901 | + * The comparison is made based on the number of parts that the |
|
| 902 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
| 903 | + * app info version is expecting version 6.0, the comparison is |
|
| 904 | + * made on the first two parts of the ownCloud version. |
|
| 905 | + * This means that it's possible to specify "requiremin" => 6 |
|
| 906 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
| 907 | + * |
|
| 908 | + * @param string $ocVersion ownCloud version to check against |
|
| 909 | + * @param array $appInfo app info (from xml) |
|
| 910 | + * |
|
| 911 | + * @return boolean true if compatible, otherwise false |
|
| 912 | + */ |
|
| 913 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
| 914 | + $requireMin = ''; |
|
| 915 | + $requireMax = ''; |
|
| 916 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 917 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
| 918 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
| 919 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
| 920 | + } else if (isset($appInfo['requiremin'])) { |
|
| 921 | + $requireMin = $appInfo['requiremin']; |
|
| 922 | + } else if (isset($appInfo['require'])) { |
|
| 923 | + $requireMin = $appInfo['require']; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 927 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
| 928 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
| 929 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
| 930 | + } else if (isset($appInfo['requiremax'])) { |
|
| 931 | + $requireMax = $appInfo['requiremax']; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + if (is_array($ocVersion)) { |
|
| 935 | + $ocVersion = implode('.', $ocVersion); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + if (!empty($requireMin) |
|
| 939 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
| 940 | + ) { |
|
| 941 | + |
|
| 942 | + return false; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + if (!empty($requireMax) |
|
| 946 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
| 947 | + ) { |
|
| 948 | + return false; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return true; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * get the installed version of all apps |
|
| 956 | + */ |
|
| 957 | + public static function getAppVersions() { |
|
| 958 | + static $versions; |
|
| 959 | + |
|
| 960 | + if(!$versions) { |
|
| 961 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 962 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
| 963 | + } |
|
| 964 | + return $versions; |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * @param string $app |
|
| 969 | + * @param \OCP\IConfig $config |
|
| 970 | + * @param \OCP\IL10N $l |
|
| 971 | + * @return bool |
|
| 972 | + * |
|
| 973 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
| 974 | + * @throws Exception if no app-name was specified |
|
| 975 | + */ |
|
| 976 | + public function installApp($app, |
|
| 977 | + \OCP\IConfig $config, |
|
| 978 | + \OCP\IL10N $l) { |
|
| 979 | + if ($app !== false) { |
|
| 980 | + // check if the app is compatible with this version of ownCloud |
|
| 981 | + $info = self::getAppInfo($app); |
|
| 982 | + if(!is_array($info)) { |
|
| 983 | + throw new \Exception( |
|
| 984 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 985 | + [$info['name']] |
|
| 986 | + ) |
|
| 987 | + ); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + $version = \OCP\Util::getVersion(); |
|
| 991 | + if (!self::isAppCompatible($version, $info)) { |
|
| 992 | + throw new \Exception( |
|
| 993 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 994 | + array($info['name']) |
|
| 995 | + ) |
|
| 996 | + ); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + // check for required dependencies |
|
| 1000 | + self::checkAppDependencies($config, $l, $info); |
|
| 1001 | + |
|
| 1002 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
| 1003 | + if (isset($appData['id'])) { |
|
| 1004 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1008 | + $appPath = self::getAppPath($app); |
|
| 1009 | + self::registerAutoloading($app, $appPath); |
|
| 1010 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
| 1014 | + } else { |
|
| 1015 | + if(empty($appName) ) { |
|
| 1016 | + throw new \Exception($l->t("No app name specified")); |
|
| 1017 | + } else { |
|
| 1018 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + return $app; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * update the database for the app and call the update script |
|
| 1027 | + * |
|
| 1028 | + * @param string $appId |
|
| 1029 | + * @return bool |
|
| 1030 | + */ |
|
| 1031 | + public static function updateApp($appId) { |
|
| 1032 | + $appPath = self::getAppPath($appId); |
|
| 1033 | + if($appPath === false) { |
|
| 1034 | + return false; |
|
| 1035 | + } |
|
| 1036 | + self::registerAutoloading($appId, $appPath); |
|
| 1037 | + |
|
| 1038 | + $appData = self::getAppInfo($appId); |
|
| 1039 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
| 1040 | + |
|
| 1041 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1042 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1043 | + } else { |
|
| 1044 | + $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
| 1045 | + $ms->migrate(); |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
| 1049 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
| 1050 | + unset(self::$appVersion[$appId]); |
|
| 1051 | + |
|
| 1052 | + // run upgrade code |
|
| 1053 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1054 | + self::loadApp($appId); |
|
| 1055 | + include $appPath . '/appinfo/update.php'; |
|
| 1056 | + } |
|
| 1057 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
| 1058 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1059 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + //set remote/public handlers |
|
| 1063 | + if (array_key_exists('ocsid', $appData)) { |
|
| 1064 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
| 1065 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1066 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
| 1067 | + } |
|
| 1068 | + foreach ($appData['remote'] as $name => $path) { |
|
| 1069 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1070 | + } |
|
| 1071 | + foreach ($appData['public'] as $name => $path) { |
|
| 1072 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + self::setAppTypes($appId); |
|
| 1076 | + |
|
| 1077 | + $version = \OC_App::getAppVersion($appId); |
|
| 1078 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
| 1079 | + |
|
| 1080 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
| 1081 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
| 1082 | + )); |
|
| 1083 | + |
|
| 1084 | + return true; |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @param string $appId |
|
| 1089 | + * @param string[] $steps |
|
| 1090 | + * @throws \OC\NeedsUpdateException |
|
| 1091 | + */ |
|
| 1092 | + public static function executeRepairSteps($appId, array $steps) { |
|
| 1093 | + if (empty($steps)) { |
|
| 1094 | + return; |
|
| 1095 | + } |
|
| 1096 | + // load the app |
|
| 1097 | + self::loadApp($appId); |
|
| 1098 | + |
|
| 1099 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
| 1100 | + |
|
| 1101 | + // load the steps |
|
| 1102 | + $r = new Repair([], $dispatcher); |
|
| 1103 | + foreach ($steps as $step) { |
|
| 1104 | + try { |
|
| 1105 | + $r->addStep($step); |
|
| 1106 | + } catch (Exception $ex) { |
|
| 1107 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
| 1108 | + \OC::$server->getLogger()->logException($ex); |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1111 | + // run the steps |
|
| 1112 | + $r->run(); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + public static function setupBackgroundJobs(array $jobs) { |
|
| 1116 | + $queue = \OC::$server->getJobList(); |
|
| 1117 | + foreach ($jobs as $job) { |
|
| 1118 | + $queue->add($job); |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + /** |
|
| 1123 | + * @param string $appId |
|
| 1124 | + * @param string[] $steps |
|
| 1125 | + */ |
|
| 1126 | + private static function setupLiveMigrations($appId, array $steps) { |
|
| 1127 | + $queue = \OC::$server->getJobList(); |
|
| 1128 | + foreach ($steps as $step) { |
|
| 1129 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
| 1130 | + 'app' => $appId, |
|
| 1131 | + 'step' => $step]); |
|
| 1132 | + } |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * @param string $appId |
|
| 1137 | + * @return \OC\Files\View|false |
|
| 1138 | + */ |
|
| 1139 | + public static function getStorage($appId) { |
|
| 1140 | + if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
| 1141 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1142 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1143 | + if (!$view->file_exists($appId)) { |
|
| 1144 | + $view->mkdir($appId); |
|
| 1145 | + } |
|
| 1146 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1147 | + } else { |
|
| 1148 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1149 | + return false; |
|
| 1150 | + } |
|
| 1151 | + } else { |
|
| 1152 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1153 | + return false; |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + protected static function findBestL10NOption($options, $lang) { |
|
| 1158 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
| 1159 | + |
|
| 1160 | + $lang = strtolower($lang); |
|
| 1161 | + $similarLang = $lang; |
|
| 1162 | + if (strpos($similarLang, '_')) { |
|
| 1163 | + // For "de_DE" we want to find "de" and the other way around |
|
| 1164 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + foreach ($options as $option) { |
|
| 1168 | + if (is_array($option)) { |
|
| 1169 | + if ($fallback === false) { |
|
| 1170 | + $fallback = $option['@value']; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + if (!isset($option['@attributes']['lang'])) { |
|
| 1174 | + continue; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
| 1178 | + if ($attributeLang === $lang) { |
|
| 1179 | + return $option['@value']; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + if ($attributeLang === $similarLang) { |
|
| 1183 | + $similarLangFallback = $option['@value']; |
|
| 1184 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1185 | + if ($similarLangFallback === false) { |
|
| 1186 | + $similarLangFallback = $option['@value']; |
|
| 1187 | + } |
|
| 1188 | + } |
|
| 1189 | + } else { |
|
| 1190 | + $englishFallback = $option; |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + if ($similarLangFallback !== false) { |
|
| 1195 | + return $similarLangFallback; |
|
| 1196 | + } else if ($englishFallback !== false) { |
|
| 1197 | + return $englishFallback; |
|
| 1198 | + } |
|
| 1199 | + return (string) $fallback; |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * parses the app data array and enhanced the 'description' value |
|
| 1204 | + * |
|
| 1205 | + * @param array $data the app data |
|
| 1206 | + * @param string $lang |
|
| 1207 | + * @return array improved app data |
|
| 1208 | + */ |
|
| 1209 | + public static function parseAppInfo(array $data, $lang = null) { |
|
| 1210 | + |
|
| 1211 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
| 1212 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
| 1213 | + } |
|
| 1214 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
| 1215 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
| 1216 | + } |
|
| 1217 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
| 1218 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
| 1219 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
| 1220 | + $data['description'] = trim($data['description']); |
|
| 1221 | + } else { |
|
| 1222 | + $data['description'] = ''; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $data; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + /** |
|
| 1229 | + * @param \OCP\IConfig $config |
|
| 1230 | + * @param \OCP\IL10N $l |
|
| 1231 | + * @param array $info |
|
| 1232 | + * @throws \Exception |
|
| 1233 | + */ |
|
| 1234 | + public static function checkAppDependencies($config, $l, $info) { |
|
| 1235 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
| 1236 | + $missing = $dependencyAnalyzer->analyze($info); |
|
| 1237 | + if (!empty($missing)) { |
|
| 1238 | + $missingMsg = implode(PHP_EOL, $missing); |
|
| 1239 | + throw new \Exception( |
|
| 1240 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
| 1241 | + [$info['name'], $missingMsg] |
|
| 1242 | + ) |
|
| 1243 | + ); |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | 1246 | } |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | $apps = self::getEnabledApps(); |
| 114 | 114 | |
| 115 | 115 | // Add each apps' folder as allowed class path |
| 116 | - foreach($apps as $app) { |
|
| 116 | + foreach ($apps as $app) { |
|
| 117 | 117 | $path = self::getAppPath($app); |
| 118 | - if($path !== false) { |
|
| 118 | + if ($path !== false) { |
|
| 119 | 119 | self::registerAutoloading($app, $path); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | public static function loadApp($app) { |
| 141 | 141 | self::$loadedApps[] = $app; |
| 142 | 142 | $appPath = self::getAppPath($app); |
| 143 | - if($appPath === false) { |
|
| 143 | + if ($appPath === false) { |
|
| 144 | 144 | return; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // in case someone calls loadApp() directly |
| 148 | 148 | self::registerAutoloading($app, $appPath); |
| 149 | 149 | |
| 150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
| 151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
| 150 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
| 151 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
| 152 | 152 | self::requireAppFile($app); |
| 153 | 153 | if (self::isType($app, array('authentication'))) { |
| 154 | 154 | // since authentication apps affect the "is app enabled for group" check, |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | // enabled for groups |
| 158 | 158 | self::$enabledAppsCache = array(); |
| 159 | 159 | } |
| 160 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
| 160 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $info = self::getAppInfo($app); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
| 182 | 182 | [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
| 183 | 183 | foreach ($plugins as $plugin) { |
| 184 | - if($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 184 | + if ($plugin['@attributes']['type'] === 'collaborator-search') { |
|
| 185 | 185 | $pluginInfo = [ |
| 186 | 186 | 'shareType' => $plugin['@attributes']['share-type'], |
| 187 | 187 | 'class' => $plugin['@value'], |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | * @param string $path |
| 201 | 201 | */ |
| 202 | 202 | public static function registerAutoloading($app, $path) { |
| 203 | - $key = $app . '-' . $path; |
|
| 204 | - if(isset(self::$alreadyRegistered[$key])) { |
|
| 203 | + $key = $app.'-'.$path; |
|
| 204 | + if (isset(self::$alreadyRegistered[$key])) { |
|
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -211,17 +211,17 @@ discard block |
||
| 211 | 211 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
| 212 | 212 | \OC::$server->registerNamespace($app, $appNamespace); |
| 213 | 213 | |
| 214 | - if (file_exists($path . '/composer/autoload.php')) { |
|
| 215 | - require_once $path . '/composer/autoload.php'; |
|
| 214 | + if (file_exists($path.'/composer/autoload.php')) { |
|
| 215 | + require_once $path.'/composer/autoload.php'; |
|
| 216 | 216 | } else { |
| 217 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
| 217 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
| 218 | 218 | // Register on legacy autoloader |
| 219 | 219 | \OC::$loader->addValidRoot($path); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Register Test namespace only when testing |
| 223 | 223 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
| 224 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
| 224 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | private static function requireAppFile($app) { |
| 234 | 234 | try { |
| 235 | 235 | // encapsulated here to avoid variable scope conflicts |
| 236 | - require_once $app . '/appinfo/app.php'; |
|
| 236 | + require_once $app.'/appinfo/app.php'; |
|
| 237 | 237 | } catch (Error $ex) { |
| 238 | 238 | \OC::$server->getLogger()->logException($ex); |
| 239 | 239 | $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public static function setAppTypes($app) { |
| 289 | 289 | $appData = self::getAppInfo($app); |
| 290 | - if(!is_array($appData)) { |
|
| 290 | + if (!is_array($appData)) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | } else { |
| 340 | 340 | $apps = $appManager->getEnabledAppsForUser($user); |
| 341 | 341 | } |
| 342 | - $apps = array_filter($apps, function ($app) { |
|
| 343 | - return $app !== 'files';//we add this manually |
|
| 342 | + $apps = array_filter($apps, function($app) { |
|
| 343 | + return $app !== 'files'; //we add this manually |
|
| 344 | 344 | }); |
| 345 | 345 | sort($apps); |
| 346 | 346 | array_unshift($apps, 'files'); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $installer = \OC::$server->query(Installer::class); |
| 379 | 379 | $isDownloaded = $installer->isDownloaded($appId); |
| 380 | 380 | |
| 381 | - if(!$isDownloaded) { |
|
| 381 | + if (!$isDownloaded) { |
|
| 382 | 382 | $installer->downloadApp($appId); |
| 383 | 383 | } |
| 384 | 384 | |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | public static function findAppInDirectories($appId) { |
| 493 | 493 | $sanitizedAppId = self::cleanAppId($appId); |
| 494 | - if($sanitizedAppId !== $appId) { |
|
| 494 | + if ($sanitizedAppId !== $appId) { |
|
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | 497 | static $app_dir = array(); |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | $possibleApps = array(); |
| 504 | 504 | foreach (OC::$APPSROOTS as $dir) { |
| 505 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
| 505 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
| 506 | 506 | $possibleApps[] = $dir; |
| 507 | 507 | } |
| 508 | 508 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | if (($dir = self::findAppInDirectories($appId)) != false) { |
| 546 | - return $dir['path'] . '/' . $appId; |
|
| 546 | + return $dir['path'].'/'.$appId; |
|
| 547 | 547 | } |
| 548 | 548 | return false; |
| 549 | 549 | } |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | */ |
| 558 | 558 | public static function getAppWebPath($appId) { |
| 559 | 559 | if (($dir = self::findAppInDirectories($appId)) != false) { |
| 560 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
| 560 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
| 561 | 561 | } |
| 562 | 562 | return false; |
| 563 | 563 | } |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @return string |
| 571 | 571 | */ |
| 572 | 572 | public static function getAppVersion($appId, $useCache = true) { |
| 573 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
| 573 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
| 574 | 574 | return self::$appVersion[$appId]; |
| 575 | 575 | } |
| 576 | 576 | |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | * @return string |
| 587 | 587 | */ |
| 588 | 588 | public static function getAppVersionByPath($path) { |
| 589 | - $infoFile = $path . '/appinfo/info.xml'; |
|
| 589 | + $infoFile = $path.'/appinfo/info.xml'; |
|
| 590 | 590 | $appData = self::getAppInfo($infoFile, true); |
| 591 | 591 | return isset($appData['version']) ? $appData['version'] : ''; |
| 592 | 592 | } |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | return self::$appInfo[$appId]; |
| 610 | 610 | } |
| 611 | 611 | $appPath = self::getAppPath($appId); |
| 612 | - if($appPath === false) { |
|
| 612 | + if ($appPath === false) { |
|
| 613 | 613 | return null; |
| 614 | 614 | } |
| 615 | - $file = $appPath . '/appinfo/info.xml'; |
|
| 615 | + $file = $appPath.'/appinfo/info.xml'; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->createLocal('core.appinfo')); |
@@ -621,9 +621,9 @@ discard block |
||
| 621 | 621 | if (is_array($data)) { |
| 622 | 622 | $data = OC_App::parseAppInfo($data, $lang); |
| 623 | 623 | } |
| 624 | - if(isset($data['ocsid'])) { |
|
| 624 | + if (isset($data['ocsid'])) { |
|
| 625 | 625 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
| 626 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 626 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
| 627 | 627 | $data['ocsid'] = $storedId; |
| 628 | 628 | } |
| 629 | 629 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @param string $page |
| 716 | 716 | */ |
| 717 | 717 | public static function registerAdmin($app, $page) { |
| 718 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
| 718 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * @param string $page |
| 725 | 725 | */ |
| 726 | 726 | public static function registerPersonal($app, $page) { |
| 727 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
| 727 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | |
| 754 | 754 | foreach (OC::$APPSROOTS as $apps_dir) { |
| 755 | 755 | if (!is_readable($apps_dir['path'])) { |
| 756 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
| 756 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
| 757 | 757 | continue; |
| 758 | 758 | } |
| 759 | 759 | $dh = opendir($apps_dir['path']); |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | if (is_resource($dh)) { |
| 762 | 762 | while (($file = readdir($dh)) !== false) { |
| 763 | 763 | |
| 764 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
| 764 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
| 765 | 765 | |
| 766 | 766 | $apps[] = $file; |
| 767 | 767 | } |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | $info = OC_App::getAppInfo($app, false, $langCode); |
| 796 | 796 | if (!is_array($info)) { |
| 797 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
| 797 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
| 798 | 798 | continue; |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | if (!isset($info['name'])) { |
| 802 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
| 802 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
| 803 | 803 | continue; |
| 804 | 804 | } |
| 805 | 805 | |
@@ -826,13 +826,13 @@ discard block |
||
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | $appPath = self::getAppPath($app); |
| 829 | - if($appPath !== false) { |
|
| 830 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
| 829 | + if ($appPath !== false) { |
|
| 830 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
| 831 | 831 | if (file_exists($appIcon)) { |
| 832 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
| 832 | + $info['preview'] = $urlGenerator->imagePath($app, $app.'.svg'); |
|
| 833 | 833 | $info['previewAsIcon'] = true; |
| 834 | 834 | } else { |
| 835 | - $appIcon = $appPath . '/img/app.svg'; |
|
| 835 | + $appIcon = $appPath.'/img/app.svg'; |
|
| 836 | 836 | if (file_exists($appIcon)) { |
| 837 | 837 | $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
| 838 | 838 | $info['previewAsIcon'] = true; |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | public static function getAppVersions() { |
| 958 | 958 | static $versions; |
| 959 | 959 | |
| 960 | - if(!$versions) { |
|
| 960 | + if (!$versions) { |
|
| 961 | 961 | $appConfig = \OC::$server->getAppConfig(); |
| 962 | 962 | $versions = $appConfig->getValues(false, 'installed_version'); |
| 963 | 963 | } |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | if ($app !== false) { |
| 980 | 980 | // check if the app is compatible with this version of ownCloud |
| 981 | 981 | $info = self::getAppInfo($app); |
| 982 | - if(!is_array($info)) { |
|
| 982 | + if (!is_array($info)) { |
|
| 983 | 983 | throw new \Exception( |
| 984 | 984 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
| 985 | 985 | [$info['name']] |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | $config->setAppValue($app, 'ocsid', $appData['id']); |
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
| 1007 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
| 1008 | 1008 | $appPath = self::getAppPath($app); |
| 1009 | 1009 | self::registerAutoloading($app, $appPath); |
| 1010 | 1010 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | |
| 1013 | 1013 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
| 1014 | 1014 | } else { |
| 1015 | - if(empty($appName) ) { |
|
| 1015 | + if (empty($appName)) { |
|
| 1016 | 1016 | throw new \Exception($l->t("No app name specified")); |
| 1017 | 1017 | } else { |
| 1018 | 1018 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | */ |
| 1031 | 1031 | public static function updateApp($appId) { |
| 1032 | 1032 | $appPath = self::getAppPath($appId); |
| 1033 | - if($appPath === false) { |
|
| 1033 | + if ($appPath === false) { |
|
| 1034 | 1034 | return false; |
| 1035 | 1035 | } |
| 1036 | 1036 | self::registerAutoloading($appId, $appPath); |
@@ -1038,8 +1038,8 @@ discard block |
||
| 1038 | 1038 | $appData = self::getAppInfo($appId); |
| 1039 | 1039 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
| 1040 | 1040 | |
| 1041 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
| 1042 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
| 1041 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
| 1042 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
| 1043 | 1043 | } else { |
| 1044 | 1044 | $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
| 1045 | 1045 | $ms->migrate(); |
@@ -1050,26 +1050,26 @@ discard block |
||
| 1050 | 1050 | unset(self::$appVersion[$appId]); |
| 1051 | 1051 | |
| 1052 | 1052 | // run upgrade code |
| 1053 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
| 1053 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
| 1054 | 1054 | self::loadApp($appId); |
| 1055 | - include $appPath . '/appinfo/update.php'; |
|
| 1055 | + include $appPath.'/appinfo/update.php'; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | self::setupBackgroundJobs($appData['background-jobs']); |
| 1058 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1058 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
| 1059 | 1059 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | //set remote/public handlers |
| 1063 | 1063 | if (array_key_exists('ocsid', $appData)) { |
| 1064 | 1064 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
| 1065 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1065 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
| 1066 | 1066 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
| 1067 | 1067 | } |
| 1068 | 1068 | foreach ($appData['remote'] as $name => $path) { |
| 1069 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
| 1069 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | foreach ($appData['public'] as $name => $path) { |
| 1072 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
| 1072 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | self::setAppTypes($appId); |
@@ -1139,17 +1139,17 @@ discard block |
||
| 1139 | 1139 | public static function getStorage($appId) { |
| 1140 | 1140 | if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
| 1141 | 1141 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
| 1142 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
| 1142 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
| 1143 | 1143 | if (!$view->file_exists($appId)) { |
| 1144 | 1144 | $view->mkdir($appId); |
| 1145 | 1145 | } |
| 1146 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
| 1146 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
| 1147 | 1147 | } else { |
| 1148 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
| 1148 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
| 1149 | 1149 | return false; |
| 1150 | 1150 | } |
| 1151 | 1151 | } else { |
| 1152 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
| 1152 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
| 1153 | 1153 | return false; |
| 1154 | 1154 | } |
| 1155 | 1155 | } |
@@ -1181,9 +1181,9 @@ discard block |
||
| 1181 | 1181 | |
| 1182 | 1182 | if ($attributeLang === $similarLang) { |
| 1183 | 1183 | $similarLangFallback = $option['@value']; |
| 1184 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
| 1184 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
| 1185 | 1185 | if ($similarLangFallback === false) { |
| 1186 | - $similarLangFallback = $option['@value']; |
|
| 1186 | + $similarLangFallback = $option['@value']; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | } |
| 1189 | 1189 | } else { |
@@ -1218,7 +1218,7 @@ discard block |
||
| 1218 | 1218 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
| 1219 | 1219 | } else if (isset($data['description']) && is_string($data['description'])) { |
| 1220 | 1220 | $data['description'] = trim($data['description']); |
| 1221 | - } else { |
|
| 1221 | + } else { |
|
| 1222 | 1222 | $data['description'] = ''; |
| 1223 | 1223 | } |
| 1224 | 1224 | |
@@ -54,593 +54,593 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | class Updater extends BasicEmitter { |
| 56 | 56 | |
| 57 | - /** @var ILogger $log */ |
|
| 58 | - private $log; |
|
| 59 | - |
|
| 60 | - /** @var IConfig */ |
|
| 61 | - private $config; |
|
| 62 | - |
|
| 63 | - /** @var Checker */ |
|
| 64 | - private $checker; |
|
| 65 | - |
|
| 66 | - /** @var Installer */ |
|
| 67 | - private $installer; |
|
| 68 | - |
|
| 69 | - /** @var bool */ |
|
| 70 | - private $skip3rdPartyAppsDisable; |
|
| 71 | - |
|
| 72 | - private $logLevelNames = [ |
|
| 73 | - 0 => 'Debug', |
|
| 74 | - 1 => 'Info', |
|
| 75 | - 2 => 'Warning', |
|
| 76 | - 3 => 'Error', |
|
| 77 | - 4 => 'Fatal', |
|
| 78 | - ]; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param IConfig $config |
|
| 82 | - * @param Checker $checker |
|
| 83 | - * @param ILogger $log |
|
| 84 | - * @param Installer $installer |
|
| 85 | - */ |
|
| 86 | - public function __construct(IConfig $config, |
|
| 87 | - Checker $checker, |
|
| 88 | - ILogger $log = null, |
|
| 89 | - Installer $installer) { |
|
| 90 | - $this->log = $log; |
|
| 91 | - $this->config = $config; |
|
| 92 | - $this->checker = $checker; |
|
| 93 | - $this->installer = $installer; |
|
| 94 | - |
|
| 95 | - // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
|
| 96 | - // fatal errors and exceptions and disable the app just instead. |
|
| 97 | - if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 98 | - $this->skip3rdPartyAppsDisable = true; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Sets whether the update disables 3rd party apps. |
|
| 104 | - * This can be set to true to skip the disable. |
|
| 105 | - * |
|
| 106 | - * @param bool $flag false to not disable, true otherwise |
|
| 107 | - */ |
|
| 108 | - public function setSkip3rdPartyAppsDisable($flag) { |
|
| 109 | - $this->skip3rdPartyAppsDisable = $flag; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 114 | - * except the main .htaccess file |
|
| 115 | - * |
|
| 116 | - * @return bool true if the operation succeeded, false otherwise |
|
| 117 | - */ |
|
| 118 | - public function upgrade() { |
|
| 119 | - $this->emitRepairEvents(); |
|
| 120 | - $this->logAllEvents(); |
|
| 121 | - |
|
| 122 | - $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
|
| 123 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 124 | - $this->config->setSystemValue('loglevel', Util::DEBUG); |
|
| 125 | - |
|
| 126 | - $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 127 | - |
|
| 128 | - if(!$wasMaintenanceModeEnabled) { |
|
| 129 | - $this->config->setSystemValue('maintenance', true); |
|
| 130 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 134 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 135 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
| 136 | - |
|
| 137 | - $success = true; |
|
| 138 | - try { |
|
| 139 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
| 140 | - } catch (HintException $exception) { |
|
| 141 | - $this->log->logException($exception, ['app' => 'core']); |
|
| 142 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
| 143 | - $success = false; |
|
| 144 | - } catch (\Exception $exception) { |
|
| 145 | - $this->log->logException($exception, ['app' => 'core']); |
|
| 146 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
| 147 | - $success = false; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
| 151 | - |
|
| 152 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
| 153 | - $this->config->setSystemValue('maintenance', false); |
|
| 154 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 155 | - } else { |
|
| 156 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 160 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
| 161 | - $this->config->setSystemValue('installed', true); |
|
| 162 | - |
|
| 163 | - return $success; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Return version from which this version is allowed to upgrade from |
|
| 168 | - * |
|
| 169 | - * @return array allowed previous versions per vendor |
|
| 170 | - */ |
|
| 171 | - private function getAllowedPreviousVersions() { |
|
| 172 | - // this should really be a JSON file |
|
| 173 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 174 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 175 | - return $OC_VersionCanBeUpgradedFrom; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Return vendor from which this version was published |
|
| 180 | - * |
|
| 181 | - * @return string Get the vendor |
|
| 182 | - */ |
|
| 183 | - private function getVendor() { |
|
| 184 | - // this should really be a JSON file |
|
| 185 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 186 | - /** @var string $vendor */ |
|
| 187 | - return (string) $vendor; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Whether an upgrade to a specified version is possible |
|
| 192 | - * @param string $oldVersion |
|
| 193 | - * @param string $newVersion |
|
| 194 | - * @param array $allowedPreviousVersions |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
| 198 | - $version = explode('.', $oldVersion); |
|
| 199 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 200 | - |
|
| 201 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 202 | - |
|
| 203 | - // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 204 | - if ($currentVendor === '') { |
|
| 205 | - if (in_array($oldVersion, [ |
|
| 206 | - '11.0.2.7', |
|
| 207 | - '11.0.1.2', |
|
| 208 | - '11.0.0.10', |
|
| 209 | - ], true)) { |
|
| 210 | - $currentVendor = 'nextcloud'; |
|
| 211 | - } else if (isset($allowedPreviousVersions['owncloud'][$oldVersion])) { |
|
| 212 | - $currentVendor = 'owncloud'; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if ($currentVendor === 'nextcloud') { |
|
| 217 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 218 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 219 | - $this->config->getSystemValue('debug', false)); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // Check if the instance can be migrated |
|
| 223 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 224 | - isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 229 | - * except the main .htaccess file |
|
| 230 | - * |
|
| 231 | - * @param string $currentVersion current version to upgrade to |
|
| 232 | - * @param string $installedVersion previous version from which to upgrade from |
|
| 233 | - * |
|
| 234 | - * @throws \Exception |
|
| 235 | - */ |
|
| 236 | - private function doUpgrade($currentVersion, $installedVersion) { |
|
| 237 | - // Stop update if the update is over several major versions |
|
| 238 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 239 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 240 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Update .htaccess files |
|
| 244 | - try { |
|
| 245 | - Setup::updateHtaccess(); |
|
| 246 | - Setup::protectDataDirectory(); |
|
| 247 | - } catch (\Exception $e) { |
|
| 248 | - throw new \Exception($e->getMessage()); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // create empty file in data dir, so we can later find |
|
| 252 | - // out that this is indeed an ownCloud data directory |
|
| 253 | - // (in case it didn't exist before) |
|
| 254 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 255 | - |
|
| 256 | - // pre-upgrade repairs |
|
| 257 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 258 | - $repair->run(); |
|
| 259 | - |
|
| 260 | - $this->doCoreUpgrade(); |
|
| 261 | - |
|
| 262 | - try { |
|
| 263 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 264 | - Setup::installBackgroundJobs(); |
|
| 265 | - } catch (\Exception $e) { |
|
| 266 | - throw new \Exception($e->getMessage()); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // update all shipped apps |
|
| 270 | - $this->checkAppsRequirements(); |
|
| 271 | - $this->doAppUpgrade(); |
|
| 272 | - |
|
| 273 | - // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 274 | - \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 275 | - |
|
| 276 | - // upgrade appstore apps |
|
| 277 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 278 | - |
|
| 279 | - // install new shipped apps on upgrade |
|
| 280 | - OC_App::loadApps('authentication'); |
|
| 281 | - $errors = Installer::installShippedApps(true); |
|
| 282 | - foreach ($errors as $appId => $exception) { |
|
| 283 | - /** @var \Exception $exception */ |
|
| 284 | - $this->log->logException($exception, ['app' => $appId]); |
|
| 285 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - // post-upgrade repairs |
|
| 289 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 290 | - $repair->run(); |
|
| 291 | - |
|
| 292 | - //Invalidate update feed |
|
| 293 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 294 | - |
|
| 295 | - // Check for code integrity if not disabled |
|
| 296 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 297 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 298 | - $this->checker->runInstanceVerification(); |
|
| 299 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // only set the final version if everything went well |
|
| 303 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 304 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - protected function doCoreUpgrade() { |
|
| 308 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 309 | - |
|
| 310 | - // execute core migrations |
|
| 311 | - $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
| 312 | - $ms->migrate(); |
|
| 313 | - |
|
| 314 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param string $version the oc version to check app compatibility with |
|
| 319 | - */ |
|
| 320 | - protected function checkAppUpgrade($version) { |
|
| 321 | - $apps = \OC_App::getEnabledApps(); |
|
| 322 | - $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
| 323 | - |
|
| 324 | - $appManager = \OC::$server->getAppManager(); |
|
| 325 | - foreach ($apps as $appId) { |
|
| 326 | - $info = \OC_App::getAppInfo($appId); |
|
| 327 | - $compatible = \OC_App::isAppCompatible($version, $info); |
|
| 328 | - $isShipped = $appManager->isShipped($appId); |
|
| 329 | - |
|
| 330 | - if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
| 331 | - /** |
|
| 332 | - * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
| 333 | - * are not possible anymore within it. - Consider this when touching the code. |
|
| 334 | - * @link https://github.com/owncloud/core/issues/10980 |
|
| 335 | - * @see \OC_App::updateApp |
|
| 336 | - */ |
|
| 337 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
| 338 | - $this->includePreUpdate($appId); |
|
| 339 | - } |
|
| 340 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
| 341 | - $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
| 342 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Includes the pre-update file. Done here to prevent namespace mixups. |
|
| 352 | - * @param string $appId |
|
| 353 | - */ |
|
| 354 | - private function includePreUpdate($appId) { |
|
| 355 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 360 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 361 | - * |
|
| 362 | - * @throws NeedsUpdateException |
|
| 363 | - */ |
|
| 364 | - protected function doAppUpgrade() { |
|
| 365 | - $apps = \OC_App::getEnabledApps(); |
|
| 366 | - $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
| 367 | - $pseudoOtherType = 'other'; |
|
| 368 | - $stacks = array($pseudoOtherType => array()); |
|
| 369 | - |
|
| 370 | - foreach ($apps as $appId) { |
|
| 371 | - $priorityType = false; |
|
| 372 | - foreach ($priorityTypes as $type) { |
|
| 373 | - if(!isset($stacks[$type])) { |
|
| 374 | - $stacks[$type] = array(); |
|
| 375 | - } |
|
| 376 | - if (\OC_App::isType($appId, $type)) { |
|
| 377 | - $stacks[$type][] = $appId; |
|
| 378 | - $priorityType = true; |
|
| 379 | - break; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - if (!$priorityType) { |
|
| 383 | - $stacks[$pseudoOtherType][] = $appId; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - foreach ($stacks as $type => $stack) { |
|
| 387 | - foreach ($stack as $appId) { |
|
| 388 | - if (\OC_App::shouldUpgrade($appId)) { |
|
| 389 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 390 | - \OC_App::updateApp($appId); |
|
| 391 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 392 | - } |
|
| 393 | - if($type !== $pseudoOtherType) { |
|
| 394 | - // load authentication, filesystem and logging apps after |
|
| 395 | - // upgrading them. Other apps my need to rely on modifying |
|
| 396 | - // user and/or filesystem aspects. |
|
| 397 | - \OC_App::loadApp($appId); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * check if the current enabled apps are compatible with the current |
|
| 405 | - * ownCloud version. disable them if not. |
|
| 406 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 407 | - * party apps installed. |
|
| 408 | - * |
|
| 409 | - * @return array |
|
| 410 | - * @throws \Exception |
|
| 411 | - */ |
|
| 412 | - private function checkAppsRequirements() { |
|
| 413 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 414 | - $apps = OC_App::getEnabledApps(); |
|
| 415 | - $version = Util::getVersion(); |
|
| 416 | - $disabledApps = []; |
|
| 417 | - $appManager = \OC::$server->getAppManager(); |
|
| 418 | - foreach ($apps as $app) { |
|
| 419 | - // check if the app is compatible with this version of ownCloud |
|
| 420 | - $info = OC_App::getAppInfo($app); |
|
| 421 | - if(!OC_App::isAppCompatible($version, $info)) { |
|
| 422 | - if ($appManager->isShipped($app)) { |
|
| 423 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 424 | - } |
|
| 425 | - OC_App::disable($app); |
|
| 426 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
| 427 | - } |
|
| 428 | - // no need to disable any app in case this is a non-core upgrade |
|
| 429 | - if (!$isCoreUpgrade) { |
|
| 430 | - continue; |
|
| 431 | - } |
|
| 432 | - // shipped apps will remain enabled |
|
| 433 | - if ($appManager->isShipped($app)) { |
|
| 434 | - continue; |
|
| 435 | - } |
|
| 436 | - // authentication and session apps will remain enabled as well |
|
| 437 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 438 | - continue; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - // disable any other 3rd party apps if not overriden |
|
| 442 | - if(!$this->skip3rdPartyAppsDisable) { |
|
| 443 | - \OC_App::disable($app); |
|
| 444 | - $disabledApps[]= $app; |
|
| 445 | - $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
|
| 446 | - }; |
|
| 447 | - } |
|
| 448 | - return $disabledApps; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return bool |
|
| 453 | - */ |
|
| 454 | - private function isCodeUpgrade() { |
|
| 455 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 456 | - $currentVersion = implode('.', Util::getVersion()); |
|
| 457 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 458 | - return true; |
|
| 459 | - } |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @param array $disabledApps |
|
| 465 | - * @throws \Exception |
|
| 466 | - */ |
|
| 467 | - private function upgradeAppStoreApps(array $disabledApps) { |
|
| 468 | - foreach($disabledApps as $app) { |
|
| 469 | - try { |
|
| 470 | - $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 471 | - if ($this->installer->isUpdateAvailable($app)) { |
|
| 472 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 473 | - $this->installer->updateAppstoreApp($app); |
|
| 474 | - } |
|
| 475 | - $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 476 | - } catch (\Exception $ex) { |
|
| 477 | - $this->log->logException($ex, ['app' => 'core']); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Forward messages emitted by the repair routine |
|
| 484 | - */ |
|
| 485 | - private function emitRepairEvents() { |
|
| 486 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 487 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 488 | - if ($event instanceof GenericEvent) { |
|
| 489 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 490 | - } |
|
| 491 | - }); |
|
| 492 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 493 | - if ($event instanceof GenericEvent) { |
|
| 494 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 495 | - } |
|
| 496 | - }); |
|
| 497 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 498 | - if ($event instanceof GenericEvent) { |
|
| 499 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 500 | - } |
|
| 501 | - }); |
|
| 502 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 503 | - if ($event instanceof GenericEvent) { |
|
| 504 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 505 | - } |
|
| 506 | - }); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - private function logAllEvents() { |
|
| 510 | - $log = $this->log; |
|
| 511 | - |
|
| 512 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 513 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
| 514 | - if (!$event instanceof GenericEvent) { |
|
| 515 | - return; |
|
| 516 | - } |
|
| 517 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 518 | - }); |
|
| 519 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
| 520 | - if (!$event instanceof GenericEvent) { |
|
| 521 | - return; |
|
| 522 | - } |
|
| 523 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 524 | - }); |
|
| 525 | - |
|
| 526 | - $repairListener = function($event) use ($log) { |
|
| 527 | - if (!$event instanceof GenericEvent) { |
|
| 528 | - return; |
|
| 529 | - } |
|
| 530 | - switch ($event->getSubject()) { |
|
| 531 | - case '\OC\Repair::startProgress': |
|
| 532 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 533 | - break; |
|
| 534 | - case '\OC\Repair::advance': |
|
| 535 | - $desc = $event->getArgument(1); |
|
| 536 | - if (empty($desc)) { |
|
| 537 | - $desc = ''; |
|
| 538 | - } |
|
| 539 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 540 | - |
|
| 541 | - break; |
|
| 542 | - case '\OC\Repair::finishProgress': |
|
| 543 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 544 | - break; |
|
| 545 | - case '\OC\Repair::step': |
|
| 546 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 547 | - break; |
|
| 548 | - case '\OC\Repair::info': |
|
| 549 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 550 | - break; |
|
| 551 | - case '\OC\Repair::warning': |
|
| 552 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 553 | - break; |
|
| 554 | - case '\OC\Repair::error': |
|
| 555 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 556 | - break; |
|
| 557 | - } |
|
| 558 | - }; |
|
| 559 | - |
|
| 560 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 561 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 562 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 563 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 564 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 565 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 566 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
| 570 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 571 | - }); |
|
| 572 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
| 573 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 574 | - }); |
|
| 575 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
| 576 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 577 | - }); |
|
| 578 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
| 579 | - if ($success) { |
|
| 580 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 581 | - } else { |
|
| 582 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 583 | - } |
|
| 584 | - }); |
|
| 585 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
| 586 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 587 | - }); |
|
| 588 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
| 589 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 590 | - }); |
|
| 591 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
| 592 | - $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 593 | - }); |
|
| 594 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
| 595 | - $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
| 596 | - }); |
|
| 597 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
| 598 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 599 | - }); |
|
| 600 | - $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
| 601 | - $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
| 602 | - }); |
|
| 603 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
| 604 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 605 | - }); |
|
| 606 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
| 607 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 608 | - }); |
|
| 609 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
| 610 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 611 | - }); |
|
| 612 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
| 613 | - $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
| 614 | - }); |
|
| 615 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 616 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 617 | - }); |
|
| 618 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
| 619 | - $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
| 620 | - }); |
|
| 621 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 622 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 623 | - }); |
|
| 624 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 625 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 626 | - }); |
|
| 627 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
| 628 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 629 | - }); |
|
| 630 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
| 631 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 632 | - }); |
|
| 633 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
| 634 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 635 | - }); |
|
| 636 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
| 637 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 638 | - }); |
|
| 639 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
| 640 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 641 | - }); |
|
| 642 | - |
|
| 643 | - } |
|
| 57 | + /** @var ILogger $log */ |
|
| 58 | + private $log; |
|
| 59 | + |
|
| 60 | + /** @var IConfig */ |
|
| 61 | + private $config; |
|
| 62 | + |
|
| 63 | + /** @var Checker */ |
|
| 64 | + private $checker; |
|
| 65 | + |
|
| 66 | + /** @var Installer */ |
|
| 67 | + private $installer; |
|
| 68 | + |
|
| 69 | + /** @var bool */ |
|
| 70 | + private $skip3rdPartyAppsDisable; |
|
| 71 | + |
|
| 72 | + private $logLevelNames = [ |
|
| 73 | + 0 => 'Debug', |
|
| 74 | + 1 => 'Info', |
|
| 75 | + 2 => 'Warning', |
|
| 76 | + 3 => 'Error', |
|
| 77 | + 4 => 'Fatal', |
|
| 78 | + ]; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param IConfig $config |
|
| 82 | + * @param Checker $checker |
|
| 83 | + * @param ILogger $log |
|
| 84 | + * @param Installer $installer |
|
| 85 | + */ |
|
| 86 | + public function __construct(IConfig $config, |
|
| 87 | + Checker $checker, |
|
| 88 | + ILogger $log = null, |
|
| 89 | + Installer $installer) { |
|
| 90 | + $this->log = $log; |
|
| 91 | + $this->config = $config; |
|
| 92 | + $this->checker = $checker; |
|
| 93 | + $this->installer = $installer; |
|
| 94 | + |
|
| 95 | + // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
|
| 96 | + // fatal errors and exceptions and disable the app just instead. |
|
| 97 | + if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 98 | + $this->skip3rdPartyAppsDisable = true; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Sets whether the update disables 3rd party apps. |
|
| 104 | + * This can be set to true to skip the disable. |
|
| 105 | + * |
|
| 106 | + * @param bool $flag false to not disable, true otherwise |
|
| 107 | + */ |
|
| 108 | + public function setSkip3rdPartyAppsDisable($flag) { |
|
| 109 | + $this->skip3rdPartyAppsDisable = $flag; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 114 | + * except the main .htaccess file |
|
| 115 | + * |
|
| 116 | + * @return bool true if the operation succeeded, false otherwise |
|
| 117 | + */ |
|
| 118 | + public function upgrade() { |
|
| 119 | + $this->emitRepairEvents(); |
|
| 120 | + $this->logAllEvents(); |
|
| 121 | + |
|
| 122 | + $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
|
| 123 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 124 | + $this->config->setSystemValue('loglevel', Util::DEBUG); |
|
| 125 | + |
|
| 126 | + $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 127 | + |
|
| 128 | + if(!$wasMaintenanceModeEnabled) { |
|
| 129 | + $this->config->setSystemValue('maintenance', true); |
|
| 130 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 134 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 135 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
| 136 | + |
|
| 137 | + $success = true; |
|
| 138 | + try { |
|
| 139 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
| 140 | + } catch (HintException $exception) { |
|
| 141 | + $this->log->logException($exception, ['app' => 'core']); |
|
| 142 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
| 143 | + $success = false; |
|
| 144 | + } catch (\Exception $exception) { |
|
| 145 | + $this->log->logException($exception, ['app' => 'core']); |
|
| 146 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
| 147 | + $success = false; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
| 151 | + |
|
| 152 | + if(!$wasMaintenanceModeEnabled && $success) { |
|
| 153 | + $this->config->setSystemValue('maintenance', false); |
|
| 154 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 155 | + } else { |
|
| 156 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 160 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
| 161 | + $this->config->setSystemValue('installed', true); |
|
| 162 | + |
|
| 163 | + return $success; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Return version from which this version is allowed to upgrade from |
|
| 168 | + * |
|
| 169 | + * @return array allowed previous versions per vendor |
|
| 170 | + */ |
|
| 171 | + private function getAllowedPreviousVersions() { |
|
| 172 | + // this should really be a JSON file |
|
| 173 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 174 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 175 | + return $OC_VersionCanBeUpgradedFrom; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Return vendor from which this version was published |
|
| 180 | + * |
|
| 181 | + * @return string Get the vendor |
|
| 182 | + */ |
|
| 183 | + private function getVendor() { |
|
| 184 | + // this should really be a JSON file |
|
| 185 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 186 | + /** @var string $vendor */ |
|
| 187 | + return (string) $vendor; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Whether an upgrade to a specified version is possible |
|
| 192 | + * @param string $oldVersion |
|
| 193 | + * @param string $newVersion |
|
| 194 | + * @param array $allowedPreviousVersions |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
| 198 | + $version = explode('.', $oldVersion); |
|
| 199 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
| 200 | + |
|
| 201 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 202 | + |
|
| 203 | + // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 204 | + if ($currentVendor === '') { |
|
| 205 | + if (in_array($oldVersion, [ |
|
| 206 | + '11.0.2.7', |
|
| 207 | + '11.0.1.2', |
|
| 208 | + '11.0.0.10', |
|
| 209 | + ], true)) { |
|
| 210 | + $currentVendor = 'nextcloud'; |
|
| 211 | + } else if (isset($allowedPreviousVersions['owncloud'][$oldVersion])) { |
|
| 212 | + $currentVendor = 'owncloud'; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if ($currentVendor === 'nextcloud') { |
|
| 217 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 218 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 219 | + $this->config->getSystemValue('debug', false)); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // Check if the instance can be migrated |
|
| 223 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 224 | + isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 229 | + * except the main .htaccess file |
|
| 230 | + * |
|
| 231 | + * @param string $currentVersion current version to upgrade to |
|
| 232 | + * @param string $installedVersion previous version from which to upgrade from |
|
| 233 | + * |
|
| 234 | + * @throws \Exception |
|
| 235 | + */ |
|
| 236 | + private function doUpgrade($currentVersion, $installedVersion) { |
|
| 237 | + // Stop update if the update is over several major versions |
|
| 238 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 239 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 240 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Update .htaccess files |
|
| 244 | + try { |
|
| 245 | + Setup::updateHtaccess(); |
|
| 246 | + Setup::protectDataDirectory(); |
|
| 247 | + } catch (\Exception $e) { |
|
| 248 | + throw new \Exception($e->getMessage()); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // create empty file in data dir, so we can later find |
|
| 252 | + // out that this is indeed an ownCloud data directory |
|
| 253 | + // (in case it didn't exist before) |
|
| 254 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 255 | + |
|
| 256 | + // pre-upgrade repairs |
|
| 257 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 258 | + $repair->run(); |
|
| 259 | + |
|
| 260 | + $this->doCoreUpgrade(); |
|
| 261 | + |
|
| 262 | + try { |
|
| 263 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 264 | + Setup::installBackgroundJobs(); |
|
| 265 | + } catch (\Exception $e) { |
|
| 266 | + throw new \Exception($e->getMessage()); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // update all shipped apps |
|
| 270 | + $this->checkAppsRequirements(); |
|
| 271 | + $this->doAppUpgrade(); |
|
| 272 | + |
|
| 273 | + // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 274 | + \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 275 | + |
|
| 276 | + // upgrade appstore apps |
|
| 277 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 278 | + |
|
| 279 | + // install new shipped apps on upgrade |
|
| 280 | + OC_App::loadApps('authentication'); |
|
| 281 | + $errors = Installer::installShippedApps(true); |
|
| 282 | + foreach ($errors as $appId => $exception) { |
|
| 283 | + /** @var \Exception $exception */ |
|
| 284 | + $this->log->logException($exception, ['app' => $appId]); |
|
| 285 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // post-upgrade repairs |
|
| 289 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 290 | + $repair->run(); |
|
| 291 | + |
|
| 292 | + //Invalidate update feed |
|
| 293 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 294 | + |
|
| 295 | + // Check for code integrity if not disabled |
|
| 296 | + if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 297 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 298 | + $this->checker->runInstanceVerification(); |
|
| 299 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // only set the final version if everything went well |
|
| 303 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 304 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + protected function doCoreUpgrade() { |
|
| 308 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 309 | + |
|
| 310 | + // execute core migrations |
|
| 311 | + $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
| 312 | + $ms->migrate(); |
|
| 313 | + |
|
| 314 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param string $version the oc version to check app compatibility with |
|
| 319 | + */ |
|
| 320 | + protected function checkAppUpgrade($version) { |
|
| 321 | + $apps = \OC_App::getEnabledApps(); |
|
| 322 | + $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
| 323 | + |
|
| 324 | + $appManager = \OC::$server->getAppManager(); |
|
| 325 | + foreach ($apps as $appId) { |
|
| 326 | + $info = \OC_App::getAppInfo($appId); |
|
| 327 | + $compatible = \OC_App::isAppCompatible($version, $info); |
|
| 328 | + $isShipped = $appManager->isShipped($appId); |
|
| 329 | + |
|
| 330 | + if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
| 331 | + /** |
|
| 332 | + * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
| 333 | + * are not possible anymore within it. - Consider this when touching the code. |
|
| 334 | + * @link https://github.com/owncloud/core/issues/10980 |
|
| 335 | + * @see \OC_App::updateApp |
|
| 336 | + */ |
|
| 337 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
| 338 | + $this->includePreUpdate($appId); |
|
| 339 | + } |
|
| 340 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
| 341 | + $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
| 342 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Includes the pre-update file. Done here to prevent namespace mixups. |
|
| 352 | + * @param string $appId |
|
| 353 | + */ |
|
| 354 | + private function includePreUpdate($appId) { |
|
| 355 | + include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 360 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 361 | + * |
|
| 362 | + * @throws NeedsUpdateException |
|
| 363 | + */ |
|
| 364 | + protected function doAppUpgrade() { |
|
| 365 | + $apps = \OC_App::getEnabledApps(); |
|
| 366 | + $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
| 367 | + $pseudoOtherType = 'other'; |
|
| 368 | + $stacks = array($pseudoOtherType => array()); |
|
| 369 | + |
|
| 370 | + foreach ($apps as $appId) { |
|
| 371 | + $priorityType = false; |
|
| 372 | + foreach ($priorityTypes as $type) { |
|
| 373 | + if(!isset($stacks[$type])) { |
|
| 374 | + $stacks[$type] = array(); |
|
| 375 | + } |
|
| 376 | + if (\OC_App::isType($appId, $type)) { |
|
| 377 | + $stacks[$type][] = $appId; |
|
| 378 | + $priorityType = true; |
|
| 379 | + break; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + if (!$priorityType) { |
|
| 383 | + $stacks[$pseudoOtherType][] = $appId; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + foreach ($stacks as $type => $stack) { |
|
| 387 | + foreach ($stack as $appId) { |
|
| 388 | + if (\OC_App::shouldUpgrade($appId)) { |
|
| 389 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 390 | + \OC_App::updateApp($appId); |
|
| 391 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 392 | + } |
|
| 393 | + if($type !== $pseudoOtherType) { |
|
| 394 | + // load authentication, filesystem and logging apps after |
|
| 395 | + // upgrading them. Other apps my need to rely on modifying |
|
| 396 | + // user and/or filesystem aspects. |
|
| 397 | + \OC_App::loadApp($appId); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * check if the current enabled apps are compatible with the current |
|
| 405 | + * ownCloud version. disable them if not. |
|
| 406 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 407 | + * party apps installed. |
|
| 408 | + * |
|
| 409 | + * @return array |
|
| 410 | + * @throws \Exception |
|
| 411 | + */ |
|
| 412 | + private function checkAppsRequirements() { |
|
| 413 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 414 | + $apps = OC_App::getEnabledApps(); |
|
| 415 | + $version = Util::getVersion(); |
|
| 416 | + $disabledApps = []; |
|
| 417 | + $appManager = \OC::$server->getAppManager(); |
|
| 418 | + foreach ($apps as $app) { |
|
| 419 | + // check if the app is compatible with this version of ownCloud |
|
| 420 | + $info = OC_App::getAppInfo($app); |
|
| 421 | + if(!OC_App::isAppCompatible($version, $info)) { |
|
| 422 | + if ($appManager->isShipped($app)) { |
|
| 423 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 424 | + } |
|
| 425 | + OC_App::disable($app); |
|
| 426 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
| 427 | + } |
|
| 428 | + // no need to disable any app in case this is a non-core upgrade |
|
| 429 | + if (!$isCoreUpgrade) { |
|
| 430 | + continue; |
|
| 431 | + } |
|
| 432 | + // shipped apps will remain enabled |
|
| 433 | + if ($appManager->isShipped($app)) { |
|
| 434 | + continue; |
|
| 435 | + } |
|
| 436 | + // authentication and session apps will remain enabled as well |
|
| 437 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 438 | + continue; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + // disable any other 3rd party apps if not overriden |
|
| 442 | + if(!$this->skip3rdPartyAppsDisable) { |
|
| 443 | + \OC_App::disable($app); |
|
| 444 | + $disabledApps[]= $app; |
|
| 445 | + $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
|
| 446 | + }; |
|
| 447 | + } |
|
| 448 | + return $disabledApps; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return bool |
|
| 453 | + */ |
|
| 454 | + private function isCodeUpgrade() { |
|
| 455 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 456 | + $currentVersion = implode('.', Util::getVersion()); |
|
| 457 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 458 | + return true; |
|
| 459 | + } |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @param array $disabledApps |
|
| 465 | + * @throws \Exception |
|
| 466 | + */ |
|
| 467 | + private function upgradeAppStoreApps(array $disabledApps) { |
|
| 468 | + foreach($disabledApps as $app) { |
|
| 469 | + try { |
|
| 470 | + $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 471 | + if ($this->installer->isUpdateAvailable($app)) { |
|
| 472 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 473 | + $this->installer->updateAppstoreApp($app); |
|
| 474 | + } |
|
| 475 | + $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 476 | + } catch (\Exception $ex) { |
|
| 477 | + $this->log->logException($ex, ['app' => 'core']); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Forward messages emitted by the repair routine |
|
| 484 | + */ |
|
| 485 | + private function emitRepairEvents() { |
|
| 486 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 487 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 488 | + if ($event instanceof GenericEvent) { |
|
| 489 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 490 | + } |
|
| 491 | + }); |
|
| 492 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 493 | + if ($event instanceof GenericEvent) { |
|
| 494 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 495 | + } |
|
| 496 | + }); |
|
| 497 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 498 | + if ($event instanceof GenericEvent) { |
|
| 499 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 500 | + } |
|
| 501 | + }); |
|
| 502 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 503 | + if ($event instanceof GenericEvent) { |
|
| 504 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 505 | + } |
|
| 506 | + }); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + private function logAllEvents() { |
|
| 510 | + $log = $this->log; |
|
| 511 | + |
|
| 512 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 513 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
| 514 | + if (!$event instanceof GenericEvent) { |
|
| 515 | + return; |
|
| 516 | + } |
|
| 517 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 518 | + }); |
|
| 519 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
| 520 | + if (!$event instanceof GenericEvent) { |
|
| 521 | + return; |
|
| 522 | + } |
|
| 523 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 524 | + }); |
|
| 525 | + |
|
| 526 | + $repairListener = function($event) use ($log) { |
|
| 527 | + if (!$event instanceof GenericEvent) { |
|
| 528 | + return; |
|
| 529 | + } |
|
| 530 | + switch ($event->getSubject()) { |
|
| 531 | + case '\OC\Repair::startProgress': |
|
| 532 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 533 | + break; |
|
| 534 | + case '\OC\Repair::advance': |
|
| 535 | + $desc = $event->getArgument(1); |
|
| 536 | + if (empty($desc)) { |
|
| 537 | + $desc = ''; |
|
| 538 | + } |
|
| 539 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 540 | + |
|
| 541 | + break; |
|
| 542 | + case '\OC\Repair::finishProgress': |
|
| 543 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 544 | + break; |
|
| 545 | + case '\OC\Repair::step': |
|
| 546 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 547 | + break; |
|
| 548 | + case '\OC\Repair::info': |
|
| 549 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 550 | + break; |
|
| 551 | + case '\OC\Repair::warning': |
|
| 552 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 553 | + break; |
|
| 554 | + case '\OC\Repair::error': |
|
| 555 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 556 | + break; |
|
| 557 | + } |
|
| 558 | + }; |
|
| 559 | + |
|
| 560 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 561 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 562 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 563 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 564 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 565 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 566 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
| 570 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 571 | + }); |
|
| 572 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
| 573 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 574 | + }); |
|
| 575 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
| 576 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 577 | + }); |
|
| 578 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
| 579 | + if ($success) { |
|
| 580 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 581 | + } else { |
|
| 582 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 583 | + } |
|
| 584 | + }); |
|
| 585 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
| 586 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 587 | + }); |
|
| 588 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
| 589 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 590 | + }); |
|
| 591 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
| 592 | + $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 593 | + }); |
|
| 594 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
| 595 | + $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
| 596 | + }); |
|
| 597 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
| 598 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 599 | + }); |
|
| 600 | + $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
| 601 | + $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
| 602 | + }); |
|
| 603 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
| 604 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 605 | + }); |
|
| 606 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
| 607 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 608 | + }); |
|
| 609 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
| 610 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 611 | + }); |
|
| 612 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
| 613 | + $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
| 614 | + }); |
|
| 615 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 616 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 617 | + }); |
|
| 618 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
| 619 | + $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
| 620 | + }); |
|
| 621 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 622 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 623 | + }); |
|
| 624 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 625 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 626 | + }); |
|
| 627 | + $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
| 628 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 629 | + }); |
|
| 630 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
| 631 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 632 | + }); |
|
| 633 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
| 634 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 635 | + }); |
|
| 636 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
| 637 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 638 | + }); |
|
| 639 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
| 640 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 641 | + }); |
|
| 642 | + |
|
| 643 | + } |
|
| 644 | 644 | |
| 645 | 645 | } |
| 646 | 646 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
| 96 | 96 | // fatal errors and exceptions and disable the app just instead. |
| 97 | - if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 97 | + if (version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 98 | 98 | $this->skip3rdPartyAppsDisable = true; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -120,43 +120,43 @@ discard block |
||
| 120 | 120 | $this->logAllEvents(); |
| 121 | 121 | |
| 122 | 122 | $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
| 123 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 123 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 124 | 124 | $this->config->setSystemValue('loglevel', Util::DEBUG); |
| 125 | 125 | |
| 126 | 126 | $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
| 127 | 127 | |
| 128 | - if(!$wasMaintenanceModeEnabled) { |
|
| 128 | + if (!$wasMaintenanceModeEnabled) { |
|
| 129 | 129 | $this->config->setSystemValue('maintenance', true); |
| 130 | 130 | $this->emit('\OC\Updater', 'maintenanceEnabled'); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
| 134 | 134 | $currentVersion = implode('.', \OCP\Util::getVersion()); |
| 135 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
| 135 | + $this->log->debug('starting upgrade from '.$installedVersion.' to '.$currentVersion, array('app' => 'core')); |
|
| 136 | 136 | |
| 137 | 137 | $success = true; |
| 138 | 138 | try { |
| 139 | 139 | $this->doUpgrade($currentVersion, $installedVersion); |
| 140 | 140 | } catch (HintException $exception) { |
| 141 | 141 | $this->log->logException($exception, ['app' => 'core']); |
| 142 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
| 142 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage().': '.$exception->getHint())); |
|
| 143 | 143 | $success = false; |
| 144 | 144 | } catch (\Exception $exception) { |
| 145 | 145 | $this->log->logException($exception, ['app' => 'core']); |
| 146 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
| 146 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception).': '.$exception->getMessage())); |
|
| 147 | 147 | $success = false; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $this->emit('\OC\Updater', 'updateEnd', array($success)); |
| 151 | 151 | |
| 152 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
| 152 | + if (!$wasMaintenanceModeEnabled && $success) { |
|
| 153 | 153 | $this->config->setSystemValue('maintenance', false); |
| 154 | 154 | $this->emit('\OC\Updater', 'maintenanceDisabled'); |
| 155 | 155 | } else { |
| 156 | 156 | $this->emit('\OC\Updater', 'maintenanceActive'); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 159 | + $this->emit('\OC\Updater', 'resetLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 160 | 160 | $this->config->setSystemValue('loglevel', $logLevel); |
| 161 | 161 | $this->config->setSystemValue('installed', true); |
| 162 | 162 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | private function getAllowedPreviousVersions() { |
| 172 | 172 | // this should really be a JSON file |
| 173 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 173 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 174 | 174 | /** @var array $OC_VersionCanBeUpgradedFrom */ |
| 175 | 175 | return $OC_VersionCanBeUpgradedFrom; |
| 176 | 176 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | private function getVendor() { |
| 184 | 184 | // this should really be a JSON file |
| 185 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 185 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 186 | 186 | /** @var string $vendor */ |
| 187 | 187 | return (string) $vendor; |
| 188 | 188 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
| 198 | 198 | $version = explode('.', $oldVersion); |
| 199 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 199 | + $majorMinor = $version[0].'.'.$version[1]; |
|
| 200 | 200 | |
| 201 | 201 | $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
| 202 | 202 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | // create empty file in data dir, so we can later find |
| 252 | 252 | // out that this is indeed an ownCloud data directory |
| 253 | 253 | // (in case it didn't exist before) |
| 254 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 254 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); |
|
| 255 | 255 | |
| 256 | 256 | // pre-upgrade repairs |
| 257 | 257 | $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | foreach ($errors as $appId => $exception) { |
| 283 | 283 | /** @var \Exception $exception */ |
| 284 | 284 | $this->log->logException($exception, ['app' => $appId]); |
| 285 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 285 | + $this->emit('\OC\Updater', 'failure', [$appId.': '.$exception->getMessage()]); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // post-upgrade repairs |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | $this->config->setAppValue('core', 'lastupdatedat', 0); |
| 294 | 294 | |
| 295 | 295 | // Check for code integrity if not disabled |
| 296 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 296 | + if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 297 | 297 | $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
| 298 | 298 | $this->checker->runInstanceVerification(); |
| 299 | 299 | $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
@@ -334,12 +334,12 @@ discard block |
||
| 334 | 334 | * @link https://github.com/owncloud/core/issues/10980 |
| 335 | 335 | * @see \OC_App::updateApp |
| 336 | 336 | */ |
| 337 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
| 337 | + if (file_exists(\OC_App::getAppPath($appId).'/appinfo/preupdate.php')) { |
|
| 338 | 338 | $this->includePreUpdate($appId); |
| 339 | 339 | } |
| 340 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
| 340 | + if (file_exists(\OC_App::getAppPath($appId).'/appinfo/database.xml')) { |
|
| 341 | 341 | $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
| 342 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
| 342 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId).'/appinfo/database.xml'); |
|
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @param string $appId |
| 353 | 353 | */ |
| 354 | 354 | private function includePreUpdate($appId) { |
| 355 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
| 355 | + include \OC_App::getAppPath($appId).'/appinfo/preupdate.php'; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | foreach ($apps as $appId) { |
| 371 | 371 | $priorityType = false; |
| 372 | 372 | foreach ($priorityTypes as $type) { |
| 373 | - if(!isset($stacks[$type])) { |
|
| 373 | + if (!isset($stacks[$type])) { |
|
| 374 | 374 | $stacks[$type] = array(); |
| 375 | 375 | } |
| 376 | 376 | if (\OC_App::isType($appId, $type)) { |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | \OC_App::updateApp($appId); |
| 391 | 391 | $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
| 392 | 392 | } |
| 393 | - if($type !== $pseudoOtherType) { |
|
| 393 | + if ($type !== $pseudoOtherType) { |
|
| 394 | 394 | // load authentication, filesystem and logging apps after |
| 395 | 395 | // upgrading them. Other apps my need to rely on modifying |
| 396 | 396 | // user and/or filesystem aspects. |
@@ -418,9 +418,9 @@ discard block |
||
| 418 | 418 | foreach ($apps as $app) { |
| 419 | 419 | // check if the app is compatible with this version of ownCloud |
| 420 | 420 | $info = OC_App::getAppInfo($app); |
| 421 | - if(!OC_App::isAppCompatible($version, $info)) { |
|
| 421 | + if (!OC_App::isAppCompatible($version, $info)) { |
|
| 422 | 422 | if ($appManager->isShipped($app)) { |
| 423 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 423 | + throw new \UnexpectedValueException('The files of the app "'.$app.'" were not correctly replaced before running the update'); |
|
| 424 | 424 | } |
| 425 | 425 | OC_App::disable($app); |
| 426 | 426 | $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
@@ -439,9 +439,9 @@ discard block |
||
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // disable any other 3rd party apps if not overriden |
| 442 | - if(!$this->skip3rdPartyAppsDisable) { |
|
| 442 | + if (!$this->skip3rdPartyAppsDisable) { |
|
| 443 | 443 | \OC_App::disable($app); |
| 444 | - $disabledApps[]= $app; |
|
| 444 | + $disabledApps[] = $app; |
|
| 445 | 445 | $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
| 446 | 446 | }; |
| 447 | 447 | } |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | * @throws \Exception |
| 466 | 466 | */ |
| 467 | 467 | private function upgradeAppStoreApps(array $disabledApps) { |
| 468 | - foreach($disabledApps as $app) { |
|
| 468 | + foreach ($disabledApps as $app) { |
|
| 469 | 469 | try { |
| 470 | 470 | $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
| 471 | 471 | if ($this->installer->isUpdateAvailable($app)) { |
@@ -484,22 +484,22 @@ discard block |
||
| 484 | 484 | */ |
| 485 | 485 | private function emitRepairEvents() { |
| 486 | 486 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 487 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 487 | + $dispatcher->addListener('\OC\Repair::warning', function($event) { |
|
| 488 | 488 | if ($event instanceof GenericEvent) { |
| 489 | 489 | $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
| 490 | 490 | } |
| 491 | 491 | }); |
| 492 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 492 | + $dispatcher->addListener('\OC\Repair::error', function($event) { |
|
| 493 | 493 | if ($event instanceof GenericEvent) { |
| 494 | 494 | $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
| 495 | 495 | } |
| 496 | 496 | }); |
| 497 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 497 | + $dispatcher->addListener('\OC\Repair::info', function($event) { |
|
| 498 | 498 | if ($event instanceof GenericEvent) { |
| 499 | 499 | $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
| 500 | 500 | } |
| 501 | 501 | }); |
| 502 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 502 | + $dispatcher->addListener('\OC\Repair::step', function($event) { |
|
| 503 | 503 | if ($event instanceof GenericEvent) { |
| 504 | 504 | $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
| 505 | 505 | } |
@@ -514,13 +514,13 @@ discard block |
||
| 514 | 514 | if (!$event instanceof GenericEvent) { |
| 515 | 515 | return; |
| 516 | 516 | } |
| 517 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 517 | + $log->info('\OC\DB\Migrator::executeSql: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 518 | 518 | }); |
| 519 | 519 | $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
| 520 | 520 | if (!$event instanceof GenericEvent) { |
| 521 | 521 | return; |
| 522 | 522 | } |
| 523 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 523 | + $log->info('\OC\DB\Migrator::checkTable: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 524 | 524 | }); |
| 525 | 525 | |
| 526 | 526 | $repairListener = function($event) use ($log) { |
@@ -529,30 +529,30 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | switch ($event->getSubject()) { |
| 531 | 531 | case '\OC\Repair::startProgress': |
| 532 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 532 | + $log->info('\OC\Repair::startProgress: Starting ... '.$event->getArgument(1).' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 533 | 533 | break; |
| 534 | 534 | case '\OC\Repair::advance': |
| 535 | 535 | $desc = $event->getArgument(1); |
| 536 | 536 | if (empty($desc)) { |
| 537 | 537 | $desc = ''; |
| 538 | 538 | } |
| 539 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 539 | + $log->info('\OC\Repair::advance: '.$desc.' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 540 | 540 | |
| 541 | 541 | break; |
| 542 | 542 | case '\OC\Repair::finishProgress': |
| 543 | 543 | $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
| 544 | 544 | break; |
| 545 | 545 | case '\OC\Repair::step': |
| 546 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 546 | + $log->info('\OC\Repair::step: Repair step: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 547 | 547 | break; |
| 548 | 548 | case '\OC\Repair::info': |
| 549 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 549 | + $log->info('\OC\Repair::info: Repair info: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 550 | 550 | break; |
| 551 | 551 | case '\OC\Repair::warning': |
| 552 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 552 | + $log->warning('\OC\Repair::warning: Repair warning: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 553 | 553 | break; |
| 554 | 554 | case '\OC\Repair::error': |
| 555 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 555 | + $log->error('\OC\Repair::error: Repair error: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 556 | 556 | break; |
| 557 | 557 | } |
| 558 | 558 | }; |
@@ -566,77 +566,77 @@ discard block |
||
| 566 | 566 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
| 567 | 567 | |
| 568 | 568 | |
| 569 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
| 569 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function() use($log) { |
|
| 570 | 570 | $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
| 571 | 571 | }); |
| 572 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
| 572 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function() use($log) { |
|
| 573 | 573 | $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
| 574 | 574 | }); |
| 575 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
| 575 | + $this->listen('\OC\Updater', 'maintenanceActive', function() use($log) { |
|
| 576 | 576 | $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
| 577 | 577 | }); |
| 578 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
| 578 | + $this->listen('\OC\Updater', 'updateEnd', function($success) use($log) { |
|
| 579 | 579 | if ($success) { |
| 580 | 580 | $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
| 581 | 581 | } else { |
| 582 | 582 | $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
| 583 | 583 | } |
| 584 | 584 | }); |
| 585 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
| 585 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function() use($log) { |
|
| 586 | 586 | $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
| 587 | 587 | }); |
| 588 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
| 588 | + $this->listen('\OC\Updater', 'dbUpgrade', function() use($log) { |
|
| 589 | 589 | $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
| 590 | 590 | }); |
| 591 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
| 591 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($log) { |
|
| 592 | 592 | $log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
| 593 | 593 | }); |
| 594 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
| 594 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function() use($log) { |
|
| 595 | 595 | $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
| 596 | 596 | }); |
| 597 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
| 598 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 597 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use($log) { |
|
| 598 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: '.$app, ['app' => 'updater']); |
|
| 599 | 599 | }); |
| 600 | - $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
| 601 | - $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
| 600 | + $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function($app) use ($log) { |
|
| 601 | + $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: '.$app, ['app' => 'updater']); |
|
| 602 | 602 | }); |
| 603 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
| 604 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 603 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use($log) { |
|
| 604 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 605 | 605 | }); |
| 606 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
| 607 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 606 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use($log) { |
|
| 607 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "'.$app.'" from appstore', ['app' => 'updater']); |
|
| 608 | 608 | }); |
| 609 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
| 610 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 609 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function($app) use($log) { |
|
| 610 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 611 | 611 | }); |
| 612 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
| 612 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($log) { |
|
| 613 | 613 | $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
| 614 | 614 | }); |
| 615 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 616 | - $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 615 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($log) { |
|
| 616 | + $log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <'.$app.'> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']); |
|
| 617 | 617 | }); |
| 618 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
| 618 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function() use ($log) { |
|
| 619 | 619 | $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
| 620 | 620 | }); |
| 621 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 622 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 621 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function($app) use ($log) { |
|
| 622 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <'.$app.'> ...', ['app' => 'updater']); |
|
| 623 | 623 | }); |
| 624 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 625 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 624 | + $this->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($log) { |
|
| 625 | + $log->info('\OC\Updater::appUpgrade: Updated <'.$app.'> to '.$version, ['app' => 'updater']); |
|
| 626 | 626 | }); |
| 627 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
| 628 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 627 | + $this->listen('\OC\Updater', 'failure', function($message) use($log) { |
|
| 628 | + $log->error('\OC\Updater::failure: '.$message, ['app' => 'updater']); |
|
| 629 | 629 | }); |
| 630 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
| 630 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function() use($log) { |
|
| 631 | 631 | $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
| 632 | 632 | }); |
| 633 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
| 634 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 633 | + $this->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($log) { |
|
| 634 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to '.$logLevelName.'('.$logLevel.')', ['app' => 'updater']); |
|
| 635 | 635 | }); |
| 636 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
| 636 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($log) { |
|
| 637 | 637 | $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
| 638 | 638 | }); |
| 639 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
| 639 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($log) { |
|
| 640 | 640 | $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
| 641 | 641 | }); |
| 642 | 642 | |