@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | require_once __DIR__ . '/../lib/base.php'; |
| 33 | 33 | |
| 34 | 34 | if (\OCP\Util::needUpgrade() |
| 35 | - || \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 36 | - // since the behavior of apps or remotes are unpredictable during |
|
| 37 | - // an upgrade, return a 503 directly |
|
| 38 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 39 | - $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable'); |
|
| 40 | - OC_API::respond($response, OC_API::requestedFormat()); |
|
| 41 | - exit; |
|
| 35 | + || \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 36 | + // since the behavior of apps or remotes are unpredictable during |
|
| 37 | + // an upgrade, return a 503 directly |
|
| 38 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 39 | + $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable'); |
|
| 40 | + OC_API::respond($response, OC_API::requestedFormat()); |
|
| 41 | + exit; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
@@ -49,56 +49,56 @@ discard block |
||
| 49 | 49 | * We first try the old routes since the appframework triggers more login stuff. |
| 50 | 50 | */ |
| 51 | 51 | try { |
| 52 | - OC_App::loadApps(['session']); |
|
| 53 | - OC_App::loadApps(['authentication']); |
|
| 54 | - // load all apps to get all api routes properly setup |
|
| 55 | - OC_App::loadApps(); |
|
| 52 | + OC_App::loadApps(['session']); |
|
| 53 | + OC_App::loadApps(['authentication']); |
|
| 54 | + // load all apps to get all api routes properly setup |
|
| 55 | + OC_App::loadApps(); |
|
| 56 | 56 | |
| 57 | - // force language as given in the http request |
|
| 58 | - \OC::$server->getL10NFactory()->setLanguageFromRequest(); |
|
| 57 | + // force language as given in the http request |
|
| 58 | + \OC::$server->getL10NFactory()->setLanguageFromRequest(); |
|
| 59 | 59 | |
| 60 | - OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 61 | - return; |
|
| 60 | + OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 61 | + return; |
|
| 62 | 62 | } catch (ResourceNotFoundException $e) { |
| 63 | - // Fall through the not found |
|
| 63 | + // Fall through the not found |
|
| 64 | 64 | } catch (MethodNotAllowedException $e) { |
| 65 | - OC_API::setContentType(); |
|
| 66 | - OC_Response::setStatus(405); |
|
| 67 | - exit(); |
|
| 65 | + OC_API::setContentType(); |
|
| 66 | + OC_Response::setStatus(405); |
|
| 67 | + exit(); |
|
| 68 | 68 | } catch (Exception $ex) { |
| 69 | - OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 70 | - exit(); |
|
| 69 | + OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 70 | + exit(); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /* |
| 74 | 74 | * Try the appframework routes |
| 75 | 75 | */ |
| 76 | 76 | try { |
| 77 | - if(!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 78 | - OC::handleLogin(\OC::$server->getRequest()); |
|
| 79 | - } |
|
| 80 | - OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 77 | + if(!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 78 | + OC::handleLogin(\OC::$server->getRequest()); |
|
| 79 | + } |
|
| 80 | + OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo()); |
|
| 81 | 81 | } catch (ResourceNotFoundException $e) { |
| 82 | - OC_API::setContentType(); |
|
| 82 | + OC_API::setContentType(); |
|
| 83 | 83 | |
| 84 | - $format = \OC::$server->getRequest()->getParam('format', 'xml'); |
|
| 85 | - $txt='Invalid query, please check the syntax. API specifications are here:' |
|
| 86 | - .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; |
|
| 87 | - OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format); |
|
| 84 | + $format = \OC::$server->getRequest()->getParam('format', 'xml'); |
|
| 85 | + $txt='Invalid query, please check the syntax. API specifications are here:' |
|
| 86 | + .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; |
|
| 87 | + OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format); |
|
| 88 | 88 | } catch (MethodNotAllowedException $e) { |
| 89 | - OC_API::setContentType(); |
|
| 90 | - OC_Response::setStatus(405); |
|
| 89 | + OC_API::setContentType(); |
|
| 90 | + OC_Response::setStatus(405); |
|
| 91 | 91 | } catch (\OC\OCS\Exception $ex) { |
| 92 | - OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 92 | + OC_API::respond($ex->getResult(), OC_API::requestedFormat()); |
|
| 93 | 93 | } catch (\OC\User\LoginException $e) { |
| 94 | - OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised')); |
|
| 94 | + OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised')); |
|
| 95 | 95 | } catch (\Exception $e) { |
| 96 | - \OC::$server->getLogger()->logException($e); |
|
| 97 | - OC_API::setContentType(); |
|
| 96 | + \OC::$server->getLogger()->logException($e); |
|
| 97 | + OC_API::setContentType(); |
|
| 98 | 98 | |
| 99 | - $format = \OC::$server->getRequest()->getParam('format', 'xml'); |
|
| 100 | - $txt='Invalid query, please check the syntax. API specifications are here:' |
|
| 101 | - .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; |
|
| 102 | - OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format); |
|
| 99 | + $format = \OC::$server->getRequest()->getParam('format', 'xml'); |
|
| 100 | + $txt='Invalid query, please check the syntax. API specifications are here:' |
|
| 101 | + .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; |
|
| 102 | + OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format); |
|
| 103 | 103 | } |
| 104 | 104 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | -require_once __DIR__ . '/../lib/base.php'; |
|
| 32 | +require_once __DIR__.'/../lib/base.php'; |
|
| 33 | 33 | |
| 34 | 34 | if (\OCP\Util::needUpgrade() |
| 35 | 35 | || \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * Try the appframework routes |
| 75 | 75 | */ |
| 76 | 76 | try { |
| 77 | - if(!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 77 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 78 | 78 | OC::handleLogin(\OC::$server->getRequest()); |
| 79 | 79 | } |
| 80 | 80 | OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo()); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | OC_API::setContentType(); |
| 83 | 83 | |
| 84 | 84 | $format = \OC::$server->getRequest()->getParam('format', 'xml'); |
| 85 | - $txt='Invalid query, please check the syntax. API specifications are here:' |
|
| 85 | + $txt = 'Invalid query, please check the syntax. API specifications are here:' |
|
| 86 | 86 | .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; |
| 87 | 87 | OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format); |
| 88 | 88 | } catch (MethodNotAllowedException $e) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | OC_API::setContentType(); |
| 98 | 98 | |
| 99 | 99 | $format = \OC::$server->getRequest()->getParam('format', 'xml'); |
| 100 | - $txt='Invalid query, please check the syntax. API specifications are here:' |
|
| 100 | + $txt = 'Invalid query, please check the syntax. API specifications are here:' |
|
| 101 | 101 | .' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; |
| 102 | 102 | OC_API::respond(new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, $txt), $format); |
| 103 | 103 | } |
@@ -29,61 +29,61 @@ |
||
| 29 | 29 | use OCP\Migration\IRepairStep; |
| 30 | 30 | |
| 31 | 31 | class UpdateLanguageCodes implements IRepairStep { |
| 32 | - /** @var IDBConnection */ |
|
| 33 | - private $connection; |
|
| 32 | + /** @var IDBConnection */ |
|
| 33 | + private $connection; |
|
| 34 | 34 | |
| 35 | - /** @var IConfig */ |
|
| 36 | - private $config; |
|
| 35 | + /** @var IConfig */ |
|
| 36 | + private $config; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param IDBConnection $connection |
|
| 40 | - * @param IConfig $config |
|
| 41 | - */ |
|
| 42 | - public function __construct(IDBConnection $connection, |
|
| 43 | - IConfig $config) { |
|
| 44 | - $this->connection = $connection; |
|
| 45 | - $this->config = $config; |
|
| 46 | - } |
|
| 38 | + /** |
|
| 39 | + * @param IDBConnection $connection |
|
| 40 | + * @param IConfig $config |
|
| 41 | + */ |
|
| 42 | + public function __construct(IDBConnection $connection, |
|
| 43 | + IConfig $config) { |
|
| 44 | + $this->connection = $connection; |
|
| 45 | + $this->config = $config; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - */ |
|
| 51 | - public function getName() { |
|
| 52 | - return 'Repair language codes'; |
|
| 53 | - } |
|
| 48 | + /** |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + */ |
|
| 51 | + public function getName() { |
|
| 52 | + return 'Repair language codes'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * {@inheritdoc} |
|
| 57 | - */ |
|
| 58 | - public function run(IOutput $output) { |
|
| 55 | + /** |
|
| 56 | + * {@inheritdoc} |
|
| 57 | + */ |
|
| 58 | + public function run(IOutput $output) { |
|
| 59 | 59 | |
| 60 | - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 60 | + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 61 | 61 | |
| 62 | - if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 62 | + if (version_compare($versionFromBeforeUpdate, '12.0.0.13', '>')) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $languages = [ |
|
| 67 | - 'bg_BG' => 'bg', |
|
| 68 | - 'cs_CZ' => 'cs', |
|
| 69 | - 'fi_FI' => 'fi', |
|
| 70 | - 'hu_HU' => 'hu', |
|
| 71 | - 'nb_NO' => 'nb', |
|
| 72 | - 'sk_SK' => 'sk', |
|
| 73 | - 'th_TH' => 'th', |
|
| 74 | - ]; |
|
| 66 | + $languages = [ |
|
| 67 | + 'bg_BG' => 'bg', |
|
| 68 | + 'cs_CZ' => 'cs', |
|
| 69 | + 'fi_FI' => 'fi', |
|
| 70 | + 'hu_HU' => 'hu', |
|
| 71 | + 'nb_NO' => 'nb', |
|
| 72 | + 'sk_SK' => 'sk', |
|
| 73 | + 'th_TH' => 'th', |
|
| 74 | + ]; |
|
| 75 | 75 | |
| 76 | - foreach ($languages as $oldCode => $newCode) { |
|
| 77 | - $qb = $this->connection->getQueryBuilder(); |
|
| 76 | + foreach ($languages as $oldCode => $newCode) { |
|
| 77 | + $qb = $this->connection->getQueryBuilder(); |
|
| 78 | 78 | |
| 79 | - $affectedRows = $qb->update('preferences') |
|
| 80 | - ->set('configvalue', $qb->createNamedParameter($newCode)) |
|
| 81 | - ->where($qb->expr()->eq('appid', $qb->createNamedParameter('core'))) |
|
| 82 | - ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang'))) |
|
| 83 | - ->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode))) |
|
| 84 | - ->execute(); |
|
| 79 | + $affectedRows = $qb->update('preferences') |
|
| 80 | + ->set('configvalue', $qb->createNamedParameter($newCode)) |
|
| 81 | + ->where($qb->expr()->eq('appid', $qb->createNamedParameter('core'))) |
|
| 82 | + ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('lang'))) |
|
| 83 | + ->andWhere($qb->expr()->eq('configvalue', $qb->createNamedParameter($oldCode))) |
|
| 84 | + ->execute(); |
|
| 85 | 85 | |
| 86 | - $output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.'); |
|
| 87 | - } |
|
| 88 | - } |
|
| 86 | + $output->info('Changed ' . $affectedRows . ' setting(s) from "' . $oldCode . '" to "' . $newCode . '" in preferences table.'); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -49,171 +49,171 @@ |
||
| 49 | 49 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 50 | 50 | |
| 51 | 51 | class Repair implements IOutput{ |
| 52 | - /* @var IRepairStep[] */ |
|
| 53 | - private $repairSteps; |
|
| 54 | - /** @var EventDispatcher */ |
|
| 55 | - private $dispatcher; |
|
| 56 | - /** @var string */ |
|
| 57 | - private $currentStep; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Creates a new repair step runner |
|
| 61 | - * |
|
| 62 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 63 | - * @param EventDispatcher $dispatcher |
|
| 64 | - */ |
|
| 65 | - public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { |
|
| 66 | - $this->repairSteps = $repairSteps; |
|
| 67 | - $this->dispatcher = $dispatcher; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Run a series of repair steps for common problems |
|
| 72 | - */ |
|
| 73 | - public function run() { |
|
| 74 | - if (count($this->repairSteps) === 0) { |
|
| 75 | - $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - // run each repair step |
|
| 79 | - foreach ($this->repairSteps as $step) { |
|
| 80 | - $this->currentStep = $step->getName(); |
|
| 81 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 82 | - $step->run($this); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Add repair step |
|
| 88 | - * |
|
| 89 | - * @param IRepairStep|string $repairStep repair step |
|
| 90 | - * @throws \Exception |
|
| 91 | - */ |
|
| 92 | - public function addStep($repairStep) { |
|
| 93 | - if (is_string($repairStep)) { |
|
| 94 | - try { |
|
| 95 | - $s = \OC::$server->query($repairStep); |
|
| 96 | - } catch (QueryException $e) { |
|
| 97 | - if (class_exists($repairStep)) { |
|
| 98 | - $s = new $repairStep(); |
|
| 99 | - } else { |
|
| 100 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($s instanceof IRepairStep) { |
|
| 105 | - $this->repairSteps[] = $s; |
|
| 106 | - } else { |
|
| 107 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 108 | - } |
|
| 109 | - } else { |
|
| 110 | - $this->repairSteps[] = $repairStep; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Returns the default repair steps to be run on the |
|
| 116 | - * command line or after an upgrade. |
|
| 117 | - * |
|
| 118 | - * @return IRepairStep[] |
|
| 119 | - */ |
|
| 120 | - public static function getRepairSteps() { |
|
| 121 | - return [ |
|
| 122 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 123 | - new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 124 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 125 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 126 | - new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 127 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 128 | - new MoveAvatars( |
|
| 129 | - \OC::$server->getJobList(), |
|
| 130 | - \OC::$server->getConfig() |
|
| 131 | - ), |
|
| 132 | - new CleanPreviews( |
|
| 133 | - \OC::$server->getJobList(), |
|
| 134 | - \OC::$server->getUserManager(), |
|
| 135 | - \OC::$server->getConfig() |
|
| 136 | - ), |
|
| 137 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 138 | - new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 139 | - ]; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Returns expensive repair steps to be run on the |
|
| 144 | - * command line with a special option. |
|
| 145 | - * |
|
| 146 | - * @return IRepairStep[] |
|
| 147 | - */ |
|
| 148 | - public static function getExpensiveRepairSteps() { |
|
| 149 | - return [ |
|
| 150 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 151 | - ]; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Returns the repair steps to be run before an |
|
| 156 | - * upgrade. |
|
| 157 | - * |
|
| 158 | - * @return IRepairStep[] |
|
| 159 | - */ |
|
| 160 | - public static function getBeforeUpgradeRepairSteps() { |
|
| 161 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 162 | - $steps = [ |
|
| 163 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 164 | - new SqliteAutoincrement($connection), |
|
| 165 | - ]; |
|
| 166 | - |
|
| 167 | - return $steps; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $scope |
|
| 172 | - * @param string $method |
|
| 173 | - * @param array $arguments |
|
| 174 | - */ |
|
| 175 | - public function emit($scope, $method, array $arguments = []) { |
|
| 176 | - if (!is_null($this->dispatcher)) { |
|
| 177 | - $this->dispatcher->dispatch("$scope::$method", |
|
| 178 | - new GenericEvent("$scope::$method", $arguments)); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - public function info($string) { |
|
| 183 | - // for now just emit as we did in the past |
|
| 184 | - $this->emit('\OC\Repair', 'info', array($string)); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param string $message |
|
| 189 | - */ |
|
| 190 | - public function warning($message) { |
|
| 191 | - // for now just emit as we did in the past |
|
| 192 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param int $max |
|
| 197 | - */ |
|
| 198 | - public function startProgress($max = 0) { |
|
| 199 | - // for now just emit as we did in the past |
|
| 200 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param int $step |
|
| 205 | - * @param string $description |
|
| 206 | - */ |
|
| 207 | - public function advance($step = 1, $description = '') { |
|
| 208 | - // for now just emit as we did in the past |
|
| 209 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @param int $max |
|
| 214 | - */ |
|
| 215 | - public function finishProgress() { |
|
| 216 | - // for now just emit as we did in the past |
|
| 217 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 218 | - } |
|
| 52 | + /* @var IRepairStep[] */ |
|
| 53 | + private $repairSteps; |
|
| 54 | + /** @var EventDispatcher */ |
|
| 55 | + private $dispatcher; |
|
| 56 | + /** @var string */ |
|
| 57 | + private $currentStep; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Creates a new repair step runner |
|
| 61 | + * |
|
| 62 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 63 | + * @param EventDispatcher $dispatcher |
|
| 64 | + */ |
|
| 65 | + public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { |
|
| 66 | + $this->repairSteps = $repairSteps; |
|
| 67 | + $this->dispatcher = $dispatcher; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Run a series of repair steps for common problems |
|
| 72 | + */ |
|
| 73 | + public function run() { |
|
| 74 | + if (count($this->repairSteps) === 0) { |
|
| 75 | + $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + // run each repair step |
|
| 79 | + foreach ($this->repairSteps as $step) { |
|
| 80 | + $this->currentStep = $step->getName(); |
|
| 81 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 82 | + $step->run($this); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Add repair step |
|
| 88 | + * |
|
| 89 | + * @param IRepairStep|string $repairStep repair step |
|
| 90 | + * @throws \Exception |
|
| 91 | + */ |
|
| 92 | + public function addStep($repairStep) { |
|
| 93 | + if (is_string($repairStep)) { |
|
| 94 | + try { |
|
| 95 | + $s = \OC::$server->query($repairStep); |
|
| 96 | + } catch (QueryException $e) { |
|
| 97 | + if (class_exists($repairStep)) { |
|
| 98 | + $s = new $repairStep(); |
|
| 99 | + } else { |
|
| 100 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($s instanceof IRepairStep) { |
|
| 105 | + $this->repairSteps[] = $s; |
|
| 106 | + } else { |
|
| 107 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 108 | + } |
|
| 109 | + } else { |
|
| 110 | + $this->repairSteps[] = $repairStep; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Returns the default repair steps to be run on the |
|
| 116 | + * command line or after an upgrade. |
|
| 117 | + * |
|
| 118 | + * @return IRepairStep[] |
|
| 119 | + */ |
|
| 120 | + public static function getRepairSteps() { |
|
| 121 | + return [ |
|
| 122 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 123 | + new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 124 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 125 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 126 | + new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 127 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 128 | + new MoveAvatars( |
|
| 129 | + \OC::$server->getJobList(), |
|
| 130 | + \OC::$server->getConfig() |
|
| 131 | + ), |
|
| 132 | + new CleanPreviews( |
|
| 133 | + \OC::$server->getJobList(), |
|
| 134 | + \OC::$server->getUserManager(), |
|
| 135 | + \OC::$server->getConfig() |
|
| 136 | + ), |
|
| 137 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 138 | + new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 139 | + ]; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Returns expensive repair steps to be run on the |
|
| 144 | + * command line with a special option. |
|
| 145 | + * |
|
| 146 | + * @return IRepairStep[] |
|
| 147 | + */ |
|
| 148 | + public static function getExpensiveRepairSteps() { |
|
| 149 | + return [ |
|
| 150 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 151 | + ]; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Returns the repair steps to be run before an |
|
| 156 | + * upgrade. |
|
| 157 | + * |
|
| 158 | + * @return IRepairStep[] |
|
| 159 | + */ |
|
| 160 | + public static function getBeforeUpgradeRepairSteps() { |
|
| 161 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 162 | + $steps = [ |
|
| 163 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 164 | + new SqliteAutoincrement($connection), |
|
| 165 | + ]; |
|
| 166 | + |
|
| 167 | + return $steps; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $scope |
|
| 172 | + * @param string $method |
|
| 173 | + * @param array $arguments |
|
| 174 | + */ |
|
| 175 | + public function emit($scope, $method, array $arguments = []) { |
|
| 176 | + if (!is_null($this->dispatcher)) { |
|
| 177 | + $this->dispatcher->dispatch("$scope::$method", |
|
| 178 | + new GenericEvent("$scope::$method", $arguments)); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + public function info($string) { |
|
| 183 | + // for now just emit as we did in the past |
|
| 184 | + $this->emit('\OC\Repair', 'info', array($string)); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param string $message |
|
| 189 | + */ |
|
| 190 | + public function warning($message) { |
|
| 191 | + // for now just emit as we did in the past |
|
| 192 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param int $max |
|
| 197 | + */ |
|
| 198 | + public function startProgress($max = 0) { |
|
| 199 | + // for now just emit as we did in the past |
|
| 200 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param int $step |
|
| 205 | + * @param string $description |
|
| 206 | + */ |
|
| 207 | + public function advance($step = 1, $description = '') { |
|
| 208 | + // for now just emit as we did in the past |
|
| 209 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @param int $max |
|
| 214 | + */ |
|
| 215 | + public function finishProgress() { |
|
| 216 | + // for now just emit as we did in the past |
|
| 217 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 218 | + } |
|
| 219 | 219 | } |