backend-01

commit cdd979f0f70815d95889cf051dea8d149a916d4b

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

services: introduce mechanism to delete associated file

will be useful when editing a bill, so we can drop the old pdf
associated with that bill and then overwrite it

 app/services/FileUploadingService.php | 12 ++++++++++++


diff --git a/app/services/FileUploadingService.php b/app/services/FileUploadingService.php
index 44c84c231a355da5151a0b9920cf78986959c333..4c8891719194400ed087b3ee2cc42598bce9cd58 100644
--- a/app/services/FileUploadingService.php
+++ b/app/services/FileUploadingService.php
@@ -1,5 +1,8 @@
 <?php
 
+// XXX: Probably could be renamed to FileManagerService instead, but I don't
+// have enough fucks to give right now.
+
 class FileUploadingService {
   const UPLOAD_DIR = __DIR__ . '/../../storage/uploads/';
   private $uploadDir;
@@ -32,6 +35,15 @@       return ['success' => true, 'filePath' => 'storage/uploads/' . $fileName];
     }
 
     return ['success' => false, 'error' => 'Failed to move the uploaded file.'];
+  }
+
+  public function deleteOldFile($filePath) {
+    $fullPath = __DIR__ . '/../../' . $filePath;
+
+    error_log("File exists: " . $fullPath);
+    if (file_exists($fullPath)) {
+      unlink($fullPath);
+    }
   }
 
   private function generateUniqueFileName($prefix, $extension) {