[DEV-367] Use FileDownloader instead of fopen

This commit is contained in:
Maxi Redigonda 2022-06-03 16:42:57 -03:00
parent 68b2d2bf63
commit 40016635a8
2 changed files with 15 additions and 2 deletions

View File

@ -52,10 +52,13 @@ class CSVImportController extends Controller {
throw new RequestException(ERRORS::INVALID_FILE);
}
$file = fopen($fileUploader->getFullFilePath(),'r');
$fileDownloader = FileDownloader::getInstance();
$fileDownloader->setFileName($fileUploader->getFileName());
$file = $fileDownloader->fopen();
$errors = [];
while(($user = fgetcsv($file)) != false) {
while($file && ($user = fgetcsv($file)) != false) {
Controller::setDataRequester(function ($key) use ($user) {
switch ($key) {
case 'email':

View File

@ -23,6 +23,16 @@ class FileDownloader extends FileManager {
}
}
public function fopen() {
$fullFilePath = $this->getFullFilePath();
if(file_exists($fullFilePath) && is_file($fullFilePath)) {
return fopen($fullFilePath, 'r');
} else {
return false;
}
}
public function eraseFile() {
unlink($this->getLocalPath() . $this->getFileName());
}