Passed
Push — master ( e55862...5c6d24 )
by Roeland
13:20 queued 11s
created
lib/private/Repair/RepairDavShares.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -38,101 +38,101 @@
 block discarded – undo
38 38
 use function urlencode;
39 39
 
40 40
 class RepairDavShares implements IRepairStep {
41
-	protected const GROUP_PRINCIPAL_PREFIX = 'principals/groups/';
41
+    protected const GROUP_PRINCIPAL_PREFIX = 'principals/groups/';
42 42
 
43
-	/** @var IConfig */
44
-	private $config;
45
-	/** @var IDBConnection */
46
-	private $dbc;
47
-	/** @var IGroupManager */
48
-	private $groupManager;
49
-	/** @var LoggerInterface */
50
-	private $logger;
51
-	/** @var bool */
52
-	private $hintInvalidShares = false;
43
+    /** @var IConfig */
44
+    private $config;
45
+    /** @var IDBConnection */
46
+    private $dbc;
47
+    /** @var IGroupManager */
48
+    private $groupManager;
49
+    /** @var LoggerInterface */
50
+    private $logger;
51
+    /** @var bool */
52
+    private $hintInvalidShares = false;
53 53
 
54
-	public function __construct(
55
-		IConfig $config,
56
-		IDBConnection $dbc,
57
-		IGroupManager $groupManager,
58
-		LoggerInterface $logger
59
-	) {
60
-		$this->config = $config;
61
-		$this->dbc = $dbc;
62
-		$this->groupManager = $groupManager;
63
-		$this->logger = $logger;
64
-	}
54
+    public function __construct(
55
+        IConfig $config,
56
+        IDBConnection $dbc,
57
+        IGroupManager $groupManager,
58
+        LoggerInterface $logger
59
+    ) {
60
+        $this->config = $config;
61
+        $this->dbc = $dbc;
62
+        $this->groupManager = $groupManager;
63
+        $this->logger = $logger;
64
+    }
65 65
 
66
-	/**
67
-	 * @inheritDoc
68
-	 */
69
-	public function getName() {
70
-		return 'Repair DAV shares';
71
-	}
66
+    /**
67
+     * @inheritDoc
68
+     */
69
+    public function getName() {
70
+        return 'Repair DAV shares';
71
+    }
72 72
 
73
-	protected function repairUnencodedGroupShares() {
74
-		$qb = $this->dbc->getQueryBuilder();
75
-		$qb->select(['id', 'principaluri'])
76
-			->from('dav_shares')
77
-			->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX . '%')));
73
+    protected function repairUnencodedGroupShares() {
74
+        $qb = $this->dbc->getQueryBuilder();
75
+        $qb->select(['id', 'principaluri'])
76
+            ->from('dav_shares')
77
+            ->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX . '%')));
78 78
 
79
-		$updateQuery = $this->dbc->getQueryBuilder();
80
-		$updateQuery->update('dav_shares')
81
-			->set('principaluri', $updateQuery->createParameter('updatedPrincipalUri'))
82
-			->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('shareId')));
79
+        $updateQuery = $this->dbc->getQueryBuilder();
80
+        $updateQuery->update('dav_shares')
81
+            ->set('principaluri', $updateQuery->createParameter('updatedPrincipalUri'))
82
+            ->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('shareId')));
83 83
 
