diff options
-rw-r--r-- | apps/files_versions/lib/Command/CleanUp.php | 3 | ||||
-rw-r--r-- | apps/files_versions/lib/Db/VersionsMapper.php | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/apps/files_versions/lib/Command/CleanUp.php b/apps/files_versions/lib/Command/CleanUp.php index 519b3689a58..be66ce8ffb3 100644 --- a/apps/files_versions/lib/Command/CleanUp.php +++ b/apps/files_versions/lib/Command/CleanUp.php @@ -24,6 +24,7 @@ */ namespace OCA\Files_Versions\Command; +use OCA\Files_Versions\Db\VersionsMapper; use OCP\Files\IRootFolder; use OCP\IUserBackend; use OCP\IUserManager; @@ -37,6 +38,7 @@ class CleanUp extends Command { public function __construct( protected IRootFolder $rootFolder, protected IUserManager $userManager, + protected VersionsMapper $versionMapper, ) { parent::__construct(); } @@ -120,6 +122,7 @@ class CleanUp extends Command { \OC_Util::setupFS($user); $fullPath = '/' . $user . '/files_versions' . ($path ? '/' . $path : ''); + $this->versionMapper->deleteAllVersionsForUser($user); if ($this->rootFolder->nodeExists($fullPath)) { $this->rootFolder->get($fullPath)->delete(); } diff --git a/apps/files_versions/lib/Db/VersionsMapper.php b/apps/files_versions/lib/Db/VersionsMapper.php index bc6e8b264de..9b5d7a52c13 100644 --- a/apps/files_versions/lib/Db/VersionsMapper.php +++ b/apps/files_versions/lib/Db/VersionsMapper.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCA\Files_Versions\Db; use OCP\AppFramework\Db\QBMapper; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; /** @@ -83,4 +84,20 @@ class VersionsMapper extends QBMapper { ->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId))) ->executeStatement(); } + + public function deleteAllVersionsForUser(string $userId): int { + $deleteQuery = $this->db->getQueryBuilder(); + $filesVersionSelect = $this->db->getQueryBuilder(); + $filesVersionSelect->select('fileid') + ->from('filecache', 'f') + ->join('f', 'mounts', 'm', $filesVersionSelect->expr()->eq('f.storage', 'm.storage_id')) + ->where($filesVersionSelect->expr()->like('f.path', $deleteQuery->createNamedParameter('files/%', IQueryBuilder::PARAM_STR))) + ->andWhere($filesVersionSelect->expr()->eq('m.user_id', $deleteQuery->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) + ->andWhere($filesVersionSelect->expr()->eq('m.mount_point', $deleteQuery->createNamedParameter("/$userId/", IQueryBuilder::PARAM_STR))); + + $deleteQuery->delete($this->getTableName()) + ->where($deleteQuery->expr()->in('file_id', $deleteQuery->createFunction($filesVersionSelect->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)); + + return $deleteQuery->executeStatement(); + } } |