Skip to content

Commit

Permalink
[DEV-367] Use FileDownloader instead of fopen
Browse files Browse the repository at this point in the history
  • Loading branch information
mredigonda committed Jun 3, 2022
1 parent 68b2d2b commit 4001663
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server/controllers/system/csv-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ public function handler() {
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':
Expand Down
10 changes: 10 additions & 0 deletions server/libs/FileDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public function download() {
}
}

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());
}
Expand Down

0 comments on commit 4001663

Please sign in to comment.