84
-		$statement = $qb->execute();
85
-		while ($share = $statement->fetch()) {
86
-			$gid = substr($share['principaluri'], strlen(self::GROUP_PRINCIPAL_PREFIX));
87
-			$decodedGid = urldecode($gid);
88
-			$encodedGid = urlencode($gid);
89
-			if ($gid === $encodedGid
90
-				|| !$this->groupManager->groupExists($gid)
91
-				|| ($gid !== $decodedGid && $this->groupManager->groupExists($decodedGid))
92
-			) {
93
-				$this->hintInvalidShares = $this->hintInvalidShares || $gid !== $encodedGid;
94
-				continue;
95
-			}
84
+        $statement = $qb->execute();
85
+        while ($share = $statement->fetch()) {
86
+            $gid = substr($share['principaluri'], strlen(self::GROUP_PRINCIPAL_PREFIX));
87
+            $decodedGid = urldecode($gid);
88
+            $encodedGid = urlencode($gid);
89
+            if ($gid === $encodedGid
90
+                || !$this->groupManager->groupExists($gid)
91
+                || ($gid !== $decodedGid && $this->groupManager->groupExists($decodedGid))
92
+            ) {
93
+                $this->hintInvalidShares = $this->hintInvalidShares || $gid !== $encodedGid;
94
+                continue;
95
+            }
96 96
 
97
-			// Repair when
98
-			// + the group name needs encoding
99
-			// + AND it is not encoded yet
100
-			// + AND there are no ambivalent groups
97
+            // Repair when
98
+            // + the group name needs encoding
99
+            // + AND it is not encoded yet
100
+            // + AND there are no ambivalent groups
101 101
 
102
-			try {
103
-				$fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX . $encodedGid;
104
-				$logParameters = [
105
-					'app' => 'core',
106
-					'id' => $share['id'],
107
-					'old' => $share['principaluri'],
108
-					'new' => $fixedPrincipal,
109
-				];
110
-				$updateQuery
111
-					->setParameter('updatedPrincipalUri', $fixedPrincipal)
112
-					->setParameter('shareId', $share['id'])
113
-					->execute();
114
-				$this->logger->info('Repaired principal for dav share {id} from {old} to {new}', $logParameters);
115
-			} catch (Exception $e) {
116
-				$logParameters['message'] = $e->getMessage();
117
-				$logParameters['exception'] = $e;
118
-				$this->logger->info('Could not repair principal for dav share {id} from {old} to {new}: {message}', $logParameters);
119
-			}
120
-		}
121
-		return true;
122
-	}
102
+            try {
103
+                $fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX . $encodedGid;
104
+                $logParameters = [
105
+                    'app' => 'core',
106
+                    'id' => $share['id'],
107
+                    'old' => $share['principaluri'],
108
+                    'new' => $fixedPrincipal,
109
+                ];
110
+                $updateQuery
111
+                    ->setParameter('updatedPrincipalUri', $fixedPrincipal)
112
+                    ->setParameter('shareId', $share['id'])
113
+                    ->execute();
114
+                $this->logger->info('Repaired principal for dav share {id} from {old} to {new}', $logParameters);
115
+            } catch (Exception $e) {
116
+                $logParameters['message'] = $e->getMessage();
117
+                $logParameters['exception'] = $e;
118
+                $this->logger->info('Could not repair principal for dav share {id} from {old} to {new}: {message}', $logParameters);
119
+            }
120
+        }
121
+        return true;
122
+    }
123 123
 
124
-	/**
125
-	 * @inheritDoc
126
-	 */
127
-	public function run(IOutput $output) {
128
-		$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
129
-		if (version_compare($versionFromBeforeUpdate, '20.0.7', '<')
130
-			&& $this->repairUnencodedGroupShares()
131
-		) {
132
-			$output->info('Repaired DAV group shares');
133
-			if ($this->hintInvalidShares) {
134
-				$output->info('Invalid shares might be left in the database, running "occ dav:remove-invalid-shares" can remove them.');
135
-			}
136
-		}
137
-	}
124
+    /**
125
+     * @inheritDoc
126
+     */
127
+    public function run(IOutput $output) {
128
+        $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
129
+        if (version_compare($versionFromBeforeUpdate, '20.0.7', '<')
130
+            && $this->repairUnencodedGroupShares()
131
+        ) {
132
+            $output->info('Repaired DAV group shares');
133
+            if ($this->hintInvalidShares) {
134
+                $output->info('Invalid shares might be left in the database, running "occ dav:remove-invalid-shares" can remove them.');
135
+            }
136
+        }
137
+    }
138 138
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		$qb = $this->dbc->getQueryBuilder();
75 75
 		$qb->select(['id', 'principaluri'])
76 76
 			->from('dav_shares')
77
-			->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX . '%')));
77
+			->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX.'%')));
78 78
 
79 79
 		$updateQuery = $this->dbc->getQueryBuilder();
80 80
 		$updateQuery->update('dav_shares')
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			// + AND there are no ambivalent groups
101 101
 
