Skip to content

Commit 6dfc6d2

Browse files
author
ispcomm
committed
_primary_id enforcing added to $params
1 parent aee2da2 commit 6dfc6d2

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ function getSQL($record, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '
200200

201201
global $app;
202202

203-
$this->primary_id_override = true;
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 = intval($record['_primary_id']);
208+
}
204209

205210
if(!is_array($this->formDef)) $app->error("Form definition not found.");
206211
$this->dataRecord = $record;

interface/lib/classes/tform_base.inc.php

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

109109
/**
110110
* Loading of the table definition
@@ -1263,20 +1263,21 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
12631263
$this->action = $action;
12641264
$this->primary_id = $primary_id;
12651265

1266-
1267-
$record = $this->encode($record, $tab, true);
12681266
$sql_insert_key = '';
12691267
$sql_insert_val = '';
12701268
$sql_update = '';
12711269

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+
12721278
if($api == true) $fields = &$this->formDef['fields'];
12731279
else $fields = &$this->formDef['tabs'][$tab]['fields'];
12741280

1275-
if($this->primary_id_override && isset($record['_primary_id'])) {
1276-
$sql_insert_key .= '`'.$this->formDef["db_table_idx"].'`, ';
1277-
$sql_insert_val .= intval($record['_primary_id']).", ";
1278-
}
1279-
12801281
// go trough all fields of the tab
12811282
if(is_array($record)) {
12821283
foreach($fields as $key => $field) {

0 commit comments

Comments
 (0)