diff --git a/CHANGELOG.md b/CHANGELOG.md index 4642605f2c91be020a718d550415a87ef1c23229..671133fe2669b9b399e58f2b40e82695e2c0071a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - Permettre à l'archiviste de modifier les status PES #1233 - Permettre l'utilisation de `/modules/actes/actes_transac_get_ARActe.php` via API +### Corrections + +- Supprimer l'exception envoyée par actes-enveloppe-menage en cas de fichier semblable déjà présent dans le répertoire sans transaction #1239 + ## 5.0.46 - 2024-11-18 ### Évolutions diff --git a/class/CloudStorage.php b/class/CloudStorage.php index 2f08d5012386538e2f987af1d1f56f9afd3dfc45..027f5f390fdc2038b8eaa2071fcee6136a5fa0e3 100644 --- a/class/CloudStorage.php +++ b/class/CloudStorage.php @@ -327,6 +327,7 @@ class CloudStorage /** * @param mixed $file + * @throws \Exception */ protected function handlerOlderFileNotInCloud(SplFileInfo $file): void { @@ -408,6 +409,10 @@ class CloudStorage private function rename(SplFileInfo $file, string $relative_destination, string $directory): bool { $destination = $directory . '/' . $relative_destination; + if (file_exists($destination) && $this->filesAreSame($destination, $file)) { + unlink($file->getRealPath()); + return true; + } if (file_exists($destination)) { throw new Exception("Le fichier $destination existe déjà "); } @@ -423,4 +428,12 @@ class CloudStorage $destination ); } + + private function filesAreSame(string $destination, SplFileInfo $file): bool + { + if (filesize($destination) !== filesize($file->getRealPath())) { + return false; + } + return sha1_file($destination) === sha1_file($file->getRealPath()); + } } diff --git a/test/PHPUnit/class/CloudStorageTest.php b/test/PHPUnit/class/CloudStorageTest.php index 914b250b46c2eb6060b3e12db54d46e1d5584f37..6cfb6d0772bfe72788e58f96b3f4b8c2f8a111c9 100644 --- a/test/PHPUnit/class/CloudStorageTest.php +++ b/test/PHPUnit/class/CloudStorageTest.php @@ -391,7 +391,7 @@ class CloudStorageTest extends S2lowTestCase /** * @throws \Exception */ - public function testMoveToOrphelinsFileAlreadyExists(): void + public function testMoveToOrphelinsDifferentFileAlreadyExistsWithSameName(): void { $file_to_send = $this->createFile(); $tmpDir = new TmpFolder(); @@ -410,6 +410,31 @@ class CloudStorageTest extends S2lowTestCase $tmpDir->delete($files_without_transaction_dir); } + /** + * @throws \Exception + */ + public function testMoveToOrphelinsSameFileAlreadyExists(): void + { + $file_to_send = $this->createFile(); + $tmpDir = new TmpFolder(); + $files_without_transaction_dir = $tmpDir->create(); + $iCloudStorable = $this->getMailIncludedFilesCloudStorage( + $file_to_send, + $files_without_transaction_dir, + 'bar.txt' + ); + + file_put_contents( + $files_without_transaction_dir . '/bar.txt', + file_get_contents($file_to_send) + ); + + $this->getCloudStorage($iCloudStorable)->deleteFilesOnDisk(0); + static::assertFileDoesNotExist($file_to_send); //Le fichier original est supprimé + + $tmpDir->delete($files_without_transaction_dir); + } + /** @dataProvider availabilityAndCloudProvider * @throws \Exception */