102 102
 			try {
103
-				$fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX . $encodedGid;
103
+				$fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX.$encodedGid;
104 104
 				$logParameters = [
105 105
 					'app' => 'core',
106 106
 					'id' => $share['id'],
Please login to merge, or discard this patch.
lib/private/Repair.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -81,201 +81,201 @@
 block discarded – undo
81 81
 
82 82
 class Repair implements IOutput {
83 83
 
84
-	/** @var IRepairStep[] */
85
-	private $repairSteps;
84
+    /** @var IRepairStep[] */
85
+    private $repairSteps;
86 86
 
87
-	/** @var EventDispatcherInterface */
88
-	private $dispatcher;
87
+    /** @var EventDispatcherInterface */
88
+    private $dispatcher;
89 89
 
90
-	/** @var string */
91
-	private $currentStep;
90
+    /** @var string */
91
+    private $currentStep;
92 92
 
93
-	/**
94
-	 * Creates a new repair step runner
95
-	 *
96
-	 * @param IRepairStep[] $repairSteps array of RepairStep instances
97
-	 * @param EventDispatcherInterface $dispatcher
98
-	 */
99
-	public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) {
100
-		$this->repairSteps = $repairSteps;
101
-		$this->dispatcher = $dispatcher;
102
-	}
93
+    /**
94
+     * Creates a new repair step runner
95
+     *
96
+     * @param IRepairStep[] $repairSteps array of RepairStep instances
97
+     * @param EventDispatcherInterface $dispatcher
98
+     */
99
+    public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) {
100
+        $this->repairSteps = $repairSteps;
101
+        $this->dispatcher = $dispatcher;
102
+    }
103 103
 
104
-	/**
105
-	 * Run a series of repair steps for common problems
106
-	 */
107
-	public function run() {
108
-		if (count($this->repairSteps) === 0) {
109
-			$this->emit('\OC\Repair', 'info', ['No repair steps available']);
104
+    /**
105
+     * Run a series of repair steps for common problems
106
+     */
107
+    public function run() {
108
+        if (count($this->repairSteps) === 0) {
109
+            $this->emit('\OC\Repair', 'info', ['No repair steps available']);
110 110
 
111
-			return;
112
-		}
113
-		// run each repair step
114
-		foreach ($this->repairSteps as $step) {
115
-			$this->currentStep = $step->getName();
116
-			$this->emit('\OC\Repair', 'step', [$this->currentStep]);
117
-			$step->run($this);
118
-		}
119
-	}
111
+            return;
112
+        }
113
+        // run each repair step
114
+        foreach ($this->repairSteps as $step) {
115
+            $this->currentStep = $step->getName();
116
+            $this->emit('\OC\Repair', 'step', [$this->currentStep]);
117
+            $step->run($this);
118
+        }
119
+    }
120 120
 
121
-	/**
122
-	 * Add repair step
123
-	 *
124
-	 * @param IRepairStep|string $repairStep repair step
125
-	 * @throws \Exception
126
-	 */
127
-	public function addStep($repairStep) {
128
-		if (is_string($repairStep)) {
129
-			try {
130
-				$s = \OC::$server->query($repairStep);
131
-			} catch (QueryException $e) {
132
-				if (class_exists($repairStep)) {
133
-					$s = new $repairStep();
134
-				} else {
135
-					throw new \Exception("Repair step '$repairStep' is unknown");
136
-				}
137
-			}
121
+    /**
122
+     * Add repair step
123
+     *
124
+     * @param IRepairStep|string $repairStep repair step
125
+     * @throws \Exception
126
+     */
127
+    public function addStep($repairStep) {
128
+        if (is_string($repairStep)) {
129
+            try {
130
+                $s = \OC::$server->query($repairStep);
131
+            } catch (QueryException $e) {
132
+                if (class_exists($repairStep)) {
133
+                    $s = new $repairStep();
134
+                } else {
135
+                    throw new \Exception("Repair step '$repairStep' is unknown");
136
+                }
137
+            }
138 138
 
139
-			if ($s instanceof IRepairStep) {
140
-				$this->repairSteps[] = $s;
141
-			} else {
142
-				throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
143
-			}
144
-		} else {
145
-			$this->repairSteps[] = $repairStep;
146
-		}
147
-	}
139
+            if ($s instanceof IRepairStep) {
140
+                $this->repairSteps[] = $s;
141
+            } else {
142
+                throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
143
+            }
144
+        } else {
145
+            $this->repairSteps[] = $repairStep;
146
+        }
147
+    }
148 148
 
149
-	/**
150
-	 * Returns the default repair steps to be run on the
151
-	 * command line or after an upgrade.
152
-	 *
153
-	 * @return IRepairStep[]
154
-	 */
155
-	public static function getRepairSteps() {
156
-		return [
157
-			new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false),
158
-			new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
159
-			new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
160
-			new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
161
-			new MoveUpdaterStepFile(\OC::$server->getConfig()),
162
-			new MoveAvatars(
163
-				\OC::$server->getJobList(),
164
-				\OC::$server->getConfig()
165
-			),
166
-			new CleanPreviews(
167
-				\OC::$server->getJobList(),
168
-				\OC::$server->getUserManager(),
169
-				\OC::$server->getConfig()
170
-			),
171
-			new FixMountStorages(\OC::$server->getDatabaseConnection()),
172
-			new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
173
-			new InstallCoreBundle(
174
-				\OC::$server->query(BundleFetcher::class),
175
-				\OC::$server->getConfig(),
176
-				\OC::$server->query(Installer::class)
177
-			),
178
-			new AddLogRotateJob(\OC::$server->getJobList()),
179
-			new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)),
180
-			new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)),
181
-			new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
182
-			new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
183
-			new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()),
184
-			new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
185
-			new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)),
186
-			new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)),
187
-			\OC::$server->query(ResetGeneratedAvatarFlag::class),
188
-			\OC::$server->query(EncryptionLegacyCipher::class),
189
-			\OC::$server->query(EncryptionMigration::class),
190
-			\OC::$server->get(ShippedDashboardEnable::class),
191
-			\OC::$server->get(AddBruteForceCleanupJob::class),
192
-			\OC::$server->get(AddCheckForUserCertificatesJob::class),
193
-			\OC::$server->get(RepairDavShares::class)
194
-		];
195
-	}
149
+    /**
150
+     * Returns the default repair steps to be run on the
151
+     * command line or after an upgrade.
152
+     *
153
+     * @return IRepairStep[]
154
+     */
155
+    public static function getRepairSteps() {
156
+        return [
157
+            new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false),
158
+            new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
159
+            new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
160
+            new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
161
+            new MoveUpdaterStepFile(\OC::$server->getConfig()),
162
+            new MoveAvatars(
163
+                \OC::$server->getJobList(),
164
+                \OC::$server->getConfig()
165
+            ),
166
+            new CleanPreviews(
167
+                \OC::$server->getJobList(),
168
+                \OC::$server->getUserManager(),
169
+                \OC::$server->getConfig()
170
+            ),
171
+            new FixMountStorages(\OC::$server->getDatabaseConnection()),
172
+            new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
173
+            new InstallCoreBundle(
174
+                \OC::$server->query(BundleFetcher::class),
175
+                \OC::$server->getConfig(),
176
+                \OC::$server->query(Installer::class)
177
+            ),
178
+            new AddLogRotateJob(\OC::$server->getJobList()),
179
+            new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)),
180
+            new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)),
181
+            new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
182
+            new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
183
+            new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()),
184
+            new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
185
+            new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)),
186
+            new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)),
187
+            \OC::$server->query(ResetGeneratedAvatarFlag::class),
188
+            \OC::$server->query(EncryptionLegacyCipher::class),
189
+            \OC::$server->query(EncryptionMigration::class),
190
+            \OC::$server->get(ShippedDashboardEnable::class),
191
+            \OC::$server->get(AddBruteForceCleanupJob::class),
192
+            \OC::$server->get(AddCheckForUserCertificatesJob::class),
193
+            \OC::$server->get(RepairDavShares::class)
194
+        ];
195
+    }
196 196
 
