1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - Setup * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * -------------------------------------------- * |
---|
6 | * This file written by Dan Kuykendall<seek3r@phpgroupware.org> * |
---|
7 | * and Miles Lott<milos@groupwhere.org> * |
---|
8 | * -------------------------------------------- * |
---|
9 | * This program is free software; you can redistribute it and/or modify it * |
---|
10 | * under the terms of the GNU General Public License as published by the * |
---|
11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
12 | * option) any later version. * |
---|
13 | \**************************************************************************/ |
---|
14 | |
---|
15 | |
---|
16 | class setup_detection |
---|
17 | { |
---|
18 | function get_versions() |
---|
19 | { |
---|
20 | $d = dir(PHPGW_SERVER_ROOT); |
---|
21 | while($entry=$d->read()) |
---|
22 | { |
---|
23 | if($entry != ".." && !preg_match("/setup/",$entry) && is_dir(PHPGW_SERVER_ROOT . '/' . $entry)) |
---|
24 | { |
---|
25 | $f = PHPGW_SERVER_ROOT . '/' . $entry . '/setup/setup.inc.php'; |
---|
26 | if (@file_exists ($f)) |
---|
27 | { |
---|
28 | include($f); |
---|
29 | $setup_info[$entry]['filename'] = $f; |
---|
30 | } |
---|
31 | } |
---|
32 | } |
---|
33 | $d->close(); |
---|
34 | |
---|
35 | // _debug_array($setup_info); |
---|
36 | @ksort($setup_info); |
---|
37 | return $setup_info; |
---|
38 | } |
---|
39 | |
---|
40 | function get_db_versions($setup_info='') |
---|
41 | { |
---|
42 | $tname = Array(); |
---|
43 | $GLOBALS['phpgw_setup']->db->Halt_On_Error = 'no'; |
---|
44 | $tables = $GLOBALS['phpgw_setup']->db->table_names(); |
---|
45 | foreach($tables as $key => $val) |
---|
46 | { |
---|
47 | $tname[] = $val['table_name']; |
---|
48 | } |
---|
49 | $newapps = in_array('phpgw_applications',$tname); |
---|
50 | $oldapps = in_array('applications',$tname); |
---|
51 | |
---|
52 | if((count($tables) > 0) && (is_array($tables)) && ($newapps || $oldapps)) |
---|
53 | { |
---|
54 | /* one of these tables exists. checking for post/pre beta version */ |
---|
55 | if($newapps) |
---|
56 | { |
---|
57 | $GLOBALS['phpgw_setup']->db->query('SELECT * FROM phpgw_applications',__LINE__,__FILE__); |
---|
58 | while(@$GLOBALS['phpgw_setup']->db->next_record()) |
---|
59 | { |
---|
60 | $setup_info[$GLOBALS['phpgw_setup']->db->f('app_name')]['currentver'] = $GLOBALS['phpgw_setup']->db->f('app_version'); |
---|
61 | $setup_info[$GLOBALS['phpgw_setup']->db->f('app_name')]['enabled'] = $GLOBALS['phpgw_setup']->db->f('app_enabled'); |
---|
62 | } |
---|
63 | /* This is to catch old setup installs that did not have phpgwapi listed as an app */ |
---|
64 | $tmp = @$setup_info['phpgwapi']['version']; /* save the file version */ |
---|
65 | if(!@$setup_info['phpgwapi']['currentver']) |
---|
66 | { |
---|
67 | $setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver']; |
---|
68 | $setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver']; |
---|
69 | $setup_info['phpgwapi']['enabled'] = $setup_info['admin']['enabled']; |
---|
70 | // _debug_array($setup_info['phpgwapi']);exit; |
---|
71 | // There seems to be a problem here. If ['phpgwapi']['currentver'] is set, |
---|
72 | // The GLOBALS never gets set. |
---|
73 | $GLOBALS['setup_info'] = $setup_info; |
---|
74 | $GLOBALS['phpgw_setup']->register_app('phpgwapi'); |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | $GLOBALS['setup_info'] = $setup_info; |
---|
79 | } |
---|
80 | $setup_info['phpgwapi']['version'] = $tmp; /* restore the file version */ |
---|
81 | } |
---|
82 | elseif($oldapps) |
---|
83 | { |
---|
84 | $GLOBALS['phpgw_setup']->db->query('select * from applications'); |
---|
85 | while(@$GLOBALS['phpgw_setup']->db->next_record()) |
---|
86 | { |
---|
87 | if($GLOBALS['phpgw_setup']->db->f('app_name') == 'admin') |
---|
88 | { |
---|
89 | $setup_info['phpgwapi']['currentver'] = $GLOBALS['phpgw_setup']->db->f('app_version'); |
---|
90 | } |
---|
91 | $setup_info[$GLOBALS['phpgw_setup']->db->f('app_name')]['currentver'] = $GLOBALS['phpgw_setup']->db->f('app_version'); |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | // _debug_array($setup_info); |
---|
96 | return $setup_info; |
---|
97 | } |
---|
98 | |
---|
99 | /* app status values: |
---|
100 | U Upgrade required/available |
---|
101 | R upgrade in pRogress |
---|
102 | C upgrade Completed successfully |
---|
103 | D Dependency failure |
---|
104 | P Post-install dependency failure |
---|
105 | F upgrade Failed |
---|
106 | V Version mismatch at end of upgrade (Not used, proposed only) |
---|
107 | M Missing files at start of upgrade (Not used, proposed only) |
---|
108 | */ |
---|
109 | function compare_versions($setup_info) |
---|
110 | { |
---|
111 | foreach($setup_info as $key => $value) |
---|
112 | { |
---|
113 | //echo '<br>'.$value['name'].'STATUS: '.$value['status']; |
---|
114 | /* Only set this if it has not already failed to upgrade - Milosch */ |
---|
115 | if(!( (@$value['status'] == 'F') || (@$value['status'] == 'C') )) |
---|
116 | { |
---|
117 | //if ($setup_info[$key]['currentver'] > $setup_info[$key]['version']) |
---|
118 | if($GLOBALS['phpgw_setup']->amorethanb($value['currentver'],@$value['version'])) |
---|
119 | { |
---|
120 | $setup_info[$key]['status'] = 'V'; |
---|
121 | } |
---|
122 | elseif(@$value['currentver'] == @$value['version']) |
---|
123 | { |
---|
124 | $setup_info[$key]['status'] = 'C'; |
---|
125 | } |
---|
126 | elseif($GLOBALS['phpgw_setup']->alessthanb(@$value['currentver'],@$value['version'])) |
---|
127 | { |
---|
128 | $setup_info[$key]['status'] = 'U'; |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | $setup_info[$key]['status'] = 'U'; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | // _debug_array($setup_info); |
---|
137 | return $setup_info; |
---|
138 | } |
---|
139 | |
---|
140 | function check_depends($setup_info) |
---|
141 | { |
---|
142 | /* Run the list of apps */ |
---|
143 | foreach($setup_info as $key => $value) |
---|
144 | { |
---|
145 | /* Does this app have any depends */ |
---|
146 | if(isset($value['depends'])) |
---|
147 | { |
---|
148 | /* If so find out which apps it depends on */ |
---|
149 | foreach($value['depends'] as $depkey => $depvalue) |
---|
150 | { |
---|
151 | /* I set this to False until we find a compatible version of this app */ |
---|
152 | $setup_info['depends'][$depkey]['status'] = False; |
---|
153 | /* Now we loop thru the versions looking for a compatible version */ |
---|
154 | |
---|
155 | foreach($depvalue['versions'] as $depskey => $depsvalue) |
---|
156 | { |
---|
157 | $currentver = $setup_info[$depvalue['appname']]['currentver']; |
---|
158 | if ($depvalue['appname'] == 'phpgwapi' && substr($currentver,0,6) == '0.9.99') |
---|
159 | { |
---|
160 | $currentver = '0.9.14.508'; |
---|
161 | } |
---|
162 | $major = $GLOBALS['phpgw_setup']->get_major($currentver); |
---|
163 | if ($major == $depsvalue) |
---|
164 | { |
---|
165 | $setup_info['depends'][$depkey]['status'] = True; |
---|
166 | } |
---|
167 | else // check if majors are equal and minors greater or equal |
---|
168 | { |
---|
169 | $major_depsvalue = $GLOBALS['phpgw_setup']->get_major($depsvalue); |
---|
170 | list(,,,$minor_depsvalue) = explode('.',$depsvalue); |
---|
171 | list(,,,$minor) = explode('.',$currentver); |
---|
172 | if ($major == $major_depsvalue && $minor <= $minor_depsvalue) |
---|
173 | { |
---|
174 | $setup_info['depends'][$depkey]['status'] = True; |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | /* |
---|
180 | Finally, we loop through the dependencies again to look for apps that still have a failure status |
---|
181 | If we find one, we set the apps overall status as a dependency failure. |
---|
182 | */ |
---|
183 | foreach($value['depends'] as $depkey => $depvalue) |
---|
184 | { |
---|
185 | if ($setup_info['depends'][$depkey]['status'] == False) |
---|
186 | { |
---|
187 | /* Only set this if it has not already failed to upgrade - Milosch */ |
---|
188 | if($setup_info[$key]['status'] != 'F')//&& $setup_info[$key]['status'] != 'C') |
---|
189 | { |
---|
190 | if($setup_info[$key]['status'] == 'C') |
---|
191 | { |
---|
192 | $setup_info[$key]['status'] = 'D'; |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | $setup_info[$key]['status'] = 'P'; |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | return $setup_info; |
---|
204 | } |
---|
205 | |
---|
206 | /* |
---|
207 | Called during the mass upgrade routine (Stage 1) to check for apps |
---|
208 | that wish to be excluded from this process. |
---|
209 | */ |
---|
210 | function upgrade_exclude($setup_info) |
---|
211 | { |
---|
212 | foreach($setup_info as $key => $value) |
---|
213 | { |
---|
214 | if(isset($value['no_mass_update'])) |
---|
215 | { |
---|
216 | unset($setup_info[$key]); |
---|
217 | } |
---|
218 | } |
---|
219 | return $setup_info; |
---|
220 | } |
---|
221 | |
---|
222 | function check_header() |
---|
223 | { |
---|
224 | if(!file_exists('../header.inc.php')) |
---|
225 | { |
---|
226 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage One'; |
---|
227 | return '1'; |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | if(!@isset($GLOBALS['phpgw_info']['server']['header_admin_password'])) |
---|
232 | { |
---|
233 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage One (No header admin password set)'; |
---|
234 | return '2'; |
---|
235 | } |
---|
236 | elseif(!@isset($GLOBALS['phpgw_domain'])) |
---|
237 | { |
---|
238 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage One (Add domains to your header.inc.php)'; |
---|
239 | return '3'; |
---|
240 | } |
---|
241 | elseif(@$GLOBALS['phpgw_info']['server']['versions']['header'] != @$GLOBALS['phpgw_info']['server']['versions']['current_header']) |
---|
242 | { |
---|
243 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage One (Upgrade your header.inc.php)'; |
---|
244 | return '4'; |
---|
245 | } |
---|
246 | } |
---|
247 | /* header.inc.php part settled. Moving to authentication */ |
---|
248 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage One (Completed)'; |
---|
249 | return '10'; |
---|
250 | } |
---|
251 | |
---|
252 | function check_db($setup_info='') |
---|
253 | { |
---|
254 | $setup_info = $setup_info ? $setup_info : $GLOBALS['setup_info']; |
---|
255 | |
---|
256 | $GLOBALS['phpgw_setup']->db->Halt_On_Error = 'no'; |
---|
257 | // _debug_array($setup_info); |
---|
258 | |
---|
259 | if (!$GLOBALS['phpgw_setup']->db->Link_ID) |
---|
260 | { |
---|
261 | $old = error_reporting(); |
---|
262 | error_reporting($old & ~E_WARNING); // no warnings |
---|
263 | $GLOBALS['phpgw_setup']->db->connect(); |
---|
264 | error_reporting($old); |
---|
265 | } |
---|
266 | if (!$GLOBALS['phpgw_setup']->db->Link_ID) |
---|
267 | { |
---|
268 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; |
---|
269 | return 1; |
---|
270 | } |
---|
271 | if(!isset($setup_info['phpgwapi']['currentver'])) |
---|
272 | { |
---|
273 | $setup_info = $this->get_db_versions($setup_info); |
---|
274 | } |
---|
275 | // _debug_array($setup_info); |
---|
276 | if (isset($setup_info['phpgwapi']['currentver'])) |
---|
277 | { |
---|
278 | if(@$setup_info['phpgwapi']['currentver'] == @$setup_info['phpgwapi']['version']) |
---|
279 | { |
---|
280 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 1 (Tables Complete)'; |
---|
281 | return 10; |
---|
282 | } |
---|
283 | else |
---|
284 | { |
---|
285 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 1 (Tables need upgrading)'; |
---|
286 | return 4; |
---|
287 | } |
---|
288 | } |
---|
289 | else |
---|
290 | { |
---|
291 | /* no tables, so checking if we can create them */ |
---|
292 | $GLOBALS['phpgw_setup']->db->query('CREATE TABLE phpgw_testrights ( testfield varchar(5) NOT NULL )'); |
---|
293 | if(!$GLOBALS['phpgw_setup']->db->Errno) |
---|
294 | { |
---|
295 | $GLOBALS['phpgw_setup']->db->query('DROP TABLE phpgw_testrights'); |
---|
296 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 3 (Install Applications)'; |
---|
297 | return 3; |
---|
298 | } |
---|
299 | else |
---|
300 | { |
---|
301 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; |
---|
302 | return 1; |
---|
303 | } |
---|
304 | } |
---|
305 | } |
---|
306 | |
---|
307 | function check_config() |
---|
308 | { |
---|
309 | $GLOBALS['phpgw_setup']->db->Halt_On_Error = 'no'; |
---|
310 | if(@$GLOBALS['phpgw_info']['setup']['stage']['db'] != 10) |
---|
311 | { |
---|
312 | return ''; |
---|
313 | } |
---|
314 | |
---|
315 | /* Since 0.9.10pre6 config table is named as phpgw_config */ |
---|
316 | $ver = explode('.',@$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']); |
---|
317 | $config_table = $ver[0] > 0 || (int)$ver[2] > 10 ? 'phpgw_config' : 'config'; |
---|
318 | |
---|
319 | if(preg_match("/([0-9]+)(pre)([0-9]+)/",$ver[2],$regs)) |
---|
320 | { |
---|
321 | if(($regs[1] == '10') && ($regs[3] >= '6')) |
---|
322 | { |
---|
323 | $config_table = 'phpgw_config'; |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | @$GLOBALS['phpgw_setup']->db->query("select config_value from $config_table where config_name='freshinstall'"); |
---|
328 | $configured = $GLOBALS['phpgw_setup']->db->next_record() ? $GLOBALS['phpgw_setup']->db->f('config_value') : False; |
---|
329 | if($configed) |
---|
330 | { |
---|
331 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 2 (Needs Configuration)'; |
---|
332 | return 1; |
---|
333 | } |
---|
334 | else |
---|
335 | { |
---|
336 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 2 (Configuration OK)'; |
---|
337 | return 10; |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | function check_lang($check = True) |
---|
342 | { |
---|
343 | $GLOBALS['phpgw_setup']->db->Halt_On_Error = 'no'; |
---|
344 | if($check && $GLOBALS['phpgw_info']['setup']['stage']['db'] != 10) |
---|
345 | { |
---|
346 | return ''; |
---|
347 | } |
---|
348 | if (!$check) |
---|
349 | { |
---|
350 | $GLOBALS['setup_info'] = $GLOBALS['phpgw_setup']->detection->get_db_versions($GLOBALS['setup_info']); |
---|
351 | } |
---|
352 | if($GLOBALS['phpgw_setup']->alessthanb($GLOBALS['setup_info']['phpgwapi']['currentver'], '0.9.14.501') || |
---|
353 | preg_match('/0\.9\.15\.00[01]{1,1}/',$GLOBALS['setup_info']['phpgwapi']['currentver'])) |
---|
354 | { |
---|
355 | $langtbl = 'lang'; |
---|
356 | $languagestbl = 'languages'; |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | $langtbl = 'phpgw_lang'; |
---|
361 | $languagestbl = 'phpgw_languages'; |
---|
362 | } |
---|
363 | $GLOBALS['phpgw_setup']->db->query($q = "SELECT DISTINCT lang FROM $langtbl",__LINE__,__FILE__); |
---|
364 | if($GLOBALS['phpgw_setup']->db->num_rows() == 0) |
---|
365 | { |
---|
366 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 3 (No languages installed)'; |
---|
367 | return 1; |
---|
368 | } |
---|
369 | else |
---|
370 | { |
---|
371 | while(@$GLOBALS['phpgw_setup']->db->next_record()) |
---|
372 | { |
---|
373 | $GLOBALS['phpgw_info']['setup']['installed_langs'][$GLOBALS['phpgw_setup']->db->f('lang')] = $GLOBALS['phpgw_setup']->db->f('lang'); |
---|
374 | } |
---|
375 | foreach($GLOBALS['phpgw_info']['setup']['installed_langs'] as $key => $value) |
---|
376 | { |
---|
377 | $sql = "SELECT lang_name FROM $languagestbl WHERE lang_id = '".$value."'"; |
---|
378 | $GLOBALS['phpgw_setup']->db->query($sql); |
---|
379 | if ($GLOBALS['phpgw_setup']->db->next_record()) |
---|
380 | { |
---|
381 | $GLOBALS['phpgw_info']['setup']['installed_langs'][$value] = $GLOBALS['phpgw_setup']->db->f('lang_name'); |
---|
382 | } |
---|
383 | } |
---|
384 | $GLOBALS['phpgw_info']['setup']['header_msg'] = 'Stage 3 (Completed)'; |
---|
385 | return 10; |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | /* |
---|
390 | @function check_app_tables |
---|
391 | @abstract Verify that all of an app's tables exist in the db |
---|
392 | @param $appname |
---|
393 | @param $any optional, set to True to see if any of the apps tables are installed |
---|
394 | */ |
---|
395 | function check_app_tables($appname,$any=False) |
---|
396 | { |
---|
397 | $none = 0; |
---|
398 | $setup_info = $GLOBALS['setup_info']; |
---|
399 | |
---|
400 | if(@$setup_info[$appname]['tables']) |
---|
401 | { |
---|
402 | /* Make a copy, else we send some callers into an infinite loop */ |
---|
403 | $copy = $setup_info; |
---|
404 | $GLOBALS['phpgw_setup']->db->Halt_On_Error = 'no'; |
---|
405 | $table_names = $GLOBALS['phpgw_setup']->db->table_names(); |
---|
406 | $tables = Array(); |
---|
407 | foreach($table_names as $key => $val) |
---|
408 | { |
---|
409 | $tables[] = $val['table_name']; |
---|
410 | } |
---|
411 | foreach($copy[$appname]['tables'] as $key => $val) |
---|
412 | { |
---|
413 | if($GLOBALS['DEBUG']) |
---|
414 | { |
---|
415 | echo '<br>check_app_tables(): Checking: ' . $appname . ',table: ' . $val; |
---|
416 | } |
---|
417 | if(!in_array($val,$tables)) |
---|
418 | { |
---|
419 | if($GLOBALS['DEBUG']) |
---|
420 | { |
---|
421 | echo '<br>check_app_tables(): ' . $val . ' missing!'; |
---|
422 | } |
---|
423 | if(!$any) |
---|
424 | { |
---|
425 | return False; |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | ++$none; |
---|
430 | } |
---|
431 | } |
---|
432 | else |
---|
433 | { |
---|
434 | if($any) |
---|
435 | { |
---|
436 | if($GLOBALS['DEBUG']) |
---|
437 | { |
---|
438 | echo '<br>check_app_tables(): Some tables installed'; |
---|
439 | } |
---|
440 | return True; |
---|
441 | } |
---|
442 | } |
---|
443 | } |
---|
444 | } |
---|
445 | if($none && $any) |
---|
446 | { |
---|
447 | if($GLOBALS['DEBUG']) |
---|
448 | { |
---|
449 | echo '<br>check_app_tables(): No tables installed'; |
---|
450 | } |
---|
451 | return False; |
---|
452 | } |
---|
453 | else |
---|
454 | { |
---|
455 | if($GLOBALS['DEBUG']) |
---|
456 | { |
---|
457 | echo '<br>check_app_tables(): All tables installed'; |
---|
458 | } |
---|
459 | return True; |
---|
460 | } |
---|
461 | } |
---|
462 | } |
---|
463 | ?> |
---|