| Conditions | 38 |
| Paths | 3666 |
| Total Lines | 128 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 230 | static function check_installed($domain='',$stop=0,$verbose=false) |
||
| 231 | { |
||
| 232 | self::_setup_enviroment($domain); |
||
| 233 | |||
| 234 | global $setup_info; |
||
| 235 | static $header_checks=true; // output the header checks only once |
||
| 236 | |||
| 237 | $messages = array(); |
||
| 238 | |||
| 239 | if ($stop && !is_array($stop)) $stop = array($stop); |
||
| 240 | |||
| 241 | $versions =& $GLOBALS['egw_info']['server']['versions']; |
||
| 242 | |||
| 243 | if (!$versions['api']) |
||
| 244 | { |
||
| 245 | if (!include(EGW_INCLUDE_ROOT.'/api/setup/setup.inc.php')) |
||
| 246 | { |
||
| 247 | throw new Api\Exception\WrongUserinput(lang("EGroupware sources in '%1' are not complete, file '%2' missing !!!",realpath('..'),'api/setup/setup.inc.php'),99); // should not happen ;-) |
||
| 248 | } |
||
| 249 | $versions['api'] = $setup_info['api']['version']; |
||
| 250 | unset($setup_info); |
||
| 251 | } |
||
| 252 | if ($header_checks) |
||
| 253 | { |
||
| 254 | $messages[] = self::_echo_message($verbose,lang('EGroupware API version %1 found.',$versions['api'])); |
||
| 255 | } |
||
| 256 | $header_stage = self::$egw_setup->detection->check_header(); |
||
| 257 | if ($stop && in_array($header_stage,$stop)) return true; |
||
| 258 | |||
| 259 | switch ($header_stage) |
||
| 260 | { |
||
| 261 | case 1: throw new Api\Exception\WrongUserinput(lang('EGroupware configuration file (header.inc.php) does NOT exist.')."\n".lang('Use --create-header to create the configuration file (--usage gives more options).'),1); |
||
| 262 | |||
| 263 | // case 2: throw new Api\Exception\WrongUserinput(lang('EGroupware configuration file (header.inc.php) version %1 exists%2',$versions['header'],'.')."\n".lang('No header admin password set! Use --edit-header <password>[,<user>] to set one (--usage gives more options).'),2); |
||
| 264 | |||
| 265 | case 3: throw new Api\Exception\WrongUserinput(lang('EGroupware configuration file (header.inc.php) version %1 exists%2',$versions['header'],'.')."\n".lang('No EGroupware domains / database instances exist! Use --edit-header --domain to add one (--usage gives more options).'),3); |
||
| 266 | |||
| 267 | case 4: throw new Api\Exception\WrongUserinput(lang('EGroupware configuration file (header.inc.php) version %1 exists%2',$versions['header'],'.')."\n".lang('It needs upgrading to version %1! Use --update-header <password>[,<user>] to do so (--usage gives more options).',$versions['current_header']),4); |
||
| 268 | } |
||
| 269 | if ($header_checks) |
||
| 270 | { |
||
| 271 | $messages[] = self::_echo_message($verbose,lang('EGroupware configuration file (header.inc.php) version %1 exists%2', |
||
| 272 | $versions['header'],' '.lang('and is up to date'))); |
||
| 273 | } |
||
| 274 | unset($header_checks); // no further output of the header checks |
||
| 275 | |||
| 276 | $domains = $GLOBALS['egw_domain']; |
||
| 277 | if ($domain) // domain to check given |
||
| 278 | { |
||
| 279 | if (!isset($GLOBALS['egw_domain'][$domain])) throw new Api\Exception\WrongUserinput(lang("Domain '%1' does NOT exist !!!",$domain), 92); |
||
| 280 | |||
| 281 | $domains = array($domain => $GLOBALS['egw_domain'][$domain]); |
||
| 282 | } |
||
| 283 | foreach($domains as $domain => $data) |
||
| 284 | { |
||
| 285 | self::$egw_setup->ConfigDomain = $domain; // set the domain the setup class operates on |
||
| 286 | if (count($GLOBALS['egw_domain']) > 1) |
||
| 287 | { |
||
| 288 | self::_echo_message($verbose); |
||
| 289 | $messages[] = self::_echo_message($verbose,lang('EGroupware domain/instance %1(%2):',$domain,$data['db_type'])); |
||
| 290 | } |
||
| 291 | $setup_info = self::$egw_setup->detection->get_versions(); |
||
| 292 | // check if there's already a db-connection and close if, otherwise the db-connection of the previous domain will be used |
||
| 293 | if (is_object(self::$egw_setup->db)) |
||
| 294 | { |
||
| 295 | self::$egw_setup->db->disconnect(); |
||
| 296 | } |
||
| 297 | self::$egw_setup->loaddb(); |
||
| 298 | |||
| 299 | $db = $data['db_type'].'://'.$data['db_user'].':'.$data['db_pass'].'@'.$data['db_host'].'/'.$data['db_name']; |
||
| 300 | |||
| 301 | $db_stage =& $GLOBALS['egw_info']['setup']['stage']['db']; |
||
| 302 | if (($db_stage = self::$egw_setup->detection->check_db($setup_info)) != 1) |
||
| 303 | { |
||
| 304 | $setup_info = self::$egw_setup->detection->get_db_versions($setup_info); |
||
| 305 | $db_stage = self::$egw_setup->detection->check_db($setup_info); |
||
| 306 | } |
||
| 307 | if ($stop && in_array(10+$db_stage,$stop)) |
||
| 308 | { |
||
| 309 | return $messages; |
||
| 310 | } |
||
| 311 | switch($db_stage) |
||
| 312 | { |
||
| 313 | case 1: throw new Api\Exception\WrongUserinput(lang('Your Database is not working!')." $db: ".self::$egw_setup->db->Error,11); |
||
| 314 | |||
| 315 | case 3: throw new Api\Exception\WrongUserinput(lang('Your database is working, but you dont have any applications installed')." ($db). ".lang("Use --install to install EGroupware."),13); |
||
| 316 | |||
| 317 | case 4: throw new Api\Exception\WrongUserinput(lang('EGroupware API needs a database (schema) update from version %1 to %2!',$setup_info['api']['currentver'],$versions['api']).' '.lang('Use --update to do so.'),14); |
||
| 318 | |||
| 319 | case 10: // also check apps of updates |
||
| 320 | self::$apps_to_upgrade = self::$apps_to_install = array(); |
||
| 321 | foreach($setup_info as $app => $data) |
||
| 322 | { |
||
| 323 | if ($data['currentver'] && $data['version'] && $data['version'] != 'deleted' && $data['version'] != $data['currentver']) |
||
| 324 | { |
||
| 325 | self::$apps_to_upgrade[] = $app; |
||
| 326 | } |
||
| 327 | if (!isset($data['enabled']) && isset($data['version'])) // jdots eg. is no app, but a template |
||
| 328 | { |
||
| 329 | self::$apps_to_install[] = $app; |
||
| 330 | } |
||
| 331 | } |
||
| 332 | // add autodeinstall apps |
||
| 333 | self::$apps_to_upgrade = array_unique(array_merge(self::$apps_to_upgrade, self::check_autodeinstall())); |
||
| 334 | |||
| 335 | if (self::$apps_to_install) |
||
| 336 | { |
||
| 337 | self::_echo_message($verbose); |
||
| 338 | $messages[] = self::_echo_message($verbose,lang('The following applications are NOT installed:').' '.implode(', ',self::$apps_to_install)); |
||
| 339 | } |
||
| 340 | if (self::$apps_to_upgrade) |
||
| 341 | { |
||
| 342 | $db_stage = 4; |
||
| 343 | if ($stop && in_array(10+$db_stage,$stop)) return $messages; |
||
| 344 | |||
| 345 | throw new Api\Exception\WrongUserinput(lang('The following applications need to be upgraded:').' '.implode(', ',self::$apps_to_upgrade).'! '.lang('Use --update to do so.'),14); |
||
| 346 | } |
||
| 347 | break; |
||
| 348 | } |
||
| 349 | $messages[] = self::_echo_message($verbose,lang("database is version %1 and up to date.",$setup_info['api']['currentver'])); |
||
| 350 | |||
| 351 | self::$egw_setup->detection->check_config(); |
||
| 352 | if ($GLOBALS['egw_info']['setup']['config_errors'] && $stop && !in_array(15,$stop)) |
||
| 353 | { |
||
| 354 | throw new Api\Exception\WrongUserinput(lang('You need to configure EGroupware:')."\n- ".@implode("\n- ",$GLOBALS['egw_info']['setup']['config_errors']),15); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | return $messages; |
||
| 358 | } |
||
| 423 |