Skip to content

Commit ece2857

Browse files
committed
add feature to update some columns (skip check constraint on update)
1 parent bc6a197 commit ece2857

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/models/EntityImport.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,18 @@ public function onRow(Row $row)
6262
$newData = array();
6363
$updatedData = array();
6464

65+
$hasNotNULL = false;
66+
//check not NULL columns
6567
foreach ($this->notNullColumnNames as $notNullColumn) {
68+
//if there is not the column in the row
6669
if (!isset($row[$notNullColumn])) {
67-
unset($row);
70+
$hasNotNULL = true;
6871
}
6972
}
7073

7174
if (!empty($row[$this->key])) {
7275
$exists = $this->model->where($this->key, '=', $row[$this->key])->count();
73-
if (!$exists) {
76+
if (!$exists && !$hasNotNULL) {
7477
$values = array();
7578
foreach ($this->columns as $col) {
7679
if ($col != $this->key && array_key_exists($col, $row)) {
@@ -96,9 +99,11 @@ public function onRow(Row $row)
9699
// update available data
97100
if (!empty($updatedData)) {
98101
foreach ($updatedData as $data) {
99-
$keyValue = $data[$this->key];
102+
$keyValue = (int)$data[$this->key];
100103
unset($data[$this->key]);
101-
$this->model->where($this->key, $keyValue)->update($data);
104+
try{
105+
$this->model->where($this->key, $keyValue)->update($data);
106+
}catch (\Exception $e){}
102107
}
103108
}
104109
}

0 commit comments

Comments
 (0)