@@ -61,175 +61,175 @@ |
||
61 | 61 | |
62 | 62 | class Repair implements IOutput { |
63 | 63 | |
64 | - /** @var IRepairStep[] */ |
|
65 | - private $repairSteps; |
|
66 | - |
|
67 | - /** @var EventDispatcherInterface */ |
|
68 | - private $dispatcher; |
|
69 | - |
|
70 | - /** @var string */ |
|
71 | - private $currentStep; |
|
72 | - |
|
73 | - /** |
|
74 | - * Creates a new repair step runner |
|
75 | - * |
|
76 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
77 | - * @param EventDispatcherInterface $dispatcher |
|
78 | - */ |
|
79 | - public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
80 | - $this->repairSteps = $repairSteps; |
|
81 | - $this->dispatcher = $dispatcher; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Run a series of repair steps for common problems |
|
86 | - */ |
|
87 | - public function run() { |
|
88 | - if (count($this->repairSteps) === 0) { |
|
89 | - $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
90 | - |
|
91 | - return; |
|
92 | - } |
|
93 | - // run each repair step |
|
94 | - foreach ($this->repairSteps as $step) { |
|
95 | - $this->currentStep = $step->getName(); |
|
96 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
97 | - $step->run($this); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Add repair step |
|
103 | - * |
|
104 | - * @param IRepairStep|string $repairStep repair step |
|
105 | - * @throws \Exception |
|
106 | - */ |
|
107 | - public function addStep($repairStep) { |
|
108 | - if (is_string($repairStep)) { |
|
109 | - try { |
|
110 | - $s = \OC::$server->query($repairStep); |
|
111 | - } catch (QueryException $e) { |
|
112 | - if (class_exists($repairStep)) { |
|
113 | - $s = new $repairStep(); |
|
114 | - } else { |
|
115 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - if ($s instanceof IRepairStep) { |
|
120 | - $this->repairSteps[] = $s; |
|
121 | - } else { |
|
122 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
123 | - } |
|
124 | - } else { |
|
125 | - $this->repairSteps[] = $repairStep; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Returns the default repair steps to be run on the |
|
131 | - * command line or after an upgrade. |
|
132 | - * |
|
133 | - * @return IRepairStep[] |
|
134 | - */ |
|
135 | - public static function getRepairSteps() { |
|
136 | - return [ |
|
137 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
138 | - new RepairMimeTypes(\OC::$server->getConfig()), |
|
139 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
140 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
141 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
142 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
143 | - new AddLogRotateJob(\OC::$server->getJobList()), |
|
144 | - new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
145 | - new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
146 | - new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
147 | - new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
148 | - new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
149 | - new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
150 | - new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
151 | - \OC::$server->query(RemoveCypressFiles::class), |
|
152 | - ]; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Returns expensive repair steps to be run on the |
|
157 | - * command line with a special option. |
|
158 | - * |
|
159 | - * @return IRepairStep[] |
|
160 | - */ |
|
161 | - public static function getExpensiveRepairSteps() { |
|
162 | - return [ |
|
163 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()) |
|
164 | - ]; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the repair steps to be run before an |
|
169 | - * upgrade. |
|
170 | - * |
|
171 | - * @return IRepairStep[] |
|
172 | - */ |
|
173 | - public static function getBeforeUpgradeRepairSteps() { |
|
174 | - $connection = \OC::$server->getDatabaseConnection(); |
|
175 | - $config = \OC::$server->getConfig(); |
|
176 | - $steps = [ |
|
177 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
178 | - new SqliteAutoincrement($connection), |
|
179 | - new SaveAccountsTableData($connection, $config), |
|
180 | - new DropAccountTermsTable($connection) |
|
181 | - ]; |
|
182 | - |
|
183 | - return $steps; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param string $scope |
|
188 | - * @param string $method |
|
189 | - * @param array $arguments |
|
190 | - */ |
|
191 | - public function emit($scope, $method, array $arguments = []) { |
|
192 | - if (!is_null($this->dispatcher)) { |
|
193 | - $this->dispatcher->dispatch("$scope::$method", |
|
194 | - new GenericEvent("$scope::$method", $arguments)); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - public function info($string) { |
|
199 | - // for now just emit as we did in the past |
|
200 | - $this->emit('\OC\Repair', 'info', array($string)); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param string $message |
|
205 | - */ |
|
206 | - public function warning($message) { |
|
207 | - // for now just emit as we did in the past |
|
208 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @param int $max |
|
213 | - */ |
|
214 | - public function startProgress($max = 0) { |
|
215 | - // for now just emit as we did in the past |
|
216 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @param int $step |
|
221 | - * @param string $description |
|
222 | - */ |
|
223 | - public function advance($step = 1, $description = '') { |
|
224 | - // for now just emit as we did in the past |
|
225 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @param int $max |
|
230 | - */ |
|
231 | - public function finishProgress() { |
|
232 | - // for now just emit as we did in the past |
|
233 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
234 | - } |
|
64 | + /** @var IRepairStep[] */ |
|
65 | + private $repairSteps; |
|
66 | + |
|
67 | + /** @var EventDispatcherInterface */ |
|
68 | + private $dispatcher; |
|
69 | + |
|
70 | + /** @var string */ |
|
71 | + private $currentStep; |
|
72 | + |
|
73 | + /** |
|
74 | + * Creates a new repair step runner |
|
75 | + * |
|
76 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
77 | + * @param EventDispatcherInterface $dispatcher |
|
78 | + */ |
|
79 | + public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
80 | + $this->repairSteps = $repairSteps; |
|
81 | + $this->dispatcher = $dispatcher; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Run a series of repair steps for common problems |
|
86 | + */ |
|
87 | + public function run() { |
|
88 | + if (count($this->repairSteps) === 0) { |
|
89 | + $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
90 | + |
|
91 | + return; |
|
92 | + } |
|
93 | + // run each repair step |
|
94 | + foreach ($this->repairSteps as $step) { |
|
95 | + $this->currentStep = $step->getName(); |
|
96 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
97 | + $step->run($this); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Add repair step |
|
103 | + * |
|
104 | + * @param IRepairStep|string $repairStep repair step |
|
105 | + * @throws \Exception |
|
106 | + */ |
|
107 | + public function addStep($repairStep) { |
|
108 | + if (is_string($repairStep)) { |
|
109 | + try { |
|
110 | + $s = \OC::$server->query($repairStep); |
|
111 | + } catch (QueryException $e) { |
|
112 | + if (class_exists($repairStep)) { |
|
113 | + $s = new $repairStep(); |
|
114 | + } else { |
|
115 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + if ($s instanceof IRepairStep) { |
|
120 | + $this->repairSteps[] = $s; |
|
121 | + } else { |
|
122 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
123 | + } |
|
124 | + } else { |
|
125 | + $this->repairSteps[] = $repairStep; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Returns the default repair steps to be run on the |
|
131 | + * command line or after an upgrade. |
|
132 | + * |
|
133 | + * @return IRepairStep[] |
|
134 | + */ |
|
135 | + public static function getRepairSteps() { |
|
136 | + return [ |
|
137 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
138 | + new RepairMimeTypes(\OC::$server->getConfig()), |
|
139 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
140 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
141 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
142 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
143 | + new AddLogRotateJob(\OC::$server->getJobList()), |
|
144 | + new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
145 | + new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
146 | + new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
147 | + new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
148 | + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
149 | + new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
150 | + new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
151 | + \OC::$server->query(RemoveCypressFiles::class), |
|
152 | + ]; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Returns expensive repair steps to be run on the |
|
157 | + * command line with a special option. |
|
158 | + * |
|
159 | + * @return IRepairStep[] |
|
160 | + */ |
|
161 | + public static function getExpensiveRepairSteps() { |
|
162 | + return [ |
|
163 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()) |
|
164 | + ]; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the repair steps to be run before an |
|
169 | + * upgrade. |
|
170 | + * |
|
171 | + * @return IRepairStep[] |
|
172 | + */ |
|
173 | + public static function getBeforeUpgradeRepairSteps() { |
|
174 | + $connection = \OC::$server->getDatabaseConnection(); |
|
175 | + $config = \OC::$server->getConfig(); |
|
176 | + $steps = [ |
|
177 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
178 | + new SqliteAutoincrement($connection), |
|
179 | + new SaveAccountsTableData($connection, $config), |
|
180 | + new DropAccountTermsTable($connection) |
|
181 | + ]; |
|
182 | + |
|
183 | + return $steps; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param string $scope |
|
188 | + * @param string $method |
|
189 | + * @param array $arguments |
|
190 | + */ |
|
191 | + public function emit($scope, $method, array $arguments = []) { |
|
192 | + if (!is_null($this->dispatcher)) { |
|
193 | + $this->dispatcher->dispatch("$scope::$method", |
|
194 | + new GenericEvent("$scope::$method", $arguments)); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + public function info($string) { |
|
199 | + // for now just emit as we did in the past |
|
200 | + $this->emit('\OC\Repair', 'info', array($string)); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param string $message |
|
205 | + */ |
|
206 | + public function warning($message) { |
|
207 | + // for now just emit as we did in the past |
|
208 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @param int $max |
|
213 | + */ |
|
214 | + public function startProgress($max = 0) { |
|
215 | + // for now just emit as we did in the past |
|
216 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @param int $step |
|
221 | + * @param string $description |
|
222 | + */ |
|
223 | + public function advance($step = 1, $description = '') { |
|
224 | + // for now just emit as we did in the past |
|
225 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @param int $max |
|
230 | + */ |
|
231 | + public function finishProgress() { |
|
232 | + // for now just emit as we did in the past |
|
233 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
234 | + } |
|
235 | 235 | } |