diff options
Diffstat (limited to 'apps/files_external/lib/Service/DBConfigService.php')
-rw-r--r-- | apps/files_external/lib/Service/DBConfigService.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php index 65995b21cc4..9394924d396 100644 --- a/apps/files_external/lib/Service/DBConfigService.php +++ b/apps/files_external/lib/Service/DBConfigService.php @@ -114,6 +114,38 @@ class DBConfigService { return $this->getMountsFromQuery($query); } + public function modifyMountsOnUserDelete(string $uid): void { + $this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER); + } + + public function modifyMountsOnGroupDelete(string $gid): void { + $this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP); + } + + protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void { + $builder = $this->connection->getQueryBuilder(); + $query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')]) + ->from('external_applicable', 'a') + ->rightJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id')) + ->where($builder->expr()->andX( + $builder->expr()->eq('a.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)), + $builder->expr()->eq('a.value', $builder->createNamedParameter($applicableId)) + ) + ) + ->groupBy(['a.mount_id']); + $stmt = $query->execute(); + $result = $stmt->fetchAll(); + $stmt->closeCursor(); + + foreach ($result as $row) { + if((int)$row['count'] > 1) { + $this->removeApplicable($row['mount_id'], $applicableType, $applicableId); + } else { + $this->removeMount($row['mount_id']); + } + } + } + /** * Get admin defined mounts * |