### Eclipse Workspace Patch 1.0 #P dolibarr Index: htdocs/categories/class/categorie.class.php =================================================================== RCS file: /sources/dolibarr/dolibarr/htdocs/categories/class/categorie.class.php,v retrieving revision 1.15 diff -u -r1.15 categorie.class.php --- htdocs/categories/class/categorie.class.php 11 Mar 2011 17:42:39 -0000 1.15 +++ htdocs/categories/class/categorie.class.php 26 May 2011 11:03:46 -0000 @@ -50,6 +50,7 @@ var $description; var $socid; var $type; // 0=Product, 1=Supplier, 2=Customer/Prospect, 3=Member + var $parentId; var $cats=array(); // Tableau en memoire des categories var $motherof = array(); // Tableau des correspondances id_fille -> id_mere @@ -109,6 +110,7 @@ { $res = $this->db->fetch_array($resql); $this->id_mere = $res['fk_categorie_mere']; + $this->parentId = $res['fk_categorie_mere'] ? $res['fk_categorie_mere'] : 0; return $this->id; } else @@ -131,6 +133,7 @@ // Clean parameters if (empty($this->visible)) $this->visible=0; + $this->parentId = ($this->id_mere) != "" ? intval($this->id_mere) : 0; if ($this->already_exists()) { @@ -144,13 +147,13 @@ { $sql.= "fk_soc,"; } - $sql.= "visible, type) "; + $sql.= "visible, type, fk_parent_id) "; $sql.= "VALUES ('".$this->db->escape($this->label)."', '".$this->db->escape($this->description)."',"; if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) { $sql.= ($this->socid != -1 ? $this->socid : 'null').","; } - $sql.= "'".$this->visible."',".$this->type.")"; + $sql.= "'".$this->visible."',".$this->type.",".$this->parentId .")"; $res = $this->db->query ($sql); @@ -204,6 +207,7 @@ // Clean parameters $this->label=trim($this->label); $this->description=trim($this->description); + $this->parentId = ($this->id_mere) != "" ? intval($this->id_mere) : 0; $this->db->begin(); @@ -243,6 +247,7 @@ $sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null'); } $sql .= ", visible = '".$this->visible."'"; + $sql .= ", fk_parent_id = ".$this->parentId; $sql .= " WHERE rowid = ".$this->id; dol_syslog("Categorie::update sql=".$sql); @@ -803,14 +808,29 @@ } /** - * \brief Check if no category with same label already exists + * \brief Check if no category with same label already exists for this cat's parent or root and for this cat's type * \return boolean 1 if already exist, 0 otherwise, -1 if error */ function already_exists() { - $sql = "SELECT count(c.rowid)"; - $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_association as ca"; - $sql.= " WHERE c.label = '".$this->db->escape($this -> label)."' AND type=".$this->type; + if($this->id_mere != "") + { + $sql = "SELECT COUNT(c.rowid)"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c "; + $sql.= " JOIN ".MAIN_DB_PREFIX."categorie_association as ca"; + $sql.= " ON c.rowid=ca.fk_categorie_fille"; + $sql.= " WHERE ca.fk_categorie_mere=".$this->id_mere; + $sql.= " AND c.label='".$this->label."'"; + } + else + { + $sql = "SELECT COUNT(c.rowid)"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c "; + $sql.= " JOIN ".MAIN_DB_PREFIX."categorie_association as ca"; + $sql.= " ON c.rowid!=ca.fk_categorie_fille"; + $sql.= " WHERE c.type=".$this->type; + $sql.= " AND c.label='".$this->label."'"; + } dol_syslog("Categorie::already_exists sql=".$sql); $res = $this->db->query($sql); if ($res) Index: htdocs/install/mysql/migration/3.0.0-3.1.0.sql =================================================================== RCS file: /sources/dolibarr/dolibarr/htdocs/install/mysql/migration/3.0.0-3.1.0.sql,v retrieving revision 1.49 diff -u -r1.49 3.0.0-3.1.0.sql --- htdocs/install/mysql/migration/3.0.0-3.1.0.sql 25 May 2011 18:16:58 -0000 1.49 +++ htdocs/install/mysql/migration/3.0.0-3.1.0.sql 26 May 2011 11:03:46 -0000 @@ -127,6 +127,11 @@ INSERT INTO llx_c_shipment_mode (rowid,code,libelle,description,active) VALUES (4,'LETTREMAX','Lettre Max','Courrier Suivi et Lettre Max',0); +-- Add a field for categorie used to complete constraint +ALTER TABLE llx_categorie ADD fk_parent_id INT DEFAULT NULL AFTER import_key; +ALTER TABLE llx_categorie DROP INDEX uk_categorie_ref; +ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref( label, TYPE , entity, fk_parent_id ) ; + --Add Chile data (id pays=67) -- Regions Chile INSERT INTO llx_c_regions (rowid, code_region, fk_pays, cheflieu, tncc, nom, active) VALUES (6701, 6701, 67, NULL, NULL, 'Tarapacá', 1); Index: htdocs/install/mysql/tables/llx_categorie.sql =================================================================== RCS file: /sources/dolibarr/dolibarr/htdocs/install/mysql/tables/llx_categorie.sql,v retrieving revision 1.3 diff -u -r1.3 llx_categorie.sql --- htdocs/install/mysql/tables/llx_categorie.sql 24 Feb 2011 09:57:04 -0000 1.3 +++ htdocs/install/mysql/tables/llx_categorie.sql 26 May 2011 11:03:46 -0000 @@ -29,7 +29,8 @@ description text, -- description of the category fk_soc integer DEFAULT NULL, -- attribution of the category has a company (for product only) visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not - import_key varchar(14) -- Import key + import_key varchar(14), -- Import key + fk_parent_id integer DEFAULT 0 -- Parent category id (0 for root, null undefined) )ENGINE=innodb; -- @@ -46,4 +47,4 @@ -- 1 : first company category type -- 2 : second company category type -- 3 : etc... --- \ No newline at end of file +--