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