Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Delete file versions entries in DB when node is deleted
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Jan 26, 2023
commit 1adc9d2aabeb773c291f718f508a15ecfb1c4d85
9 changes: 9 additions & 0 deletions apps/files_versions/lib/Db/VersionsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Files_Versions\Db\VersionEntity;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\IResult;

/**
* @extends QBMapper<VersionEntity>
Expand Down Expand Up @@ -61,4 +62,12 @@ public function findVersionForFileId(int $fileId, int $timestamp): VersionEntity

return $this->findEntity($qb);
}

public function deleteAllVersionsForFileId(int $fileId): int {
$qb = $this->db->getQueryBuilder();

return $qb->delete($this->getTableName())
->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId)))
->executeStatement();
}
}
1 change: 1 addition & 0 deletions apps/files_versions/lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function post_write_hook(Node $node): void {
public function remove_hook(Node $node): void {
$path = $this->userFolder->getRelativePath($node->getPath());
Storage::delete($path);
$this->versionsMapper->deleteAllVersionsForFileId($node->getId());
}

/**
Expand Down