197
-	/**
198
-	 * Returns expensive repair steps to be run on the
199
-	 * command line with a special option.
200
-	 *
201
-	 * @return IRepairStep[]
202
-	 */
203
-	public static function getExpensiveRepairSteps() {
204
-		return [
205
-			new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
206
-			\OC::$server->get(ValidatePhoneNumber::class),
207
-		];
208
-	}
197
+    /**
198
+     * Returns expensive repair steps to be run on the
199
+     * command line with a special option.
200
+     *
201
+     * @return IRepairStep[]
202
+     */
203
+    public static function getExpensiveRepairSteps() {
204
+        return [
205
+            new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
206
+            \OC::$server->get(ValidatePhoneNumber::class),
207
+        ];
208
+    }
209 209
 
210
-	/**
211
-	 * Returns the repair steps to be run before an
212
-	 * upgrade.
213
-	 *
214
-	 * @return IRepairStep[]
215
-	 */
216
-	public static function getBeforeUpgradeRepairSteps() {
217
-		/** @var Connection $connection */
218
-		$connection = \OC::$server->get(Connection::class);
219
-		/** @var ConnectionAdapter $connectionAdapter */
220
-		$connectionAdapter = \OC::$server->get(ConnectionAdapter::class);
221
-		$config = \OC::$server->getConfig();
222
-		$steps = [
223
-			new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connectionAdapter, true),
224
-			new SqliteAutoincrement($connection),
225
-			new SaveAccountsTableData($connectionAdapter, $config),
226
-			new DropAccountTermsTable($connectionAdapter),
227
-		];
210
+    /**
211
+     * Returns the repair steps to be run before an
212
+     * upgrade.
213
+     *
214
+     * @return IRepairStep[]
215
+     */
216
+    public static function getBeforeUpgradeRepairSteps() {
217
+        /** @var Connection $connection */
218
+        $connection = \OC::$server->get(Connection::class);
219
+        /** @var ConnectionAdapter $connectionAdapter */
220
+        $connectionAdapter = \OC::$server->get(ConnectionAdapter::class);
221
+        $config = \OC::$server->getConfig();
222
+        $steps = [
223
+            new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connectionAdapter, true),
224
+            new SqliteAutoincrement($connection),
225
+            new SaveAccountsTableData($connectionAdapter, $config),
226
+            new DropAccountTermsTable($connectionAdapter),
227
+        ];
228 228
 
