public attr / function, constructeurs __construct
[mtweb] / mw / app / data / modules / xml / mw_data_xml_install.php
1 <?php
2
3   class mw_data_xml_install extends mw_data{
4
5     public function install_xml($params){
6       $env = $this->env();
7       $data = $env->data();
8       $sgbd = $data->sgbd();
9       $host = isset($params["host"]) ? $params["host"] : "";
10       $base = isset($params["base"]) ? $params["base"] : "";
11       $user = isset($params["user"]) ? $params["user"] : "";
12       $password = isset($params["password"]) ? $params["password"] : "";
13       if(!$host || !$base) return "paramètres manquant pour la base XML";
14       $host .= substr($host, -1) == "/" ? "" : "/";
15       if(!is_dir($host)){
16         $parent_dir = dirname($host);
17         if(is_dir($parent_dir)) @mkdir($host);
18         if(!is_dir($host)) return "impossible de créer le répertoire des données XML";
19       }
20       $base_dir = $host.$base;
21       if(!is_dir($base_dir)) @mkdir($base_dir);
22       if(!is_dir($base_dir)) return "impossible de créer le dossier de la base XML";
23       $base .= substr($base, -1) == "/" ? "" : "/";
24       if(
25             !$sgbd->connect(
26               $host,
27               $base,
28               $user,
29               $password
30             )
31         ||  !$sgbd->select_db($base)
32       ){
33         return "impossible de se connecter à la base XML";
34       }
35       if(!($version = $env->version("mtweb"))){
36         return "impossible de lire la version de mtweb";
37       }
38       $ERROR = false;
39       $EXISTS = false;
40       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("actions_roles");
41       $ERROR = !isset($EXISTS);
42       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("config");
43       $ERROR = !isset($EXISTS);
44       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("roles");
45       $ERROR = !isset($EXISTS);
46       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users");
47       $ERROR = !isset($EXISTS);
48       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("users_roles");
49       $ERROR = !isset($EXISTS);
50       if(!$ERROR && !$EXISTS) $EXISTS = $sgbd->data_exists("versions");
51       $ERROR = !isset($EXISTS);
52       if($ERROR){
53         return "impossible de savoir si les tables existent deja";
54       }
55       if($EXISTS){
56         return "des tables a installer existent deja en base. installation annulee";
57       }
58       if(!$ERROR) if(!$sgbd->create_data("actions_roles")) $ERROR = true;
59       if(!$ERROR) if(!$sgbd->create_data("config")) $ERROR = true;
60       if(!$ERROR) if(!$sgbd->create_data("roles")) $ERROR = true;
61       if(!$ERROR) if(!$sgbd->create_data("users")) $ERROR = true;
62       if(!$ERROR) if(!$sgbd->create_data("users_roles")) $ERROR = true;
63       if(!$ERROR) if(!$sgbd->create_data("versions")) $ERROR = true;
64       if($ERROR){
65         return "imposible de creer les tables en base";
66       }
67
68       // ------------------------------------ actions_roles
69       if(!$ERROR) if(
70         !$sgbd->add_data(
71           "actions_roles",
72           array(
73             "action" => "admin",
74             "id_role" => 1
75           )
76         )
77       ) $ERROR = true;
78       if(!$ERROR) if(
79         !$sgbd->add_data(
80           "actions_roles",
81           array(
82             "action" => "users",
83             "id_role" => 2
84           )
85         )
86       ) $ERROR = true;
87       if(!$ERROR) if(
88         !$sgbd->add_data(
89           "actions_roles",
90           array(
91             "action" => "users/identification",
92             "id_role" => 0
93           )
94         )
95       ) $ERROR = true;
96       if(!$ERROR) if(
97         !$sgbd->add_data(
98           "actions_roles",
99           array(
100             "action" => "config",
101             "id_role" => 3
102           )
103         )
104       ) $ERROR = true;
105
106       // ------------------------------------ config
107       if(!$ERROR) if(
108         !$sgbd->add_data(
109           "config",
110           array(
111             "key" => "site_name",
112             "value" => "mtweb"
113           )
114         )
115       ) $ERROR = true;
116       if(!$ERROR) if(
117         !$sgbd->add_data(
118           "config",
119           array(
120             "key" => "max_list",
121             "value" => "10"
122           )
123         )
124       ) $ERROR = true;
125       if(!$ERROR) if(
126         !$sgbd->add_data(
127           "config",
128           array(
129             "key" => "description",
130             "value" => ""
131           )
132         )
133       ) $ERROR = true;
134       if(!$ERROR) if(
135         !$sgbd->add_data(
136           "config",
137           array(
138             "key" => "out",
139             "value" => "default"
140           )
141         )
142       ) $ERROR = true;
143       if(!$ERROR) if(
144         !$sgbd->add_data(
145           "config",
146           array(
147             "key" => "start_action",
148             "value" => ""
149           )
150         )
151       ) $ERROR = true;
152       if(!$ERROR) if(
153         !$sgbd->add_data(
154           "config",
155           array(
156             "key" => "contact_form",
157             "value" => "0"
158           )
159         )
160       ) $ERROR = true;
161       if(!$ERROR) if(
162         !$sgbd->add_data(
163           "config",
164           array(
165             "key" => "email",
166             "value" => ""
167           )
168         )
169       ) $ERROR = true;
170       if(!$ERROR) if(
171         !$sgbd->add_data(
172           "config",
173           array(
174             "key" => "captcha",
175             "value" => "0"
176           )
177         )
178       ) $ERROR = true;
179       if(!$ERROR) if(
180         !$sgbd->add_data(
181           "config",
182           array(
183             "key" => "start_action_params",
184             "value" => ""
185           )
186         )
187       ) $ERROR = true;
188       if(!$ERROR) if(
189         !$sgbd->add_data(
190           "config",
191           array(
192             "key" => "out_navig_menu_top",
193             "value" => "on"
194           )
195         )
196       ) $ERROR = true;
197       if(!$ERROR) if(
198         !$sgbd->add_data(
199           "config",
200           array(
201             "key" => "out_colonne",
202             "value" => "on"
203           )
204         )
205       ) $ERROR = true;
206       if(!$ERROR) if(
207         !$sgbd->add_data(
208           "config",
209           array(
210             "key" => "default_allow",
211             "value" => "1"
212           )
213         )
214       ) $ERROR = true;
215
216       // ------------------------------------ roles
217       if(!$ERROR){
218         $res = $sgbd->add_data(
219           "roles",
220           array(
221             "nom" => "guest",
222             "intitule" => "invité"
223           ),
224           0
225         );
226         if(!isset($res)) $ERROR = true;
227       } 
228       if(!$ERROR) if(
229         !$sgbd->add_data(
230           "roles",
231           array(
232             "nom" => "admin",
233             "intitule" => "administrateur"
234           )
235         )
236       ) $ERROR = true;
237       if(!$ERROR) if(
238         !$sgbd->add_data(
239           "roles",
240           array(
241             "nom" => "membre",
242             "intitule" => "membre"
243           )
244         )
245       ) $ERROR = true;
246       if(!$ERROR) if(
247         !$sgbd->add_data(
248           "roles",
249           array(
250             "nom" => "webmaster",
251             "intitule" => "webmaster"
252           )
253         )
254       ) $ERROR = true;
255
256       // ------------------------------------ versions
257       if(!$ERROR){
258         $res = $sgbd->add_data(
259           "versions",
260           array(
261             "application" => "mtweb",
262             "version" => $version
263           ),
264           0
265         );
266         if(!isset($res)) $ERROR = true;
267       }
268
269       if($ERROR){
270         return "les tables ont ete ajoutees en base mais impossible d'y enregistrer les valeurs par defaut.";
271       }
272
273       return true;
274     }
275
276   }