Fix regression

This commit is contained in:
Laurent Destailleur 2017-07-26 13:46:27 +02:00
parent 8c681f6a96
commit dac0b6c2a7

View File

@ -42,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
*/ */
class Categorie extends CommonObject class Categorie extends CommonObject
{ {
// Categories types // Categories types (we use string because we want to accept any modules/types in a future)
const TYPE_PRODUCT = 'product'; const TYPE_PRODUCT = 'product';
const TYPE_SUPPLIER = 'supplier'; const TYPE_SUPPLIER = 'supplier';
const TYPE_CUSTOMER = 'customer'; const TYPE_CUSTOMER = 'customer';
@ -189,15 +189,16 @@ class Categorie extends CommonObject
* *
* @param int $id Id of category * @param int $id Id of category
* @param string $label Label of category * @param string $label Label of category
* @param string $type Type of category * @param string $type Type of category ('product', '...') or (0, 1, ...)
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch($id,$label='',$type='') function fetch($id, $label='', $type=null)
{ {
global $conf; global $conf;
// Check parameters // Check parameters
if (empty($id) && empty($label)) return -1; if (empty($id) && empty($label)) return -1;
if (! is_numeric($type)) $type=$this->MAP_ID[$type];
$sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type"; $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
@ -208,7 +209,7 @@ class Categorie extends CommonObject
else else
{ {
$sql.= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")";
if ($type) $sql.= " AND type = '".$this->db->escape($type)."'"; if (! is_null($type)) $sql.= " AND type = ".$this->db->escape($type);
} }
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@ -265,6 +266,10 @@ class Categorie extends CommonObject
global $conf,$langs,$hookmanager; global $conf,$langs,$hookmanager;
$langs->load('categories'); $langs->load('categories');
$type=$this->type;
if (! is_numeric($type)) $type=$this->MAP_ID[$type];
$error=0; $error=0;
dol_syslog(get_class($this).'::create', LOG_DEBUG); dol_syslog(get_class($this).'::create', LOG_DEBUG);
@ -310,7 +315,7 @@ class Categorie extends CommonObject
$sql.= ($this->socid != -1 ? $this->socid : 'null').","; $sql.= ($this->socid != -1 ? $this->socid : 'null').",";
} }
$sql.= "'".$this->visible."',"; $sql.= "'".$this->visible."',";
$sql.= $this->type.","; $sql.= $type.",";
$sql.= (! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":'null').","; $sql.= (! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":'null').",";
$sql.= $conf->entity; $sql.= $conf->entity;
$sql.= ")"; $sql.= ")";
@ -630,8 +635,7 @@ class Categorie extends CommonObject
* Link an object to the category * Link an object to the category
* *
* @param CommonObject $obj Object to link to category * @param CommonObject $obj Object to link to category
* @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member') * @param string $type Type of category ('product', ...)
*
* @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked * @return int 1 : OK, -1 : erreur SQL, -2 : id not defined, -3 : Already linked
*/ */
function add_type($obj, $type) function add_type($obj, $type)
@ -852,9 +856,8 @@ class Categorie extends CommonObject
* Check for the presence of an object in a category * Check for the presence of an object in a category
* *
* @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member') * @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member')
* @param int $object_id id of the object to search * @param int $object_id Id of the object to search
* * @return int Number of occurrences
* @return int number of occurrences
* @see getObjectsInCateg * @see getObjectsInCateg
*/ */
function containsObject($type, $object_id) function containsObject($type, $object_id)
@ -944,8 +947,7 @@ class Categorie extends CommonObject
* fulllabel = nom avec chemin complet de la categorie * fulllabel = nom avec chemin complet de la categorie
* fullpath = chemin complet compose des id * fullpath = chemin complet compose des id
* *
* @param string $type Type of categories ('customer', 'supplier', 'contact', 'product', 'member'). * @param string $type Type of categories ('customer', 'supplier', 'contact', 'product', 'member') or (0, 1, 2, ...).
* Old mode (0, 1, 2, ...) is deprecated.
* @param int $markafterid Removed all categories including the leaf $markafterid in category tree. * @param int $markafterid Removed all categories including the leaf $markafterid in category tree.
* *
* @return array Array of categories. this->cats and this->motherof are set. * @return array Array of categories. this->cats and this->motherof are set.
@ -954,14 +956,7 @@ class Categorie extends CommonObject
{ {
global $conf, $langs; global $conf, $langs;
// For backward compatibility if (! is_numeric($type)) $type = $this->MAP_ID[$type];
if (is_numeric($type))
{
// We want to reverse lookup
$map_type = array_flip($this->MAP_ID);
$type = $map_type[$type];
dol_syslog( get_class( $this ) . "::get_full_arbo(): numeric types are deprecated, please use string instead", LOG_WARNING);
}
$this->cats = array(); $this->cats = array();
@ -975,7 +970,7 @@ class Categorie extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c";
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$current_lang."'"; if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$current_lang."'";
$sql .= " WHERE c.entity IN (" . getEntity( 'category', 1 ) . ")"; $sql .= " WHERE c.entity IN (" . getEntity( 'category', 1 ) . ")";
$sql .= " AND c.type = " . $this->MAP_ID[$type]; $sql .= " AND c.type = " . $type;
dol_syslog(get_class($this)."::get_full_arbo get category list", LOG_DEBUG); dol_syslog(get_class($this)."::get_full_arbo get category list", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -1099,7 +1094,7 @@ class Categorie extends CommonObject
/** /**
* Returns all categories * Returns all categories
* *
* @param int $type Type of category * @param int $type Type of category (0, 1, ...)
* @param boolean $parent Just parent categories if true * @param boolean $parent Just parent categories if true
* @return array Table of Object Category * @return array Table of Object Category
*/ */
@ -1162,13 +1157,17 @@ class Categorie extends CommonObject
*/ */
function already_exists() function already_exists()
{ {
$type=$this->type;
if (! is_numeric($type)) $type=$this->MAP_ID[$type];
/* We have to select any rowid from llx_categorie which category's mother and label /* We have to select any rowid from llx_categorie which category's mother and label
* are equals to those of the calling category * are equals to those of the calling category
*/ */
$sql = "SELECT c.rowid"; $sql = "SELECT c.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c "; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c ";
$sql.= " WHERE c.entity IN (".getEntity('category').")"; $sql.= " WHERE c.entity IN (".getEntity('category').")";
$sql.= " AND c.type = ".$this->type; $sql.= " AND c.type = ".$type;
$sql.= " AND c.fk_parent = ".$this->fk_parent; $sql.= " AND c.fk_parent = ".$this->fk_parent;
$sql.= " AND c.label = '".$this->db->escape($this->label)."'"; $sql.= " AND c.label = '".$this->db->escape($this->label)."'";
@ -1203,7 +1202,7 @@ class Categorie extends CommonObject
/** /**
* Returns the top level categories (which are not girls) * Returns the top level categories (which are not girls)
* *
* @param int $type Type of category * @param int $type Type of category (0, 1, ...)
* @return array * @return array
*/ */
function get_main_categories($type=null) function get_main_categories($type=null)
@ -1342,7 +1341,7 @@ class Categorie extends CommonObject
* Should be named getListOfCategForObject * Should be named getListOfCategForObject
* *
* @param int $id Id of element * @param int $id Id of element
* @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated. * @param int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member') or (0, 1, 2, ...)
* @param string $mode 'id'=Get array of category ids, 'object'=Get array of fetched category instances, 'label'=Get array of category * @param string $mode 'id'=Get array of category ids, 'object'=Get array of fetched category instances, 'label'=Get array of category
* labels, 'id'= Get array of category IDs * labels, 'id'= Get array of category IDs
* @return mixed Array of category objects or < 0 if KO * @return mixed Array of category objects or < 0 if KO
@ -1351,14 +1350,7 @@ class Categorie extends CommonObject
{ {
$cats = array(); $cats = array();
// For backward compatibility if (is_numeric($type)) $type = Categorie::$MAP_ID_TO_CODE[$type];
if (is_numeric($type))
{
dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
// We want to reverse lookup
$map_type = array_flip($this->MAP_ID);
$type = $map_type[$type];
}
if ($type == Categorie::TYPE_BANK_LINE) // TODO Remove this with standard category code if ($type == Categorie::TYPE_BANK_LINE) // TODO Remove this with standard category code
{ {