From bc6a197fa03f2229db0902d4f9ebe737fdb0fb1e Mon Sep 17 00:00:00 2001 From: Reza Date: Sun, 1 Mar 2020 15:47:01 +0330 Subject: [PATCH 1/2] fix a bug on uploading excel file for import method --- src/controllers/ExportImportController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/ExportImportController.php b/src/controllers/ExportImportController.php index ab205b4..92bf497 100755 --- a/src/controllers/ExportImportController.php +++ b/src/controllers/ExportImportController.php @@ -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) From ece2857f83e65b4f4bbcf2b003cc11ebaf9380b5 Mon Sep 17 00:00:00 2001 From: Reza Date: Sun, 1 Mar 2020 17:33:24 +0330 Subject: [PATCH 2/2] add feature to update some columns (skip check constraint on update) --- src/models/EntityImport.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/models/EntityImport.php b/src/models/EntityImport.php index 9b24f35..3776d3a 100644 --- a/src/models/EntityImport.php +++ b/src/models/EntityImport.php @@ -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)) { @@ -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){} } } }