1 | <?php |
---|
2 | /** |
---|
3 | * Plugin Comptes & Contacts pour Spip 2.0 |
---|
4 | * Licence GPL (c) 2009 - 2010 - Ateliers CYM |
---|
5 | */ |
---|
6 | |
---|
7 | include_spip('inc/meta'); |
---|
8 | include_spip('base/create'); |
---|
9 | |
---|
10 | function contacts_upgrade($nom_meta_base_version, $version_cible){ |
---|
11 | |
---|
12 | $current_version = "0.0"; |
---|
13 | if (isset($GLOBALS['meta'][$nom_meta_base_version])) |
---|
14 | $current_version = $GLOBALS['meta'][$nom_meta_base_version]; |
---|
15 | |
---|
16 | if ($current_version=="0.0") { |
---|
17 | creer_base(); |
---|
18 | spip_log('Tables C&O correctement créées','contacts'); |
---|
19 | ecrire_meta($nom_meta_base_version, $current_version=$version_cible); |
---|
20 | } |
---|
21 | if (version_compare($current_version,"1.1.0","<")){ |
---|
22 | sql_alter("TABLE spip_contacts CHANGE prenom prenom tinytext NOT NULL DEFAULT ''"); |
---|
23 | ecrire_meta($nom_meta_base_version, $current_version="1.1.0"); |
---|
24 | } |
---|
25 | if (version_compare($current_version,"1.1.1","<")){ |
---|
26 | maj_tables('spip_contacts'); |
---|
27 | ecrire_meta($nom_meta_base_version, $current_version="1.1.1"); |
---|
28 | } |
---|
29 | if (version_compare($current_version,"1.1.2","<")){ |
---|
30 | // dupliquer id_ pour les jointures automatiques. |
---|
31 | maj_tables(array('spip_contacts', 'spip_comptes')); |
---|
32 | sql_alter('TABLE spip_contacts ADD INDEX (id_contact)'); |
---|
33 | sql_alter('TABLE spip_comptes ADD INDEX (id_compte)'); |
---|
34 | sql_alter('TABLE spip_comptes_contacts ADD INDEX (id_contact)'); |
---|
35 | sql_update('spip_contacts', array('id_contact'=>'id_auteur')); |
---|
36 | sql_update('spip_comptes', array('id_compte'=>'id_auteur')); |
---|
37 | ecrire_meta($nom_meta_base_version, $current_version="1.1.2"); |
---|
38 | } |
---|
39 | if (version_compare($current_version,"1.2.0","<")){ |
---|
40 | // on passe de compte a organisation... |
---|
41 | sql_alter('TABLE spip_comptes DROP INDEX id_compte'); |
---|
42 | sql_alter('TABLE spip_comptes_contacts DROP INDEX id_compte'); |
---|
43 | |
---|
44 | sql_alter('TABLE spip_comptes RENAME spip_organisations'); |
---|
45 | sql_alter('TABLE spip_comptes_contacts RENAME spip_organisations_contacts'); |
---|
46 | |
---|
47 | sql_alter('TABLE spip_organisations CHANGE id_compte id_organisation bigint(21) NOT NULL'); |
---|
48 | sql_alter('TABLE spip_organisations_contacts CHANGE id_compte id_organisation bigint(21) NOT NULL'); |
---|
49 | |
---|
50 | sql_alter('TABLE spip_organisations ADD INDEX (id_organisation)'); |
---|
51 | sql_alter('TABLE spip_organisations_contacts ADD INDEX (id_organisation)'); |
---|
52 | ecrire_meta($nom_meta_base_version, $current_version="1.2.0"); |
---|
53 | } |
---|
54 | if (version_compare($current_version,"1.2.1","<")){ |
---|
55 | // on modifie quelques champs de la table organisations |
---|
56 | sql_alter("TABLE spip_organisations CHANGE type statut_juridique TINYTEXT NOT NULL DEFAULT ''"); // renomme le champ 'type' en 'statut_juridique' |
---|
57 | sql_alter("TABLE spip_organisations CHANGE siret identification TINYTEXT NOT NULL DEFAULT ''"); // renomme le champ 'siret' en 'identification' |
---|
58 | sql_alter("TABLE spip_organisations ADD activite TINYTEXT NOT NULL DEFAULT '' AFTER identification"); // ajoute le champ 'activite' |
---|
59 | spip_log('Tables correctement passsées en version 1.2.1','contacts'); |
---|
60 | ecrire_meta($nom_meta_base_version, $current_version="1.2.1"); |
---|
61 | } |
---|
62 | if (version_compare($current_version,"1.3.0","<")){ |
---|
63 | // les clés primaires des tables contacts et organisations |
---|
64 | // passent sur le id_contact et id_organisation au lieu du id_auteur |
---|
65 | // afin de gérer éventuellement des contacts/organisations autonomes. |
---|
66 | sql_alter('TABLE spip_organisations DROP INDEX id_organisation'); |
---|
67 | sql_alter('TABLE spip_organisations DROP PRIMARY KEY'); |
---|
68 | sql_alter('TABLE spip_organisations CHANGE id_auteur id_auteur bigint(21) NOT NULL'); |
---|
69 | sql_alter('TABLE spip_organisations CHANGE id_organisation id_organisation bigint(21) NOT NULL auto_increment PRIMARY KEY'); |
---|
70 | sql_alter('TABLE spip_organisations ADD INDEX (id_auteur)'); |
---|
71 | |
---|
72 | sql_alter('TABLE spip_contacts DROP INDEX id_contact'); |
---|
73 | sql_alter('TABLE spip_contacts DROP PRIMARY KEY'); |
---|
74 | sql_alter('TABLE spip_contacts CHANGE id_auteur id_auteur bigint(21) NOT NULL'); |
---|
75 | sql_alter('TABLE spip_contacts CHANGE id_contact id_contact bigint(21) NOT NULL auto_increment PRIMARY KEY'); |
---|
76 | sql_alter('TABLE spip_contacts ADD INDEX (id_auteur)'); |
---|
77 | |
---|
78 | spip_log('Tables correctement passsées en version 1.3.0','contacts'); |
---|
79 | ecrire_meta($nom_meta_base_version, $current_version="1.3.0"); |
---|
80 | } |
---|
81 | |
---|
82 | if (version_compare($current_version,"1.3.1","<")){ |
---|
83 | if (!sql_alter("TABLE spip_contacts CHANGE descriptif descriptif TEXT DEFAULT '' NOT NULL")) { |
---|
84 | spip_log('Probleme lors de la modif de la table spip_contacts','contacts'); |
---|
85 | } else { |
---|
86 | spip_log('Table spip_contacts correctement passsée en version 1.3.1','contacts'); |
---|
87 | } |
---|
88 | if (!sql_alter("TABLE spip_organisations CHANGE descriptif descriptif TEXT DEFAULT '' NOT NULL")) { |
---|
89 | spip_log('Probleme lors de la modif de la table spip_organisations','contacts'); |
---|
90 | } else { |
---|
91 | spip_log('Table spip_organisations correctement passsée en version 1.3.1','contacts'); |
---|
92 | } |
---|
93 | |
---|
94 | ecrire_meta($nom_meta_base_version, $current_version="1.3.1"); |
---|
95 | } |
---|
96 | |
---|
97 | if (version_compare($current_version,"1.3.2","<")){ |
---|
98 | maj_tables('spip_contacts_liens'); |
---|
99 | $res = sql_select(array("id_auteur","id_contact"),"spip_contacts"); |
---|
100 | while ($row = sql_fetch($res)) { |
---|
101 | sql_insertq( |
---|
102 | 'spip_contacts_liens', |
---|
103 | array( |
---|
104 | "id_objet" => $row['id_auteur'], |
---|
105 | "objet" => "auteur", |
---|
106 | "id_contact" => $row['id_contact'] |
---|
107 | ) |
---|
108 | ); |
---|
109 | } |
---|
110 | |
---|
111 | if (!sql_alter("TABLE spip_contacts DROP id_auteur")) { |
---|
112 | spip_log('Probleme lors de la modif de la table spip_contacts','contacts'); |
---|
113 | } else { |
---|
114 | spip_log('Table spip_contacts correctement passsée en version 1.3.2','contacts'); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | spip_log('Tables correctement passsées en version 1.3.2','contacts'); |
---|
119 | ecrire_meta($nom_meta_base_version, $current_version="1.3.2"); |
---|
120 | } |
---|
121 | |
---|
122 | // le champ descriptif ne changeait pas sur les nouvelles installations (c'etait encore declare tinytext |
---|
123 | if (version_compare($current_version,"1.3.3","<")){ |
---|
124 | if (!sql_alter("TABLE spip_contacts CHANGE descriptif descriptif TEXT DEFAULT '' NOT NULL")) { |
---|
125 | ecrire_meta($nom_meta_base_version, $current_version="1.3.3"); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | function contacts_vider_tables($nom_meta_base_version) { |
---|
131 | sql_drop_table("spip_organisations"); |
---|
132 | sql_drop_table("spip_contacts"); |
---|
133 | sql_drop_table("spip_contacts_liens"); |
---|
134 | sql_drop_table("spip_organisations_contacts"); |
---|
135 | |
---|
136 | effacer_meta($nom_meta_base_version); |
---|
137 | } |
---|
138 | |
---|
139 | ?> |
---|