diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 0f3549d443e..47ab4686a1d 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -440,7 +440,7 @@ class Setup extends DolibarrApi /** * Get country by Code. * - * @param string $code Code of country + * @param string $code Code of country (2 characters) * @param string $lang Code of the language the name of the * country must be translated to * @return array Array of cleaned object properties @@ -457,7 +457,7 @@ class Setup extends DolibarrApi /** * Get country by Iso. * - * @param string $iso ISO of country + * @param string $iso ISO of country (3 characters) * @param string $lang Code of the language the name of the * country must be translated to * @return array Array of cleaned object properties @@ -498,8 +498,8 @@ class Setup extends DolibarrApi * Get country. * * @param int $id ID of country - * @param string $code Code of country - * @param string $iso ISO of country + * @param string $code Code of country (2 characters) + * @param string $iso ISO of country (3 characters) * @param string $lang Code of the language the name of the * country must be translated to * @return array Array of cleaned object properties @@ -511,10 +511,11 @@ class Setup extends DolibarrApi $country = new Ccountry($this->db); $result = $country->fetch($id, $code, $iso); + if ($result < 0) { throw new RestException(503, 'Error when retrieving country : '.$country->error); } elseif ($result == 0) { - throw new RestException(404, 'country not found'); + throw new RestException(404, 'Country not found'); } $this->translateLabel($country, $lang, 'Country'); diff --git a/htdocs/core/class/ccountry.class.php b/htdocs/core/class/ccountry.class.php index d19e6d00a36..561d0527796 100644 --- a/htdocs/core/class/ccountry.class.php +++ b/htdocs/core/class/ccountry.class.php @@ -162,9 +162,9 @@ class Ccountry // extends CommonObject $sql .= " t.label,"; $sql .= " t.active"; $sql .= " FROM ".MAIN_DB_PREFIX."c_country as t"; - if ($id) $sql .= " WHERE t.rowid = ".$id; - elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'"; - elseif ($code_iso) $sql .= " WHERE t.code_iso = '".$this->db->escape($code_iso)."'"; + if ($id) $sql .= " WHERE t.rowid = ".((int) $id); + elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape(strtoupper($code))."'"; + elseif ($code_iso) $sql .= " WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso))."'"; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -174,11 +174,13 @@ class Ccountry // extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->code = $obj->code; - $this->code_iso = $obj->code_iso; - $this->label = $obj->label; - $this->active = $obj->active; + if ($obj) { + $this->id = $obj->rowid; + $this->code = $obj->code; + $this->code_iso = $obj->code_iso; + $this->label = $obj->label; + $this->active = $obj->active; + } $this->db->free($resql); return 1;