From f49f7325c2166fd64320651194153553edafd77b Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Thu, 13 Feb 2020 10:02:01 +0100
Subject: [PATCH] FEAT #12471 TIME 0:10 removed entity owner column in tags

---
 migration/20.03/2003.sql                     |  7 ++----
 modules/tags/class/TagControler_Abstract.php |  4 +--
 modules/tags/manage_tag_list_controller.php  | 11 +++------
 sql/data_en.sql                              | 26 ++++++++++----------
 sql/data_fr.sql                              | 26 ++++++++++----------
 sql/structure.sql                            |  1 -
 6 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/migration/20.03/2003.sql b/migration/20.03/2003.sql
index d82d912be0d..abf3c1b5827 100644
--- a/migration/20.03/2003.sql
+++ b/migration/20.03/2003.sql
@@ -236,7 +236,7 @@ DO $$ BEGIN
 	  ALTER TABLE tags ADD COLUMN id serial NOT NULL;
 	  UPDATE tags SET id = tag_id;
       ALTER TABLE tags DROP COLUMN IF EXISTS tag_id;
-
+      ALTER TABLE tags DROP COLUMN IF EXISTS entity_id_owner
       ALTER TABLE tags DROP COLUMN IF EXISTS description;
 	  ALTER TABLE tags ADD COLUMN description TEXT;
       ALTER TABLE tags DROP COLUMN IF EXISTS parent_id;
@@ -247,16 +247,13 @@ DO $$ BEGIN
       ALTER TABLE tags ADD COLUMN links jsonb DEFAULT '[]';
       ALTER TABLE tags DROP COLUMN IF EXISTS usage;
       ALTER TABLE tags ADD COLUMN usage TEXT;
-  END IF;
-END$$;
 
-DO $$ BEGIN
-  IF (SELECT count(attname) FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'tag_res')) = 1 THEN
       DROP TABLE IF EXISTS resources_tags;
       ALTER TABLE tag_res ADD COLUMN id serial NOT NULL;
       ALTER TABLE tag_res RENAME TO resources_tags;
   END IF;
 END$$;
+
 SELECT setval('tags_id_seq', (SELECT MAX(id) from tags));
 
 DROP TABLE IF EXISTS tags_entities;
