diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-10-19 15:39:39 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-10-29 09:26:26 +0100 |
commit | ca2fd3007343dc4ba10d2b9d5e44ada0340d90cc (patch) | |
tree | 67f34ff6161b63c6b797843cd1fc37a60bee9b31 /lib | |
parent | 527ef76dd6e45c2776edbc90829323e0ca534214 (diff) | |
download | nextcloud-server-ca2fd3007343dc4ba10d2b9d5e44ada0340d90cc.tar.gz nextcloud-server-ca2fd3007343dc4ba10d2b9d5e44ada0340d90cc.zip |
Remove shares where the parent does not exist anymore
Diffstat (limited to 'lib')
-rw-r--r-- | lib/repair/repairinvalidshares.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/repair/repairinvalidshares.php b/lib/repair/repairinvalidshares.php index 4b0aeb70c12..5a4cb445ce9 100644 --- a/lib/repair/repairinvalidshares.php +++ b/lib/repair/repairinvalidshares.php @@ -70,11 +70,43 @@ class RepairInvalidShares extends BasicEmitter implements \OC\RepairStep { } } + /** + * Remove shares where the parent share does not exist anymore + */ + private function removeSharesNonExistingParent() { + $deletedEntries = 0; + + $query = $this->connection->getQueryBuilder(); + $query->select('s1.parent') + ->from('share', 's1') + ->where($query->expr()->isNotNull('s1.parent')) + ->andWhere($query->expr()->isNull('s2.id')) + ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id')) + ->groupBy('s1.parent'); + + $deleteQuery = $this->connection->getQueryBuilder(); + $deleteQuery->delete('share') + ->where($query->expr()->eq('parent', $deleteQuery->createParameter('parent'))); + + $result = $query->execute(); + while ($row = $result->fetch()) { + $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent']) + ->execute(); + } + $result->closeCursor(); + + if ($deletedEntries) { + $this->emit('\OC\Repair', 'info', array('Removed ' . $deletedEntries . ' shares where the parent did not exist')); + } + } + public function run() { $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.7', '<')) { // this situation was only possible before 8.2 $this->removeExpirationDateFromNonLinkShares(); } + + $this->removeSharesNonExistingParent(); } } |