diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2015-01-15 10:25:54 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2015-01-15 14:43:06 +0100 |
commit | 6769adcd0d1a3ba014f53e42be3655cf73132a8a (patch) | |
tree | 6c45b8fc44d6c5df95fa165d2297c62935bbd7c8 /lib/repair | |
parent | 4c233fef2a05a6e2142f4b619688dca1144a7cd3 (diff) | |
download | nextcloud-server-6769adcd0d1a3ba014f53e42be3655cf73132a8a.tar.gz nextcloud-server-6769adcd0d1a3ba014f53e42be3655cf73132a8a.zip |
Mask table and column names with backticks and add lastInsertID() workaround
Diffstat (limited to 'lib/repair')
-rw-r--r-- | lib/repair/cleantags.php | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/repair/cleantags.php b/lib/repair/cleantags.php index 6aa325df0b6..fdc36c110ba 100644 --- a/lib/repair/cleantags.php +++ b/lib/repair/cleantags.php @@ -40,22 +40,37 @@ class CleanTags extends BasicEmitter implements RepairStep { * Updates the configuration after running an update */ public function run() { + $this->deleteOrphanFileEntries(); + $this->deleteOrphanTagEntries(); + $this->deleteOrphanCategoryEntries(); + } - // Delete tag entries for deleted files + /** + * Delete tag entries for deleted files + */ + protected function deleteOrphanFileEntries() { $this->deleteOrphanEntries( '%d tags for delete files have been removed.', '*PREFIX*vcategory_to_object', 'objid', - '*PREFIX*filecache', 'fileid', 'fileid' + '*PREFIX*filecache', 'fileid', 'path_hash' ); + } - // Delete tag entries for deleted tags + /** + * Delete tag entries for deleted tags + */ + protected function deleteOrphanTagEntries() { $this->deleteOrphanEntries( '%d tag entries for deleted tags have been removed.', '*PREFIX*vcategory_to_object', 'categoryid', '*PREFIX*vcategory', 'id', 'uid' ); + } - // Delete tags that have no entries + /** + * Delete tags that have no entries + */ + protected function deleteOrphanCategoryEntries() { $this->deleteOrphanEntries( '%d tags with no entries have been removed.', '*PREFIX*vcategory', 'id', @@ -81,14 +96,14 @@ class CleanTags extends BasicEmitter implements RepairStep { protected function deleteOrphanEntries($repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { $qb = $this->connection->createQueryBuilder(); - $qb->select('d.' . $deleteId) - ->from($deleteTable, 'd') - ->leftJoin('d', $sourceTable, 's', 'd.' . $deleteId . ' = s.' . $sourceId) + $qb->select('d.`' . $deleteId . '`') + ->from('`' . $deleteTable . '`', 'd') + ->leftJoin('d', '`' . $sourceTable . '`', 's', 'd.`' . $deleteId . '` = s.`' . $sourceId . '`') ->where( - 'd.type = ' . $qb->expr()->literal('files') + 'd.`type` = ' . $qb->expr()->literal('files') ) ->andWhere( - $qb->expr()->isNull('s.' . $sourceNullColumn) + $qb->expr()->isNull('s.`' . $sourceNullColumn . '`') ); $result = $qb->execute(); @@ -100,8 +115,11 @@ class CleanTags extends BasicEmitter implements RepairStep { if (!empty($orphanItems)) { $orphanItemsBatch = array_chunk($orphanItems, 200); foreach ($orphanItemsBatch as $items) { - $qb->delete($deleteTable) - ->where($qb->expr()->in($deleteId, ':ids')); + $qb->delete('`' . $deleteTable . '`') + ->where( + '`type` = ' . $qb->expr()->literal('files') + ) + ->andWhere($qb->expr()->in('`' . $deleteId . '`', ':ids')); $qb->setParameter('ids', $items, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY); $qb->execute(); } |