* InfoLog: fix SQL errors for custom types containing non-ascii chars (eg. German umlauts or Frensh acents

This commit is contained in:
Ralf Becker 2015-08-18 09:42:31 +00:00
parent 59ca017000
commit 774bce4ea9

View File

@ -50,12 +50,29 @@ class contenthistory
),__LINE__,__FILE__,'syncml'); ),__LINE__,__FILE__,'syncml');
} }
/**
* Encode app-name for egw_api_content_history.sync_appname only allowing ascii
*
* We encode all non-ascii as "?" for MySQL, as it happend during schema update and for inserts.
*
* @param string $_appname
* @return string
*/
protected function encode_appname($_appname)
{
if ($this->db->Type == 'mysql')
{
$_appname = preg_replace('/[\x80-\xFF]/u', '?', $_appname);
}
return $_appname;
}
/** /**
* get the timestamp for action * get the timestamp for action
* *
* find which content changed since $_ts for application $_appName * find which content changed since $_ts for application $_appName
* *
* @param string$_appName the appname example: infolog_notes * @param string $_appName the appname example: infolog_notes
* @param string $_action can be modify, add or delete * @param string $_action can be modify, add or delete
* @param string $_ts timestamp where to start searching from * @param string $_ts timestamp where to start searching from
* @param array $readableItems (optional) readable items of current user * @param array $readableItems (optional) readable items of current user
@ -63,10 +80,10 @@ class contenthistory
*/ */
function getHistory($_appName, $_action, $_ts, $readableItems = false) function getHistory($_appName, $_action, $_ts, $readableItems = false)
{ {
$where = array('sync_appname' => $_appName); $where = array('sync_appname' => $this->encode_appname($_appName));
$ts = $this->db->to_timestamp($_ts); $ts = $this->db->to_timestamp($_ts);
$idList = array(); $idList = array();
switch($_action) switch($_action)
{ {
case 'modify': case 'modify':
@ -82,7 +99,7 @@ class contenthistory
// no valid $_action set // no valid $_action set
return array(); return array();
} }
if (is_array($readableItems)) if (is_array($readableItems))
{ {
foreach ($readableItems as $id) foreach ($readableItems as $id)
@ -91,7 +108,7 @@ class contenthistory
if ($this->db->select(self::TABLE,'sync_contentid',$where,__LINE__,__FILE__)->fetchColumn()) if ($this->db->select(self::TABLE,'sync_contentid',$where,__LINE__,__FILE__)->fetchColumn())
{ {
$idList[] = $id; $idList[] = $id;
} }
} }
} }
else else
@ -129,7 +146,7 @@ class contenthistory
return false; return false;
} }
$where = array ( $where = array (
'sync_appname' => $_appName, 'sync_appname' => $this->encode_appname($_appName),
'sync_contentid' => $_id, 'sync_contentid' => $_id,
); );
@ -152,7 +169,7 @@ class contenthistory
function updateTimeStamp($_appName, $_id, $_action, $_ts) function updateTimeStamp($_appName, $_id, $_action, $_ts)
{ {
$newData = array ( $newData = array (
'sync_appname' => $_appName, 'sync_appname' => $this->encode_appname($_appName),
'sync_contentid' => $_id, 'sync_contentid' => $_id,
'sync_added' => $this->db->to_timestamp($_ts), 'sync_added' => $this->db->to_timestamp($_ts),
'sync_changedby' => $GLOBALS['egw_info']['user']['account_id'], 'sync_changedby' => $GLOBALS['egw_info']['user']['account_id'],
@ -168,7 +185,7 @@ class contenthistory
case 'delete': case 'delete':
// first check that this entry got ever added to database already // first check that this entry got ever added to database already
$where = array ( $where = array (
'sync_appname' => $_appName, 'sync_appname' => $this->encode_appname($_appName),
'sync_contentid' => $_id, 'sync_contentid' => $_id,
); );
@ -187,21 +204,21 @@ class contenthistory
} }
return true; return true;
} }
/** /**
* get the timestamp of last change for appname * get the timestamp of last change for appname
* *
* find which content changed since $_ts for application $_appName * find which content changed since $_ts for application $_appName
* *
* @param string$_appName the appname example: infolog_notes * @param string$_appName the appname example: infolog_notes
* *
* @return timestamp of last change for this application * @return timestamp of last change for this application
*/ */
function getLastChange($_appName) function getLastChange($_appName)
{ {
$max = 0; $max = 0;
$where = array('sync_appname' => $_appName); $where = array('sync_appname' => $this->encode_appname($_appName));
foreach (array('modified','deleted','added') as $action) foreach (array('modified','deleted','added') as $action)
{ {
@ -211,8 +228,8 @@ class contenthistory
if ($ts > $max) $max = $ts; if ($ts > $max) $max = $ts;
} }
} }
return $max; return $max;
} }
} }