3 class sml_data_install extends mw_data{
5 // ---------------------------------------------------------------------------------
9 function mw_sourceml_install_mysql($plugin, $env){
10 $sgbd = $this->sgbd();
13 $sgbd->table_exists("#--sml_authors")
14 || $sgbd->table_exists("#--sml_classes")
15 || $sgbd->table_exists("#--sml_licences")
16 || $sgbd->table_exists("#--sml_sources")
17 || $sgbd->table_exists("#--sml_sources_access")
18 || $sgbd->table_exists("#--sml_sources_authors")
19 || $sgbd->table_exists("#--sml_sources_infos")
20 || $sgbd->table_exists("#--sml_source_cache")
21 || $sgbd->table_exists("#--sml_source_compositions")
22 || $sgbd->table_exists("#--sml_source_derivations")
23 || $sgbd->table_exists("#--sml_source_documents")
24 || $sgbd->table_exists("#--sml_sources_invitations");
27 return "impossible de savoir si les tables existent deja";
30 return "des tables existent deja en base. installation annulee";
32 if(!($version = $env->version("mw_sourceml"))){
33 return "impossible de lire la version de sourceml";
37 "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"";
41 "CREATE TABLE `#--sml_authors`("
42 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
43 ." `id_user` int(11) NOT NULL,"
44 ." `nom` varchar(255) NOT NULL,"
45 ." `image` varchar(255) DEFAULT NULL,"
46 ." `description` text,"
47 ." `email` varchar(255) NOT NULL,"
48 ." `contact_form` tinyint(4) NOT NULL,"
49 ." `captcha` tinyint(4) NOT NULL,"
50 ." PRIMARY KEY (`id`),"
51 ." KEY `id_user` (`id_user`)"
52 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
56 "CREATE TABLE `#--sml_classes`("
57 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
58 ." `nom` varchar(255) NOT NULL,"
59 ." PRIMARY KEY (`id`)"
60 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
64 "CREATE TABLE `#--sml_licences`("
65 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
66 ." `nom` varchar(255) NOT NULL,"
67 ." `url` varchar(255) NOT NULL,"
68 ." PRIMARY KEY (`id`)"
69 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
73 "CREATE TABLE `#--sml_sources`("
74 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
75 ." `id_class` int(11) NOT NULL,"
76 ." `reference` varchar(255) DEFAULT NULL,"
77 ." `titre` varchar(255) DEFAULT NULL,"
78 ." `licence` int(11) DEFAULT NULL,"
79 ." `date_creation` date DEFAULT NULL,"
80 ." `date_inscription` datetime NOT NULL,"
81 ." PRIMARY KEY (`id`),"
82 ." KEY `id_class` (`id_class`),"
83 ." KEY `licence` (`licence`)"
84 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
88 "CREATE TABLE `#--sml_sources_access`("
89 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
90 ." `nom` varchar(255) NOT NULL,"
91 ." `intitule` varchar(255) NOT NULL,"
92 ." PRIMARY KEY (`id`)"
93 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
97 "CREATE TABLE `#--sml_sources_authors`("
98 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
99 ." `id_source` int(11) NOT NULL,"
100 ." `id_author` int(11) NOT NULL,"
101 ." `id_sources_access` int(11) NOT NULL,"
102 ." PRIMARY KEY (`id`),"
103 ." KEY `id_object` (`id_source`),"
104 ." KEY `id_author` (`id_author`),"
105 ." KEY `id_sources_access` (`id_sources_access`)"
106 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
110 "CREATE TABLE `#--sml_sources_infos`("
111 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
112 ." `id_source` int(11) NOT NULL,"
113 ." `key` varchar(255) NOT NULL,"
114 ." `value` text NOT NULL,"
115 ." PRIMARY KEY (`id`),"
116 ." KEY `id_source` (`id_source`)"
117 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
121 "CREATE TABLE `#--sml_source_cache`("
122 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
123 ." `url` varchar(255) NOT NULL,"
124 ." `id_source` int(11) NOT NULL,"
125 ." `last_update` datetime NOT NULL,"
126 ." PRIMARY KEY (`id`)"
127 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
131 "CREATE TABLE `#--sml_source_compositions`("
132 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
133 ." `id_source` int(11) NOT NULL,"
134 ." `id_composition` int(11) NOT NULL,"
135 ." PRIMARY KEY (`id`),"
136 ." KEY `id_source` (`id_source`),"
137 ." KEY `id_composition` (`id_composition`)"
138 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
142 "CREATE TABLE `#--sml_source_derivations`("
143 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
144 ." `id_source` int(11) NOT NULL,"
145 ." `derivation` varchar(255) NOT NULL,"
146 ." PRIMARY KEY (`id`),"
147 ." KEY `derivation` (`derivation`)"
148 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
152 "CREATE TABLE `#--sml_source_documents`("
153 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
154 ." `id_source` int(11) NOT NULL,"
155 ." `nom` varchar(255) NOT NULL,"
156 ." `url` varchar(255) NOT NULL,"
157 ." PRIMARY KEY (`id`),"
158 ." KEY `id_source` (`id_source`)"
159 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
163 "CREATE TABLE `#--sml_sources_invitations`("
164 ." `id` INT(11) NOT NULL AUTO_INCREMENT,"
165 ." `id_user` INT(11) NOT NULL,"
166 ." `id_source` INT(11) NOT NULL,"
167 ." `id_author` INT(11) NOT NULL,"
168 ." `id_sources_access` INT(11) NOT NULL,"
169 ." `date_invitation` datetime NOT NULL,"
170 ." PRIMARY KEY (`id`)"
176 return "imposible de creer les tables en base";
180 "INSERT INTO `#--sml_licences` (`id`, `nom`, `url`) VALUES"
181 ."(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr'),"
182 ."(2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/'),"
183 ."(3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/'),"
184 ."(4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/'),"
185 ."(5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/'),"
186 ."(6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/'),"
187 ."(7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/'),"
188 ."(8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/'),"
189 ."(9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm'),"
190 ."(10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html'),"
191 ."(11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
195 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES"
202 "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES"
\r
203 ."(1, 'admin', 'administrateur'),"
\r
204 ."(2, 'editeur', 'éditeur'),"
\r
205 ."(3, 'contributeur', 'contributeur')";
209 "INSERT INTO `#--versions` (`application`, `version`) VALUES"
\r
210 ."('mw_sourceml', ".$this->eq($version).")";
215 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
220 function mw_sourceml_install_sqlite($plugin, $env){
221 $sgbd = $this->sgbd();
224 $sgbd->table_exists("#--sml_authors")
225 || $sgbd->table_exists("#--sml_classes")
226 || $sgbd->table_exists("#--sml_licences")
227 || $sgbd->table_exists("#--sml_sources")
228 || $sgbd->table_exists("#--sml_sources_access")
229 || $sgbd->table_exists("#--sml_sources_authors")
230 || $sgbd->table_exists("#--sml_sources_infos")
231 || $sgbd->table_exists("#--sml_source_cache")
232 || $sgbd->table_exists("#--sml_source_compositions")
233 || $sgbd->table_exists("#--sml_source_derivations")
234 || $sgbd->table_exists("#--sml_source_documents")
235 || $sgbd->table_exists("#--sml_sources_invitations");
238 return "impossible de savoir si les tables existent deja";
241 return "des tables existent deja en base. installation annulee";
243 if(!($version = $env->version("mw_sourceml"))){
244 return "impossible de lire la version de sourceml";
249 "CREATE TABLE #--sml_authors("
250 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
251 ." `id_user` INTEGER NOT NULL,"
252 ." `nom` TEXT NOT NULL,"
253 ." `image` TEXT DEFAULT NULL,"
254 ." `description` TEXT,"
255 ." `email` TEXT NOT NULL,"
256 ." `contact_form` INTEGER NOT NULL,"
257 ." `captcha` INTEGER NOT NULL"
262 "CREATE TABLE #--sml_classes("
263 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
264 ." `nom` TEXT NOT NULL"
269 "CREATE TABLE #--sml_licences("
270 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
271 ." `nom` TEXT NOT NULL,"
272 ." `url` TEXT NOT NULL"
277 "CREATE TABLE #--sml_sources("
278 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
279 ." `id_class` INTEGER NOT NULL,"
280 ." `reference` TEXT DEFAULT NULL,"
281 ." `titre` TEXT DEFAULT NULL,"
282 ." `licence` INTEGER DEFAULT NULL,"
283 ." `date_creation` TEXT DEFAULT NULL,"
284 ." `date_inscription` TEXT NOT NULL"
289 "CREATE TABLE #--sml_sources_access("
290 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
291 ." `nom` TEXT NOT NULL,"
292 ." `intitule` TEXT NOT NULL"
297 "CREATE TABLE #--sml_sources_authors("
298 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
299 ." `id_source` INTEGER NOT NULL,"
300 ." `id_author` INTEGER NOT NULL,"
301 ." `id_sources_access` INTEGER NOT NULL"
306 "CREATE TABLE #--sml_sources_infos("
307 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
308 ." `id_source` INTEGER NOT NULL,"
309 ." `key` TEXT NOT NULL,"
310 ." `value` TEXT NOT NULL"
315 "CREATE TABLE #--sml_source_cache("
316 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
317 ." `url` TEXT NOT NULL,"
318 ." `id_source` INTEGER NOT NULL,"
319 ." `last_update` TEXT NOT NULL"
324 "CREATE TABLE #--sml_source_compositions("
325 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
326 ." `id_source` INTEGER NOT NULL,"
327 ." `id_composition` INTEGER NOT NULL"
332 "CREATE TABLE #--sml_source_derivations("
333 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
334 ." `id_source` INTEGER NOT NULL,"
335 ." `derivation` TEXT NOT NULL"
340 "CREATE TABLE #--sml_source_documents("
341 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
342 ." `id_source` INTEGER NOT NULL,"
343 ." `nom` TEXT NOT NULL,"
344 ." `url` TEXT NOT NULL"
349 "CREATE TABLE #--sml_sources_invitations("
350 ." `id` INTEGER PRIMARY KEY AUTOINCREMENT,"
351 ." `id_user` INTEGER NOT NULL,"
352 ." `id_source` INTEGER NOT NULL,"
353 ." `id_author` INTEGER NOT NULL,"
354 ." `id_sources_access` INTEGER NOT NULL,"
355 ." `date_invitation` TEXT NOT NULL"
361 return "imposible de creer les tables en base";
365 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
366 ." VALUES(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr')";
370 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
371 ." VALUES (2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/')";
375 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
376 ." VALUES (3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/')";
380 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
381 ." VALUES (4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/')";
385 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
386 ." VALUES (5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/')";
390 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
391 ." VALUES (6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/')";
395 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
396 ." VALUES (7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/')";
400 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
401 ." VALUES (8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/')";
405 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
406 ." VALUES (9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm')";
410 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
411 ." VALUES (10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html')";
415 "INSERT INTO #--sml_licences(`id`, `nom`, `url`)"
416 ." VALUES (11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
420 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (1, 'album')";
424 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (2, 'morceau')";
428 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES (3, 'piste')";
432 "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES (1, 'admin', 'administrateur')";
\r
436 "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES (2, 'editeur', 'éditeur')";
440 "INSERT INTO `#--sml_sources_access` (`id`, `nom`, `intitule`) VALUES (3, 'contributeur', 'contributeur')";
444 "INSERT INTO `#--versions` (`application`, `version`) VALUES ('mw_sourceml', ".$this->eq($version).")";
449 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
454 // ---------------------------------------------------------------------------------
458 function mw_sourceml_uninstall_sql($plugin, $env){
459 $sgbd = $this->sgbd();
460 if(!$plugin->disable($env)) return "impossible de desactiver le plugin";
461 if(!($version = $env->version("mw_sourceml"))){
462 return "impossible de lire la version de sourceml";
465 $sgbd->query("DROP TABLE #--sml_authors");
468 return "impossible de supprimer la table #--sml_authors";
471 $sgbd->query("DROP TABLE #--sml_classes");
474 return "impossible de supprimer la table #--sml_classes";
477 $sgbd->query("DROP TABLE #--sml_licences");
480 return "impossible de supprimer la table #--sml_licences";
483 $sgbd->query("DROP TABLE #--sml_sources");
486 return "impossible de supprimer la table #--sml_sources";
489 $sgbd->query("DROP TABLE #--sml_sources_access");
492 return "impossible de supprimer la table #--sml_sources_access";
495 $sgbd->query("DROP TABLE #--sml_sources_authors");
498 return "impossible de supprimer la table #--sml_sources_authors";
501 $sgbd->query("DROP TABLE #--sml_sources_infos");
504 return "impossible de supprimer la table #--sml_sources_infos";
507 $sgbd->query("DROP TABLE #--sml_source_cache");
510 return "impossible de supprimer la table #--sml_source_cache";
513 $sgbd->query("DROP TABLE #--sml_source_compositions");
516 return "impossible de supprimer la table #--sml_source_compositions";
519 $sgbd->query("DROP TABLE #--sml_source_derivations");
522 return "impossible de supprimer la table #--sml_source_derivations";
525 $sgbd->query("DROP TABLE #--sml_source_documents");
528 return "impossible de supprimer la table #--sml_source_documents";
531 $sgbd->query("DROP TABLE #--sml_sources_invitations");
534 return "impossible de supprimer la table #--sml_sources_invitations";
537 $sgbd->query("DELETE FROM #--versions WHERE application='mw_sourceml'");
540 return "impossible de supprimer la table #--sml_sources_invitations";