fix: replace only missing uploads with dummy document

This commit is contained in:
fromme committed 2026-09-26 12:13:16 +02:00
1 parent 69b8e549ee
commit 80c6016da3
2 files changed
+72 -31

No files matched your search

+22 -6
View File
@@ -164,24 +164,40 @@ class UploadHandler
}
/**
* Returns the upload file path, substituting the stand-in document while the
* upload_replacement feature is on. Use this for read-only access (downloads, email
* attachments); getUploadFilepath() stays the real location and is what writes target.
* Returns the upload file path, falling back to the stand-in document when the real file is
* missing and the upload_replacement feature is on.
*
* Environments other than prod run on anonymized copies of the production database but never
* carry over the uploaded files, so most rows point at a file that is not there. The stand-in
* fills exactly that gap: a file that is present - one uploaded while testing - is always
* served as it is, which is what keeps the upload flow exercisable.
*
* Use this for read-only access (downloads, email attachments); getUploadFilepath() stays the
* real location and is what writes target.
*/
public function getResolvedUploadFilepath(Upload $upload): string
{
$originalPath = $this->getUploadFilepath($upload);
if (true === file_exists($originalPath)) {
return $originalPath;
}
if (false === $this->featureManager->isActive('upload_replacement')) {
return $this->getUploadFilepath($upload);
return $originalPath;
}
$replacementPath = sprintf('%s/%s', $this->projectDir, $this->uploadReplacementFile);
if (false === file_exists($replacementPath)) {
// Falling back to the real document here is what made the old behaviour opaque: the
// feature would look active and quietly serve the genuine file instead.
throw new \RuntimeException('Upload replacement file not found at '.$replacementPath);
}
$this->logger->info('Serving upload replacement', [
'file_id' => $upload->getId(),
'missing_path' => $originalPath,
]);
return $replacementPath;
}