Skip to content

Commit 81cc283

Browse files
author
Marius Burkard
committed
- backported MR !640
1 parent 7ddeb2a commit 81cc283

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

interface/lib/classes/remoting.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ protected function insertQueryExecute($sql, $params, $event_identifier = '')
295295
return false;
296296
}
297297

298-
$insert_id = $app->db->insertID();
298+
if ( isset($params['_primary_id'] ))
299+
$insert_id = $params['_primary_id'];
300+
else
301+
$insert_id = $app->db->insertID();
299302

300303
// set a few values for compatibility with tform actions, mostly used by plugins
301304
$this->id = $insert_id;

interface/lib/classes/remoting_lib.inc.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ function encode($record, $tab = '', $dbencode = true) {
199199
function getSQL($record, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '', $dummy = '') {
200200

201201
global $app;
202-
202+
203+
// early usage. make sure _primary_id is sanitized if present.
204+
if ( isset($record['_primary_id']) && is_numeric($record['_primary_id'])) {
205+
$_primary_id = intval($record['_primary_id']);
206+
if ($_primary_id > 0)
207+
$this->primary_id_override = $_primary_id;
208+
}
209+
203210
if(!is_array($this->formDef)) $app->error("Form definition not found.");
204211
$this->dataRecord = $record;
205212

interface/lib/classes/tform_base.inc.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class tform_base {
104104
var $module;
105105
var $primary_id;
106106
var $diffrec = array();
107+
var $primary_id_override = 0;
107108

108109
/**
109110
* Loading of the table definition
@@ -1253,12 +1254,18 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
12531254
$this->action = $action;
12541255
$this->primary_id = $primary_id;
12551256

1256-
1257-
$record = $this->encode($record, $tab, true);
12581257
$sql_insert_key = '';
12591258
$sql_insert_val = '';
12601259
$sql_update = '';
12611260

1261+
$record = $this->encode($record, $tab, true);
1262+
1263+
if(($this->primary_id_override > 0)) {
1264+
$sql_insert_key .= '`'.$this->formDef["db_table_idx"].'`, ';
1265+
$sql_insert_val .= $this->primary_id_override.", ";
1266+
$record['_primary_id'] = $this->primary_id_override;
1267+
}
1268+
12621269
if($api == true) $fields = &$this->formDef['fields'];
12631270
else $fields = &$this->formDef['tabs'][$tab]['fields'];
12641271

0 commit comments

Comments
 (0)