diff options
Diffstat (limited to 'core/ajax')
-rw-r--r-- | core/ajax/appconfig.php | 69 | ||||
-rw-r--r-- | core/ajax/preview.php | 64 | ||||
-rw-r--r-- | core/ajax/share.php | 374 | ||||
-rw-r--r-- | core/ajax/update.php | 200 |
4 files changed, 109 insertions, 598 deletions
diff --git a/core/ajax/appconfig.php b/core/ajax/appconfig.php deleted file mode 100644 index 9602269d7a7..00000000000 --- a/core/ajax/appconfig.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php -/** - * @author Lukas Reschke <lukas@owncloud.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -OC_Util::checkAdminUser(); -OCP\JSON::callCheck(); - -$action=isset($_POST['action'])?$_POST['action']:$_GET['action']; - -if(isset($_POST['app']) || isset($_GET['app'])) { - $app=OC_App::cleanAppId(isset($_POST['app'])? (string)$_POST['app']: (string)$_GET['app']); -} - -// An admin should not be able to add remote and public services -// on its own. This should only be possible programmatically. -// This change is due the fact that an admin may not be expected -// to execute arbitrary code in every environment. -if($app === 'core' && isset($_POST['key']) &&(substr((string)$_POST['key'],0,7) === 'remote_' || substr((string)$_POST['key'],0,7) === 'public_')) { - OC_JSON::error(array('data' => array('message' => 'Unexpected error!'))); - return; -} - -$result=false; -$appConfig = \OC::$server->getAppConfig(); -switch($action) { - case 'getValue': - $result=$appConfig->getValue($app, (string)$_GET['key'], (string)$_GET['defaultValue']); - break; - case 'setValue': - $result=$appConfig->setValue($app, (string)$_POST['key'], (string)$_POST['value']); - break; - case 'getApps': - $result=$appConfig->getApps(); - break; - case 'getKeys': - $result=$appConfig->getKeys($app); - break; - case 'hasKey': - $result=$appConfig->hasKey($app, (string)$_GET['key']); - break; - case 'deleteKey': - $result=$appConfig->deleteKey($app, (string)$_POST['key']); - break; - case 'deleteApp': - $result=$appConfig->deleteApp($app); - break; -} -OC_JSON::success(array('data'=>$result)); - diff --git a/core/ajax/preview.php b/core/ajax/preview.php deleted file mode 100644 index 119bad1eea2..00000000000 --- a/core/ajax/preview.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php -/** - * @author Georg Ehrke <georg@owncloud.com> - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Lukas Reschke <lukas@owncloud.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -\OC_Util::checkLoggedIn(); -\OC::$server->getSession()->close(); - -$file = array_key_exists('file', $_GET) ? (string)$_GET['file'] : ''; -$maxX = array_key_exists('x', $_GET) ? (int)$_GET['x'] : '32'; -$maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '32'; -$scalingUp = array_key_exists('scalingup', $_GET) ? (bool)$_GET['scalingup'] : true; -$keepAspect = array_key_exists('a', $_GET) ? true : false; -$always = array_key_exists('forceIcon', $_GET) ? (bool)$_GET['forceIcon'] : true; -$mode = array_key_exists('mode', $_GET) ? $_GET['mode'] : 'fill'; - -if ($file === '') { - //400 Bad Request - \OC_Response::setStatus(400); - \OCP\Util::writeLog('core-preview', 'No file parameter was passed', \OCP\Util::DEBUG); - exit; -} - -if ($maxX === 0 || $maxY === 0) { - //400 Bad Request - \OC_Response::setStatus(400); - \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG); - exit; -} - -$info = \OC\Files\Filesystem::getFileInfo($file); - -if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) { - \OC_Response::setStatus(404); -} else { - $preview = new \OC\Preview(\OC_User::getUser(), 'files'); - $preview->setFile($file, $info); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingUp); - $preview->setMode($mode); - $preview->setKeepAspect($keepAspect); - $preview->showPreview(); -} diff --git a/core/ajax/share.php b/core/ajax/share.php deleted file mode 100644 index 44144b791e2..00000000000 --- a/core/ajax/share.php +++ /dev/null @@ -1,374 +0,0 @@ -<?php -/** - * @author Arthur Schiwon <blizzz@owncloud.com> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Björn Schießle <schiessle@owncloud.com> - * @author Craig Morrissey <craig@owncloud.com> - * @author dampfklon <me@dampfklon.de> - * @author Felix Böhm <felixboehm@gmx.de> - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Leonardo Diez <leio10@users.noreply.github.com> - * @author Lukas Reschke <lukas@owncloud.com> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Ramiro Aparicio <rapariciog@gmail.com> - * @author Robin Appelman <icewind@owncloud.com> - * @author Roeland Jago Douma <rullzer@owncloud.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Thomas Tanghus <thomas@tanghus.net> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -use OCP\IUser; - -OC_JSON::checkLoggedIn(); -OCP\JSON::callCheck(); - -$defaults = new \OCP\Defaults(); - -if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) { - switch ($_POST['action']) { - case 'informRecipients': - $l = \OC::$server->getL10N('core'); - $shareType = (int) $_POST['shareType']; - $itemType = (string)$_POST['itemType']; - $itemSource = (string)$_POST['itemSource']; - $recipient = (string)$_POST['recipient']; - - $userManager = \OC::$server->getUserManager(); - $recipientList = []; - if($shareType === \OCP\Share::SHARE_TYPE_USER) { - $recipientList[] = $userManager->get($recipient); - } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { - $recipientList = \OC_Group::usersInGroup($recipient); - $group = \OC::$server->getGroupManager()->get($recipient); - $recipientList = $group->searchUsers(''); - } - // don't send a mail to the user who shared the file - $recipientList = array_filter($recipientList, function($user) { - /** @var IUser $user */ - return $user->getUID() !== \OCP\User::getUser(); - }); - - $mailNotification = new \OC\Share\MailNotifications( - \OC::$server->getUserSession()->getUser(), - \OC::$server->getL10N('lib'), - \OC::$server->getMailer(), - \OC::$server->getLogger(), - $defaults, - \OC::$server->getURLGenerator() - ); - $result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType); - - \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, true); - - if (empty($result)) { - OCP\JSON::success(); - } else { - OCP\JSON::error(array( - 'data' => array( - 'message' => $l->t("Couldn't send mail to following users: %s ", - implode(', ', $result) - ) - ) - )); - } - break; - case 'informRecipientsDisabled': - $itemSource = (string)$_POST['itemSource']; - $shareType = (int)$_POST['shareType']; - $itemType = (string)$_POST['itemType']; - $recipient = (string)$_POST['recipient']; - \OCP\Share::setSendMailStatus($itemType, $itemSource, $shareType, $recipient, false); - OCP\JSON::success(); - break; - - case 'email': - // read post variables - $link = (string)$_POST['link']; - $file = (string)$_POST['file']; - $to_address = (string)$_POST['toaddress']; - - $mailNotification = new \OC\Share\MailNotifications( - \OC::$server->getUserSession()->getUser(), - \OC::$server->getL10N('lib'), - \OC::$server->getMailer(), - \OC::$server->getLogger(), - $defaults, - \OC::$server->getURLGenerator() - ); - - $expiration = null; - if (isset($_POST['expiration']) && $_POST['expiration'] !== '') { - try { - $date = new DateTime((string)$_POST['expiration']); - $expiration = $date->getTimestamp(); - } catch (Exception $e) { - \OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR); - } - } - - $result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration); - if(empty($result)) { - // Get the token from the link - $linkParts = explode('/', $link); - $token = array_pop($linkParts); - - // Get the share for the token - $share = \OCP\Share::getShareByToken($token, false); - if ($share !== false) { - $currentUser = \OC::$server->getUserSession()->getUser()->getUID(); - $file = '/' . ltrim($file, '/'); - - // Check whether share belongs to the user and whether the file is the same - if ($share['file_target'] === $file && $share['uid_owner'] === $currentUser) { - - // Get the path for the user - $view = new \OC\Files\View('/' . $currentUser . '/files'); - $fileId = (int) $share['item_source']; - $path = $view->getPath((int) $share['item_source']); - - if ($path !== null) { - $event = \OC::$server->getActivityManager()->generateEvent(); - $event->setApp(\OCA\Files_Sharing\Activity::FILES_SHARING_APP) - ->setType(\OCA\Files_Sharing\Activity::TYPE_SHARED) - ->setAuthor($currentUser) - ->setAffectedUser($currentUser) - ->setObject('files', $fileId, $path) - ->setSubject(\OCA\Files_Sharing\Activity::SUBJECT_SHARED_EMAIL, [$path, $to_address]); - \OC::$server->getActivityManager()->publish($event); - } - } - } - - \OCP\JSON::success(); - } else { - $l = \OC::$server->getL10N('core'); - OCP\JSON::error(array( - 'data' => array( - 'message' => $l->t("Couldn't send mail to following users: %s ", - implode(', ', $result) - ) - ) - )); - } - - break; - } -} else if (isset($_GET['fetch'])) { - switch ($_GET['fetch']) { - case 'getItemsSharedStatuses': - if (isset($_GET['itemType'])) { - $return = OCP\Share::getItemsShared((string)$_GET['itemType'], OCP\Share::FORMAT_STATUSES); - is_array($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error(); - } - break; - case 'getItem': - if (isset($_GET['itemType']) - && isset($_GET['itemSource']) - && isset($_GET['checkReshare']) - && isset($_GET['checkShares'])) { - if ($_GET['checkReshare'] == 'true') { - $reshare = OCP\Share::getItemSharedWithBySource( - (string)$_GET['itemType'], - (string)$_GET['itemSource'], - OCP\Share::FORMAT_NONE, - null, - true - ); - } else { - $reshare = false; - } - if ($_GET['checkShares'] == 'true') { - $shares = OCP\Share::getItemShared( - (string)$_GET['itemType'], - (string)$_GET['itemSource'], - OCP\Share::FORMAT_NONE, - null, - true - ); - } else { - $shares = false; - } - OC_JSON::success(array('data' => array('reshare' => $reshare, 'shares' => $shares))); - } - break; - case 'getShareWithEmail': - $result = array(); - if (isset($_GET['search'])) { - $cm = OC::$server->getContactsManager(); - if (!is_null($cm) && $cm->isEnabled()) { - $contacts = $cm->search((string)$_GET['search'], array('FN', 'EMAIL')); - foreach ($contacts as $contact) { - if (!isset($contact['EMAIL'])) { - continue; - } - - $emails = $contact['EMAIL']; - if (!is_array($emails)) { - $emails = array($emails); - } - - foreach($emails as $email) { - $result[] = array( - 'id' => $contact['id'], - 'email' => $email, - 'displayname' => $contact['FN'], - ); - } - } - } - } - OC_JSON::success(array('data' => $result)); - break; - case 'getShareWith': - if (isset($_GET['search'])) { - $shareWithinGroupOnly = OC\Share\Share::shareWithGroupMembersOnly(); - $shareWith = array(); - $groups = OC_Group::getGroups((string)$_GET['search']); - if ($shareWithinGroupOnly) { - $usergroups = OC_Group::getUserGroups(OC_User::getUser()); - $groups = array_intersect($groups, $usergroups); - } - - $sharedUsers = []; - $sharedGroups = []; - if (isset($_GET['itemShares'])) { - if (isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]) && - is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])) { - $sharedUsers = $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]; - } - - if (isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) && - is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])) { - $sharedGroups = $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]; - } - } - - $count = 0; - $users = array(); - $limit = 0; - $offset = 0; - // limit defaults to 15 if not specified via request parameter and can be no larger than 500 - $request_limit = min((int)$_GET['limit'] ?: 15, 500); - while ($count < $request_limit && count($users) == $limit) { - $limit = $request_limit - $count; - if ($shareWithinGroupOnly) { - $users = OC_Group::displayNamesInGroups($usergroups, (string)$_GET['search'], $limit, $offset); - } else { - $users = OC_User::getDisplayNames((string)$_GET['search'], $limit, $offset); - } - - $offset += $limit; - foreach ($users as $uid => $displayName) { - if (in_array($uid, $sharedUsers)) { - continue; - } - - if ((!isset($_GET['itemShares']) - || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]) - || !in_array($uid, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])) - && $uid != OC_User::getUser()) { - $shareWith[] = array( - 'label' => $displayName, - 'value' => array( - 'shareType' => OCP\Share::SHARE_TYPE_USER, - 'shareWith' => $uid) - ); - $count++; - } - } - } - $count = 0; - - // enable l10n support - $l = \OC::$server->getL10N('core'); - - foreach ($groups as $group) { - if (in_array($group, $sharedGroups)) { - continue; - } - - if ($count < $request_limit) { - if (!isset($_GET['itemShares']) - || !isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) - || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) - || !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])) { - $shareWith[] = array( - 'label' => $group, - 'value' => array( - 'shareType' => OCP\Share::SHARE_TYPE_GROUP, - 'shareWith' => $group - ) - ); - $count++; - } - } else { - break; - } - } - - // allow user to add unknown remote addresses for server-to-server share - $backend = \OCP\Share::getBackend((string)$_GET['itemType']); - if ($backend->isShareTypeAllowed(\OCP\Share::SHARE_TYPE_REMOTE)) { - if (substr_count((string)$_GET['search'], '@') >= 1) { - $shareWith[] = array( - 'label' => (string)$_GET['search'], - 'value' => array( - 'shareType' => \OCP\Share::SHARE_TYPE_REMOTE, - 'shareWith' => (string)$_GET['search'] - ) - ); - } - $contactManager = \OC::$server->getContactsManager(); - $addressBookContacts = $contactManager->search($_GET['search'], ['CLOUD', 'FN']); - foreach ($addressBookContacts as $contact) { - if (isset($contact['CLOUD'])) { - foreach ($contact['CLOUD'] as $cloudId) { - $shareWith[] = array( - 'label' => $contact['FN'] . ' (' . $cloudId . ')', - 'value' => array( - 'shareType' => \OCP\Share::SHARE_TYPE_REMOTE, - 'shareWith' => $cloudId - ) - ); - } - } - } - } - - $sharingAutocompletion = \OC::$server->getConfig() - ->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'); - - if ($sharingAutocompletion !== 'yes') { - $searchTerm = strtolower($_GET['search']); - $shareWith = array_filter($shareWith, function($user) use ($searchTerm) { - return strtolower($user['label']) === $searchTerm - || strtolower($user['value']['shareWith']) === $searchTerm; - }); - } - - $sorter = new \OC\Share\SearchResultSorter((string)$_GET['search'], - 'label', - \OC::$server->getLogger()); - usort($shareWith, array($sorter, 'sort')); - OC_JSON::success(array('data' => $shareWith)); - } - break; - } -} diff --git a/core/ajax/update.php b/core/ajax/update.php index 4d8fe19f168..69665cf62df 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -1,145 +1,163 @@ <?php + /** - * @author Björn Schießle <schiessle@owncloud.com> - * @author Joas Schilling <nickvergessen@owncloud.com> - * @author Lukas Reschke <lukas@owncloud.com> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ -set_time_limit(0); +use OC\Core\Listener\FeedBackHandler; +use OC\DB\MigratorExecuteSqlEvent; +use OC\Installer; +use OC\IntegrityCheck\Checker; +use OC\Repair\Events\RepairAdvanceEvent; +use OC\Repair\Events\RepairErrorEvent; +use OC\Repair\Events\RepairFinishEvent; +use OC\Repair\Events\RepairInfoEvent; +use OC\Repair\Events\RepairStartEvent; +use OC\Repair\Events\RepairStepEvent; +use OC\Repair\Events\RepairWarningEvent; +use OC\SystemConfig; +use OC\Updater; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IAppConfig; +use OCP\IConfig; +use OCP\IEventSourceFactory; +use OCP\IL10N; +use OCP\L10N\IFactory; +use OCP\Server; +use OCP\ServerVersion; +use OCP\Util; +use Psr\Log\LoggerInterface; + +if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) { + @set_time_limit(0); +} + require_once '../../lib/base.php'; -$l = \OC::$server->getL10N('core'); +/** @var IL10N $l */ +$l = Server::get(IFactory::class)->get('core'); -$eventSource = \OC::$server->createEventSource(); +$eventSource = Server::get(IEventSourceFactory::class)->create(); // need to send an initial message to force-init the event source, // which will then trigger its own CSRF check and produces its own CSRF error // message -$eventSource->send('success', (string)$l->t('Preparing update')); +$eventSource->send('success', $l->t('Preparing update')); + +if (Util::needUpgrade()) { + $config = Server::get(SystemConfig::class); + if ($config->getValue('upgrade.disable-web', false)) { + $eventSource->send('failure', $l->t('Please use the command line updater because updating via browser is disabled in your config.php.')); + $eventSource->close(); + exit(); + } -if (OC::checkUpgrade(false)) { // if a user is currently logged in, their session must be ignored to // avoid side effects \OC_User::setIncognitoMode(true); - $logger = \OC::$server->getLogger(); - $config = \OC::$server->getConfig(); - $updater = new \OC\Updater( - \OC::$server->getHTTPHelper(), - $config, - \OC::$server->getIntegrityCodeChecker(), - $logger + $config = Server::get(IConfig::class); + $updater = new Updater( + Server::get(ServerVersion::class), + $config, + Server::get(IAppConfig::class), + Server::get(Checker::class), + Server::get(LoggerInterface::class), + Server::get(Installer::class) ); $incompatibleApps = []; - $disabledThirdPartyApps = []; + $incompatibleOverwrites = $config->getSystemValue('app_install_overwrite', []); - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); - }); - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); - }); - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); - }); - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Updating database schema')); - }); - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Updated database')); - }); - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($eventSource, $l) { - $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)')); - }); - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Checked database schema update')); + /** @var IEventDispatcher $dispatcher */ + $dispatcher = Server::get(IEventDispatcher::class); + $dispatcher->addListener( + MigratorExecuteSqlEvent::class, + function (MigratorExecuteSqlEvent $event) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('[%d / %d]: %s', [$event->getCurrentStep(), $event->getMaxStep(), $event->getSql()])); + } + ); + $feedBack = new FeedBackHandler($eventSource, $l); + $dispatcher->addListener(RepairStartEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairAdvanceEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairFinishEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairStepEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairInfoEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairWarningEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairErrorEvent::class, [$feedBack, 'handleRepairFeedback']); + + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Turned on maintenance mode')); }); - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Checking updates of apps')); + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Turned off maintenance mode')); }); - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { - $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])); + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Maintenance mode is kept active')); }); - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Updating database schema')); }); - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version))); + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Updated database')); }); - $updater->listen('\OC\Updater', 'repairWarning', function ($description) use ($eventSource, $l) { - $eventSource->send('notice', (string)$l->t('Repair warning: ') . $description); + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Update app "%s" from App Store', [$app])); }); - $updater->listen('\OC\Updater', 'repairError', function ($description) use ($eventSource, $l) { - $eventSource->send('notice', (string)$l->t('Repair error: ') . $description); + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); }); - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { - $incompatibleApps[]= $app; + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Updated "%1$s" to %2$s', [$app, $version])); }); - $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) { - $disabledThirdPartyApps[]= $app; + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps, &$incompatibleOverwrites): void { + if (!in_array($app, $incompatibleOverwrites)) { + $incompatibleApps[] = $app; + } }); - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config): void { $eventSource->send('failure', $message); $eventSource->close(); $config->setSystemValue('maintenance', false); }); - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Set log level to debug')); + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Set log level to debug')); }); - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Reset log level')); + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Reset log level')); }); - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Starting code integrity check')); + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Starting code integrity check')); }); - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($eventSource, $l) { - $eventSource->send('success', (string)$l->t('Finished code integrity check')); + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l): void { + $eventSource->send('success', $l->t('Finished code integrity check')); }); try { $updater->upgrade(); } catch (\Exception $e) { + Server::get(LoggerInterface::class)->error( + $e->getMessage(), + [ + 'exception' => $e, + 'app' => 'update', + ]); $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); $eventSource->close(); exit(); } $disabledApps = []; - foreach ($disabledThirdPartyApps as $app) { - $disabledApps[$app] = (string) $l->t('%s (3rdparty)', [$app]); - } foreach ($incompatibleApps as $app) { - $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); + $disabledApps[$app] = $l->t('%s (incompatible)', [$app]); } if (!empty($disabledApps)) { - $eventSource->send('notice', - (string)$l->t('Following apps have been disabled: %s', implode(', ', $disabledApps))); + $eventSource->send('notice', $l->t('The following apps have been disabled: %s', [implode(', ', $disabledApps)])); } } else { - $eventSource->send('notice', (string)$l->t('Already up to date')); + $eventSource->send('notice', $l->t('Already up to date')); } $eventSource->send('done', ''); $eventSource->close(); - |