PHRAS-3519_upload-tmp-then-move

implement atomic (?) "tmp+move" method on uploaded file
add traces of document filesize
This commit is contained in:
jygaulier
2021-09-07 15:48:49 +02:00
parent 88a6506ded
commit d225b381e4
5 changed files with 106 additions and 12 deletions

View File

@@ -1700,12 +1700,31 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$pathhd = $filesystem->generateDataboxDocumentBasePath($databox);
$newname = $filesystem->generateDocumentFilename($record, $file->getFile());
$newname_tmp = $newname.".tmp";
clearstatcache(true, $file->getFile()->getRealPath());
file_put_contents(dirname(__FILE__).'/../../../logs/trace.txt', sprintf("%s [%s] : %s (%s); %s\n", (date('Y-m-d\TH:i:s')), getmypid(), __FILE__, __LINE__,
sprintf("copy \"%s\" to \"%s\"", $file->getFile()->getRealPath(), $pathhd . $newname)
sprintf("copying \"%s\" (size=%s) to \"%s\"", $file->getFile()->getRealPath(), filesize($file->getFile()->getRealPath()), $pathhd . $newname_tmp)
), FILE_APPEND | LOCK_EX);
$filesystem->copy($file->getFile()->getRealPath(), $pathhd . $newname_tmp);
clearstatcache(true, $pathhd . $newname_tmp);
file_put_contents(dirname(__FILE__).'/../../../logs/trace.txt', sprintf("%s [%s] : %s (%s); %s\n", (date('Y-m-d\TH:i:s')), getmypid(), __FILE__, __LINE__,
sprintf("copied \"%s\" to \"%s\" (size=%s)", $file->getFile()->getRealPath(), $pathhd . $newname_tmp, filesize($pathhd . $newname_tmp))
), FILE_APPEND | LOCK_EX);
file_put_contents(dirname(__FILE__).'/../../../logs/trace.txt', sprintf("%s [%s] : %s (%s); %s\n", (date('Y-m-d\TH:i:s')), getmypid(), __FILE__, __LINE__,
sprintf("moving \"%s\" (size=%s) to \"%s\"", $pathhd . $newname_tmp, filesize($pathhd . $newname_tmp), $pathhd . $newname)
), FILE_APPEND | LOCK_EX);
$filesystem->rename($pathhd . $newname_tmp, $pathhd . $newname);
clearstatcache(true, $pathhd . $newname);
file_put_contents(dirname(__FILE__).'/../../../logs/trace.txt', sprintf("%s [%s] : %s (%s); %s\n", (date('Y-m-d\TH:i:s')), getmypid(), __FILE__, __LINE__,
sprintf("moved \"%s\"to \"%s\" (size=%s) ", $pathhd . $newname_tmp, $pathhd . $newname, filesize($pathhd . $newname))
), FILE_APPEND | LOCK_EX);
$filesystem->copy($file->getFile()->getRealPath(), $pathhd . $newname);
$media = $app->getMediaFromUri($pathhd . $newname);
media_subdef::create($app, $record, 'document', $media);