Skip to content

Commit 094e6e2

Browse files
author
Till Brehm
committed
Merge branch 'till_primary_force' into 'master'
Primary ID force for remoting api on insertion of new objects See merge request !640
2 parents 73c9aef + 7fb8191 commit 094e6e2

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
@@ -333,7 +333,10 @@ protected function insertQueryExecute($sql, $params, $event_identifier = '')
333333
return false;
334334
}
335335

336-
$insert_id = $app->db->insertID();
336+
if ( isset($params['_primary_id'] ))
337+
$insert_id = $params['_primary_id'];
338+
else
339+
$insert_id = $app->db->insertID();
337340

338341
// set a few values for compatibility with tform actions, mostly used by plugins
339342
$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
@@ -1262,12 +1263,18 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
12621263
$this->action = $action;
12631264
$this->primary_id = $primary_id;
12641265

1265-
1266-
$record = $this->encode($record, $tab, true);
12671266
$sql_insert_key = '';
12681267
$sql_insert_val = '';
12691268
$sql_update = '';
12701269

1270+
$record = $this->encode($record, $tab, true);
1271+
1272+
if(($this->primary_id_override > 0)) {
1273+
$sql_insert_key .= '`'.$this->formDef["db_table_idx"].'`, ';
1274+
$sql_insert_val .= $this->primary_id_override.", ";
1275+
$record['_primary_id'] = $this->primary_id_override;
1276+
}
1277+
12711278
if($api == true) $fields = &$this->formDef['fields'];
12721279
else $fields = &$this->formDef['tabs'][$tab]['fields'];
12731280

0 commit comments

Comments
 (0)