From cfeacab117b47a1456a82bf9c49399dba39d1b34 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 4 Oct 2016 11:30:02 +0200 Subject: [PATCH] allow to specify an info_id when creating a new entry eg. for import, replacing 5800eff use of insert, as it broker other stuff --- infolog/inc/class.infolog_bo.inc.php | 2 +- infolog/inc/class.infolog_so.inc.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php index 0ad3a75f18..32f1ddf727 100644 --- a/infolog/inc/class.infolog_bo.inc.php +++ b/infolog/inc/class.infolog_bo.inc.php @@ -932,7 +932,7 @@ class infolog_bo //_debug_array($values); // error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".array2string($values)."\n",3,'/tmp/infolog'); - if (($info_id = $this->so->write($to_write, $check_modified, $purge_cfs))) + if (($info_id = $this->so->write($to_write, $check_modified, $purge_cfs, !isset($old)))) { if (!isset($values['info_type']) || $status_only || empty($values['caldav_url'])) { diff --git a/infolog/inc/class.infolog_so.inc.php b/infolog/inc/class.infolog_so.inc.php index d487e2e30d..a8af4b59b4 100644 --- a/infolog/inc/class.infolog_so.inc.php +++ b/infolog/inc/class.infolog_so.inc.php @@ -511,9 +511,10 @@ class infolog_so * @param array $values with the data of the log-entry * @param int $check_modified =0 old modification date to check before update (include in WHERE) * @param string $purge_cfs =null null=dont, 'ical'=only iCal X-properties (cfs name starting with "#"), 'all'=all cfs + * @param boolean $force_insert =false force using insert, even if an id is given eg. for import * @return int|boolean info_id, false on error or 0 if the entry has been updated in the meantime */ - function write($values, $check_modified=0, $purge_cfs=null) // did _not_ ensure ACL + function write($values, $check_modified=0, $purge_cfs=null, $force_insert=false) // did _not_ ensure ACL { if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { @@ -535,7 +536,7 @@ class infolog_so $to_write = array(); foreach($values as $key => $val) { - if ($key != 'info_id' && isset($table_def['fd'][$key])) + if (($key != 'info_id' || $force_insert) && isset($table_def['fd'][$key])) { $to_write[$key] = $this->data[$key] = $val; // update internal data } @@ -543,11 +544,11 @@ class infolog_so // writing no price as SQL NULL (required by postgres) if ($to_write['info_price'] === '') $to_write['info_price'] = NULL; - if (($this->data['info_id'] = $info_id)) + if (($this->data['info_id'] = $info_id) && !$force_insert) { $where = array('info_id' => $info_id); if ($check_modified) $where['info_datemodified'] = $check_modified; - if (!$this->db->insert($this->info_table,$to_write,$where,__LINE__,__FILE__)) + if (!$this->db->update($this->info_table,$to_write,$where,__LINE__,__FILE__)) { //error_log("### soinfolog::write(".print_r($to_write,true).") where=".print_r($where,true)." returning false"); return false; // Error