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