3 class mw_sourceml extends mw_plugin{
9 function description(){
10 return "Publication de sources musicales";
15 $env->set_link("admin/sourceml", $env->url("admin/sourceml"), "SourceML", 50);
16 $env->set_link("admin/sourceml/licences", $env->url("admin/licences"), "Licences", 10);
17 $env->set_link("admin/sourceml/cache", $env->url("admin/cache"), "Cache", 20);
18 $env->set_link("admin/sourceml/maintenance", $env->url("admin/maintenance"), "Maintenance", 30);
20 $env->set_link("users/authors", $env->url("users/groupes"), "Groupes", 30);
21 $env->set_link("users/albums", $env->url("users/albums"), "Albums", 31);
22 $env->set_link("users/morceaux", $env->url("users/morceaux"), "Morceaux", 32);
23 $env->set_link("users/pistes", $env->url("users/pistes"), "Sources", 33);
25 $env->set_link("menu_top/groupes", $env->url("sources/groupe"), "Groupes", 10);
26 $env->set_link("menu_top/albums", $env->url("sources/album"), "Albums", 11);
27 $env->set_link("menu_top/morceaux", $env->url("sources/morceau"), "Morceaux", 12);
28 $env->set_link("menu_top/pistes", $env->url("sources/piste"), "Sources", 13);
33 function enable($env){
37 function disable($env){
41 // ---------------------------------------------------------------------------------
45 function install($env){
47 $env->bdd("sgbd") == "mysql"
48 || $env->bdd("sgbd") == "pdo_mysql"
49 ) return $this->install_mysql($env);
53 function install_mysql($env){
55 $sgbd = $data->sgbd();
58 $sgbd->table_exists("#--sml_authors")
59 || $sgbd->table_exists("#--sml_classes")
60 || $sgbd->table_exists("#--sml_licences")
61 || $sgbd->table_exists("#--sml_sources")
62 || $sgbd->table_exists("#--sml_sources_access")
63 || $sgbd->table_exists("#--sml_sources_authors")
64 || $sgbd->table_exists("#--sml_sources_infos")
65 || $sgbd->table_exists("#--sml_source_cache")
66 || $sgbd->table_exists("#--sml_source_compositions")
67 || $sgbd->table_exists("#--sml_source_derivations")
68 || $sgbd->table_exists("#--sml_source_documents");
71 return "impossible de savoir si les tables existent deja";
74 return "des tables existent deja en base. installation annulee";
78 "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"";
82 "CREATE TABLE `#--sml_authors`("
83 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
84 ." `id_user` int(11) NOT NULL,"
85 ." `nom` varchar(255) NOT NULL,"
86 ." `image` varchar(255) DEFAULT NULL,"
87 ." `description` text,"
88 ." `email` varchar(255) NOT NULL,"
89 ." `contact_form` tinyint(4) NOT NULL,"
90 ." `captcha` tinyint(4) NOT NULL,"
91 ." PRIMARY KEY (`id`),"
92 ." KEY `id_user` (`id_user`)"
93 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
97 "CREATE TABLE `#--sml_classes`("
98 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
99 ." `nom` varchar(255) NOT NULL,"
100 ." PRIMARY KEY (`id`)"
101 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
105 "CREATE TABLE `#--sml_licences`("
106 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
107 ." `nom` varchar(255) NOT NULL,"
108 ." `url` varchar(255) NOT NULL,"
109 ." PRIMARY KEY (`id`)"
110 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
114 "CREATE TABLE `#--sml_sources`("
115 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
116 ." `id_class` int(11) NOT NULL,"
117 ." `reference` varchar(255) DEFAULT NULL,"
118 ." `titre` varchar(255) DEFAULT NULL,"
119 ." `licence` int(11) DEFAULT NULL,"
120 ." `date_creation` date DEFAULT NULL,"
121 ." `date_inscription` datetime NOT NULL,"
122 ." PRIMARY KEY (`id`),"
123 ." KEY `id_class` (`id_class`),"
124 ." KEY `licence` (`licence`)"
125 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
129 "CREATE TABLE `#--sml_sources_access`("
130 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
131 ." `nom` varchar(255) NOT NULL,"
132 ." `intitule` varchar(255) NOT NULL,"
133 ." PRIMARY KEY (`id`)"
134 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
138 "CREATE TABLE `#--sml_sources_authors`("
139 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
140 ." `id_source` int(11) NOT NULL,"
141 ." `id_author` int(11) NOT NULL,"
142 ." `id_sources_access` int(11) NOT NULL,"
143 ." PRIMARY KEY (`id`),"
144 ." KEY `id_object` (`id_source`),"
145 ." KEY `id_author` (`id_author`),"
146 ." KEY `id_sources_access` (`id_sources_access`)"
147 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
151 "CREATE TABLE `#--sml_sources_infos`("
152 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
153 ." `id_source` int(11) NOT NULL,"
154 ." `key` varchar(255) NOT NULL,"
155 ." `value` text NOT NULL,"
156 ." PRIMARY KEY (`id`),"
157 ." KEY `id_source` (`id_source`)"
158 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
162 "CREATE TABLE `#--sml_source_cache`("
163 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
164 ." `url` varchar(255) NOT NULL,"
165 ." `id_source` int(11) NOT NULL,"
166 ." `last_update` datetime NOT NULL,"
167 ." PRIMARY KEY (`id`)"
168 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
172 "CREATE TABLE `#--sml_source_compositions`("
173 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
174 ." `id_source` int(11) NOT NULL,"
175 ." `id_composition` int(11) NOT NULL,"
176 ." PRIMARY KEY (`id`),"
177 ." KEY `id_source` (`id_source`),"
178 ." KEY `id_composition` (`id_composition`)"
179 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
183 "CREATE TABLE `#--sml_source_derivations`("
184 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
185 ." `id_source` int(11) NOT NULL,"
186 ." `derivation` varchar(255) NOT NULL,"
187 ." PRIMARY KEY (`id`),"
188 ." KEY `derivation` (`derivation`)"
189 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
193 "CREATE TABLE `#--sml_source_documents`("
194 ." `id` int(11) NOT NULL AUTO_INCREMENT,"
195 ." `id_source` int(11) NOT NULL,"
196 ." `nom` varchar(255) NOT NULL,"
197 ." `url` varchar(255) NOT NULL,"
198 ." PRIMARY KEY (`id`),"
199 ." KEY `id_source` (`id_source`)"
200 .") DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
205 return "imposible de creer les tables en base";
209 "INSERT INTO `#--sml_licences` (`id`, `nom`, `url`) VALUES"
210 ."(1, 'Creative commons by-sa 2.0', 'http://creativecommons.org/licenses/by-sa/2.0/deed.fr'),"
211 ."(2, 'Creative Commons by-nc-nd 2.5', 'http://creativecommons.org/licenses/by-nc-nd/2.5/'),"
212 ."(3, 'Creative Commons by-nc-sa 2.5', 'http://creativecommons.org/licenses/by-nc-sa/2.5/'),"
213 ."(4, 'Creative Commons by-nc 2.5', 'http://creativecommons.org/licenses/by-nc/2.5/'),"
214 ."(5, 'Creative Commons by-nd 2.5', 'http://creativecommons.org/licenses/by-nd/2.5/'),"
215 ."(6, 'Creative Commons by-sa 2.5', 'http://creativecommons.org/licenses/by-sa/2.5/'),"
216 ."(7, 'Creative Commons by 2.5', 'http://creativecommons.org/licenses/by/2.5/'),"
217 ."(8, 'Licence Art Libre', 'http://artlibre.org/licence/lal/'),"
218 ."(9, 'Licence C Reaction', 'http://morne.free.fr/Necktar7/creactionfr.htm'),"
219 ."(10, 'Yellow OpenMusic License', 'http://openmusic.linuxtag.org/yellow.html'),"
220 ."(11, 'Green OpenMusic License', 'http://openmusic.linuxtag.org/green.html')";
224 "INSERT INTO `#--sml_classes` (`id`, `nom`) VALUES"
231 "INSERT INTO `mw_sml_sources_access` (`id`, `nom`, `intitule`) VALUES"
\r
232 ."(1, 'admin', 'administrateur'),"
\r
233 ."(2, 'editeur', 'éditeur'),"
\r
234 ."(3, 'contributeur', 'contributeur')";
239 return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
244 // ---------------------------------------------------------------------------------
248 function uninstall($env){
250 $env->bdd("sgbd") == "mysql"
251 || $env->bdd("sgbd") == "pdo_mysql"
252 ) return $this->uninstall_mysql($env);
256 function uninstall_mysql($env){
257 $data = $env->data();
258 $sgbd = $data->sgbd();
259 if(!$this->disable($env)) return "impossible de desactiver le plugin";
261 $sgbd->query("DROP TABLE #--sml_authors");
264 return "impossible de supprimer la table #--sml_authors";
267 $sgbd->query("DROP TABLE #--sml_classes");
270 return "impossible de supprimer la table #--sml_classes";
273 $sgbd->query("DROP TABLE #--sml_licences");
276 return "impossible de supprimer la table #--sml_licences";
279 $sgbd->query("DROP TABLE #--sml_sources");
282 return "impossible de supprimer la table #--sml_sources";
285 $sgbd->query("DROP TABLE #--sml_sources_access");
288 return "impossible de supprimer la table #--sml_sources_access";
291 $sgbd->query("DROP TABLE #--sml_sources_authors");
294 return "impossible de supprimer la table #--sml_sources_authors";
297 $sgbd->query("DROP TABLE #--sml_sources_infos");
300 return "impossible de supprimer la table #--sml_sources_infos";
303 $sgbd->query("DROP TABLE #--sml_source_cache");
306 return "impossible de supprimer la table #--sml_source_cache";
309 $sgbd->query("DROP TABLE #--sml_source_compositions");
312 return "impossible de supprimer la table #--sml_source_compositions";
315 $sgbd->query("DROP TABLE #--sml_source_derivations");
318 return "impossible de supprimer la table #--sml_source_derivations";
321 $sgbd->query("DROP TABLE #--sml_source_documents");
324 return "impossible de supprimer la table #--sml_source_documents";