import update

This commit is contained in:
yuri
2015-08-31 15:19:09 +03:00
parent e5ad31a965
commit f9cc21a06d
5 changed files with 51 additions and 10 deletions

View File

@@ -133,6 +133,10 @@ class Import extends \Espo\Core\Controllers\Record
'action' => $data['action'],
);
if (array_key_exists('updateBy', $data)) {
$importParams['updateBy'] = $data['updateBy'];
}
$attachmentId = $data['attachmentId'];
if (!$this->getAcl()->check($data['entityType'], 'edit')) {

View File

@@ -14,7 +14,11 @@
"Remove Duplicates": "Remove Duplicates",
"importedCount": "Imported (count)",
"duplicateCount": "Duplicates (count)",
"updatedCount": "Updated (count)"
"updatedCount": "Updated (count)",
"Create Only": "Create Only",
"Create and Update": "Create & Update",
"Update Only": "Update Only",
"Update by": "Update by"
},
"messages": {
"utf8": "Should be UTF-8 encoded",

View File

@@ -342,25 +342,33 @@ class Import extends \Espo\Services\Record
$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;
if (in_array($action, ['createAndUpdate', 'update'])) {
if (!empty($params['updateBy']) && is_array($params['updateBy'])) {
$updateByFieldList = [];
$whereClause = array();
foreach ($params['updateBy'] as $i) {
if (array_key_exists($i, $fields)) {
$updateByFieldList[] = $fields[$i];
$whereClause[$fields[$i]] = $row[$i];
}
}
}
}
$recordService = $this->getRecordService($scope);
if (in_array($action, ['createAndUpdate', 'update'])) {
if (!$id) {
if (!count($updateByFieldList)) {
return;
}
$entity = $this->getEntityManager()->getEntity($scope, $id);
$entity = $this->getEntityManager()->getRepository($scope)->where($whereClause)->findOne();
if (!$entity) {
if ($action == 'createAndUpdate') {
$entity = $this->getEntityManager()->getEntity($scope);
$entity->set('id', $id);
if (array_key_exists('id', $whereClause)) {
$entity->set('id', $whereClause['id']);
}
} else {
return;
}

View File

@@ -25,6 +25,7 @@
<select class="form-control" id="import-action">
<option value="create">{{translate 'Create Only' scope='Import'}}</option>
<option value="createAndUpdate">{{translate 'Create and Update' scope='Import'}}</option>
<option value="update">{{translate 'Update Only' scope='Import'}}</option>
</select>
</div>
</div>

View File

@@ -107,6 +107,11 @@ Espo.define('Views.Import.Step2', 'View', function (Dep) {
$row.append($cell);
$cell = $('<th>').html(this.translate('First Row Value', 'labels', 'Import'));
$row.append($cell);
if (~['update', 'createAndUpdate'].indexOf(this.formData.action)) {
$cell = $('<th>').html(this.translate('Update by', 'labels', 'Import'));
$row.append($cell);
}
$table.append($row);
this.mapping.forEach(function (d, i) {
@@ -122,6 +127,15 @@ Espo.define('Views.Import.Step2', 'View', function (Dep) {
$cell = $('<td>').html(d.value);
$row.append($cell);
if (~['update', 'createAndUpdate'].indexOf(this.formData.action)) {
var $checkbox = $('<input>').attr('type', 'checkbox').attr('id', 'update-by-' + i.toString());
if (d.name == 'id') {
$checkbox.attr('checked', true);
}
$cell = $('<td>').append($checkbox);
$row.append($cell);
}
$table.append($row);
}, this);
@@ -303,9 +317,19 @@ Espo.define('Views.Import.Step2', 'View', function (Dep) {
fields.push($('#column-' + i).val());
}, this);
this.formData.fields = fields;
if (~['update', 'createAndUpdate'].indexOf(this.formData.action)) {
var updateBy = [];
this.mapping.forEach(function (d, i) {
if ($('#update-by-' + i).get(0).checked) {
updateBy.push(i);
}
}, this);
this.formData.updateBy = updateBy;
}
this.getParentView().formData = this.formData;
this.disableButtons();