Bonjour à tous,
Il y avait encore un problème, cette fois lors de l'update d'une
catégorie (ma solution au problème précédent empêchait du coup de
mettre à jour les catégories si on ne changeait pas leur label).
Corrigé et opérationnel. Ca devrait être bon, désolé pour
l'interminable chaîne de posts.
[email protected] a écrit :
Une dernière correction avant la fin de semaine, un problème
subsistait lors des update de catégories où l'on remplaçait le label
d'une catégorie par celui d'une autre existant dans la même branche.
Corrigé, le patch devrait être stable.
[email protected] a écrit :
Hmmm, fausse alerte, désolé pour le multi post - l'erreur venait
d'un require sur une classe de debug que j'avais ommis dans une
classe de synchro n'ayant rien à voir avec les catégories.
Le patch devrait donc être fonctionnel.
[email protected] a écrit :
Un autre petit détail dans la foulée, j'ai l'impression que le
patch provoque une erreur d'action à l'appel du form de création
d'une catégorie.
La création fonctionne, mais la redirection mène a une page
blanche (ce qui m'étonne, c'est l'adresse:
http://dev.dolibarr.fr/categories/fiche.php?type=0 , qui est
valide lorsqu'on l'appelle directement).
J'imagine que le problème vient d'un param qui passe en post, je
travaille dessus.
[email protected] a écrit :
Bonjour,
Je me suis rendu compte en appliquant mon propre patch que la
version head actuelle était maintenant la 3.1 alpha, et qu'une
petite erreur cvs venait perturber le fichier de migration
3.0->3.1.
J'ai corriger celle-ci et regénéré le patch, pour qu'il
s'applique sur la 3.1 alpha. Vous le trouverez donc en pièce
jointe.
Anthony Poiret
[email protected] a écrit :
Bonjour à tous,
Ci-joint un petit patch pour categorie.class et les scripts de
migrations et de table MySQL associés.
Il corrige le problème d'unicité des label dans l'arbre des
catégories. J'ai du rajouter un champ à la table llx_categories pour
identifier le parent plus simplement, et modifier ses contraintes
(l'anciennes contrainte d'unicité liait label, type et entité, sans
prendre en compte le parent puisqu'il n'existait pas dans la table).
En parlant de cela, j'ai bien compris l'intérêt des tables
d'association catégories/objets (sociétés, produits, etc...) puisqu'un
catégories peut comprendre plusieurs objets et un objet appartenir à
plusieurs catégories.
Cependant, la table d'association de catégorie avec elle même
m'échappe quelque peut: qu'une catégorie puisse avoir plusieurs filles
me parait en effet évident, mais il me semble qu'une fille ne puisse
avoir qu'une ou pas de mère. L'utilisation d'une table d'association
me parait donc superflu.
Je n'ai pas retouché toute la classe (mon objectif était de parvenir à
remettre en route le module magento), mais je pense qu'on pourrait
éviter une multitude de join et de difficultées liées à cette table
d'association en utilisant un champ répertoriant le parent plutôt
qu'une table d'association.
Cordialement,
AnthonyP
translation:
Hello everyone,
Attached a small patch categorie.class, migration scripts and MySQL
table associated.
It corrects the problem unicity of the label in the tree of
categories. I had to add a field to the table to identify the parent
llx_categories more simply, and modify its constraints (the old unique
constraint bound label, type and entity, without caring of the parent
because there was not in the table).
Speaking of which, I understand the interest tables Association
classes / objects (companies, products, etc. ...) because a category
may include multiple objects and an object belong to multiple
categories.
However, the association table with itself eludes me somewhat: a
category can have many daughters seems to me evident but it seems to
me that a daughter can have one or no parent. So the use of an
association table seems to me superfluous.
I have not reworked the whole class (my goal was to back on the road
the magento module), but I think we could avoid a multitude of issues
and of joins regarding this association table using a field rather
than listing the parent in an association table.
Cordially,
AnthonyP
_______________________________________________
Dolibarr-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
_______________________________________________
Dolibarr-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev
### 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 30 May 2011 07:58:49 -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);
@@ -199,12 +202,20 @@
*/
function update()
{
- global $conf;
+ global $conf, $langs;
// Clean parameters
$this->label=trim($this->label);
$this->description=trim($this->description);
+ $this->parentId = ($this->id_mere) != "" ?
intval($this->id_mere) : 0;
+ if ($this->already_exists())
+ {
+ $this->error=$langs->trans("ImpossibleUpdateCat");
+ $this->error.=" :
".$langs->trans("CategoryExistsAtSameLevel");
+ return -1;
+ }
+
$this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'categorie_association';
@@ -243,6 +254,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,21 +815,51 @@
}
/**
- * \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 != "")
// mother_id defined
+ {
+ /* We have to select any rowid from llx_categorie which
category's mother and label
+ * are equals to those of the calling category
+ */
+ $sql = "SELECT 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
// mother_id undefined (so it's root)
+ {
+ /* We have to select any rowid from llx_categorie which
which category's type and label
+ * are equals to those of the calling category, AND
which doesn't exist in categorie association
+ * as children (rowid != fk_categorie_fille)
+ */
+ $sql = "SELECT 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)
- {
- $obj = $this->db->fetch_array($res);
- if($obj[0] > 0) return 1;
- else return 0;
+ {
+ if($this->db->num_rows($resql) > 0)
// Checking for empty resql
+ {
+ $obj = $this->db->fetch_array($res);
+ /* If object called create, obj cannot have is
id.
+ * If object called update, he mustn't have the
same label as an other category for this mother.
+ * So if the result have the same id, update is
not for label, and if result have an other one,
+ * update may be for label.
+ */
+ if($obj[0] > 0 && $obj[0] != $this->id) return
1;
+ }
+ return 0;
}
else
{
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 30 May 2011 07:58:49
-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 30 May 2011 07:58:49
-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
+--
_______________________________________________
Dolibarr-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/dolibarr-dev