@@ -52,178 +52,178 @@ |
||
| 52 | 52 | use Symfony\Component\EventDispatcher\GenericEvent; |
| 53 | 53 | |
| 54 | 54 | class Repair implements IOutput{ |
| 55 | - /* @var IRepairStep[] */ |
|
| 56 | - private $repairSteps; |
|
| 57 | - /** @var EventDispatcher */ |
|
| 58 | - private $dispatcher; |
|
| 59 | - /** @var string */ |
|
| 60 | - private $currentStep; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Creates a new repair step runner |
|
| 64 | - * |
|
| 65 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 66 | - * @param EventDispatcher $dispatcher |
|
| 67 | - */ |
|
| 68 | - public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { |
|
| 69 | - $this->repairSteps = $repairSteps; |
|
| 70 | - $this->dispatcher = $dispatcher; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Run a series of repair steps for common problems |
|
| 75 | - */ |
|
| 76 | - public function run() { |
|
| 77 | - if (count($this->repairSteps) === 0) { |
|
| 78 | - $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 79 | - return; |
|
| 80 | - } |
|
| 81 | - // run each repair step |
|
| 82 | - foreach ($this->repairSteps as $step) { |
|
| 83 | - $this->currentStep = $step->getName(); |
|
| 84 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 85 | - $step->run($this); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Add repair step |
|
| 91 | - * |
|
| 92 | - * @param IRepairStep|string $repairStep repair step |
|
| 93 | - * @throws \Exception |
|
| 94 | - */ |
|
| 95 | - public function addStep($repairStep) { |
|
| 96 | - if (is_string($repairStep)) { |
|
| 97 | - try { |
|
| 98 | - $s = \OC::$server->query($repairStep); |
|
| 99 | - } catch (QueryException $e) { |
|
| 100 | - if (class_exists($repairStep)) { |
|
| 101 | - $s = new $repairStep(); |
|
| 102 | - } else { |
|
| 103 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ($s instanceof IRepairStep) { |
|
| 108 | - $this->repairSteps[] = $s; |
|
| 109 | - } else { |
|
| 110 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 111 | - } |
|
| 112 | - } else { |
|
| 113 | - $this->repairSteps[] = $repairStep; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Returns the default repair steps to be run on the |
|
| 119 | - * command line or after an upgrade. |
|
| 120 | - * |
|
| 121 | - * @return IRepairStep[] |
|
| 122 | - */ |
|
| 123 | - public static function getRepairSteps() { |
|
| 124 | - return [ |
|
| 125 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 126 | - new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 127 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 128 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 129 | - new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 130 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 131 | - new MoveAvatars( |
|
| 132 | - \OC::$server->getJobList(), |
|
| 133 | - \OC::$server->getConfig() |
|
| 134 | - ), |
|
| 135 | - new CleanPreviews( |
|
| 136 | - \OC::$server->getJobList(), |
|
| 137 | - \OC::$server->getUserManager(), |
|
| 138 | - \OC::$server->getConfig() |
|
| 139 | - ), |
|
| 140 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 141 | - new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 142 | - new InstallCoreBundle( |
|
| 143 | - \OC::$server->query(BundleFetcher::class), |
|
| 144 | - \OC::$server->getConfig(), |
|
| 145 | - \OC::$server->query(Installer::class) |
|
| 146 | - ) |
|
| 147 | - ]; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Returns expensive repair steps to be run on the |
|
| 152 | - * command line with a special option. |
|
| 153 | - * |
|
| 154 | - * @return IRepairStep[] |
|
| 155 | - */ |
|
| 156 | - public static function getExpensiveRepairSteps() { |
|
| 157 | - return [ |
|
| 158 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 159 | - ]; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Returns the repair steps to be run before an |
|
| 164 | - * upgrade. |
|
| 165 | - * |
|
| 166 | - * @return IRepairStep[] |
|
| 167 | - */ |
|
| 168 | - public static function getBeforeUpgradeRepairSteps() { |
|
| 169 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 170 | - $config = \OC::$server->getConfig(); |
|
| 171 | - $steps = [ |
|
| 172 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 173 | - new SqliteAutoincrement($connection), |
|
| 174 | - new SaveAccountsTableData($connection, $config), |
|
| 175 | - ]; |
|
| 176 | - |
|
| 177 | - return $steps; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param string $scope |
|
| 182 | - * @param string $method |
|
| 183 | - * @param array $arguments |
|
| 184 | - */ |
|
| 185 | - public function emit($scope, $method, array $arguments = []) { |
|
| 186 | - if (!is_null($this->dispatcher)) { |
|
| 187 | - $this->dispatcher->dispatch("$scope::$method", |
|
| 188 | - new GenericEvent("$scope::$method", $arguments)); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function info($string) { |
|
| 193 | - // for now just emit as we did in the past |
|
| 194 | - $this->emit('\OC\Repair', 'info', array($string)); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param string $message |
|
| 199 | - */ |
|
| 200 | - public function warning($message) { |
|
| 201 | - // for now just emit as we did in the past |
|
| 202 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param int $max |
|
| 207 | - */ |
|
| 208 | - public function startProgress($max = 0) { |
|
| 209 | - // for now just emit as we did in the past |
|
| 210 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @param int $step |
|
| 215 | - * @param string $description |
|
| 216 | - */ |
|
| 217 | - public function advance($step = 1, $description = '') { |
|
| 218 | - // for now just emit as we did in the past |
|
| 219 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @param int $max |
|
| 224 | - */ |
|
| 225 | - public function finishProgress() { |
|
| 226 | - // for now just emit as we did in the past |
|
| 227 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 228 | - } |
|
| 55 | + /* @var IRepairStep[] */ |
|
| 56 | + private $repairSteps; |
|
| 57 | + /** @var EventDispatcher */ |
|
| 58 | + private $dispatcher; |
|
| 59 | + /** @var string */ |
|
| 60 | + private $currentStep; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Creates a new repair step runner |
|
| 64 | + * |
|
| 65 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 66 | + * @param EventDispatcher $dispatcher |
|
| 67 | + */ |
|
| 68 | + public function __construct($repairSteps = [], EventDispatcher $dispatcher = null) { |
|
| 69 | + $this->repairSteps = $repairSteps; |
|
| 70 | + $this->dispatcher = $dispatcher; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Run a series of repair steps for common problems |
|
| 75 | + */ |
|
| 76 | + public function run() { |
|
| 77 | + if (count($this->repairSteps) === 0) { |
|
| 78 | + $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 79 | + return; |
|
| 80 | + } |
|
| 81 | + // run each repair step |
|
| 82 | + foreach ($this->repairSteps as $step) { |
|
| 83 | + $this->currentStep = $step->getName(); |
|
| 84 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 85 | + $step->run($this); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Add repair step |
|
| 91 | + * |
|
| 92 | + * @param IRepairStep|string $repairStep repair step |
|
| 93 | + * @throws \Exception |
|
| 94 | + */ |
|
| 95 | + public function addStep($repairStep) { |
|
| 96 | + if (is_string($repairStep)) { |
|
| 97 | + try { |
|
| 98 | + $s = \OC::$server->query($repairStep); |
|
| 99 | + } catch (QueryException $e) { |
|
| 100 | + if (class_exists($repairStep)) { |
|
| 101 | + $s = new $repairStep(); |
|
| 102 | + } else { |
|
| 103 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ($s instanceof IRepairStep) { |
|
| 108 | + $this->repairSteps[] = $s; |
|
| 109 | + } else { |
|
| 110 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 111 | + } |
|
| 112 | + } else { |
|
| 113 | + $this->repairSteps[] = $repairStep; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Returns the default repair steps to be run on the |
|
| 119 | + * command line or after an upgrade. |
|
| 120 | + * |
|
| 121 | + * @return IRepairStep[] |
|
| 122 | + */ |
|
| 123 | + public static function getRepairSteps() { |
|
| 124 | + return [ |
|
| 125 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 126 | + new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 127 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 128 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 129 | + new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 130 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 131 | + new MoveAvatars( |
|
| 132 | + \OC::$server->getJobList(), |
|
| 133 | + \OC::$server->getConfig() |
|
| 134 | + ), |
|
| 135 | + new CleanPreviews( |
|
| 136 | + \OC::$server->getJobList(), |
|
| 137 | + \OC::$server->getUserManager(), |
|
| 138 | + \OC::$server->getConfig() |
|
| 139 | + ), |
|
| 140 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 141 | + new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 142 | + new InstallCoreBundle( |
|
| 143 | + \OC::$server->query(BundleFetcher::class), |
|
| 144 | + \OC::$server->getConfig(), |
|
| 145 | + \OC::$server->query(Installer::class) |
|
| 146 | + ) |
|
| 147 | + ]; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Returns expensive repair steps to be run on the |
|
| 152 | + * command line with a special option. |
|
| 153 | + * |
|
| 154 | + * @return IRepairStep[] |
|
| 155 | + */ |
|
| 156 | + public static function getExpensiveRepairSteps() { |
|
| 157 | + return [ |
|
| 158 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 159 | + ]; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Returns the repair steps to be run before an |
|
| 164 | + * upgrade. |
|
| 165 | + * |
|
| 166 | + * @return IRepairStep[] |
|
| 167 | + */ |
|
| 168 | + public static function getBeforeUpgradeRepairSteps() { |
|
| 169 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 170 | + $config = \OC::$server->getConfig(); |
|
| 171 | + $steps = [ |
|
| 172 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 173 | + new SqliteAutoincrement($connection), |
|
| 174 | + new SaveAccountsTableData($connection, $config), |
|
| 175 | + ]; |
|
| 176 | + |
|
| 177 | + return $steps; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param string $scope |
|
| 182 | + * @param string $method |
|
| 183 | + * @param array $arguments |
|
| 184 | + */ |
|
| 185 | + public function emit($scope, $method, array $arguments = []) { |
|
| 186 | + if (!is_null($this->dispatcher)) { |
|
| 187 | + $this->dispatcher->dispatch("$scope::$method", |
|
| 188 | + new GenericEvent("$scope::$method", $arguments)); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function info($string) { |
|
| 193 | + // for now just emit as we did in the past |
|
| 194 | + $this->emit('\OC\Repair', 'info', array($string)); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param string $message |
|
| 199 | + */ |
|
| 200 | + public function warning($message) { |
|
| 201 | + // for now just emit as we did in the past |
|
| 202 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param int $max |
|
| 207 | + */ |
|
| 208 | + public function startProgress($max = 0) { |
|
| 209 | + // for now just emit as we did in the past |
|
| 210 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @param int $step |
|
| 215 | + * @param string $description |
|
| 216 | + */ |
|
| 217 | + public function advance($step = 1, $description = '') { |
|
| 218 | + // for now just emit as we did in the past |
|
| 219 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @param int $max |
|
| 224 | + */ |
|
| 225 | + public function finishProgress() { |
|
| 226 | + // for now just emit as we did in the past |
|
| 227 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 228 | + } |
|
| 229 | 229 | } |
@@ -37,140 +37,140 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class SaveAccountsTableData implements IRepairStep { |
| 39 | 39 | |
| 40 | - const BATCH_SIZE = 75; |
|
| 41 | - |
|
| 42 | - /** @var IDBConnection */ |
|
| 43 | - protected $db; |
|
| 44 | - |
|
| 45 | - /** @var IConfig */ |
|
| 46 | - protected $config; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param IDBConnection $db |
|
| 50 | - * @param IConfig $config |
|
| 51 | - */ |
|
| 52 | - public function __construct(IDBConnection $db, IConfig $config) { |
|
| 53 | - $this->db = $db; |
|
| 54 | - $this->config = $config; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function getName() { |
|
| 61 | - return 'Copy data from accounts table when migrating from ownCloud'; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param IOutput $output |
|
| 66 | - */ |
|
| 67 | - public function run(IOutput $output) { |
|
| 68 | - if (!$this->shouldRun()) { |
|
| 69 | - return; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $offset = 0; |
|
| 73 | - $numUsers = $this->runStep($offset); |
|
| 74 | - |
|
| 75 | - while ($numUsers === self::BATCH_SIZE) { |
|
| 76 | - $offset += $numUsers; |
|
| 77 | - $numUsers = $this->runStep($offset); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Remove the table |
|
| 81 | - $this->db->dropTable('accounts'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return bool |
|
| 86 | - */ |
|
| 87 | - protected function shouldRun() { |
|
| 88 | - $query = $this->db->getQueryBuilder(); |
|
| 89 | - $query->select('*') |
|
| 90 | - ->from('accounts') |
|
| 91 | - ->where($query->expr()->isNotNull('user_id')) |
|
| 92 | - ->setMaxResults(1); |
|
| 93 | - |
|
| 94 | - try { |
|
| 95 | - $query->execute(); |
|
| 96 | - return true; |
|
| 97 | - } catch (InvalidFieldNameException $e) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param int $offset |
|
| 104 | - * @return int Number of copied users |
|
| 105 | - */ |
|
| 106 | - protected function runStep($offset) { |
|
| 107 | - $query = $this->db->getQueryBuilder(); |
|
| 108 | - $query->select('*') |
|
| 109 | - ->from('accounts') |
|
| 110 | - ->orderBy('id') |
|
| 111 | - ->setMaxResults(self::BATCH_SIZE); |
|
| 112 | - |
|
| 113 | - if ($offset > 0) { |
|
| 114 | - $query->setFirstResult($offset); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $result = $query->execute(); |
|
| 118 | - |
|
| 119 | - $update = $this->db->getQueryBuilder(); |
|
| 120 | - $update->update('users') |
|
| 121 | - ->set('displayname', $update->createParameter('displayname')) |
|
| 122 | - ->where($update->expr()->eq('uid', $update->createParameter('userid'))); |
|
| 123 | - |
|
| 124 | - $updatedUsers = 0; |
|
| 125 | - while ($row = $result->fetch()) { |
|
| 126 | - try { |
|
| 127 | - $this->migrateUserInfo($update, $row); |
|
| 128 | - } catch (PreConditionNotMetException $e) { |
|
| 129 | - // Ignore and continue |
|
| 130 | - } catch (\UnexpectedValueException $e) { |
|
| 131 | - // Ignore and continue |
|
| 132 | - } |
|
| 133 | - $updatedUsers++; |
|
| 134 | - } |
|
| 135 | - $result->closeCursor(); |
|
| 136 | - |
|
| 137 | - return $updatedUsers; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param IQueryBuilder $update |
|
| 142 | - * @param array $userdata |
|
| 143 | - * @throws PreConditionNotMetException |
|
| 144 | - * @throws \UnexpectedValueException |
|
| 145 | - */ |
|
| 146 | - protected function migrateUserInfo(IQueryBuilder $update, $userdata) { |
|
| 147 | - $state = (int) $userdata['state']; |
|
| 148 | - if ($state === 3) { |
|
| 149 | - // Deleted user, ignore |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if ($userdata['email'] !== null) { |
|
| 154 | - $this->config->setUserValue($userdata['user_id'], 'settings', 'email', $userdata['email']); |
|
| 155 | - } |
|
| 156 | - if ($userdata['quota'] !== null) { |
|
| 157 | - $this->config->setUserValue($userdata['user_id'], 'files', 'quota', $userdata['quota']); |
|
| 158 | - } |
|
| 159 | - if ($userdata['last_login'] !== null) { |
|
| 160 | - $this->config->setUserValue($userdata['user_id'], 'login', 'lastLogin', $userdata['last_login']); |
|
| 161 | - } |
|
| 162 | - if ($state === 1) { |
|
| 163 | - $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'true'); |
|
| 164 | - } else if ($state === 2) { |
|
| 165 | - $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'false'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if ($userdata['display_name'] !== null) { |
|
| 169 | - $update->setParameter('displayname', $userdata['display_name']) |
|
| 170 | - ->setParameter('userid', $userdata['user_id']); |
|
| 171 | - $update->execute(); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - } |
|
| 40 | + const BATCH_SIZE = 75; |
|
| 41 | + |
|
| 42 | + /** @var IDBConnection */ |
|
| 43 | + protected $db; |
|
| 44 | + |
|
| 45 | + /** @var IConfig */ |
|
| 46 | + protected $config; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param IDBConnection $db |
|
| 50 | + * @param IConfig $config |
|
| 51 | + */ |
|
| 52 | + public function __construct(IDBConnection $db, IConfig $config) { |
|
| 53 | + $this->db = $db; |
|
| 54 | + $this->config = $config; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function getName() { |
|
| 61 | + return 'Copy data from accounts table when migrating from ownCloud'; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param IOutput $output |
|
| 66 | + */ |
|
| 67 | + public function run(IOutput $output) { |
|
| 68 | + if (!$this->shouldRun()) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $offset = 0; |
|
| 73 | + $numUsers = $this->runStep($offset); |
|
| 74 | + |
|
| 75 | + while ($numUsers === self::BATCH_SIZE) { |
|
| 76 | + $offset += $numUsers; |
|
| 77 | + $numUsers = $this->runStep($offset); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Remove the table |
|
| 81 | + $this->db->dropTable('accounts'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return bool |
|
| 86 | + */ |
|
| 87 | + protected function shouldRun() { |
|
| 88 | + $query = $this->db->getQueryBuilder(); |
|
| 89 | + $query->select('*') |
|
| 90 | + ->from('accounts') |
|
| 91 | + ->where($query->expr()->isNotNull('user_id')) |
|
| 92 | + ->setMaxResults(1); |
|
| 93 | + |
|
| 94 | + try { |
|
| 95 | + $query->execute(); |
|
| 96 | + return true; |
|
| 97 | + } catch (InvalidFieldNameException $e) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param int $offset |
|
| 104 | + * @return int Number of copied users |
|
| 105 | + */ |
|
| 106 | + protected function runStep($offset) { |
|
| 107 | + $query = $this->db->getQueryBuilder(); |
|
| 108 | + $query->select('*') |
|
| 109 | + ->from('accounts') |
|
| 110 | + ->orderBy('id') |
|
| 111 | + ->setMaxResults(self::BATCH_SIZE); |
|
| 112 | + |
|
| 113 | + if ($offset > 0) { |
|
| 114 | + $query->setFirstResult($offset); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $result = $query->execute(); |
|
| 118 | + |
|
| 119 | + $update = $this->db->getQueryBuilder(); |
|
| 120 | + $update->update('users') |
|
| 121 | + ->set('displayname', $update->createParameter('displayname')) |
|
| 122 | + ->where($update->expr()->eq('uid', $update->createParameter('userid'))); |
|
| 123 | + |
|
| 124 | + $updatedUsers = 0; |
|
| 125 | + while ($row = $result->fetch()) { |
|
| 126 | + try { |
|
| 127 | + $this->migrateUserInfo($update, $row); |
|
| 128 | + } catch (PreConditionNotMetException $e) { |
|
| 129 | + // Ignore and continue |
|
| 130 | + } catch (\UnexpectedValueException $e) { |
|
| 131 | + // Ignore and continue |
|
| 132 | + } |
|
| 133 | + $updatedUsers++; |
|
| 134 | + } |
|
| 135 | + $result->closeCursor(); |
|
| 136 | + |
|
| 137 | + return $updatedUsers; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param IQueryBuilder $update |
|
| 142 | + * @param array $userdata |
|
| 143 | + * @throws PreConditionNotMetException |
|
| 144 | + * @throws \UnexpectedValueException |
|
| 145 | + */ |
|
| 146 | + protected function migrateUserInfo(IQueryBuilder $update, $userdata) { |
|
| 147 | + $state = (int) $userdata['state']; |
|
| 148 | + if ($state === 3) { |
|
| 149 | + // Deleted user, ignore |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if ($userdata['email'] !== null) { |
|
| 154 | + $this->config->setUserValue($userdata['user_id'], 'settings', 'email', $userdata['email']); |
|
| 155 | + } |
|
| 156 | + if ($userdata['quota'] !== null) { |
|
| 157 | + $this->config->setUserValue($userdata['user_id'], 'files', 'quota', $userdata['quota']); |
|
| 158 | + } |
|
| 159 | + if ($userdata['last_login'] !== null) { |
|
| 160 | + $this->config->setUserValue($userdata['user_id'], 'login', 'lastLogin', $userdata['last_login']); |
|
| 161 | + } |
|
| 162 | + if ($state === 1) { |
|
| 163 | + $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'true'); |
|
| 164 | + } else if ($state === 2) { |
|
| 165 | + $this->config->setUserValue($userdata['user_id'], 'core', 'enabled', 'false'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if ($userdata['display_name'] !== null) { |
|
| 169 | + $update->setParameter('displayname', $userdata['display_name']) |
|
| 170 | + ->setParameter('userid', $userdata['user_id']); |
|
| 171 | + $update->execute(); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + } |
|
| 175 | 175 | } |
| 176 | 176 | |
@@ -51,593 +51,593 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | class Updater extends BasicEmitter { |
| 53 | 53 | |
| 54 | - /** @var ILogger $log */ |
|
| 55 | - private $log; |
|
| 56 | - |
|
| 57 | - /** @var IConfig */ |
|
| 58 | - private $config; |
|
| 59 | - |
|
| 60 | - /** @var Checker */ |
|
| 61 | - private $checker; |
|
| 62 | - |
|
| 63 | - /** @var bool */ |
|
| 64 | - private $skip3rdPartyAppsDisable; |
|
| 65 | - |
|
| 66 | - private $logLevelNames = [ |
|
| 67 | - 0 => 'Debug', |
|
| 68 | - 1 => 'Info', |
|
| 69 | - 2 => 'Warning', |
|
| 70 | - 3 => 'Error', |
|
| 71 | - 4 => 'Fatal', |
|
| 72 | - ]; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param IConfig $config |
|
| 76 | - * @param Checker $checker |
|
| 77 | - * @param ILogger $log |
|
| 78 | - */ |
|
| 79 | - public function __construct(IConfig $config, |
|
| 80 | - Checker $checker, |
|
| 81 | - ILogger $log = null) { |
|
| 82 | - $this->log = $log; |
|
| 83 | - $this->config = $config; |
|
| 84 | - $this->checker = $checker; |
|
| 85 | - |
|
| 86 | - // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
|
| 87 | - // fatal errors and exceptions and disable the app just instead. |
|
| 88 | - if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 89 | - $this->skip3rdPartyAppsDisable = true; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Sets whether the update disables 3rd party apps. |
|
| 95 | - * This can be set to true to skip the disable. |
|
| 96 | - * |
|
| 97 | - * @param bool $flag false to not disable, true otherwise |
|
| 98 | - */ |
|
| 99 | - public function setSkip3rdPartyAppsDisable($flag) { |
|
| 100 | - $this->skip3rdPartyAppsDisable = $flag; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 105 | - * except the main .htaccess file |
|
| 106 | - * |
|
| 107 | - * @return bool true if the operation succeeded, false otherwise |
|
| 108 | - */ |
|
| 109 | - public function upgrade() { |
|
| 110 | - $this->emitRepairEvents(); |
|
| 111 | - $this->logAllEvents(); |
|
| 112 | - |
|
| 113 | - $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
|
| 114 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 115 | - $this->config->setSystemValue('loglevel', Util::DEBUG); |
|
| 116 | - |
|
| 117 | - $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 118 | - |
|
| 119 | - if(!$wasMaintenanceModeEnabled) { |
|
| 120 | - $this->config->setSystemValue('maintenance', true); |
|
| 121 | - $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 125 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 126 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
| 127 | - |
|
| 128 | - $success = true; |
|
| 129 | - try { |
|
| 130 | - $this->doUpgrade($currentVersion, $installedVersion); |
|
| 131 | - } catch (HintException $exception) { |
|
| 132 | - $this->log->logException($exception, ['app' => 'core']); |
|
| 133 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
| 134 | - $success = false; |
|
| 135 | - } catch (\Exception $exception) { |
|
| 136 | - $this->log->logException($exception, ['app' => 'core']); |
|
| 137 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
| 138 | - $success = false; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
| 142 | - |
|
| 143 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
| 144 | - $this->config->setSystemValue('maintenance', false); |
|
| 145 | - $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 146 | - } else { |
|
| 147 | - $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 151 | - $this->config->setSystemValue('loglevel', $logLevel); |
|
| 152 | - $this->config->setSystemValue('installed', true); |
|
| 153 | - |
|
| 154 | - return $success; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Return version from which this version is allowed to upgrade from |
|
| 159 | - * |
|
| 160 | - * @return array allowed previous versions per vendor |
|
| 161 | - */ |
|
| 162 | - private function getAllowedPreviousVersions() { |
|
| 163 | - // this should really be a JSON file |
|
| 164 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 165 | - /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 166 | - return $OC_VersionCanBeUpgradedFrom; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Return vendor from which this version was published |
|
| 171 | - * |
|
| 172 | - * @return string Get the vendor |
|
| 173 | - */ |
|
| 174 | - private function getVendor() { |
|
| 175 | - // this should really be a JSON file |
|
| 176 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 177 | - /** @var string $vendor */ |
|
| 178 | - return (string) $vendor; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Whether an upgrade to a specified version is possible |
|
| 183 | - * @param string $oldVersion |
|
| 184 | - * @param string $newVersion |
|
| 185 | - * @param array $allowedPreviousVersions |
|
| 186 | - * @return bool |
|
| 187 | - */ |
|
| 188 | - public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
| 189 | - $version = explode('.', $oldVersion); |
|
| 190 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 191 | - |
|
| 192 | - $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 193 | - |
|
| 194 | - // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 195 | - if ($currentVendor === '') { |
|
| 196 | - if (in_array($oldVersion, [ |
|
| 197 | - '11.0.2.7', |
|
| 198 | - '11.0.1.2', |
|
| 199 | - '11.0.0.10', |
|
| 200 | - ], true)) { |
|
| 201 | - $currentVendor = 'nextcloud'; |
|
| 202 | - } else if (in_array($oldVersion, [ |
|
| 203 | - '10.0.0.12', |
|
| 204 | - ], true)) { |
|
| 205 | - $currentVendor = 'owncloud'; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ($currentVendor === 'nextcloud') { |
|
| 210 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 211 | - && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 212 | - $this->config->getSystemValue('debug', false)); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // Check if the instance can be migrated |
|
| 216 | - return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 217 | - isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 222 | - * except the main .htaccess file |
|
| 223 | - * |
|
| 224 | - * @param string $currentVersion current version to upgrade to |
|
| 225 | - * @param string $installedVersion previous version from which to upgrade from |
|
| 226 | - * |
|
| 227 | - * @throws \Exception |
|
| 228 | - */ |
|
| 229 | - private function doUpgrade($currentVersion, $installedVersion) { |
|
| 230 | - // Stop update if the update is over several major versions |
|
| 231 | - $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 232 | - if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 233 | - throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // Update .htaccess files |
|
| 237 | - try { |
|
| 238 | - Setup::updateHtaccess(); |
|
| 239 | - Setup::protectDataDirectory(); |
|
| 240 | - } catch (\Exception $e) { |
|
| 241 | - throw new \Exception($e->getMessage()); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // create empty file in data dir, so we can later find |
|
| 245 | - // out that this is indeed an ownCloud data directory |
|
| 246 | - // (in case it didn't exist before) |
|
| 247 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 248 | - |
|
| 249 | - // pre-upgrade repairs |
|
| 250 | - $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 251 | - $repair->run(); |
|
| 252 | - |
|
| 253 | - $this->doCoreUpgrade(); |
|
| 254 | - |
|
| 255 | - try { |
|
| 256 | - // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 257 | - Setup::installBackgroundJobs(); |
|
| 258 | - } catch (\Exception $e) { |
|
| 259 | - throw new \Exception($e->getMessage()); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - // update all shipped apps |
|
| 263 | - $this->checkAppsRequirements(); |
|
| 264 | - $this->doAppUpgrade(); |
|
| 265 | - |
|
| 266 | - // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 267 | - \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 268 | - |
|
| 269 | - // upgrade appstore apps |
|
| 270 | - $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 271 | - |
|
| 272 | - // install new shipped apps on upgrade |
|
| 273 | - OC_App::loadApps('authentication'); |
|
| 274 | - $errors = Installer::installShippedApps(true); |
|
| 275 | - foreach ($errors as $appId => $exception) { |
|
| 276 | - /** @var \Exception $exception */ |
|
| 277 | - $this->log->logException($exception, ['app' => $appId]); |
|
| 278 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // post-upgrade repairs |
|
| 282 | - $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 283 | - $repair->run(); |
|
| 284 | - |
|
| 285 | - //Invalidate update feed |
|
| 286 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 287 | - |
|
| 288 | - // Check for code integrity if not disabled |
|
| 289 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 290 | - $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 291 | - $this->checker->runInstanceVerification(); |
|
| 292 | - $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // only set the final version if everything went well |
|
| 296 | - $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 297 | - $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - protected function doCoreUpgrade() { |
|
| 301 | - $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 302 | - |
|
| 303 | - // do the real upgrade |
|
| 304 | - \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); |
|
| 305 | - |
|
| 306 | - $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @param string $version the oc version to check app compatibility with |
|
| 311 | - */ |
|
| 312 | - protected function checkAppUpgrade($version) { |
|
| 313 | - $apps = \OC_App::getEnabledApps(); |
|
| 314 | - $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
| 315 | - |
|
| 316 | - foreach ($apps as $appId) { |
|
| 317 | - $info = \OC_App::getAppInfo($appId); |
|
| 318 | - $compatible = \OC_App::isAppCompatible($version, $info); |
|
| 319 | - $isShipped = \OC_App::isShipped($appId); |
|
| 320 | - |
|
| 321 | - if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
| 322 | - /** |
|
| 323 | - * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
| 324 | - * are not possible anymore within it. - Consider this when touching the code. |
|
| 325 | - * @link https://github.com/owncloud/core/issues/10980 |
|
| 326 | - * @see \OC_App::updateApp |
|
| 327 | - */ |
|
| 328 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
| 329 | - $this->includePreUpdate($appId); |
|
| 330 | - } |
|
| 331 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
| 332 | - $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
| 333 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Includes the pre-update file. Done here to prevent namespace mixups. |
|
| 343 | - * @param string $appId |
|
| 344 | - */ |
|
| 345 | - private function includePreUpdate($appId) { |
|
| 346 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 351 | - * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 352 | - * |
|
| 353 | - * @throws NeedsUpdateException |
|
| 354 | - */ |
|
| 355 | - protected function doAppUpgrade() { |
|
| 356 | - $apps = \OC_App::getEnabledApps(); |
|
| 357 | - $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
| 358 | - $pseudoOtherType = 'other'; |
|
| 359 | - $stacks = array($pseudoOtherType => array()); |
|
| 360 | - |
|
| 361 | - foreach ($apps as $appId) { |
|
| 362 | - $priorityType = false; |
|
| 363 | - foreach ($priorityTypes as $type) { |
|
| 364 | - if(!isset($stacks[$type])) { |
|
| 365 | - $stacks[$type] = array(); |
|
| 366 | - } |
|
| 367 | - if (\OC_App::isType($appId, $type)) { |
|
| 368 | - $stacks[$type][] = $appId; |
|
| 369 | - $priorityType = true; |
|
| 370 | - break; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - if (!$priorityType) { |
|
| 374 | - $stacks[$pseudoOtherType][] = $appId; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - foreach ($stacks as $type => $stack) { |
|
| 378 | - foreach ($stack as $appId) { |
|
| 379 | - if (\OC_App::shouldUpgrade($appId)) { |
|
| 380 | - $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 381 | - \OC_App::updateApp($appId); |
|
| 382 | - $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 383 | - } |
|
| 384 | - if($type !== $pseudoOtherType) { |
|
| 385 | - // load authentication, filesystem and logging apps after |
|
| 386 | - // upgrading them. Other apps my need to rely on modifying |
|
| 387 | - // user and/or filesystem aspects. |
|
| 388 | - \OC_App::loadApp($appId); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * check if the current enabled apps are compatible with the current |
|
| 396 | - * ownCloud version. disable them if not. |
|
| 397 | - * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 398 | - * party apps installed. |
|
| 399 | - * |
|
| 400 | - * @return array |
|
| 401 | - * @throws \Exception |
|
| 402 | - */ |
|
| 403 | - private function checkAppsRequirements() { |
|
| 404 | - $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 405 | - $apps = OC_App::getEnabledApps(); |
|
| 406 | - $version = Util::getVersion(); |
|
| 407 | - $disabledApps = []; |
|
| 408 | - foreach ($apps as $app) { |
|
| 409 | - // check if the app is compatible with this version of ownCloud |
|
| 410 | - $info = OC_App::getAppInfo($app); |
|
| 411 | - if(!OC_App::isAppCompatible($version, $info)) { |
|
| 412 | - if (OC_App::isShipped($app)) { |
|
| 413 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 414 | - } |
|
| 415 | - OC_App::disable($app); |
|
| 416 | - $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
| 417 | - } |
|
| 418 | - // no need to disable any app in case this is a non-core upgrade |
|
| 419 | - if (!$isCoreUpgrade) { |
|
| 420 | - continue; |
|
| 421 | - } |
|
| 422 | - // shipped apps will remain enabled |
|
| 423 | - if (OC_App::isShipped($app)) { |
|
| 424 | - continue; |
|
| 425 | - } |
|
| 426 | - // authentication and session apps will remain enabled as well |
|
| 427 | - if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 428 | - continue; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // disable any other 3rd party apps if not overriden |
|
| 432 | - if(!$this->skip3rdPartyAppsDisable) { |
|
| 433 | - \OC_App::disable($app); |
|
| 434 | - $disabledApps[]= $app; |
|
| 435 | - $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
|
| 436 | - }; |
|
| 437 | - } |
|
| 438 | - return $disabledApps; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @return bool |
|
| 443 | - */ |
|
| 444 | - private function isCodeUpgrade() { |
|
| 445 | - $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 446 | - $currentVersion = implode('.', Util::getVersion()); |
|
| 447 | - if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 448 | - return true; |
|
| 449 | - } |
|
| 450 | - return false; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @param array $disabledApps |
|
| 455 | - * @throws \Exception |
|
| 456 | - */ |
|
| 457 | - private function upgradeAppStoreApps(array $disabledApps) { |
|
| 458 | - foreach($disabledApps as $app) { |
|
| 459 | - try { |
|
| 460 | - $installer = new Installer( |
|
| 461 | - \OC::$server->getAppFetcher(), |
|
| 462 | - \OC::$server->getHTTPClientService(), |
|
| 463 | - \OC::$server->getTempManager(), |
|
| 464 | - $this->log, |
|
| 465 | - \OC::$server->getConfig() |
|
| 466 | - ); |
|
| 467 | - $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 468 | - if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) { |
|
| 469 | - $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 470 | - $installer->updateAppstoreApp($app); |
|
| 471 | - } |
|
| 472 | - $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 473 | - } catch (\Exception $ex) { |
|
| 474 | - $this->log->logException($ex, ['app' => 'core']); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Forward messages emitted by the repair routine |
|
| 481 | - */ |
|
| 482 | - private function emitRepairEvents() { |
|
| 483 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 484 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 485 | - if ($event instanceof GenericEvent) { |
|
| 486 | - $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 487 | - } |
|
| 488 | - }); |
|
| 489 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 490 | - if ($event instanceof GenericEvent) { |
|
| 491 | - $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 492 | - } |
|
| 493 | - }); |
|
| 494 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 495 | - if ($event instanceof GenericEvent) { |
|
| 496 | - $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 497 | - } |
|
| 498 | - }); |
|
| 499 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 500 | - if ($event instanceof GenericEvent) { |
|
| 501 | - $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 502 | - } |
|
| 503 | - }); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - private function logAllEvents() { |
|
| 507 | - $log = $this->log; |
|
| 508 | - |
|
| 509 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 510 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
| 511 | - if (!$event instanceof GenericEvent) { |
|
| 512 | - return; |
|
| 513 | - } |
|
| 514 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 515 | - }); |
|
| 516 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
| 517 | - if (!$event instanceof GenericEvent) { |
|
| 518 | - return; |
|
| 519 | - } |
|
| 520 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 521 | - }); |
|
| 522 | - |
|
| 523 | - $repairListener = function($event) use ($log) { |
|
| 524 | - if (!$event instanceof GenericEvent) { |
|
| 525 | - return; |
|
| 526 | - } |
|
| 527 | - switch ($event->getSubject()) { |
|
| 528 | - case '\OC\Repair::startProgress': |
|
| 529 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 530 | - break; |
|
| 531 | - case '\OC\Repair::advance': |
|
| 532 | - $desc = $event->getArgument(1); |
|
| 533 | - if (empty($desc)) { |
|
| 534 | - $desc = ''; |
|
| 535 | - } |
|
| 536 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 537 | - |
|
| 538 | - break; |
|
| 539 | - case '\OC\Repair::finishProgress': |
|
| 540 | - $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 541 | - break; |
|
| 542 | - case '\OC\Repair::step': |
|
| 543 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 544 | - break; |
|
| 545 | - case '\OC\Repair::info': |
|
| 546 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 547 | - break; |
|
| 548 | - case '\OC\Repair::warning': |
|
| 549 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 550 | - break; |
|
| 551 | - case '\OC\Repair::error': |
|
| 552 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 553 | - break; |
|
| 554 | - } |
|
| 555 | - }; |
|
| 556 | - |
|
| 557 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 558 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 559 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 560 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 561 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 562 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 563 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
| 567 | - $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 568 | - }); |
|
| 569 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
| 570 | - $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 571 | - }); |
|
| 572 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
| 573 | - $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 574 | - }); |
|
| 575 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
| 576 | - if ($success) { |
|
| 577 | - $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 578 | - } else { |
|
| 579 | - $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 580 | - } |
|
| 581 | - }); |
|
| 582 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
| 583 | - $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 584 | - }); |
|
| 585 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
| 586 | - $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 587 | - }); |
|
| 588 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
| 589 | - $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']); |
|
| 590 | - }); |
|
| 591 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
| 592 | - $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
| 593 | - }); |
|
| 594 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
| 595 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 596 | - }); |
|
| 597 | - $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
| 598 | - $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
| 599 | - }); |
|
| 600 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
| 601 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 602 | - }); |
|
| 603 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
| 604 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 605 | - }); |
|
| 606 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
| 607 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 608 | - }); |
|
| 609 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
| 610 | - $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
| 611 | - }); |
|
| 612 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 613 | - $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']); |
|
| 614 | - }); |
|
| 615 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
| 616 | - $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
| 617 | - }); |
|
| 618 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 619 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 620 | - }); |
|
| 621 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 622 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 623 | - }); |
|
| 624 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
| 625 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 626 | - }); |
|
| 627 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
| 628 | - $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 629 | - }); |
|
| 630 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
| 631 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 632 | - }); |
|
| 633 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
| 634 | - $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 635 | - }); |
|
| 636 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
| 637 | - $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 638 | - }); |
|
| 639 | - |
|
| 640 | - } |
|
| 54 | + /** @var ILogger $log */ |
|
| 55 | + private $log; |
|
| 56 | + |
|
| 57 | + /** @var IConfig */ |
|
| 58 | + private $config; |
|
| 59 | + |
|
| 60 | + /** @var Checker */ |
|
| 61 | + private $checker; |
|
| 62 | + |
|
| 63 | + /** @var bool */ |
|
| 64 | + private $skip3rdPartyAppsDisable; |
|
| 65 | + |
|
| 66 | + private $logLevelNames = [ |
|
| 67 | + 0 => 'Debug', |
|
| 68 | + 1 => 'Info', |
|
| 69 | + 2 => 'Warning', |
|
| 70 | + 3 => 'Error', |
|
| 71 | + 4 => 'Fatal', |
|
| 72 | + ]; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param IConfig $config |
|
| 76 | + * @param Checker $checker |
|
| 77 | + * @param ILogger $log |
|
| 78 | + */ |
|
| 79 | + public function __construct(IConfig $config, |
|
| 80 | + Checker $checker, |
|
| 81 | + ILogger $log = null) { |
|
| 82 | + $this->log = $log; |
|
| 83 | + $this->config = $config; |
|
| 84 | + $this->checker = $checker; |
|
| 85 | + |
|
| 86 | + // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
|
| 87 | + // fatal errors and exceptions and disable the app just instead. |
|
| 88 | + if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 89 | + $this->skip3rdPartyAppsDisable = true; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Sets whether the update disables 3rd party apps. |
|
| 95 | + * This can be set to true to skip the disable. |
|
| 96 | + * |
|
| 97 | + * @param bool $flag false to not disable, true otherwise |
|
| 98 | + */ |
|
| 99 | + public function setSkip3rdPartyAppsDisable($flag) { |
|
| 100 | + $this->skip3rdPartyAppsDisable = $flag; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 105 | + * except the main .htaccess file |
|
| 106 | + * |
|
| 107 | + * @return bool true if the operation succeeded, false otherwise |
|
| 108 | + */ |
|
| 109 | + public function upgrade() { |
|
| 110 | + $this->emitRepairEvents(); |
|
| 111 | + $this->logAllEvents(); |
|
| 112 | + |
|
| 113 | + $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
|
| 114 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 115 | + $this->config->setSystemValue('loglevel', Util::DEBUG); |
|
| 116 | + |
|
| 117 | + $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
| 118 | + |
|
| 119 | + if(!$wasMaintenanceModeEnabled) { |
|
| 120 | + $this->config->setSystemValue('maintenance', true); |
|
| 121 | + $this->emit('\OC\Updater', 'maintenanceEnabled'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 125 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 126 | + $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
| 127 | + |
|
| 128 | + $success = true; |
|
| 129 | + try { |
|
| 130 | + $this->doUpgrade($currentVersion, $installedVersion); |
|
| 131 | + } catch (HintException $exception) { |
|
| 132 | + $this->log->logException($exception, ['app' => 'core']); |
|
| 133 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
| 134 | + $success = false; |
|
| 135 | + } catch (\Exception $exception) { |
|
| 136 | + $this->log->logException($exception, ['app' => 'core']); |
|
| 137 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
| 138 | + $success = false; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $this->emit('\OC\Updater', 'updateEnd', array($success)); |
|
| 142 | + |
|
| 143 | + if(!$wasMaintenanceModeEnabled && $success) { |
|
| 144 | + $this->config->setSystemValue('maintenance', false); |
|
| 145 | + $this->emit('\OC\Updater', 'maintenanceDisabled'); |
|
| 146 | + } else { |
|
| 147 | + $this->emit('\OC\Updater', 'maintenanceActive'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 151 | + $this->config->setSystemValue('loglevel', $logLevel); |
|
| 152 | + $this->config->setSystemValue('installed', true); |
|
| 153 | + |
|
| 154 | + return $success; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Return version from which this version is allowed to upgrade from |
|
| 159 | + * |
|
| 160 | + * @return array allowed previous versions per vendor |
|
| 161 | + */ |
|
| 162 | + private function getAllowedPreviousVersions() { |
|
| 163 | + // this should really be a JSON file |
|
| 164 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 165 | + /** @var array $OC_VersionCanBeUpgradedFrom */ |
|
| 166 | + return $OC_VersionCanBeUpgradedFrom; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Return vendor from which this version was published |
|
| 171 | + * |
|
| 172 | + * @return string Get the vendor |
|
| 173 | + */ |
|
| 174 | + private function getVendor() { |
|
| 175 | + // this should really be a JSON file |
|
| 176 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 177 | + /** @var string $vendor */ |
|
| 178 | + return (string) $vendor; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Whether an upgrade to a specified version is possible |
|
| 183 | + * @param string $oldVersion |
|
| 184 | + * @param string $newVersion |
|
| 185 | + * @param array $allowedPreviousVersions |
|
| 186 | + * @return bool |
|
| 187 | + */ |
|
| 188 | + public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
|
| 189 | + $version = explode('.', $oldVersion); |
|
| 190 | + $majorMinor = $version[0] . '.' . $version[1]; |
|
| 191 | + |
|
| 192 | + $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
|
| 193 | + |
|
| 194 | + // Vendor was not set correctly on install, so we have to white-list known versions |
|
| 195 | + if ($currentVendor === '') { |
|
| 196 | + if (in_array($oldVersion, [ |
|
| 197 | + '11.0.2.7', |
|
| 198 | + '11.0.1.2', |
|
| 199 | + '11.0.0.10', |
|
| 200 | + ], true)) { |
|
| 201 | + $currentVendor = 'nextcloud'; |
|
| 202 | + } else if (in_array($oldVersion, [ |
|
| 203 | + '10.0.0.12', |
|
| 204 | + ], true)) { |
|
| 205 | + $currentVendor = 'owncloud'; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ($currentVendor === 'nextcloud') { |
|
| 210 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) |
|
| 211 | + && (version_compare($oldVersion, $newVersion, '<=') || |
|
| 212 | + $this->config->getSystemValue('debug', false)); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // Check if the instance can be migrated |
|
| 216 | + return isset($allowedPreviousVersions[$currentVendor][$majorMinor]) || |
|
| 217 | + isset($allowedPreviousVersions[$currentVendor][$oldVersion]); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * runs the update actions in maintenance mode, does not upgrade the source files |
|
| 222 | + * except the main .htaccess file |
|
| 223 | + * |
|
| 224 | + * @param string $currentVersion current version to upgrade to |
|
| 225 | + * @param string $installedVersion previous version from which to upgrade from |
|
| 226 | + * |
|
| 227 | + * @throws \Exception |
|
| 228 | + */ |
|
| 229 | + private function doUpgrade($currentVersion, $installedVersion) { |
|
| 230 | + // Stop update if the update is over several major versions |
|
| 231 | + $allowedPreviousVersions = $this->getAllowedPreviousVersions(); |
|
| 232 | + if (!$this->isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersions)) { |
|
| 233 | + throw new \Exception('Updates between multiple major versions and downgrades are unsupported.'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // Update .htaccess files |
|
| 237 | + try { |
|
| 238 | + Setup::updateHtaccess(); |
|
| 239 | + Setup::protectDataDirectory(); |
|
| 240 | + } catch (\Exception $e) { |
|
| 241 | + throw new \Exception($e->getMessage()); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // create empty file in data dir, so we can later find |
|
| 245 | + // out that this is indeed an ownCloud data directory |
|
| 246 | + // (in case it didn't exist before) |
|
| 247 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 248 | + |
|
| 249 | + // pre-upgrade repairs |
|
| 250 | + $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 251 | + $repair->run(); |
|
| 252 | + |
|
| 253 | + $this->doCoreUpgrade(); |
|
| 254 | + |
|
| 255 | + try { |
|
| 256 | + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 |
|
| 257 | + Setup::installBackgroundJobs(); |
|
| 258 | + } catch (\Exception $e) { |
|
| 259 | + throw new \Exception($e->getMessage()); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + // update all shipped apps |
|
| 263 | + $this->checkAppsRequirements(); |
|
| 264 | + $this->doAppUpgrade(); |
|
| 265 | + |
|
| 266 | + // Update the appfetchers version so it downloads the correct list from the appstore |
|
| 267 | + \OC::$server->getAppFetcher()->setVersion($currentVersion); |
|
| 268 | + |
|
| 269 | + // upgrade appstore apps |
|
| 270 | + $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); |
|
| 271 | + |
|
| 272 | + // install new shipped apps on upgrade |
|
| 273 | + OC_App::loadApps('authentication'); |
|
| 274 | + $errors = Installer::installShippedApps(true); |
|
| 275 | + foreach ($errors as $appId => $exception) { |
|
| 276 | + /** @var \Exception $exception */ |
|
| 277 | + $this->log->logException($exception, ['app' => $appId]); |
|
| 278 | + $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // post-upgrade repairs |
|
| 282 | + $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher()); |
|
| 283 | + $repair->run(); |
|
| 284 | + |
|
| 285 | + //Invalidate update feed |
|
| 286 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 287 | + |
|
| 288 | + // Check for code integrity if not disabled |
|
| 289 | + if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 290 | + $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
|
| 291 | + $this->checker->runInstanceVerification(); |
|
| 292 | + $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // only set the final version if everything went well |
|
| 296 | + $this->config->setSystemValue('version', implode('.', Util::getVersion())); |
|
| 297 | + $this->config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + protected function doCoreUpgrade() { |
|
| 301 | + $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
|
| 302 | + |
|
| 303 | + // do the real upgrade |
|
| 304 | + \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); |
|
| 305 | + |
|
| 306 | + $this->emit('\OC\Updater', 'dbUpgrade'); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @param string $version the oc version to check app compatibility with |
|
| 311 | + */ |
|
| 312 | + protected function checkAppUpgrade($version) { |
|
| 313 | + $apps = \OC_App::getEnabledApps(); |
|
| 314 | + $this->emit('\OC\Updater', 'appUpgradeCheckBefore'); |
|
| 315 | + |
|
| 316 | + foreach ($apps as $appId) { |
|
| 317 | + $info = \OC_App::getAppInfo($appId); |
|
| 318 | + $compatible = \OC_App::isAppCompatible($version, $info); |
|
| 319 | + $isShipped = \OC_App::isShipped($appId); |
|
| 320 | + |
|
| 321 | + if ($compatible && $isShipped && \OC_App::shouldUpgrade($appId)) { |
|
| 322 | + /** |
|
| 323 | + * FIXME: The preupdate check is performed before the database migration, otherwise database changes |
|
| 324 | + * are not possible anymore within it. - Consider this when touching the code. |
|
| 325 | + * @link https://github.com/owncloud/core/issues/10980 |
|
| 326 | + * @see \OC_App::updateApp |
|
| 327 | + */ |
|
| 328 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
| 329 | + $this->includePreUpdate($appId); |
|
| 330 | + } |
|
| 331 | + if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
| 332 | + $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
|
| 333 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $this->emit('\OC\Updater', 'appUpgradeCheck'); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Includes the pre-update file. Done here to prevent namespace mixups. |
|
| 343 | + * @param string $appId |
|
| 344 | + */ |
|
| 345 | + private function includePreUpdate($appId) { |
|
| 346 | + include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * upgrades all apps within a major ownCloud upgrade. Also loads "priority" |
|
| 351 | + * (types authentication, filesystem, logging, in that order) afterwards. |
|
| 352 | + * |
|
| 353 | + * @throws NeedsUpdateException |
|
| 354 | + */ |
|
| 355 | + protected function doAppUpgrade() { |
|
| 356 | + $apps = \OC_App::getEnabledApps(); |
|
| 357 | + $priorityTypes = array('authentication', 'filesystem', 'logging'); |
|
| 358 | + $pseudoOtherType = 'other'; |
|
| 359 | + $stacks = array($pseudoOtherType => array()); |
|
| 360 | + |
|
| 361 | + foreach ($apps as $appId) { |
|
| 362 | + $priorityType = false; |
|
| 363 | + foreach ($priorityTypes as $type) { |
|
| 364 | + if(!isset($stacks[$type])) { |
|
| 365 | + $stacks[$type] = array(); |
|
| 366 | + } |
|
| 367 | + if (\OC_App::isType($appId, $type)) { |
|
| 368 | + $stacks[$type][] = $appId; |
|
| 369 | + $priorityType = true; |
|
| 370 | + break; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + if (!$priorityType) { |
|
| 374 | + $stacks[$pseudoOtherType][] = $appId; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + foreach ($stacks as $type => $stack) { |
|
| 378 | + foreach ($stack as $appId) { |
|
| 379 | + if (\OC_App::shouldUpgrade($appId)) { |
|
| 380 | + $this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 381 | + \OC_App::updateApp($appId); |
|
| 382 | + $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
|
| 383 | + } |
|
| 384 | + if($type !== $pseudoOtherType) { |
|
| 385 | + // load authentication, filesystem and logging apps after |
|
| 386 | + // upgrading them. Other apps my need to rely on modifying |
|
| 387 | + // user and/or filesystem aspects. |
|
| 388 | + \OC_App::loadApp($appId); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * check if the current enabled apps are compatible with the current |
|
| 396 | + * ownCloud version. disable them if not. |
|
| 397 | + * This is important if you upgrade ownCloud and have non ported 3rd |
|
| 398 | + * party apps installed. |
|
| 399 | + * |
|
| 400 | + * @return array |
|
| 401 | + * @throws \Exception |
|
| 402 | + */ |
|
| 403 | + private function checkAppsRequirements() { |
|
| 404 | + $isCoreUpgrade = $this->isCodeUpgrade(); |
|
| 405 | + $apps = OC_App::getEnabledApps(); |
|
| 406 | + $version = Util::getVersion(); |
|
| 407 | + $disabledApps = []; |
|
| 408 | + foreach ($apps as $app) { |
|
| 409 | + // check if the app is compatible with this version of ownCloud |
|
| 410 | + $info = OC_App::getAppInfo($app); |
|
| 411 | + if(!OC_App::isAppCompatible($version, $info)) { |
|
| 412 | + if (OC_App::isShipped($app)) { |
|
| 413 | + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 414 | + } |
|
| 415 | + OC_App::disable($app); |
|
| 416 | + $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
|
| 417 | + } |
|
| 418 | + // no need to disable any app in case this is a non-core upgrade |
|
| 419 | + if (!$isCoreUpgrade) { |
|
| 420 | + continue; |
|
| 421 | + } |
|
| 422 | + // shipped apps will remain enabled |
|
| 423 | + if (OC_App::isShipped($app)) { |
|
| 424 | + continue; |
|
| 425 | + } |
|
| 426 | + // authentication and session apps will remain enabled as well |
|
| 427 | + if (OC_App::isType($app, ['session', 'authentication'])) { |
|
| 428 | + continue; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // disable any other 3rd party apps if not overriden |
|
| 432 | + if(!$this->skip3rdPartyAppsDisable) { |
|
| 433 | + \OC_App::disable($app); |
|
| 434 | + $disabledApps[]= $app; |
|
| 435 | + $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
|
| 436 | + }; |
|
| 437 | + } |
|
| 438 | + return $disabledApps; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @return bool |
|
| 443 | + */ |
|
| 444 | + private function isCodeUpgrade() { |
|
| 445 | + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
|
| 446 | + $currentVersion = implode('.', Util::getVersion()); |
|
| 447 | + if (version_compare($currentVersion, $installedVersion, '>')) { |
|
| 448 | + return true; |
|
| 449 | + } |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @param array $disabledApps |
|
| 455 | + * @throws \Exception |
|
| 456 | + */ |
|
| 457 | + private function upgradeAppStoreApps(array $disabledApps) { |
|
| 458 | + foreach($disabledApps as $app) { |
|
| 459 | + try { |
|
| 460 | + $installer = new Installer( |
|
| 461 | + \OC::$server->getAppFetcher(), |
|
| 462 | + \OC::$server->getHTTPClientService(), |
|
| 463 | + \OC::$server->getTempManager(), |
|
| 464 | + $this->log, |
|
| 465 | + \OC::$server->getConfig() |
|
| 466 | + ); |
|
| 467 | + $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); |
|
| 468 | + if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) { |
|
| 469 | + $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); |
|
| 470 | + $installer->updateAppstoreApp($app); |
|
| 471 | + } |
|
| 472 | + $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); |
|
| 473 | + } catch (\Exception $ex) { |
|
| 474 | + $this->log->logException($ex, ['app' => 'core']); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Forward messages emitted by the repair routine |
|
| 481 | + */ |
|
| 482 | + private function emitRepairEvents() { |
|
| 483 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 484 | + $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 485 | + if ($event instanceof GenericEvent) { |
|
| 486 | + $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
|
| 487 | + } |
|
| 488 | + }); |
|
| 489 | + $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 490 | + if ($event instanceof GenericEvent) { |
|
| 491 | + $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
|
| 492 | + } |
|
| 493 | + }); |
|
| 494 | + $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 495 | + if ($event instanceof GenericEvent) { |
|
| 496 | + $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
|
| 497 | + } |
|
| 498 | + }); |
|
| 499 | + $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 500 | + if ($event instanceof GenericEvent) { |
|
| 501 | + $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
|
| 502 | + } |
|
| 503 | + }); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + private function logAllEvents() { |
|
| 507 | + $log = $this->log; |
|
| 508 | + |
|
| 509 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 510 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) { |
|
| 511 | + if (!$event instanceof GenericEvent) { |
|
| 512 | + return; |
|
| 513 | + } |
|
| 514 | + $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 515 | + }); |
|
| 516 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
|
| 517 | + if (!$event instanceof GenericEvent) { |
|
| 518 | + return; |
|
| 519 | + } |
|
| 520 | + $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 521 | + }); |
|
| 522 | + |
|
| 523 | + $repairListener = function($event) use ($log) { |
|
| 524 | + if (!$event instanceof GenericEvent) { |
|
| 525 | + return; |
|
| 526 | + } |
|
| 527 | + switch ($event->getSubject()) { |
|
| 528 | + case '\OC\Repair::startProgress': |
|
| 529 | + $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 530 | + break; |
|
| 531 | + case '\OC\Repair::advance': |
|
| 532 | + $desc = $event->getArgument(1); |
|
| 533 | + if (empty($desc)) { |
|
| 534 | + $desc = ''; |
|
| 535 | + } |
|
| 536 | + $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 537 | + |
|
| 538 | + break; |
|
| 539 | + case '\OC\Repair::finishProgress': |
|
| 540 | + $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
|
| 541 | + break; |
|
| 542 | + case '\OC\Repair::step': |
|
| 543 | + $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 544 | + break; |
|
| 545 | + case '\OC\Repair::info': |
|
| 546 | + $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 547 | + break; |
|
| 548 | + case '\OC\Repair::warning': |
|
| 549 | + $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 550 | + break; |
|
| 551 | + case '\OC\Repair::error': |
|
| 552 | + $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 553 | + break; |
|
| 554 | + } |
|
| 555 | + }; |
|
| 556 | + |
|
| 557 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
| 558 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
| 559 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
| 560 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
| 561 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
| 562 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
| 563 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
| 567 | + $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
|
| 568 | + }); |
|
| 569 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
| 570 | + $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
|
| 571 | + }); |
|
| 572 | + $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
| 573 | + $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
|
| 574 | + }); |
|
| 575 | + $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
| 576 | + if ($success) { |
|
| 577 | + $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
|
| 578 | + } else { |
|
| 579 | + $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
|
| 580 | + } |
|
| 581 | + }); |
|
| 582 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
| 583 | + $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
|
| 584 | + }); |
|
| 585 | + $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
| 586 | + $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
|
| 587 | + }); |
|
| 588 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
| 589 | + $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']); |
|
| 590 | + }); |
|
| 591 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
| 592 | + $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
|
| 593 | + }); |
|
| 594 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
| 595 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 596 | + }); |
|
| 597 | + $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
| 598 | + $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
| 599 | + }); |
|
| 600 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
| 601 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 602 | + }); |
|
| 603 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
| 604 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 605 | + }); |
|
| 606 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
| 607 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 608 | + }); |
|
| 609 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
| 610 | + $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
|
| 611 | + }); |
|
| 612 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 613 | + $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']); |
|
| 614 | + }); |
|
| 615 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
| 616 | + $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
|
| 617 | + }); |
|
| 618 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 619 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 620 | + }); |
|
| 621 | + $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 622 | + $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 623 | + }); |
|
| 624 | + $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
| 625 | + $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 626 | + }); |
|
| 627 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
| 628 | + $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
|
| 629 | + }); |
|
| 630 | + $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
| 631 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 632 | + }); |
|
| 633 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
| 634 | + $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
|
| 635 | + }); |
|
| 636 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
| 637 | + $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
|
| 638 | + }); |
|
| 639 | + |
|
| 640 | + } |
|
| 641 | 641 | |
| 642 | 642 | } |
| 643 | 643 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // If at least PHP 7.0.0 is used we don't need to disable apps as we catch |
| 87 | 87 | // fatal errors and exceptions and disable the app just instead. |
| 88 | - if(version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 88 | + if (version_compare(phpversion(), '7.0.0', '>=')) { |
|
| 89 | 89 | $this->skip3rdPartyAppsDisable = true; |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -111,43 +111,43 @@ discard block |
||
| 111 | 111 | $this->logAllEvents(); |
| 112 | 112 | |
| 113 | 113 | $logLevel = $this->config->getSystemValue('loglevel', Util::WARN); |
| 114 | - $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 114 | + $this->emit('\OC\Updater', 'setDebugLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 115 | 115 | $this->config->setSystemValue('loglevel', Util::DEBUG); |
| 116 | 116 | |
| 117 | 117 | $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
| 118 | 118 | |
| 119 | - if(!$wasMaintenanceModeEnabled) { |
|
| 119 | + if (!$wasMaintenanceModeEnabled) { |
|
| 120 | 120 | $this->config->setSystemValue('maintenance', true); |
| 121 | 121 | $this->emit('\OC\Updater', 'maintenanceEnabled'); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $installedVersion = $this->config->getSystemValue('version', '0.0.0'); |
| 125 | 125 | $currentVersion = implode('.', \OCP\Util::getVersion()); |
| 126 | - $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core')); |
|
| 126 | + $this->log->debug('starting upgrade from '.$installedVersion.' to '.$currentVersion, array('app' => 'core')); |
|
| 127 | 127 | |
| 128 | 128 | $success = true; |
| 129 | 129 | try { |
| 130 | 130 | $this->doUpgrade($currentVersion, $installedVersion); |
| 131 | 131 | } catch (HintException $exception) { |
| 132 | 132 | $this->log->logException($exception, ['app' => 'core']); |
| 133 | - $this->emit('\OC\Updater', 'failure', array($exception->getMessage() . ': ' .$exception->getHint())); |
|
| 133 | + $this->emit('\OC\Updater', 'failure', array($exception->getMessage().': '.$exception->getHint())); |
|
| 134 | 134 | $success = false; |
| 135 | 135 | } catch (\Exception $exception) { |
| 136 | 136 | $this->log->logException($exception, ['app' => 'core']); |
| 137 | - $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); |
|
| 137 | + $this->emit('\OC\Updater', 'failure', array(get_class($exception).': '.$exception->getMessage())); |
|
| 138 | 138 | $success = false; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $this->emit('\OC\Updater', 'updateEnd', array($success)); |
| 142 | 142 | |
| 143 | - if(!$wasMaintenanceModeEnabled && $success) { |
|
| 143 | + if (!$wasMaintenanceModeEnabled && $success) { |
|
| 144 | 144 | $this->config->setSystemValue('maintenance', false); |
| 145 | 145 | $this->emit('\OC\Updater', 'maintenanceDisabled'); |
| 146 | 146 | } else { |
| 147 | 147 | $this->emit('\OC\Updater', 'maintenanceActive'); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $this->emit('\OC\Updater', 'resetLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); |
|
| 150 | + $this->emit('\OC\Updater', 'resetLogLevel', [$logLevel, $this->logLevelNames[$logLevel]]); |
|
| 151 | 151 | $this->config->setSystemValue('loglevel', $logLevel); |
| 152 | 152 | $this->config->setSystemValue('installed', true); |
| 153 | 153 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | private function getAllowedPreviousVersions() { |
| 163 | 163 | // this should really be a JSON file |
| 164 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 164 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 165 | 165 | /** @var array $OC_VersionCanBeUpgradedFrom */ |
| 166 | 166 | return $OC_VersionCanBeUpgradedFrom; |
| 167 | 167 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | private function getVendor() { |
| 175 | 175 | // this should really be a JSON file |
| 176 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 176 | + require \OC::$SERVERROOT.'/version.php'; |
|
| 177 | 177 | /** @var string $vendor */ |
| 178 | 178 | return (string) $vendor; |
| 179 | 179 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function isUpgradePossible($oldVersion, $newVersion, array $allowedPreviousVersions) { |
| 189 | 189 | $version = explode('.', $oldVersion); |
| 190 | - $majorMinor = $version[0] . '.' . $version[1]; |
|
| 190 | + $majorMinor = $version[0].'.'.$version[1]; |
|
| 191 | 191 | |
| 192 | 192 | $currentVendor = $this->config->getAppValue('core', 'vendor', ''); |
| 193 | 193 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | // create empty file in data dir, so we can later find |
| 245 | 245 | // out that this is indeed an ownCloud data directory |
| 246 | 246 | // (in case it didn't exist before) |
| 247 | - file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 247 | + file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); |
|
| 248 | 248 | |
| 249 | 249 | // pre-upgrade repairs |
| 250 | 250 | $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher()); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | foreach ($errors as $appId => $exception) { |
| 276 | 276 | /** @var \Exception $exception */ |
| 277 | 277 | $this->log->logException($exception, ['app' => $appId]); |
| 278 | - $this->emit('\OC\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]); |
|
| 278 | + $this->emit('\OC\Updater', 'failure', [$appId.': '.$exception->getMessage()]); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // post-upgrade repairs |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | $this->config->setAppValue('core', 'lastupdatedat', 0); |
| 287 | 287 | |
| 288 | 288 | // Check for code integrity if not disabled |
| 289 | - if(\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 289 | + if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) { |
|
| 290 | 290 | $this->emit('\OC\Updater', 'startCheckCodeIntegrity'); |
| 291 | 291 | $this->checker->runInstanceVerification(); |
| 292 | 292 | $this->emit('\OC\Updater', 'finishedCheckCodeIntegrity'); |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | $this->emit('\OC\Updater', 'dbUpgradeBefore'); |
| 302 | 302 | |
| 303 | 303 | // do the real upgrade |
| 304 | - \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); |
|
| 304 | + \OC_DB::updateDbFromStructure(\OC::$SERVERROOT.'/db_structure.xml'); |
|
| 305 | 305 | |
| 306 | 306 | $this->emit('\OC\Updater', 'dbUpgrade'); |
| 307 | 307 | } |
@@ -325,12 +325,12 @@ discard block |
||
| 325 | 325 | * @link https://github.com/owncloud/core/issues/10980 |
| 326 | 326 | * @see \OC_App::updateApp |
| 327 | 327 | */ |
| 328 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) { |
|
| 328 | + if (file_exists(\OC_App::getAppPath($appId).'/appinfo/preupdate.php')) { |
|
| 329 | 329 | $this->includePreUpdate($appId); |
| 330 | 330 | } |
| 331 | - if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) { |
|
| 331 | + if (file_exists(\OC_App::getAppPath($appId).'/appinfo/database.xml')) { |
|
| 332 | 332 | $this->emit('\OC\Updater', 'appSimulateUpdate', array($appId)); |
| 333 | - \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml'); |
|
| 333 | + \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId).'/appinfo/database.xml'); |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | } |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | * @param string $appId |
| 344 | 344 | */ |
| 345 | 345 | private function includePreUpdate($appId) { |
| 346 | - include \OC_App::getAppPath($appId) . '/appinfo/preupdate.php'; |
|
| 346 | + include \OC_App::getAppPath($appId).'/appinfo/preupdate.php'; |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | foreach ($apps as $appId) { |
| 362 | 362 | $priorityType = false; |
| 363 | 363 | foreach ($priorityTypes as $type) { |
| 364 | - if(!isset($stacks[$type])) { |
|
| 364 | + if (!isset($stacks[$type])) { |
|
| 365 | 365 | $stacks[$type] = array(); |
| 366 | 366 | } |
| 367 | 367 | if (\OC_App::isType($appId, $type)) { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | \OC_App::updateApp($appId); |
| 382 | 382 | $this->emit('\OC\Updater', 'appUpgrade', [$appId, \OC_App::getAppVersion($appId)]); |
| 383 | 383 | } |
| 384 | - if($type !== $pseudoOtherType) { |
|
| 384 | + if ($type !== $pseudoOtherType) { |
|
| 385 | 385 | // load authentication, filesystem and logging apps after |
| 386 | 386 | // upgrading them. Other apps my need to rely on modifying |
| 387 | 387 | // user and/or filesystem aspects. |
@@ -408,9 +408,9 @@ discard block |
||
| 408 | 408 | foreach ($apps as $app) { |
| 409 | 409 | // check if the app is compatible with this version of ownCloud |
| 410 | 410 | $info = OC_App::getAppInfo($app); |
| 411 | - if(!OC_App::isAppCompatible($version, $info)) { |
|
| 411 | + if (!OC_App::isAppCompatible($version, $info)) { |
|
| 412 | 412 | if (OC_App::isShipped($app)) { |
| 413 | - throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); |
|
| 413 | + throw new \UnexpectedValueException('The files of the app "'.$app.'" were not correctly replaced before running the update'); |
|
| 414 | 414 | } |
| 415 | 415 | OC_App::disable($app); |
| 416 | 416 | $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); |
@@ -429,9 +429,9 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // disable any other 3rd party apps if not overriden |
| 432 | - if(!$this->skip3rdPartyAppsDisable) { |
|
| 432 | + if (!$this->skip3rdPartyAppsDisable) { |
|
| 433 | 433 | \OC_App::disable($app); |
| 434 | - $disabledApps[]= $app; |
|
| 434 | + $disabledApps[] = $app; |
|
| 435 | 435 | $this->emit('\OC\Updater', 'thirdPartyAppDisabled', array($app)); |
| 436 | 436 | }; |
| 437 | 437 | } |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | * @throws \Exception |
| 456 | 456 | */ |
| 457 | 457 | private function upgradeAppStoreApps(array $disabledApps) { |
| 458 | - foreach($disabledApps as $app) { |
|
| 458 | + foreach ($disabledApps as $app) { |
|
| 459 | 459 | try { |
| 460 | 460 | $installer = new Installer( |
| 461 | 461 | \OC::$server->getAppFetcher(), |
@@ -481,22 +481,22 @@ discard block |
||
| 481 | 481 | */ |
| 482 | 482 | private function emitRepairEvents() { |
| 483 | 483 | $dispatcher = \OC::$server->getEventDispatcher(); |
| 484 | - $dispatcher->addListener('\OC\Repair::warning', function ($event) { |
|
| 484 | + $dispatcher->addListener('\OC\Repair::warning', function($event) { |
|
| 485 | 485 | if ($event instanceof GenericEvent) { |
| 486 | 486 | $this->emit('\OC\Updater', 'repairWarning', $event->getArguments()); |
| 487 | 487 | } |
| 488 | 488 | }); |
| 489 | - $dispatcher->addListener('\OC\Repair::error', function ($event) { |
|
| 489 | + $dispatcher->addListener('\OC\Repair::error', function($event) { |
|
| 490 | 490 | if ($event instanceof GenericEvent) { |
| 491 | 491 | $this->emit('\OC\Updater', 'repairError', $event->getArguments()); |
| 492 | 492 | } |
| 493 | 493 | }); |
| 494 | - $dispatcher->addListener('\OC\Repair::info', function ($event) { |
|
| 494 | + $dispatcher->addListener('\OC\Repair::info', function($event) { |
|
| 495 | 495 | if ($event instanceof GenericEvent) { |
| 496 | 496 | $this->emit('\OC\Updater', 'repairInfo', $event->getArguments()); |
| 497 | 497 | } |
| 498 | 498 | }); |
| 499 | - $dispatcher->addListener('\OC\Repair::step', function ($event) { |
|
| 499 | + $dispatcher->addListener('\OC\Repair::step', function($event) { |
|
| 500 | 500 | if ($event instanceof GenericEvent) { |
| 501 | 501 | $this->emit('\OC\Updater', 'repairStep', $event->getArguments()); |
| 502 | 502 | } |
@@ -511,13 +511,13 @@ discard block |
||
| 511 | 511 | if (!$event instanceof GenericEvent) { |
| 512 | 512 | return; |
| 513 | 513 | } |
| 514 | - $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 514 | + $log->info('\OC\DB\Migrator::executeSql: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 515 | 515 | }); |
| 516 | 516 | $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) { |
| 517 | 517 | if (!$event instanceof GenericEvent) { |
| 518 | 518 | return; |
| 519 | 519 | } |
| 520 | - $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']); |
|
| 520 | + $log->info('\OC\DB\Migrator::checkTable: '.$event->getSubject().' ('.$event->getArgument(0).' of '.$event->getArgument(1).')', ['app' => 'updater']); |
|
| 521 | 521 | }); |
| 522 | 522 | |
| 523 | 523 | $repairListener = function($event) use ($log) { |
@@ -526,30 +526,30 @@ discard block |
||
| 526 | 526 | } |
| 527 | 527 | switch ($event->getSubject()) { |
| 528 | 528 | case '\OC\Repair::startProgress': |
| 529 | - $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 529 | + $log->info('\OC\Repair::startProgress: Starting ... '.$event->getArgument(1).' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 530 | 530 | break; |
| 531 | 531 | case '\OC\Repair::advance': |
| 532 | 532 | $desc = $event->getArgument(1); |
| 533 | 533 | if (empty($desc)) { |
| 534 | 534 | $desc = ''; |
| 535 | 535 | } |
| 536 | - $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']); |
|
| 536 | + $log->info('\OC\Repair::advance: '.$desc.' ('.$event->getArgument(0).')', ['app' => 'updater']); |
|
| 537 | 537 | |
| 538 | 538 | break; |
| 539 | 539 | case '\OC\Repair::finishProgress': |
| 540 | 540 | $log->info('\OC\Repair::finishProgress', ['app' => 'updater']); |
| 541 | 541 | break; |
| 542 | 542 | case '\OC\Repair::step': |
| 543 | - $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 543 | + $log->info('\OC\Repair::step: Repair step: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 544 | 544 | break; |
| 545 | 545 | case '\OC\Repair::info': |
| 546 | - $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 546 | + $log->info('\OC\Repair::info: Repair info: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 547 | 547 | break; |
| 548 | 548 | case '\OC\Repair::warning': |
| 549 | - $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 549 | + $log->warning('\OC\Repair::warning: Repair warning: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 550 | 550 | break; |
| 551 | 551 | case '\OC\Repair::error': |
| 552 | - $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']); |
|
| 552 | + $log->error('\OC\Repair::error: Repair error: '.$event->getArgument(0), ['app' => 'updater']); |
|
| 553 | 553 | break; |
| 554 | 554 | } |
| 555 | 555 | }; |
@@ -563,77 +563,77 @@ discard block |
||
| 563 | 563 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
| 564 | 564 | |
| 565 | 565 | |
| 566 | - $this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) { |
|
| 566 | + $this->listen('\OC\Updater', 'maintenanceEnabled', function() use($log) { |
|
| 567 | 567 | $log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']); |
| 568 | 568 | }); |
| 569 | - $this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) { |
|
| 569 | + $this->listen('\OC\Updater', 'maintenanceDisabled', function() use($log) { |
|
| 570 | 570 | $log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']); |
| 571 | 571 | }); |
| 572 | - $this->listen('\OC\Updater', 'maintenanceActive', function () use($log) { |
|
| 572 | + $this->listen('\OC\Updater', 'maintenanceActive', function() use($log) { |
|
| 573 | 573 | $log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']); |
| 574 | 574 | }); |
| 575 | - $this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) { |
|
| 575 | + $this->listen('\OC\Updater', 'updateEnd', function($success) use($log) { |
|
| 576 | 576 | if ($success) { |
| 577 | 577 | $log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']); |
| 578 | 578 | } else { |
| 579 | 579 | $log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']); |
| 580 | 580 | } |
| 581 | 581 | }); |
| 582 | - $this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) { |
|
| 582 | + $this->listen('\OC\Updater', 'dbUpgradeBefore', function() use($log) { |
|
| 583 | 583 | $log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']); |
| 584 | 584 | }); |
| 585 | - $this->listen('\OC\Updater', 'dbUpgrade', function () use($log) { |
|
| 585 | + $this->listen('\OC\Updater', 'dbUpgrade', function() use($log) { |
|
| 586 | 586 | $log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']); |
| 587 | 587 | }); |
| 588 | - $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) { |
|
| 588 | + $this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use($log) { |
|
| 589 | 589 | $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']); |
| 590 | 590 | }); |
| 591 | - $this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) { |
|
| 591 | + $this->listen('\OC\Updater', 'dbSimulateUpgrade', function() use($log) { |
|
| 592 | 592 | $log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']); |
| 593 | 593 | }); |
| 594 | - $this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) { |
|
| 595 | - $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']); |
|
| 594 | + $this->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use($log) { |
|
| 595 | + $log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: '.$app, ['app' => 'updater']); |
|
| 596 | 596 | }); |
| 597 | - $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) { |
|
| 598 | - $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']); |
|
| 597 | + $this->listen('\OC\Updater', 'thirdPartyAppDisabled', function($app) use ($log) { |
|
| 598 | + $log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: '.$app, ['app' => 'updater']); |
|
| 599 | 599 | }); |
| 600 | - $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($log) { |
|
| 601 | - $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 600 | + $this->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use($log) { |
|
| 601 | + $log->info('\OC\Updater::checkAppStoreAppBefore: Checking for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 602 | 602 | }); |
| 603 | - $this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) { |
|
| 604 | - $log->info('\OC\Updater::upgradeAppStoreApp: Update app "' . $app . '" from appstore', ['app' => 'updater']); |
|
| 603 | + $this->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use($log) { |
|
| 604 | + $log->info('\OC\Updater::upgradeAppStoreApp: Update app "'.$app.'" from appstore', ['app' => 'updater']); |
|
| 605 | 605 | }); |
| 606 | - $this->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($log) { |
|
| 607 | - $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "' . $app . '" in appstore', ['app' => 'updater']); |
|
| 606 | + $this->listen('\OC\Updater', 'checkAppStoreApp', function($app) use($log) { |
|
| 607 | + $log->info('\OC\Updater::checkAppStoreApp: Checked for update of app "'.$app.'" in appstore', ['app' => 'updater']); |
|
| 608 | 608 | }); |
| 609 | - $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) { |
|
| 609 | + $this->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($log) { |
|
| 610 | 610 | $log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']); |
| 611 | 611 | }); |
| 612 | - $this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) { |
|
| 613 | - $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']); |
|
| 612 | + $this->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($log) { |
|
| 613 | + $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']); |
|
| 614 | 614 | }); |
| 615 | - $this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) { |
|
| 615 | + $this->listen('\OC\Updater', 'appUpgradeCheck', function() use ($log) { |
|
| 616 | 616 | $log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']); |
| 617 | 617 | }); |
| 618 | - $this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) { |
|
| 619 | - $log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']); |
|
| 618 | + $this->listen('\OC\Updater', 'appUpgradeStarted', function($app) use ($log) { |
|
| 619 | + $log->info('\OC\Updater::appUpgradeStarted: Updating <'.$app.'> ...', ['app' => 'updater']); |
|
| 620 | 620 | }); |
| 621 | - $this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) { |
|
| 622 | - $log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']); |
|
| 621 | + $this->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($log) { |
|
| 622 | + $log->info('\OC\Updater::appUpgrade: Updated <'.$app.'> to '.$version, ['app' => 'updater']); |
|
| 623 | 623 | }); |
| 624 | - $this->listen('\OC\Updater', 'failure', function ($message) use($log) { |
|
| 625 | - $log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']); |
|
| 624 | + $this->listen('\OC\Updater', 'failure', function($message) use($log) { |
|
| 625 | + $log->error('\OC\Updater::failure: '.$message, ['app' => 'updater']); |
|
| 626 | 626 | }); |
| 627 | - $this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) { |
|
| 627 | + $this->listen('\OC\Updater', 'setDebugLogLevel', function() use($log) { |
|
| 628 | 628 | $log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']); |
| 629 | 629 | }); |
| 630 | - $this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) { |
|
| 631 | - $log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']); |
|
| 630 | + $this->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use($log) { |
|
| 631 | + $log->info('\OC\Updater::resetLogLevel: Reset log level to '.$logLevelName.'('.$logLevel.')', ['app' => 'updater']); |
|
| 632 | 632 | }); |
| 633 | - $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) { |
|
| 633 | + $this->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use($log) { |
|
| 634 | 634 | $log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']); |
| 635 | 635 | }); |
| 636 | - $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) { |
|
| 636 | + $this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use($log) { |
|
| 637 | 637 | $log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']); |
| 638 | 638 | }); |
| 639 | 639 | |
@@ -35,110 +35,110 @@ |
||
| 35 | 35 | |
| 36 | 36 | class MoveAvatarsBackgroundJob extends QueuedJob { |
| 37 | 37 | |
| 38 | - /** @var IUserManager */ |
|
| 39 | - private $userManager; |
|
| 40 | - |
|
| 41 | - /** @var IRootFolder */ |
|
| 42 | - private $rootFolder; |
|
| 43 | - |
|
| 44 | - /** @var IAppData */ |
|
| 45 | - private $appData; |
|
| 46 | - |
|
| 47 | - /** @var ILogger */ |
|
| 48 | - private $logger; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * MoveAvatars constructor. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - $this->userManager = \OC::$server->getUserManager(); |
|
| 55 | - $this->rootFolder = \OC::$server->getRootFolder(); |
|
| 56 | - $this->logger = \OC::$server->getLogger(); |
|
| 57 | - $this->appData = \OC::$server->getAppDataDir('avatar'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function run($arguments) { |
|
| 61 | - $this->logger->info('Started migrating avatars to AppData folder'); |
|
| 62 | - $this->moveAvatars(); |
|
| 63 | - $this->logger->info('All avatars migrated to AppData folder'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - private function moveAvatars() { |
|
| 67 | - try { |
|
| 68 | - $ownCloudAvatars = $this->rootFolder->get('avatars'); |
|
| 69 | - } catch (NotFoundException $e) { |
|
| 70 | - $ownCloudAvatars = null; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $counter = 0; |
|
| 74 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($counter, $ownCloudAvatars) { |
|
| 75 | - $uid = $user->getUID(); |
|
| 76 | - |
|
| 77 | - \OC\Files\Filesystem::initMountPoints($uid); |
|
| 78 | - /** @var Folder $userFolder */ |
|
| 79 | - $userFolder = $this->rootFolder->get($uid); |
|
| 80 | - |
|
| 81 | - try { |
|
| 82 | - $userData = $this->appData->getFolder($uid); |
|
| 83 | - } catch (NotFoundException $e) { |
|
| 84 | - $userData = $this->appData->newFolder($uid); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $foundAvatars = $this->copyAvatarsFromFolder($userFolder, $userData); |
|
| 88 | - |
|
| 89 | - // ownCloud migration? |
|
| 90 | - if ($foundAvatars === 0 && $ownCloudAvatars instanceof Folder) { |
|
| 91 | - $parts = $this->buildOwnCloudAvatarPath($uid); |
|
| 92 | - $userOwnCloudAvatar = $ownCloudAvatars; |
|
| 93 | - foreach ($parts as $part) { |
|
| 94 | - try { |
|
| 95 | - $userOwnCloudAvatar = $userOwnCloudAvatar->get($part); |
|
| 96 | - } catch (NotFoundException $e) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $this->copyAvatarsFromFolder($userOwnCloudAvatar, $userData); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $counter++; |
|
| 105 | - if ($counter % 100 === 0) { |
|
| 106 | - $this->logger->info('{amount} avatars migrated', ['amount' => $counter]); |
|
| 107 | - } |
|
| 108 | - }); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param Folder $source |
|
| 113 | - * @param ISimpleFolder $target |
|
| 114 | - * @return int |
|
| 115 | - * @throws \OCP\Files\NotPermittedException |
|
| 116 | - * @throws NotFoundException |
|
| 117 | - */ |
|
| 118 | - protected function copyAvatarsFromFolder(Folder $source, ISimpleFolder $target) { |
|
| 119 | - $foundAvatars = 0; |
|
| 120 | - $avatars = $source->getDirectoryListing(); |
|
| 121 | - $regex = '/^avatar\.([0-9]+\.)?(jpg|png)$/'; |
|
| 122 | - |
|
| 123 | - foreach ($avatars as $avatar) { |
|
| 124 | - /** @var File $avatar */ |
|
| 125 | - if (preg_match($regex, $avatar->getName())) { |
|
| 126 | - /* |
|
| 38 | + /** @var IUserManager */ |
|
| 39 | + private $userManager; |
|
| 40 | + |
|
| 41 | + /** @var IRootFolder */ |
|
| 42 | + private $rootFolder; |
|
| 43 | + |
|
| 44 | + /** @var IAppData */ |
|
| 45 | + private $appData; |
|
| 46 | + |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + private $logger; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * MoveAvatars constructor. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + $this->userManager = \OC::$server->getUserManager(); |
|
| 55 | + $this->rootFolder = \OC::$server->getRootFolder(); |
|
| 56 | + $this->logger = \OC::$server->getLogger(); |
|
| 57 | + $this->appData = \OC::$server->getAppDataDir('avatar'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function run($arguments) { |
|
| 61 | + $this->logger->info('Started migrating avatars to AppData folder'); |
|
| 62 | + $this->moveAvatars(); |
|
| 63 | + $this->logger->info('All avatars migrated to AppData folder'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + private function moveAvatars() { |
|
| 67 | + try { |
|
| 68 | + $ownCloudAvatars = $this->rootFolder->get('avatars'); |
|
| 69 | + } catch (NotFoundException $e) { |
|
| 70 | + $ownCloudAvatars = null; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $counter = 0; |
|
| 74 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($counter, $ownCloudAvatars) { |
|
| 75 | + $uid = $user->getUID(); |
|
| 76 | + |
|
| 77 | + \OC\Files\Filesystem::initMountPoints($uid); |
|
| 78 | + /** @var Folder $userFolder */ |
|
| 79 | + $userFolder = $this->rootFolder->get($uid); |
|
| 80 | + |
|
| 81 | + try { |
|
| 82 | + $userData = $this->appData->getFolder($uid); |
|
| 83 | + } catch (NotFoundException $e) { |
|
| 84 | + $userData = $this->appData->newFolder($uid); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $foundAvatars = $this->copyAvatarsFromFolder($userFolder, $userData); |
|
| 88 | + |
|
| 89 | + // ownCloud migration? |
|
| 90 | + if ($foundAvatars === 0 && $ownCloudAvatars instanceof Folder) { |
|
| 91 | + $parts = $this->buildOwnCloudAvatarPath($uid); |
|
| 92 | + $userOwnCloudAvatar = $ownCloudAvatars; |
|
| 93 | + foreach ($parts as $part) { |
|
| 94 | + try { |
|
| 95 | + $userOwnCloudAvatar = $userOwnCloudAvatar->get($part); |
|
| 96 | + } catch (NotFoundException $e) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $this->copyAvatarsFromFolder($userOwnCloudAvatar, $userData); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $counter++; |
|
| 105 | + if ($counter % 100 === 0) { |
|
| 106 | + $this->logger->info('{amount} avatars migrated', ['amount' => $counter]); |
|
| 107 | + } |
|
| 108 | + }); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param Folder $source |
|
| 113 | + * @param ISimpleFolder $target |
|
| 114 | + * @return int |
|
| 115 | + * @throws \OCP\Files\NotPermittedException |
|
| 116 | + * @throws NotFoundException |
|
| 117 | + */ |
|
| 118 | + protected function copyAvatarsFromFolder(Folder $source, ISimpleFolder $target) { |
|
| 119 | + $foundAvatars = 0; |
|
| 120 | + $avatars = $source->getDirectoryListing(); |
|
| 121 | + $regex = '/^avatar\.([0-9]+\.)?(jpg|png)$/'; |
|
| 122 | + |
|
| 123 | + foreach ($avatars as $avatar) { |
|
| 124 | + /** @var File $avatar */ |
|
| 125 | + if (preg_match($regex, $avatar->getName())) { |
|
| 126 | + /* |
|
| 127 | 127 | * This is not the most effective but it is the most abstract way |
| 128 | 128 | * to handle this. Avatars should be small anyways. |
| 129 | 129 | */ |
| 130 | - $newAvatar = $target->newFile($avatar->getName()); |
|
| 131 | - $newAvatar->putContent($avatar->getContent()); |
|
| 132 | - $avatar->delete(); |
|
| 133 | - $foundAvatars++; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $foundAvatars; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - protected function buildOwnCloudAvatarPath($userId) { |
|
| 141 | - $avatar = substr_replace(substr_replace(md5($userId), '/', 4, 0), '/', 2, 0); |
|
| 142 | - return explode('/', $avatar); |
|
| 143 | - } |
|
| 130 | + $newAvatar = $target->newFile($avatar->getName()); |
|
| 131 | + $newAvatar->putContent($avatar->getContent()); |
|
| 132 | + $avatar->delete(); |
|
| 133 | + $foundAvatars++; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $foundAvatars; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + protected function buildOwnCloudAvatarPath($userId) { |
|
| 141 | + $avatar = substr_replace(substr_replace(md5($userId), '/', 4, 0), '/', 2, 0); |
|
| 142 | + return explode('/', $avatar); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $counter = 0; |
| 74 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($counter, $ownCloudAvatars) { |
|
| 74 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($counter, $ownCloudAvatars) { |
|
| 75 | 75 | $uid = $user->getUID(); |
| 76 | 76 | |
| 77 | 77 | \OC\Files\Filesystem::initMountPoints($uid); |
@@ -32,13 +32,13 @@ |
||
| 32 | 32 | $OC_VersionString = '12.0 beta 4'; |
| 33 | 33 | |
| 34 | 34 | $OC_VersionCanBeUpgradedFrom = [ |
| 35 | - 'nextcloud' => [ |
|
| 36 | - '11.0' => true, |
|
| 37 | - '12.0' => true, |
|
| 38 | - ], |
|
| 39 | - 'owncloud' => [ |
|
| 40 | - '10.0.0.12' => true, |
|
| 41 | - ], |
|
| 35 | + 'nextcloud' => [ |
|
| 36 | + '11.0' => true, |
|
| 37 | + '12.0' => true, |
|
| 38 | + ], |
|
| 39 | + 'owncloud' => [ |
|
| 40 | + '10.0.0.12' => true, |
|
| 41 | + ], |
|
| 42 | 42 | ]; |
| 43 | 43 | |
| 44 | 44 | // default Nextcloud channel |