229
-		return $steps;
230
-	}
229
+        return $steps;
230
+    }
231 231
 
232
-	/**
233
-	 * @param string $scope
234
-	 * @param string $method
235
-	 * @param array $arguments
236
-	 */
237
-	public function emit($scope, $method, array $arguments = []) {
238
-		if (!is_null($this->dispatcher)) {
239
-			$this->dispatcher->dispatch("$scope::$method",
240
-				new GenericEvent("$scope::$method", $arguments));
241
-		}
242
-	}
232
+    /**
233
+     * @param string $scope
234
+     * @param string $method
235
+     * @param array $arguments
236
+     */
237
+    public function emit($scope, $method, array $arguments = []) {
238
+        if (!is_null($this->dispatcher)) {
239
+            $this->dispatcher->dispatch("$scope::$method",
240
+                new GenericEvent("$scope::$method", $arguments));
241
+        }
242
+    }
243 243
 
244
-	public function info($string) {
245
-		// for now just emit as we did in the past
246
-		$this->emit('\OC\Repair', 'info', [$string]);
247
-	}
244
+    public function info($string) {
245
+        // for now just emit as we did in the past
246
+        $this->emit('\OC\Repair', 'info', [$string]);
247
+    }
248 248
 
249
-	/**
250
-	 * @param string $message
251
-	 */
252
-	public function warning($message) {
253
-		// for now just emit as we did in the past
254
-		$this->emit('\OC\Repair', 'warning', [$message]);
255
-	}
249
+    /**
250
+     * @param string $message
251
+     */
252
+    public function warning($message) {
253
+        // for now just emit as we did in the past
254
+        $this->emit('\OC\Repair', 'warning', [$message]);
255
+    }
256 256
 
257
-	/**
258
-	 * @param int $max
259
-	 */
260
-	public function startProgress($max = 0) {
261
-		// for now just emit as we did in the past
262
-		$this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
263
-	}
257
+    /**
258
+     * @param int $max
259
+     */
260
+    public function startProgress($max = 0) {
261
+        // for now just emit as we did in the past
262
+        $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
263
+    }
264 264
 
265
-	/**
266
-	 * @param int $step
267
-	 * @param string $description
268
-	 */
269
-	public function advance($step = 1, $description = '') {
270
-		// for now just emit as we did in the past
271
-		$this->emit('\OC\Repair', 'advance', [$step, $description]);
272
-	}
265
+    /**
266
+     * @param int $step
267
+     * @param string $description
268
+     */
269
+    public function advance($step = 1, $description = '') {
270
+        // for now just emit as we did in the past
271
+        $this->emit('\OC\Repair', 'advance', [$step, $description]);
272
+    }
273 273
 
274
-	/**
275
-	 * @param int $max
276
-	 */
277
-	public function finishProgress() {
278
-		// for now just emit as we did in the past
279
-		$this->emit('\OC\Repair', 'finishProgress', []);
280
-	}
274
+    /**
275
+     * @param int $max
276
+     */
277
+    public function finishProgress() {
278
+        // for now just emit as we did in the past
279
+        $this->emit('\OC\Repair', 'finishProgress', []);
280
+    }
281 281
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/Backend.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -36,215 +36,215 @@
 block discarded – undo
36 36
 
