77 */
88namespace OC ;
99
10- use OC \DB \ConnectionAdapter ;
1110use OC \Repair \AddBruteForceCleanupJob ;
1211use OC \Repair \AddCleanupDeletedUsersBackgroundJob ;
1312use OC \Repair \AddCleanupUpdaterBackupsJob ;
5756use OC \Repair \RepairInvalidShares ;
5857use OC \Repair \RepairLogoDimension ;
5958use OC \Repair \RepairMimeTypes ;
60- use OC \Template \JSCombiner ;
6159use OCA \DAV \Migration \DeleteSchedulingObjects ;
6260use OCA \DAV \Migration \RemoveObjectProperties ;
63- use OCP \AppFramework \QueryException ;
64- use OCP \AppFramework \Utility \ITimeFactory ;
65- use OCP \BackgroundJob \IJobList ;
66- use OCP \Collaboration \Resources \IManager ;
6761use OCP \EventDispatcher \IEventDispatcher ;
68- use OCP \Files \AppData \IAppDataFactory ;
69- use OCP \IAppConfig ;
70- use OCP \ICacheFactory ;
7162use OCP \IConfig ;
7263use OCP \IDBConnection ;
73- use OCP \IGroupManager ;
74- use OCP \IUserManager ;
7564use OCP \Migration \IOutput ;
7665use OCP \Migration \IRepairStep ;
77- use OCP \Notification \IManager as INotificationManager ;
7866use OCP \Server ;
67+ use Psr \Container \ContainerExceptionInterface ;
7968use Psr \Log \LoggerInterface ;
8069use Throwable ;
8170
8271class Repair implements IOutput {
83- /** @var IRepairStep[] */
72+ /** @var list< IRepairStep> */
8473 private array $ repairSteps = [];
8574
8675 private string $ currentStep ;
8776
8877 public function __construct (
89- private IEventDispatcher $ dispatcher ,
90- private LoggerInterface $ logger ,
78+ private readonly IEventDispatcher $ dispatcher ,
79+ private readonly LoggerInterface $ logger ,
9180 ) {
9281 }
9382
94- /** @param IRepairStep[] $repairSteps */
83+ /** @param list< IRepairStep> $repairSteps */
9584 public function setRepairSteps (array $ repairSteps ): void {
9685 $ this ->repairSteps = $ repairSteps ;
9786 }
9887
9988 /**
10089 * Run a series of repair steps for common problems
10190 */
102- public function run () {
91+ public function run (): void {
10392 if (count ($ this ->repairSteps ) === 0 ) {
10493 $ this ->dispatcher ->dispatchTyped (new RepairInfoEvent ('No repair steps available ' ));
10594
@@ -123,19 +112,19 @@ public function run() {
123112 /**
124113 * Add repair step
125114 *
126- * @param IRepairStep|string $repairStep repair step
115+ * @param IRepairStep|class- string<IRepairStep> $repairStep repair step
127116 * @throws \Exception
128117 */
129- public function addStep ($ repairStep ) {
118+ public function addStep (IRepairStep | string $ repairStep ): void {
130119 if (is_string ($ repairStep )) {
131120 try {
132121 $ s = Server::get ($ repairStep );
133- } catch (QueryException $ e ) {
122+ } catch (ContainerExceptionInterface $ e ) {
134123 if (class_exists ($ repairStep )) {
135124 try {
136125 // Last resort: hope there are no constructor arguments
137126 $ s = new $ repairStep ();
138- } catch (Throwable $ inner ) {
127+ } catch (Throwable ) {
139128 // Well, it was worth a try
140129 throw new \Exception ("Repair step ' $ repairStep' can't be instantiated: " . $ e ->getMessage (), 0 , $ e );
141130 }
@@ -158,35 +147,28 @@ public function addStep($repairStep) {
158147 * Returns the default repair steps to be run on the
159148 * command line or after an upgrade.
160149 *
161- * @return IRepairStep[]
150+ * @return list< IRepairStep>
162151 */
163152 public static function getRepairSteps (): array {
164153 return [
165154 new Collation (Server::get (IConfig::class), Server::get (LoggerInterface::class), Server::get (IDBConnection::class), false ),
166- new CleanTags (Server::get (IDBConnection::class), Server::get (IUserManager::class)),
167- new RepairInvalidShares (Server::get (IConfig::class), Server::get (IDBConnection::class)),
168- new MoveUpdaterStepFile (Server::get (IConfig::class)),
169- new MoveAvatars (
170- Server::get (IJobList::class),
171- Server::get (IConfig::class)
172- ),
173- new CleanPreviews (
174- Server::get (IJobList::class),
175- Server::get (IUserManager::class),
176- Server::get (IConfig::class)
177- ),
155+ Server::get (CleanTags::class),
156+ Server::get (RepairInvalidShares::class),
157+ Server::get (MoveUpdaterStepFile::class),
158+ Server::get (MoveAvatars::class),
159+ Server::get (CleanPreviews::class),
178160 Server::get (MigratePropertiesTable::class),
179161 Server::get (MigrateOauthTables::class),
180- new UpdateLanguageCodes ( Server::get (IDBConnection ::class), Server:: get (IConfig::class) ),
181- new AddLogRotateJob ( Server::get (IJobList ::class) ),
182- new ClearFrontendCaches ( Server::get (ICacheFactory ::class), Server:: get (JSCombiner::class) ),
162+ Server::get (UpdateLanguageCodes ::class),
163+ Server::get (AddLogRotateJob ::class),
164+ Server::get (ClearFrontendCaches ::class),
183165 Server::get (ClearGeneratedAvatarCache::class),
184- new AddPreviewBackgroundCleanupJob ( Server::get (IJobList ::class) ),
185- new AddCleanupUpdaterBackupsJob ( Server::get (IJobList ::class) ),
186- new CleanupCardDAVPhotoCache ( Server::get (IConfig ::class), Server:: get (IAppDataFactory::class), Server:: get (LoggerInterface::class) ),
187- new AddClenupLoginFlowV2BackgroundJob ( Server::get (IJobList ::class) ),
188- new RemoveLinkShares ( Server::get (IDBConnection ::class), Server:: get (IConfig::class), Server:: get (IGroupManager::class), Server:: get (INotificationManager::class), Server:: get (ITimeFactory::class) ),
189- new ClearCollectionsAccessCache ( Server::get (IConfig ::class), Server:: get (IManager::class) ),
166+ Server::get (AddPreviewBackgroundCleanupJob ::class),
167+ Server::get (AddCleanupUpdaterBackupsJob ::class),
168+ Server::get (CleanupCardDAVPhotoCache ::class),
169+ Server::get (AddClenupLoginFlowV2BackgroundJob ::class),
170+ Server::get (RemoveLinkShares ::class),
171+ Server::get (ClearCollectionsAccessCache ::class),
190172 Server::get (ResetGeneratedAvatarFlag::class),
191173 Server::get (EncryptionLegacyCipher::class),
192174 Server::get (EncryptionMigration::class),
@@ -213,17 +195,13 @@ public static function getRepairSteps(): array {
213195 * Returns expensive repair steps to be run on the
214196 * command line with a special option.
215197 *
216- * @return IRepairStep[]
198+ * @return list< IRepairStep>
217199 */
218- public static function getExpensiveRepairSteps () {
200+ public static function getExpensiveRepairSteps (): array {
219201 return [
220- new OldGroupMembershipShares (Server::get (IDBConnection::class), Server::get (IGroupManager::class)),
221- new RemoveBrokenProperties (Server::get (IDBConnection::class)),
222- new RepairMimeTypes (
223- Server::get (IConfig::class),
224- Server::get (IAppConfig::class),
225- Server::get (IDBConnection::class)
226- ),
202+ Server::get (OldGroupMembershipShares::class),
203+ Server::get (RemoveBrokenProperties::class),
204+ Server::get (RepairMimeTypes::class),
227205 Server::get (DeleteSchedulingObjects::class),
228206 Server::get (RemoveObjectProperties::class),
229207 ];
@@ -233,19 +211,14 @@ public static function getExpensiveRepairSteps() {
233211 * Returns the repair steps to be run before an
234212 * upgrade.
235213 *
236- * @return IRepairStep[]
214+ * @return list< IRepairStep>
237215 */
238- public static function getBeforeUpgradeRepairSteps () {
239- /** @var ConnectionAdapter $connectionAdapter */
240- $ connectionAdapter = Server::get (ConnectionAdapter::class);
241- $ config = Server::get (IConfig::class);
242- $ steps = [
243- new Collation (Server::get (IConfig::class), Server::get (LoggerInterface::class), $ connectionAdapter , true ),
244- new SaveAccountsTableData ($ connectionAdapter , $ config ),
245- new DropAccountTermsTable ($ connectionAdapter ),
216+ public static function getBeforeUpgradeRepairSteps (): array {
217+ return [
218+ new Collation (Server::get (IConfig::class), Server::get (LoggerInterface::class), Server::get (IDBConnection::class), true ),
219+ Server::get (SaveAccountsTableData::class),
220+ Server::get (DropAccountTermsTable::class),
246221 ];
247-
248- return $ steps ;
249222 }
250223
251224 public function debug (string $ message ): void {
@@ -254,23 +227,23 @@ public function debug(string $message): void {
254227 /**
255228 * @param string $message
256229 */
257- public function info ($ message ) {
230+ public function info ($ message ): void {
258231 // for now just emit as we did in the past
259232 $ this ->dispatcher ->dispatchTyped (new RepairInfoEvent ($ message ));
260233 }
261234
262235 /**
263236 * @param string $message
264237 */
265- public function warning ($ message ) {
238+ public function warning ($ message ): void {
266239 // for now just emit as we did in the past
267240 $ this ->dispatcher ->dispatchTyped (new RepairWarningEvent ($ message ));
268241 }
269242
270243 /**
271244 * @param int $max
272245 */
273- public function startProgress ($ max = 0 ) {
246+ public function startProgress ($ max = 0 ): void {
274247 // for now just emit as we did in the past
275248 $ this ->dispatcher ->dispatchTyped (new RepairStartEvent ($ max , $ this ->currentStep ));
276249 }
@@ -279,15 +252,12 @@ public function startProgress($max = 0) {
279252 * @param int $step number of step to advance
280253 * @param string $description
281254 */
282- public function advance ($ step = 1 , $ description = '' ) {
255+ public function advance ($ step = 1 , $ description = '' ): void {
283256 // for now just emit as we did in the past
284257 $ this ->dispatcher ->dispatchTyped (new RepairAdvanceEvent ($ step , $ description ));
285258 }
286259
287- /**
288- * @param int $max
289- */
290- public function finishProgress () {
260+ public function finishProgress (): void {
291261 // for now just emit as we did in the past
292262 $ this ->dispatcher ->dispatchTyped (new RepairFinishEvent ());
293263 }
0 commit comments