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