0b9ea5580588072f62962b435c5a83a7bd7b6362
[mw_sourceml] / app / data / modules / xml / sml_data_install.php
1 <?php
2
3   class sml_data_install extends mw_data{
4
5     // ---------------------------------------------------------------------------------
6     //                                                                           install
7     //
8
9     function mw_sourceml_install_xml($plugin, $env){
10       $sgbd = $this->sgbd();
11
12       $RES = true;
13       $res = $sgbd->data_exists("sml_authors"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
14       $res = $sgbd->data_exists("sml_classes"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
15       $res = $sgbd->data_exists("sml_licences"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
16       $res = $sgbd->data_exists("sml_sources"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
17       $res = $sgbd->data_exists("sml_sources_access"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
18       $res = $sgbd->data_exists("sml_sources_authors"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
19       $res = $sgbd->data_exists("sml_source_cache"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
20       $res = $sgbd->data_exists("sml_source_compositions"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
21       $res = $sgbd->data_exists("sml_source_derivations"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
22       $res = $sgbd->data_exists("sml_sources_invitations"); if(isset($res)){ if($res) $RES = 1; } else $RES = -1;
23
24       if($RES === -1) return "impossible de savoir si les tables existent deja. installation annulee";
25       if($RES === 1) return "des tables existent deja en base. installation annulee";
26
27       if(!($version = $env->version("mw_sourceml"))){
28         return "impossible de lire la version de sourceml";
29       }
30
31       if(!$sgbd->create_data("sml_authors")) return "impossible de creer la table sml_authors";
32       if(!$sgbd->create_data("sml_classes")) return "impossible de creer la table sml_classes";
33       if(!$sgbd->create_data("sml_licences")) return "impossible de creer la table sml_licences";
34       if(!$sgbd->create_data("sml_sources")) return "impossible de creer la table sml_sources";
35       if(!$sgbd->create_data("sml_sources_access")) return "impossible de creer la table sml_sources_access";
36       if(!$sgbd->create_data("sml_sources_authors")) return "impossible de creer la table sml_sources_authors";
37       if(!$sgbd->create_data("sml_source_cache")) return "impossible de creer la table sml_source_cache";
38       if(!$sgbd->create_data("sml_source_compositions")) return "impossible de creer la table sml_source_compositions";
39       if(!$sgbd->create_data("sml_source_derivations")) return "impossible de creer la table sml_source_derivations";
40       if(!$sgbd->create_data("sml_sources_invitations")) return "impossible de creer la table sml_sources_invitations";
41
42       $ERROR = false;
43
44       // ------------------------------------ sml_licences
45
46       if(!$ERROR) if(
47         !$sgbd->add_data(
48           "sml_licences",
49           array(
50             "nom" => "Creative commons by-sa 2.0",
51             "url" => "http://creativecommons.org/licenses/by-sa/2.0/deed.fr"
52           )
53         )
54       ) $ERROR = true;
55       if(!$ERROR) if(
56         !$sgbd->add_data(
57           "sml_licences",
58           array(
59             "nom" => "Creative Commons by-nc-nd 2.5",
60             "url" => "http://creativecommons.org/licenses/by-nc-nd/2.5/"
61           )
62         )
63       ) $ERROR = true;
64       if(!$ERROR) if(
65         !$sgbd->add_data(
66           "sml_licences",
67           array(
68             "nom" => "Creative Commons by-nc-sa 2.5",
69             "url" => "http://creativecommons.org/licenses/by-nc-sa/2.5/"
70           )
71         )
72       ) $ERROR = true;
73       if(!$ERROR) if(
74         !$sgbd->add_data(
75           "sml_licences",
76           array(
77             "nom" => "Creative Commons by-nc 2.5",
78             "url" => "http://creativecommons.org/licenses/by-nc/2.5/"
79           )
80         )
81       ) $ERROR = true;
82       if(!$ERROR) if(
83         !$sgbd->add_data(
84           "sml_licences",
85           array(
86             "nom" => "Creative Commons by-nd 2.5",
87             "url" => "http://creativecommons.org/licenses/by-nd/2.5/"
88           )
89         )
90       ) $ERROR = true;
91       if(!$ERROR) if(
92         !$sgbd->add_data(
93           "sml_licences",
94           array(
95             "nom" => "Creative Commons by-sa 2.5",
96             "url" => "http://creativecommons.org/licenses/by-sa/2.5/"
97           )
98         )
99       ) $ERROR = true;
100       if(!$ERROR) if(
101         !$sgbd->add_data(
102           "sml_licences",
103           array(
104             "nom" => "Creative Commons by 2.5",
105             "url" => "http://creativecommons.org/licenses/by/2.5/"
106           )
107         )
108       ) $ERROR = true;
109       if(!$ERROR) if(
110         !$sgbd->add_data(
111           "sml_licences",
112           array(
113             "nom" => "Licence Art Libre",
114             "url" => "http://artlibre.org/licence/lal/"
115           )
116         )
117       ) $ERROR = true;
118       if(!$ERROR) if(
119         !$sgbd->add_data(
120           "sml_licences",
121           array(
122             "nom" => "Licence C Reaction",
123             "url" => "http://morne.free.fr/Necktar7/creactionfr.htm"
124           )
125         )
126       ) $ERROR = true;
127       if(!$ERROR) if(
128         !$sgbd->add_data(
129           "sml_licences",
130           array(
131             "nom" => "Yellow OpenMusic License",
132             "url" => "http://openmusic.linuxtag.org/yellow.html"
133           )
134         )
135       ) $ERROR = true;
136       if(!$ERROR) if(
137         !$sgbd->add_data(
138           "sml_licences",
139           array(
140             "nom" => "Green OpenMusic License",
141             "url" => "http://openmusic.linuxtag.org/green.html"
142           )
143         )
144       ) $ERROR = true;
145
146       // ------------------------------------ sml_classes
147
148       if(!$ERROR) if(
149         !$sgbd->add_data(
150           "sml_classes",
151           array(
152             "nom" => "album"
153           )
154         )
155       ) $ERROR = true;
156       if(!$ERROR) if(
157         !$sgbd->add_data(
158           "sml_classes",
159           array(
160             "nom" => "morceau"
161           )
162         )
163       ) $ERROR = true;
164       if(!$ERROR) if(
165         !$sgbd->add_data(
166           "sml_classes",
167           array(
168             "nom" => "piste"
169           )
170         )
171       ) $ERROR = true;
172
173       // ------------------------------------ sml_sources_access
174
175       if(!$ERROR) if(
176         !$sgbd->add_data(
177           "sml_sources_access",
178           array(
179             "nom" => "admin",
180             "intitule" => "administrateur"
181           )
182         )
183       ) $ERROR = true;
184       if(!$ERROR) if(
185         !$sgbd->add_data(
186           "sml_sources_access",
187           array(
188             "nom" => "editeur",
189             "intitule" => "éditeur"
190           )
191         )
192       ) $ERROR = true;
193       if(!$ERROR) if(
194         !$sgbd->add_data(
195           "sml_sources_access",
196           array(
197             "nom" => "contributeur",
198             "intitule" => "contributeur"
199           )
200         )
201       ) $ERROR = true;
202
203       // ------------------------------------ versions
204
205       if(!$ERROR) if(
206         !$sgbd->add_data(
207           "versions",
208           array(
209             "application" => "mw_sourceml",
210             "version" => $version
211           )
212         )
213       ) $ERROR = true;
214
215       if($ERROR){
216         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
217       }
218
219       return true;
220     }
221
222     // ---------------------------------------------------------------------------------
223     //                                                                         uninstall
224     //
225
226     function mw_sourceml_uninstall_xml($plugin, $env){
227       $sgbd = $this->sgbd();
228       if(!$plugin->disable($env)) return "impossible de desactiver le plugin";
229
230       $ERROR = false;
231
232       if(!$ERROR) if(!$sgbd->remove_data("sml_authors")) $ERROR = true;
233       if(!$ERROR) if(!$sgbd->remove_data("sml_classes")) $ERROR = true;
234       if(!$ERROR) if(!$sgbd->remove_data("sml_licences")) $ERROR = true;
235       if(!$ERROR) if(!$sgbd->remove_data("sml_sources")) $ERROR = true;
236       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_access")) $ERROR = true;
237       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_authors")) $ERROR = true;
238       if(!$ERROR) if(!$sgbd->remove_data("sml_source_cache")) $ERROR = true;
239       if(!$ERROR) if(!$sgbd->remove_data("sml_source_compositions")) $ERROR = true;
240       if(!$ERROR) if(!$sgbd->remove_data("sml_source_derivations")) $ERROR = true;
241       if(!$ERROR) if(!$sgbd->remove_data("sml_sources_invitations")) $ERROR = true;
242
243       if(!$ERROR) if(
244         !$this->data_delete(
245           array(
246             "table_name" => "versions",
247             "index_name" => "application",
248             "index_value" => "mw_sourceml"
249           )
250         )
251       ) $ERROR = true;
252
253       if($ERROR){
254         return "erreur lors de la suppression des tables";
255       }
256
257       return true;
258     }
259
260   }