fix import
This commit is contained in:
@@ -298,6 +298,9 @@ class Import extends \Espo\Services\Record
|
||||
continue;
|
||||
}
|
||||
$r = $this->importRow($scope, $fields, $arr, $params);
|
||||
if (empty($r)) {
|
||||
continue;
|
||||
}
|
||||
if (!empty($r['isImported'])) {
|
||||
$result['importedIds'][] = $r['id'];
|
||||
}
|
||||
@@ -334,22 +337,36 @@ class Import extends \Espo\Services\Record
|
||||
public function importRow($scope, array $fields, array $row, array $params = array())
|
||||
{
|
||||
$id = null;
|
||||
$action = 'create';
|
||||
if (!empty($params['action'])) {
|
||||
if ($params['action'] == 'createAndUpdate' && in_array('id', $fields)) {
|
||||
$i = array_search('id', $fields);
|
||||
$id = $row[$i];
|
||||
if (empty($id)) {
|
||||
$id = null;
|
||||
}
|
||||
$action = $params['action'];
|
||||
}
|
||||
|
||||
if (in_array($action, ['createAndUpdate', 'update']) && in_array('id', $fields)) {
|
||||
$i = array_search('id', $fields);
|
||||
$id = $row[$i];
|
||||
if (empty($id)) {
|
||||
$id = null;
|
||||
}
|
||||
}
|
||||
|
||||
$recordService = $this->getRecordService($scope);
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($scope, $id);
|
||||
if (!$entity) {
|
||||
if (in_array($action, ['createAndUpdate', 'update'])) {
|
||||
if (!$id) {
|
||||
return;
|
||||
}
|
||||
$entity = $this->getEntityManager()->getEntity($scope, $id);
|
||||
if (!$entity) {
|
||||
if ($action == 'createAndUpdate') {
|
||||
$entity = $this->getEntityManager()->getEntity($scope);
|
||||
$entity->set('id', $id);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$entity = $this->getEntityManager()->getEntity($scope);
|
||||
$entity->set('id', $id);
|
||||
}
|
||||
|
||||
$isNew = $entity->isNew();
|
||||
|
||||
@@ -36,21 +36,50 @@ Espo.define('Views.Import.Detail', 'Views.Detail', function (Dep) {
|
||||
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
|
||||
this.setupMenu();
|
||||
|
||||
this.listenTo(this.model, 'change', function () {
|
||||
this.setupMenu();
|
||||
if (this.isRendered()) {
|
||||
this.getView('header').reRender();
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
||||
setupMenu: function () {
|
||||
if (this.model.get('importedCount')) {
|
||||
this.menu.buttons.unshift({
|
||||
"label": "Revert Import",
|
||||
"action": "revert",
|
||||
"style": "danger",
|
||||
"acl": "edit"
|
||||
});
|
||||
var i = 0;
|
||||
this.menu.buttons.forEach(function (item) {
|
||||
if (item.action == 'revert') {
|
||||
i = 1;
|
||||
}
|
||||
}, this);
|
||||
if (!i) {
|
||||
this.menu.buttons.unshift({
|
||||
"label": "Revert Import",
|
||||
"action": "revert",
|
||||
"style": "danger",
|
||||
"acl": "edit"
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.model.get('duplicateCount')) {
|
||||
this.menu.buttons.unshift({
|
||||
"label": "Remove Duplicates",
|
||||
"action": "removeDuplicates",
|
||||
"style": "default",
|
||||
"acl": "edit"
|
||||
});
|
||||
var i = 0;
|
||||
this.menu.buttons.forEach(function (item) {
|
||||
if (item.action == 'removeDuplicates') {
|
||||
i = 1;
|
||||
}
|
||||
}, this);
|
||||
if (!i) {
|
||||
this.menu.buttons.unshift({
|
||||
"label": "Remove Duplicates",
|
||||
"action": "removeDuplicates",
|
||||
"style": "default",
|
||||
"acl": "edit"
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user