From 43f6eab2ea72319be7a8059a9ab22ff2653c4934 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Thu, 13 Jul 2017 15:16:17 +0200 Subject: [PATCH] FIX #7146 --- htdocs/categories/admin/categorie_extrafields.php | 2 +- htdocs/categories/class/categorie.class.php | 2 +- htdocs/core/class/commonobject.class.php | 12 +++++++++--- htdocs/core/class/extrafields.class.php | 3 +++ htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 3 +++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/htdocs/categories/admin/categorie_extrafields.php b/htdocs/categories/admin/categorie_extrafields.php index 6291d2065c2..c72ef73e970 100644 --- a/htdocs/categories/admin/categorie_extrafields.php +++ b/htdocs/categories/admin/categorie_extrafields.php @@ -41,7 +41,7 @@ foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); $action=GETPOST('action', 'alpha'); $attrname=GETPOST('attrname', 'alpha'); -$elementtype='categories'; //Must be the $element of the class that manage extrafield +$elementtype='categorie'; //Must be the $element of the class that manage extrafield if (!$user->admin) accessforbidden(); diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 1b292b9e470..ecf95c5096d 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -51,7 +51,7 @@ class Categorie extends CommonObject const TYPE_USER = 4; // categorie contact and user are same ! TODO Replace this value with 'user' const TYPE_ACCOUNT = 5; // TODO Replace this value with 'bank_account' - const TYPE_PROJECT = 6; + const TYPE_PROJECT = 6; // TODO Replace this value with 'project' const TYPE_BANK_LINE = 'bank_line'; public $picto = 'category'; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1a26fba6b23..ab6013b74ee 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4169,6 +4169,9 @@ abstract class CommonObject $optionsArray = $extrafields->attributes[$this->table_element]['label']; } + $table_element = $this->table_element; + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility + // Request to get complementary values if (count($optionsArray) > 0) { @@ -4180,7 +4183,7 @@ abstract class CommonObject $sql.= ", ".$name; } } - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; + $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; $sql.= " WHERE fk_object = ".$rowid; dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); @@ -4335,11 +4338,14 @@ abstract class CommonObject } $this->db->begin(); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; + $table_element = $this->table_element; + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility + + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 4b5f151ec72..e44fa8a5aec 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -197,6 +197,7 @@ class ExtraFields if ($elementtype == 'contact') $elementtype='socpeople'; $table=$elementtype.'_extrafields'; + if ($elementtype == 'categorie') $table='categories_extrafields'; if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/",$attrname) && ! is_numeric($attrname)) { @@ -350,6 +351,7 @@ class ExtraFields if ($elementtype == 'contact') $elementtype='socpeople'; $table=$elementtype.'_extrafields'; + if ($elementtype == 'categorie') $table='categories_extrafields'; $error=0; @@ -460,6 +462,7 @@ class ExtraFields if ($elementtype == 'contact') $elementtype='socpeople'; $table=$elementtype.'_extrafields'; + if ($elementtype == 'categorie') $table='categories_extrafields'; if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index edb63662e65..721e35505bb 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -519,6 +519,9 @@ ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website,pa ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); +UPDATE llx_extrafields set elementtype='categorie' where elementtype='categories'; + + -- For new module blockedlog CREATE TABLE llx_blockedlog -- GitLab