diff options
author | Louis Chemineau <louis@chmn.me> | 2024-02-01 16:44:57 +0100 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2024-02-01 16:44:57 +0100 |
commit | 1ec9f3e5f9dd84723008137af73cf365beaf4d1b (patch) | |
tree | e95570cbed1661bf7f03886b270ac7d593af8647 /apps | |
parent | 4993dac98fdffd4bb4bb13b6f5f42f4b53489385 (diff) | |
download | nextcloud-server-1ec9f3e5f9dd84723008137af73cf365beaf4d1b.tar.gz nextcloud-server-1ec9f3e5f9dd84723008137af73cf365beaf4d1b.zip |
Cleanup versions entity in during versions:clean command
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps')
-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(); + } } |