37 37
 class Backend {
38 38
 
39
-	/** @var IDBConnection */
40
-	private $db;
41
-	/** @var IUserManager */
42
-	private $userManager;
43
-	/** @var IGroupManager */
44
-	private $groupManager;
45
-	/** @var Principal */
46
-	private $principalBackend;
47
-	/** @var string */
48
-	private $resourceType;
49
-
50
-	public const ACCESS_OWNER = 1;
51
-	public const ACCESS_READ_WRITE = 2;
52
-	public const ACCESS_READ = 3;
53
-
54
-	/**
55
-	 * @param IDBConnection $db
56
-	 * @param IUserManager $userManager
57
-	 * @param IGroupManager $groupManager
58
-	 * @param Principal $principalBackend
59
-	 * @param string $resourceType
60
-	 */
61
-	public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) {
62
-		$this->db = $db;
63
-		$this->userManager = $userManager;
64
-		$this->groupManager = $groupManager;
65
-		$this->principalBackend = $principalBackend;
66
-		$this->resourceType = $resourceType;
67
-	}
68
-
69
-	/**
70
-	 * @param IShareable $shareable
71
-	 * @param string[] $add
72
-	 * @param string[] $remove
73
-	 */
74
-	public function updateShares(IShareable $shareable, array $add, array $remove) {
75
-		foreach ($add as $element) {
76
-			$principal = $this->principalBackend->findByUri($element['href'], '');
77
-			if ($principal !== '') {
78
-				$this->shareWith($shareable, $element);
79
-			}
80
-		}
81
-		foreach ($remove as $element) {
82
-			$principal = $this->principalBackend->findByUri($element, '');
83
-			if ($principal !== '') {
84
-				$this->unshare($shareable, $element);
85
-			}
86
-		}
87
-	}
88
-
89
-	/**
90
-	 * @param IShareable $shareable
91
-	 * @param string $element
92
-	 */
93
-	private function shareWith($shareable, $element) {
94
-		$user = $element['href'];
95
-		$parts = explode(':', $user, 2);
96
-		if ($parts[0] !== 'principal') {
97
-			return;
98
-		}
99
-
100
-		// don't share with owner
101
-		if ($shareable->getOwner() === $parts[1]) {
102
-			return;
103
-		}
104
-
105
-		$principal = explode('/', $parts[1], 3);
106
-		if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups', 'circles'], true)) {
107
-			// Invalid principal
108
-			return;
109
-		}
110
-
111
-		$principal[2] = urldecode($principal[2]);
112
-		if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) ||
113
-			($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) {
114
-			// User or group does not exist
115
-			return;
116
-		}
117
-
118
-		// remove the share if it already exists
119
-		$this->unshare($shareable, $element['href']);
120
-		$access = self::ACCESS_READ;
121
-		if (isset($element['readOnly'])) {
122
-			$access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE;
123
-		}
124
-
125
-		$query = $this->db->getQueryBuilder();
126
-		$query->insert('dav_shares')
127
-			->values([
128
-				'principaluri' => $query->createNamedParameter($parts[1]),
129
-				'type' => $query->createNamedParameter($this->resourceType),
130
-				'access' => $query->createNamedParameter($access),
131
-				'resourceid' => $query->createNamedParameter($shareable->getResourceId())
132
-			]);
133
-		$query->execute();
134
-	}
135
-
136
-	/**
137
-	 * @param $resourceId
138
-	 */
139
-	public function deleteAllShares($resourceId) {
140
-		$query = $this->db->getQueryBuilder();
141
-		$query->delete('dav_shares')
142
-			->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
143
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
144
-			->execute();
145
-	}
146
-
147
-	public function deleteAllSharesByUser($principaluri) {
148
-		$query = $this->db->getQueryBuilder();
149
-		$query->delete('dav_shares')
150
-			->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri)))
151
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
152
-			->execute();
153
-	}
154
-
155
-	/**
156
-	 * @param IShareable $shareable
157
-	 * @param string $element
158
-	 */
159
-	private function unshare($shareable, $element) {
160
-		$parts = explode(':', $element, 2);
161
-		if ($parts[0] !== 'principal') {
162
-			return;
163
-		}
164
-
165
-		// don't share with owner
166
-		if ($shareable->getOwner() === $parts[1]) {
167
-			return;
168
-		}
169
-
170
-		$query = $this->db->getQueryBuilder();
171
-		$query->delete('dav_shares')
172
-			->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId())))
173
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
174
-			->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1])))
175
-		;
176
-		$query->execute();
177
-	}
178
-
179
-	/**
180
-	 * Returns the list of people whom this resource is shared with.
181
-	 *
182
-	 * Every element in this array should have the following properties:
183
-	 *   * href - Often a mailto: address
184
-	 *   * commonName - Optional, for example a first + last name
185
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
186
-	 *   * readOnly - boolean
187
-	 *   * summary - Optional, a description for the share
188
-	 *
189
-	 * @param int $resourceId
190
-	 * @return array
191
-	 */
192
-	public function getShares($resourceId) {
193
-		$query = $this->db->getQueryBuilder();
194
-		$result = $query->select(['principaluri', 'access'])
195
-			->from('dav_shares')
196
-			->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
197
-			->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
198
-			->groupBy(['principaluri', 'access'])
199
-			->execute();
200
-
201
-		$shares = [];
202
-		while ($row = $result->fetch()) {
203
-			$p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
204
-			$shares[] = [
205
-				'href' => "principal:${row['principaluri']}",
206
-				'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '',
207
-				'status' => 1,
208
-				'readOnly' => (int) $row['access'] === self::ACCESS_READ,
209
-				'{http://owncloud.org/ns}principal' => $row['principaluri'],
210
-				'{http://owncloud.org/ns}group-share' => is_null($p)
211
-			];
212
-		}
213
-
214
-		return $shares;
215
-	}
216
-
217
-	/**
218
-	 * For shared resources the sharee is set in the ACL of the resource
219
-	 *
220
-	 * @param int $resourceId
221
-	 * @param array $acl
222
-	 * @return array
223
-	 */
224
-	public function applyShareAcl($resourceId, $acl) {
225
-		$shares = $this->getShares($resourceId);
226
-		foreach ($shares as $share) {
227
-			$acl[] = [
228
-				'privilege' => '{DAV:}read',
229
-				'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
230
-				'protected' => true,
231
-			];
232
-			if (!$share['readOnly']) {
233
-				$acl[] = [
234
-					'privilege' => '{DAV:}write',
235
-					'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
236
-					'protected' => true,
237
-				];
238
-			} elseif ($this->resourceType === 'calendar') {
239
-				// Allow changing the properties of read only calendars,
240
-				// so users can change the visibility.
241
-				$acl[] = [
242
-					'privilege' => '{DAV:}write-properties',
243
-					'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
244
-					'protected' => true,
245
-				];
246
-			}
247
-		}
248
-		return $acl;
249
-	}
39
+    /** @var IDBConnection */
40
+    private $db;
41
+    /** @var IUserManager */
42
+    private $userManager;
43
+    /** @var IGroupManager */
44
+    private $groupManager;
45
+    /** @var Principal */
46
+    private $principalBackend;
47
+    /** @var string */
48
+    private $resourceType;
49
+
50
+    public const ACCESS_OWNER = 1;
51
+    public const ACCESS_READ_WRITE = 2;
52
+    public const ACCESS_READ = 3;
53
+
54
+    /**
55
+     * @param IDBConnection $db
56
+     * @param IUserManager $userManager
57
+     * @param IGroupManager $groupManager
58
+     * @param Principal $principalBackend
59
+     * @param string $resourceType
60
+     */
61
+    public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) {
62
+        $this->db = $db;
63
+        $this->userManager = $userManager;
64
+        $this->groupManager = $groupManager;
65
+        $this->principalBackend = $principalBackend;
66
+        $this->resourceType = $resourceType;
67
+    }
68
+
69
+    /**
70
+     * @param IShareable $shareable
71
+     * @param string[] $add
72
+     * @param string[] $remove
73
+     */
74
+    public function updateShares(IShareable $shareable, array $add, array $remove) {
75
+        foreach ($add as $element) {
76
+            $principal = $this->principalBackend->findByUri($element['href'], '');
77
+            if ($principal !== '') {
78
+                $this->shareWith($shareable, $element);
79
+            }
80
+        }
81
+        foreach ($remove as $element) {
82
+            $principal = $this->principalBackend->findByUri($element, '');
83
+            if ($principal !== '') {
84
+                $this->unshare($shareable, $element);
85
+            }
86
+        }
87
+    }
88
+
89
+    /**
90
+     * @param IShareable $shareable
91
+     * @param string $element
92
+     */
93
+    private function shareWith($shareable, $element) {
94
+        $user = $element['href'];
95
+        $parts = explode(':', $user, 2);
96
+        if ($parts[0] !== 'principal') {
97
+            return;
98
+        }
99
+
100
+        // don't share with owner
101
+        if ($shareable->getOwner() === $parts[1]) {
102
+            return;
103
+        }
104
+
105
+        $principal = explode('/', $parts[1], 3);
106
+        if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups', 'circles'], true)) {
107
+            // Invalid principal
108
+            return;
109
+        }
110
+
111
+        $principal[2] = urldecode($principal[2]);
112
+        if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) ||
113
+            ($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) {
114
+            // User or group does not exist
115
+            return;
116
+        }
117
+
118
+        // remove the share if it already exists
119
+        $this->unshare($shareable, $element['href']);
120
+        $access = self::ACCESS_READ;
121
+        if (isset($element['readOnly'])) {
122
+            $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE;
123
+        }
124
+
125
+        $query = $this->db->getQueryBuilder();
126
+        $query->insert('dav_shares')
127
+            ->values([
128
+                'principaluri' => $query->createNamedParameter($parts[1]),
129
+                'type' => $query->createNamedParameter($this->resourceType),
130
+                'access' => $query->createNamedParameter($access),
131
+                'resourceid' => $query->createNamedParameter($shareable->getResourceId())
132
+            ]);
133
+        $query->execute();
134
+    }
135
+
136
+    /**
137
+     * @param $resourceId
138
+     */
139
+    public function deleteAllShares($resourceId) {
140
+        $query = $this->db->getQueryBuilder();
141
+        $query->delete('dav_shares')
142
+            ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
143
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
144
+            ->execute();
145
+    }
146
+
147
+    public function deleteAllSharesByUser($principaluri) {
148
+        $query = $this->db->getQueryBuilder();
149
+        $query->delete('dav_shares')
150
+            ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri)))
151
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
152
+            ->execute();
153
+    }
154
+
155
+    /**
156
+     * @param IShareable $shareable
157
+     * @param string $element
158
+     */
159
+    private function unshare($shareable, $element) {
160
+        $parts = explode(':', $element, 2);
161
+        if ($parts[0] !== 'principal') {
162
+            return;
163
+        }
164
+
165
+        // don't share with owner
166
+        if ($shareable->getOwner() === $parts[1]) {
167
+            return;
168
+        }
169
+
170
+        $query = $this->db->getQueryBuilder();
171
+        $query->delete('dav_shares')
172
+            ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId())))
173
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
174
+            ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1])))
175
+        ;
176
+        $query->execute();
177
+    }
178
+
179
+    /**
180
+     * Returns the list of people whom this resource is shared with.
181
+     *
182
+     * Every element in this array should have the following properties:
183
+     *   * href - Often a mailto: address
184
+     *   * commonName - Optional, for example a first + last name
185
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
186
+     *   * readOnly - boolean
187
+     *   * summary - Optional, a description for the share
188
+     *
189
+     * @param int $resourceId
190
+     * @return array
191
+     */
192
+    public function getShares($resourceId) {
193
+        $query = $this->db->getQueryBuilder();
194
+        $result = $query->select(['principaluri', 'access'])
195
+            ->from('dav_shares')
196
+            ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
197
+            ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
198
+            ->groupBy(['principaluri', 'access'])
199
+            ->execute();
200
+
201
+        $shares = [];
202
+        while ($row = $result->fetch()) {
203
+            $p = $this->principalBackend->getPrincipalByPath($row['principaluri']);
204
+            $shares[] = [
205
+                'href' => "principal:${row['principaluri']}",
206
+                'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '',
207
+                'status' => 1,
208
+                'readOnly' => (int) $row['access'] === self::ACCESS_READ,
209
+                '{http://owncloud.org/ns}principal' => $row['principaluri'],
210
+                '{http://owncloud.org/ns}group-share' => is_null($p)
211
+            ];
212
+        }
213
+
214
+        return $shares;
215
+    }
216
+
217
+    /**
218
+     * For shared resources the sharee is set in the ACL of the resource
219
+     *
220
+     * @param int $resourceId
221
+     * @param array $acl
222
+     * @return array
223
+     */
224
+    public function applyShareAcl($resourceId, $acl) {
225
+        $shares = $this->getShares($resourceId);
226
+        foreach ($shares as $share) {
227
+            $acl[] = [
228
+                'privilege' => '{DAV:}read',
229
+                'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
230
+                'protected' => true,
231
+            ];
232
+            if (!$share['readOnly']) {
233
+                $acl[] = [
234
+                    'privilege' => '{DAV:}write',
235
+                    'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
236
+                    'protected' => true,
237
+                ];
238
+            } elseif ($this->resourceType === 'calendar') {
239
+                // Allow changing the properties of read only calendars,
240
+                // so users can change the visibility.
241
+                $acl[] = [
242
+                    'privilege' => '{DAV:}write-properties',
243
+                    'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'],
244
+                    'protected' => true,
245
+                ];
246
+            }
247
+        }
248
+        return $acl;
249
+    }
250 250
 }
Please login to merge, or discard this patch.