diff --git a/modules/tags/class/TagControler_Abstract.php b/modules/tags/class/TagControler_Abstract.php
index c3a164b345b..436a0354204 100755
--- a/modules/tags/class/TagControler_Abstract.php
+++ b/modules/tags/class/TagControler_Abstract.php
@@ -594,8 +594,8 @@ abstract class tag_controler_Abstract extends ObjectControler
         {*/
         $stmt = $db->query(
                 "INSERT INTO " ._TAG_TABLE_NAME
-                . "(label, entity_id_owner) VALUES (?, ?)",
-                 array($new_tag_label,$_SESSION['user']['primaryentity']['id'])
+                . "(label) VALUES (?, ?)",
+                 array($new_tag_label)
              );
              
         $tag_id = $db->lastInsertId('tags_id_seq');
diff --git a/modules/tags/manage_tag_list_controller.php b/modules/tags/manage_tag_list_controller.php
index 2987ea6391e..1c29e4a1a62 100755
--- a/modules/tags/manage_tag_list_controller.php
+++ b/modules/tags/manage_tag_list_controller.php
@@ -187,13 +187,10 @@ function display_list()
     array_push(
         $select['tags'], 'id', 'label'
     );
-    if ($_SESSION['user']['UserId'] == 'superadmin') {
-        $where = '';
-        $where_what = array();
-    } else {
-        $where = '(entity_id_owner = ? OR entity_id_owner IS NULL)';
-        $where_what = array($_SESSION['user']['primaryentity']['id']);   
-    }
+
+    $where = '';
+    $where_what = array();
+
     $what = '';
 
     if (isset($_REQUEST['what'])) {
diff --git a/sql/data_en.sql b/sql/data_en.sql
index e698292a5a6..a3787361218 100644
--- a/sql/data_en.sql
+++ b/sql/data_en.sql
@@ -1057,19 +1057,19 @@ INSERT INTO templates_doctype_ext (template_id, type_id, is_generated) VALUES (9
 --KEYWORDS / TAGS
 ------------
 TRUNCATE TABLE tags;
-INSERT INTO tags (label, entity_id_owner) VALUES ('SEMINAIRE', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('INNOVATION', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('MAARCH', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('ENVIRONNEMENT', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('PARTENARIAT', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('JUMELAGE', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('ECONOMIE', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('ASSOCIATIONS', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('RH', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('BUDGET', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('QUARTIERS', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('LITTORAL', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('SPORT', 'COU');
+INSERT INTO tags (label) VALUES ('SEMINAIRE');
+INSERT INTO tags (label) VALUES ('INNOVATION');
+INSERT INTO tags (label) VALUES ('MAARCH');
+INSERT INTO tags (label) VALUES ('ENVIRONNEMENT');
+INSERT INTO tags (label) VALUES ('PARTENARIAT');
+INSERT INTO tags (label) VALUES ('JUMELAGE');
+INSERT INTO tags (label) VALUES ('ECONOMIE');
+INSERT INTO tags (label) VALUES ('ASSOCIATIONS');
+INSERT INTO tags (label) VALUES ('RH');
+INSERT INTO tags (label) VALUES ('BUDGET');
+INSERT INTO tags (label) VALUES ('QUARTIERS');
+INSERT INTO tags (label) VALUES ('LITTORAL');
+INSERT INTO tags (label) VALUES ('SPORT');
 
 TRUNCATE TABLE tags_entities;
 INSERT INTO tags_entities (tag_id, entity_id) VALUES (1, 'COU');
diff --git a/sql/data_fr.sql b/sql/data_fr.sql
index 5540f05e9f2..cf9b11f76e6 100755
--- a/sql/data_fr.sql
+++ b/sql/data_fr.sql
@@ -1185,19 +1185,19 @@ Select setval('groupbasket_redirect_system_id_seq', (select max(system_id)+1 fro
 --KEYWORDS / TAGS
 ------------
 TRUNCATE TABLE tags;
-INSERT INTO tags (label, entity_id_owner) VALUES ('SEMINAIRE', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('INNOVATION', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('MAARCH', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('ENVIRONNEMENT', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('PARTENARIAT', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('JUMELAGE', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('ECONOMIE', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('ASSOCIATIONS', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('RH', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('BUDGET', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('QUARTIERS', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('LITTORAL', 'COU');
-INSERT INTO tags (label, entity_id_owner) VALUES ('SPORT', 'COU');
+INSERT INTO tags (label) VALUES ('SEMINAIRE');
+INSERT INTO tags (label) VALUES ('INNOVATION');
+INSERT INTO tags (label) VALUES ('MAARCH');
+INSERT INTO tags (label) VALUES ('ENVIRONNEMENT');
+INSERT INTO tags (label) VALUES ('PARTENARIAT');
+INSERT INTO tags (label) VALUES ('JUMELAGE');
+INSERT INTO tags (label) VALUES ('ECONOMIE');
+INSERT INTO tags (label) VALUES ('ASSOCIATIONS');
+INSERT INTO tags (label) VALUES ('RH');
+INSERT INTO tags (label) VALUES ('BUDGET');
+INSERT INTO tags (label) VALUES ('QUARTIERS');
+INSERT INTO tags (label) VALUES ('LITTORAL');
+INSERT INTO tags (label) VALUES ('SPORT');
 
 ------------
 ------------
diff --git a/sql/structure.sql b/sql/structure.sql
index 6c6e97ad33a..00f3b1e87c1 100755
--- a/sql/structure.sql
+++ b/sql/structure.sql
@@ -900,7 +900,6 @@ CREATE TABLE tags
 (
   id serial NOT NULL,
   label character varying(128) NOT NULL,
-  entity_id_owner character varying(32),
   description text,
   parent_id INT,
   creation_date timestamp DEFAULT NOW(),
-- 
GitLab