From b4a6e233f1b020869234e79787380e9561a5e219 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 29 Sep 2022 07:04:53 +0000 Subject: [PATCH] Delete csv file and directory after processing file. #708 --- src/Command/LoadWarrantySerialCommand.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Command/LoadWarrantySerialCommand.php b/src/Command/LoadWarrantySerialCommand.php index 9abb600e..40c89620 100644 --- a/src/Command/LoadWarrantySerialCommand.php +++ b/src/Command/LoadWarrantySerialCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\Filesystem\Filesystem; use Doctrine\ORM\EntityManagerInterface; @@ -32,15 +33,18 @@ class LoadWarrantySerialCommand extends Command protected $project_dir; protected $callback_url; protected $log_data; + protected $filesystem; public function __construct(EntityManagerInterface $em, WarrantySerialUploadLogger $upload_logger, - WarrantySerialLoadLogger $load_logger, KernelInterface $kernel, $callback_url) + WarrantySerialLoadLogger $load_logger, KernelInterface $kernel, $callback_url, + FileSystem $filesystem) { $this->em = $em; $this->upload_logger = $upload_logger; $this->load_logger = $load_logger; $this->project_dir = $kernel->getProjectDir(); $this->callback_url = $callback_url; + $this->filesystem = $filesystem; parent::__construct(); } @@ -81,7 +85,11 @@ class LoadWarrantySerialCommand extends Command $output_info[] = $this->processWarrantySerialFile($filename, $user_id, $file_id, $orig_filename); + // remove entry from queue table $this->updateWarrantySerialQueue($id); + + // delete the uploaded csv file and directory + $this->deleteDirectoryAndFile($file_id); } if (count($output_info) > 0) @@ -409,6 +417,13 @@ class LoadWarrantySerialCommand extends Command $db->exec('UNLOCK TABLES;'); } + protected function deleteDirectoryAndFile($filedir) + { + $csv_filedir = $this->project_dir . '/public/warranty_serial_uploads/' . $filedir; + + $this->filesystem->remove($csv_filedir); + } + protected function setOutputInfo($filename, $file_id, $has_error, $error_message, $entries, $orig_filename) { $info = [