summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Service
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2019-12-04 15:28:57 +0100
committerGitHub <noreply@github.com>2019-12-04 15:28:57 +0100
commit254d4e096427bf6c8219247b1e1186e626478914 (patch)
treefc14f199d6436bec611232f1b3aa7f85a1c9df61 /apps/files_external/lib/Service
parent81b919ed9f497c975d1b8158abdcdabb0712f39e (diff)
parent4baab51f4ccdf44399f656e5a5acf89d1f6b779b (diff)
downloadnextcloud-server-254d4e096427bf6c8219247b1e1186e626478914.tar.gz
nextcloud-server-254d4e096427bf6c8219247b1e1186e626478914.zip
Merge pull request #17920 from nextcloud/fix/15258/ext-storage-respect-deletion
when a user was deleted remove them from applicable list, unless...
Diffstat (limited to 'apps/files_external/lib/Service')
-rw-r--r--apps/files_external/lib/Service/DBConfigService.php32
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
*