From 63c54259918be35ceb16d74d3c0c835f9eaba8b6 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 17 Aug 2016 14:46:15 +0200 Subject: [PATCH 1/2] another fix for Ressource module in PgSQL --- htdocs/resource/class/dolresource.class.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 0a738846363..72c77ef7108 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -339,7 +339,7 @@ class Dolresource extends CommonObject if ($this->db->query($sql)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; - $sql.= " WHERE element_type='resource' AND resource_id ='".$this->db->escape($rowid)."'"; + $sql.= " WHERE element_type='resource' AND resource_id =".$this->db->escape($rowid); dol_syslog(get_class($this)."::delete", LOG_DEBUG); if ($this->db->query($sql)) { @@ -393,7 +393,6 @@ class Dolresource extends CommonObject } } } - $sql.= " GROUP BY t.rowid, t.entity, t.ref, t.description, t.fk_code_type_resource, t.tms, ty.label"; $sql.= $this->db->order($sortfield,$sortorder); $this->num_all = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) @@ -473,7 +472,6 @@ class Dolresource extends CommonObject } } } - $sql.= " GROUP BY t.rowid, ty.label"; $sql.= $this->db->order($sortfield,$sortorder); if ($limit) $sql.= $this->db->plimit($limit+1,$offset); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); @@ -559,7 +557,6 @@ class Dolresource extends CommonObject } } } - $sql.= " GROUP BY t.resource_id"; $sql.= $this->db->order($sortfield,$sortorder); if ($limit) $sql.= $this->db->plimit($limit+1,$offset); dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); @@ -570,10 +567,9 @@ class Dolresource extends CommonObject $num = $this->db->num_rows($resql); if ($num) { - $i = 0; - while ($i < $num) + $this->lines=array(); + while ($obj = $this->db->fetch_object($resql)) { - $obj = $this->db->fetch_object($resql); $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->resource_id = $obj->resource_id; @@ -584,7 +580,7 @@ class Dolresource extends CommonObject $line->mandatory = $obj->mandatory; $line->fk_user_create = $obj->fk_user_create; - $this->lines[$i] = fetchObjectByElement($obj->resource_id,$obj->resource_type); + $this->lines[] = fetchObjectByElement($obj->resource_id,$obj->resource_type); $i++; } @@ -759,7 +755,7 @@ class Dolresource extends CommonObject /** * Return an array with resources linked to the element - * + * * @param string $element Element * @param int $element_id Id * @param string $resource_type Type From f7bb2483d8436adac643de02595ed7ccbae2da5b Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 17 Aug 2016 14:53:51 +0200 Subject: [PATCH 2/2] fix ressource for PGSQL --- htdocs/resource/class/dolresource.class.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 72c77ef7108..dab3bf6e735 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -409,10 +409,9 @@ class Dolresource extends CommonObject $num = $this->db->num_rows($resql); if ($num) { - $i = 0; - while ($i < $num) + $this->lines=array(); + while ($obj = $this->db->fetch_object($resql)) { - $obj = $this->db->fetch_object($resql); $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->ref = $obj->ref; @@ -420,8 +419,7 @@ class Dolresource extends CommonObject $line->fk_code_type_resource = $obj->fk_code_type_resource; $line->type_label = $obj->type_label; - $this->lines[$i] = $line; - $i++; + $this->lines[] = $line; } $this->db->free($resql); } @@ -482,10 +480,8 @@ class Dolresource extends CommonObject $num = $this->db->num_rows($resql); if ($num) { - $i = 0; - while ($i < $num) + while ($obj = $this->db->fetch_object($resql)) { - $obj = $this->db->fetch_object($resql); $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->resource_id = $obj->resource_id; @@ -500,9 +496,8 @@ class Dolresource extends CommonObject $line->objresource = fetchObjectByElement($obj->resource_id,$obj->resource_type); if($obj->element_id && $obj->element_type) $line->objelement = fetchObjectByElement($obj->element_id,$obj->element_type); - $this->lines[$i] = $line; + $this->lines[] = $line; - $i++; } $this->db->free($resql); } @@ -581,8 +576,6 @@ class Dolresource extends CommonObject $line->fk_user_create = $obj->fk_user_create; $this->lines[] = fetchObjectByElement($obj->resource_id,$obj->resource_type); - - $i++; } $this->db->free($resql); } @@ -766,7 +759,7 @@ class Dolresource extends CommonObject // Links beetween objects are stored in this table $sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory'; $sql.= ' FROM '.MAIN_DB_PREFIX.'element_resources'; - $sql.= " WHERE element_id='".$element_id."' AND element_type='".$element."'"; + $sql.= " WHERE element_id=".$element_id." AND element_type='".$element."'"; if($resource_type) $sql.=" AND resource_type LIKE '%".$resource_type."%'"; $sql .= ' ORDER BY resource_type';