From 9fc4e0b06e138462e2d1e6b2dddc8663ff85dfbe Mon Sep 17 00:00:00 2001 From: yuri Date: Fri, 24 Jul 2015 14:58:00 +0300 Subject: [PATCH] fix import --- application/Espo/Services/Import.php | 35 ++++++++++---- frontend/client/src/views/import/detail.js | 53 +++++++++++++++++----- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/application/Espo/Services/Import.php b/application/Espo/Services/Import.php index bec1ab7622..1ec5f83434 100644 --- a/application/Espo/Services/Import.php +++ b/application/Espo/Services/Import.php @@ -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(); diff --git a/frontend/client/src/views/import/detail.js b/frontend/client/src/views/import/detail.js index 9a17e18a00..a92925c2b6 100644 --- a/frontend/client/src/views/import/detail.js +++ b/frontend/client/src/views/import/detail.js @@ -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" + }); + } + } },