Skip to content

Commit

Permalink
Merge pull request #404 from RezaAb/master
Browse files Browse the repository at this point in the history
fix some bugs on Import data
  • Loading branch information
AlirezaAlgo authored Mar 1, 2020
2 parents ebb95af + ece2857 commit 02b71f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/controllers/ExportImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function import($entity) {

$filePath = null;
if (Input::hasFile('import_file') && Input::file('import_file')->isValid()) {
$filePath = Input::file('import_file')->getRealPath();
$pathTemp = Input::file('import_file')->store('temp');
$filePath = storage_path('app').'/'.$pathTemp;
}

if ($filePath)
Expand Down
13 changes: 9 additions & 4 deletions src/models/EntityImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ public function onRow(Row $row)
$newData = array();
$updatedData = array();

$hasNotNULL = false;
//check not NULL columns
foreach ($this->notNullColumnNames as $notNullColumn) {
//if there is not the column in the row
if (!isset($row[$notNullColumn])) {
unset($row);
$hasNotNULL = true;
}
}

if (!empty($row[$this->key])) {
$exists = $this->model->where($this->key, '=', $row[$this->key])->count();
if (!$exists) {
if (!$exists && !$hasNotNULL) {
$values = array();
foreach ($this->columns as $col) {
if ($col != $this->key && array_key_exists($col, $row)) {
Expand All @@ -96,9 +99,11 @@ public function onRow(Row $row)
// update available data
if (!empty($updatedData)) {
foreach ($updatedData as $data) {
$keyValue = $data[$this->key];
$keyValue = (int)$data[$this->key];
unset($data[$this->key]);
$this->model->where($this->key, $keyValue)->update($data);
try{
$this->model->where($this->key, $keyValue)->update($data);
}catch (\Exception $e){}
}
}
}
Expand Down

0 comments on commit 02b71f9

Please sign in to comment.