handle the cache where a cache entry with the correct path has already been recreated

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2021-01-26 20:24:30 +01:00 committed by backportbot[bot]
parent 0e790dad31
commit f8346f43f1
1 changed files with 28 additions and 6 deletions

View File

@ -69,6 +69,11 @@ class RepairTree extends Command {
$output->writeln("Path of file ${row['fileid']} is ${row['path']} but should be ${row['parent_path']}/${row['name']} based on it's parent", OutputInterface::VERBOSITY_VERBOSE);
if ($fix) {
$fileId = $this->getFileId($row['parent_storage'], $row['parent_path'] . '/' . $row['name']);
if ($fileId > 0) {
$output->writeln("Cache entry has already be recreated with id $fileId, deleting instead");
$this->deleteById($row['fileid']);
} else {
$query->setParameters([
'fileid' => $row['fileid'],
'path' => $row['parent_path'] . '/' . $row['name'],
@ -77,6 +82,7 @@ class RepairTree extends Command {
$query->execute();
}
}
}
if ($fix) {
$this->connection->commit();
@ -85,6 +91,22 @@ class RepairTree extends Command {
return 0;
}
private function getFileId(int $storage, string $path) {
$query = $this->connection->getQueryBuilder();
$query->select('fileid')
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($storage)))
->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5($path))));
return $query->execute()->fetch(\PDO::FETCH_COLUMN);
}
private function deleteById(int $fileId) {
$query = $this->connection->getQueryBuilder();
$query->delete('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId)));
$query->execute();
}
private function findBrokenTreeBits(): array {
$query = $this->connection->getQueryBuilder();