[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
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 /* $Id: class.setup_detection.inc.php 19992 2005-11-25 09:21:42Z ralfbecker $ */ 16 17 class setup_detection 18 { 19 function get_versions() 20 { 21 $d = dir(EGW_SERVER_ROOT); 22 while($entry=$d->read()) 23 { 24 if($entry != ".." && !ereg('setup',$entry) && is_dir(EGW_SERVER_ROOT . '/' . $entry)) 25 { 26 $f = EGW_SERVER_ROOT . '/' . $entry . '/setup/setup.inc.php'; 27 if (@file_exists ($f)) 28 { 29 include($f); 30 $setup_info[$entry]['filename'] = $f; 31 } 32 } 33 } 34 $d->close(); 35 36 // _debug_array($setup_info); 37 @ksort($setup_info); 38 return $setup_info; 39 } 40 41 function get_db_versions($setup_info='') 42 { 43 $tname = Array(); 44 $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; 45 46 $GLOBALS['egw_setup']->set_table_names(); 47 48 if($GLOBALS['egw_setup']->table_exist(array($GLOBALS['egw_setup']->applications_table))) 49 { 50 /* one of these tables exists. checking for post/pre beta version */ 51 if($GLOBALS['egw_setup']->applications_table != 'applications') 52 { 53 $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->applications_table,'*',false,__LINE__,__FILE__); 54 while(@$GLOBALS['egw_setup']->db->next_record()) 55 { 56 $setup_info[$GLOBALS['egw_setup']->db->f('app_name')]['currentver'] = $GLOBALS['egw_setup']->db->f('app_version'); 57 $setup_info[$GLOBALS['egw_setup']->db->f('app_name')]['enabled'] = $GLOBALS['egw_setup']->db->f('app_enabled'); 58 } 59 /* This is to catch old setup installs that did not have phpgwapi listed as an app */ 60 $tmp = @$setup_info['phpgwapi']['version']; /* save the file version */ 61 if(!@$setup_info['phpgwapi']['currentver']) 62 { 63 $setup_info['phpgwapi']['currentver'] = $setup_info['admin']['currentver']; 64 $setup_info['phpgwapi']['version'] = $setup_info['admin']['currentver']; 65 $setup_info['phpgwapi']['enabled'] = $setup_info['admin']['enabled']; 66 // _debug_array($setup_info['phpgwapi']);exit; 67 // There seems to be a problem here. If ['phpgwapi']['currentver'] is set, 68 // The GLOBALS never gets set. 69 $GLOBALS['setup_info'] = $setup_info; 70 $GLOBALS['egw_setup']->register_app('phpgwapi'); 71 } 72 else 73 { 74 $GLOBALS['setup_info'] = $setup_info; 75 } 76 $setup_info['phpgwapi']['version'] = $tmp; /* restore the file version */ 77 } 78 else 79 { 80 $GLOBALS['egw_setup']->db->query('select * from applications'); 81 while(@$GLOBALS['egw_setup']->db->next_record()) 82 { 83 if($GLOBALS['egw_setup']->db->f('app_name') == 'admin') 84 { 85 $setup_info['phpgwapi']['currentver'] = $GLOBALS['egw_setup']->db->f('app_version'); 86 } 87 $setup_info[$GLOBALS['egw_setup']->db->f('app_name')]['currentver'] = $GLOBALS['egw_setup']->db->f('app_version'); 88 } 89 } 90 } 91 // _debug_array($setup_info); 92 return $setup_info; 93 } 94 95 /* app status values: 96 U Upgrade required/available 97 R upgrade in pRogress 98 C upgrade Completed successfully 99 D Dependency failure 100 P Post-install dependency failure 101 F upgrade Failed 102 V Version mismatch at end of upgrade (Not used, proposed only) 103 M Missing files at start of upgrade (Not used, proposed only) 104 */ 105 function compare_versions($setup_info) 106 { 107 foreach($setup_info as $key => $value) 108 { 109 //echo '<br>'.$value['name'].'STATUS: '.$value['status']; 110 /* Only set this if it has not already failed to upgrade - Milosch */ 111 if(!( (@$value['status'] == 'F') || (@$value['status'] == 'C') )) 112 { 113 //if ($setup_info[$key]['currentver'] > $setup_info[$key]['version']) 114 if($GLOBALS['egw_setup']->amorethanb($value['currentver'],@$value['version'])) 115 { 116 $setup_info[$key]['status'] = 'V'; 117 } 118 elseif(@$value['currentver'] == @$value['version']) 119 { 120 $setup_info[$key]['status'] = 'C'; 121 } 122 elseif($GLOBALS['egw_setup']->alessthanb(@$value['currentver'],@$value['version'])) 123 { 124 $setup_info[$key]['status'] = 'U'; 125 } 126 else 127 { 128 $setup_info[$key]['status'] = 'U'; 129 } 130 } 131 } 132 // _debug_array($setup_info); 133 return $setup_info; 134 } 135 136 function check_depends($setup_info) 137 { 138 /* Run the list of apps */ 139 foreach($setup_info as $key => $value) 140 { 141 /* Does this app have any depends */ 142 if(isset($value['depends'])) 143 { 144 /* If so find out which apps it depends on */ 145 foreach($value['depends'] as $depkey => $depvalue) 146 { 147 /* I set this to False until we find a compatible version of this app */ 148 $setup_info['depends'][$depkey]['status'] = False; 149 /* Now we loop thru the versions looking for a compatible version */ 150 151 foreach($depvalue['versions'] as $depskey => $depsvalue) 152 { 153 $currentver = $setup_info[$depvalue['appname']]['currentver']; 154 if ($depvalue['appname'] == 'phpgwapi' && substr($currentver,0,6) == '0.9.99') 155 { 156 $currentver = '0.9.14.508'; 157 } 158 $major = $GLOBALS['egw_setup']->get_major($currentver); 159 if ($major == $depsvalue || substr($major,0,strlen($depsvalue)+1) == $depsvalue.'.') 160 { 161 $setup_info['depends'][$depkey]['status'] = True; 162 } 163 else // check if majors are equal and minors greater or equal 164 { 165 $major_depsvalue = $GLOBALS['egw_setup']->get_major($depsvalue); 166 $tmp = explode('.',$depsvalue); $minor_depsvalue = array_pop($tmp); 167 $tmp = explode('.',$currentver); $minor = array_pop($tmp); 168 if ($major == $major_depsvalue && $minor <= $minor_depsvalue) 169 { 170 $setup_info['depends'][$depkey]['status'] = True; 171 } 172 } 173 //echo "<p>app=$key depends on $depvalue[appname](".implode(',',$depvalue['versions']).") current=$currentver, major=$major, depsvalue=$depsvalue, major_depsvalue=$major_depsvalue, minor_depsvalue=$minor_depsvalue, minor=$minor ==> ".(int)$setup_info['depends'][$depkey]['status']."</p>\n"; 174 } 175 } 176 /* 177 Finally, we loop through the dependencies again to look for apps that still have a failure status 178 If we find one, we set the apps overall status as a dependency failure. 179 */ 180 foreach($value['depends'] as $depkey => $depvalue) 181 { 182 if ($setup_info['depends'][$depkey]['status'] == False) 183 { 184 /* Only set this if it has not already failed to upgrade - Milosch */ 185 if($setup_info[$key]['status'] != 'F')//&& $setup_info[$key]['status'] != 'C') 186 { 187 /* Added check for status U - uninstalled apps carry this flag (upgrade from nothing == install). 188 * This should fix apps showing post-install dep failure when they are not yet installed. 189 */ 190 if($setup_info[$key]['status'] == 'C' || $setup_info[$key]['status'] == 'U') 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['egw_info']['setup']['header_msg'] = 'Stage One'; 227 return '1'; 228 } 229 else 230 { 231 if(!@isset($GLOBALS['egw_info']['server']['header_admin_password'])) 232 { 233 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage One (No header admin password set)'; 234 return '2'; 235 } 236 elseif(!@isset($GLOBALS['egw_domain'])) 237 { 238 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage One (Add domains to your header.inc.php)'; 239 return '3'; 240 } 241 elseif(@$GLOBALS['egw_info']['server']['versions']['header'] != @$GLOBALS['egw_info']['server']['versions']['current_header']) 242 { 243 $GLOBALS['egw_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['egw_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['egw_setup']->db->Halt_On_Error = 'no'; 257 // _debug_array($setup_info); 258 259 if (!$GLOBALS['egw_setup']->db->Link_ID) 260 { 261 $old = error_reporting(); 262 error_reporting($old & ~E_WARNING); // no warnings 263 $GLOBALS['egw_setup']->db->connect(); 264 error_reporting($old); 265 } 266 $GLOBALS['egw_setup']->set_table_names(); 267 268 if (!$GLOBALS['egw_setup']->db->Link_ID || !$GLOBALS['egw_setup']->db->Link_ID->_connectionID) 269 { 270 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; 271 return 1; 272 } 273 if(!isset($setup_info['phpgwapi']['currentver'])) 274 { 275 $setup_info = $this->get_db_versions($setup_info); 276 } 277 //_debug_array($setup_info); 278 if (isset($setup_info['phpgwapi']['currentver'])) 279 { 280 if(@$setup_info['phpgwapi']['currentver'] == @$setup_info['phpgwapi']['version']) 281 { 282 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Tables Complete)'; 283 return 10; 284 } 285 else 286 { 287 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Tables need upgrading)'; 288 return 4; 289 } 290 } 291 else 292 { 293 /* no tables, so checking if we can create them */ 294 $GLOBALS['egw_setup']->db->query('CREATE TABLE egw_testrights ( testfield varchar(5) NOT NULL )'); 295 if(!$GLOBALS['egw_setup']->db->Errno) 296 { 297 $GLOBALS['egw_setup']->db->query('DROP TABLE egw_testrights'); 298 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Install Applications)'; 299 return 3; 300 } 301 else 302 { 303 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 1 (Create Database)'; 304 return 1; 305 } 306 } 307 } 308 309 function check_config() 310 { 311 $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; 312 if(@$GLOBALS['egw_info']['setup']['stage']['db'] != 10) 313 { 314 return ''; 315 } 316 317 $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_value',array('config_name'=>'freshinstall'),__LINE__,__FILE__); 318 $configured = $GLOBALS['egw_setup']->db->next_record() ? $GLOBALS['egw_setup']->db->f('config_value') : False; 319 if($configed) 320 { 321 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 2 (Needs Configuration)'; 322 return 1; 323 } 324 else 325 { 326 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 2 (Configuration OK)'; 327 return 10; 328 } 329 } 330 331 function check_lang($check = True) 332 { 333 $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; 334 if($check && $GLOBALS['egw_info']['setup']['stage']['db'] != 10) 335 { 336 return ''; 337 } 338 if (!$check) 339 { 340 $GLOBALS['setup_info'] = $GLOBALS['egw_setup']->detection->get_db_versions($GLOBALS['setup_info']); 341 } 342 $GLOBALS['egw_setup']->db->query($q = "SELECT DISTINCT lang FROM {$GLOBALS['egw_setup']->lang_table}",__LINE__,__FILE__); 343 if($GLOBALS['egw_setup']->db->num_rows() == 0) 344 { 345 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (No languages installed)'; 346 return 1; 347 } 348 else 349 { 350 while(@$GLOBALS['egw_setup']->db->next_record()) 351 { 352 $GLOBALS['egw_info']['setup']['installed_langs'][$GLOBALS['egw_setup']->db->f('lang')] = $GLOBALS['egw_setup']->db->f('lang'); 353 } 354 foreach($GLOBALS['egw_info']['setup']['installed_langs'] as $key => $value) 355 { 356 $sql = "SELECT lang_name FROM {$GLOBALS['egw_setup']->languages_table} WHERE lang_id = '".$value."'"; 357 $GLOBALS['egw_setup']->db->query($sql); 358 if ($GLOBALS['egw_setup']->db->next_record()) 359 { 360 $GLOBALS['egw_info']['setup']['installed_langs'][$value] = $GLOBALS['egw_setup']->db->f('lang_name'); 361 } 362 } 363 $GLOBALS['egw_info']['setup']['header_msg'] = 'Stage 3 (Completed)'; 364 return 10; 365 } 366 } 367 368 /** 369 * Verify that all of an app's tables exist in the db 370 * @param $appname 371 * @param $any optional, set to True to see if any of the apps tables are installed 372 */ 373 function check_app_tables($appname,$any=False) 374 { 375 $none = 0; 376 $setup_info = $GLOBALS['setup_info']; 377 378 if(@$setup_info[$appname]['tables']) 379 { 380 /* Make a copy, else we send some callers into an infinite loop */ 381 $copy = $setup_info; 382 $GLOBALS['egw_setup']->db->Halt_On_Error = 'no'; 383 $table_names = $GLOBALS['egw_setup']->db->table_names(); 384 $tables = Array(); 385 foreach($table_names as $key => $val) 386 { 387 $tables[] = $val['table_name']; 388 } 389 foreach($copy[$appname]['tables'] as $key => $val) 390 { 391 if($GLOBALS['DEBUG']) 392 { 393 echo '<br>check_app_tables(): Checking: ' . $appname . ',table: ' . $val; 394 } 395 if(!in_array($val,$tables) && !in_array(strtolower($val),$tables)) // names in tables might be lowercase 396 { 397 if($GLOBALS['DEBUG']) 398 { 399 echo '<br>check_app_tables(): ' . $val . ' missing!'; 400 } 401 if(!$any) 402 { 403 return False; 404 } 405 else 406 { 407 $none++; 408 } 409 } 410 else 411 { 412 if($any) 413 { 414 if($GLOBALS['DEBUG']) 415 { 416 echo '<br>check_app_tables(): Some tables installed'; 417 } 418 return True; 419 } 420 } 421 } 422 } 423 if($none && $any) 424 { 425 if($GLOBALS['DEBUG']) 426 { 427 echo '<br>check_app_tables(): No tables installed'; 428 } 429 return False; 430 } 431 else 432 { 433 if($GLOBALS['DEBUG']) 434 { 435 echo '<br>check_app_tables(): All tables installed'; 436 } 437 return True; 438 } 439 } 440 } 441 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |