@@ -38,101 +38,101 @@ |
||
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.8', '<') |
|
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.8', '<') |
|
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 | } |