throw $e; } $errormessage = ob_get_contents(); if (!$errormessage) { $errormessage = $e->getMessage(); } ob_end_clean(); $errormessage = get_string('dbconnfailed', 'error') . $errormessage; throw new ConfigSanityException($errormessage); } try { db_ignore_sql_exceptions(true); load_config(); db_ignore_sql_exceptions(false); } catch (SQLException $e) { db_ignore_sql_exceptions(false); } // Make sure wwwroot is set and available, either in the database or in the // config file. Cron requires it when sending out forums emails. if (!isset($CFG->wwwroot) && isset($_SERVER['HTTP_HOST'])) { $proto = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ? 'https://' : 'http://'; $host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; if (false !== strpos($host, ',')) { list($host) = explode(',', $host); $host = trim($host); } $path = ''; if (strpos(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT'])) === 0) { $path = substr(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT'])); } else { $self = explode('/', $_SERVER['PHP_SELF']);
/** * This function sets a config variable * both in $CFG and in the database * * @param string $key config field to set * @param string $value config value */ function set_config($key, $value) { global $CFG; db_ignore_sql_exceptions(true); if (get_record('config', 'field', $key)) { if (set_field('config', 'value', $value, 'field', $key)) { $status = true; } } else { $config = new StdClass(); $config->field = $key; $config->value = $value; $status = insert_record('config', $config); } db_ignore_sql_exceptions(false); if (!empty($status)) { $CFG->{$key} = $value; return true; } return false; }
/** * Install mahara from scratch. Does both database tables and core data. * Exactly the same as the web-based installer * except for logging the current user in. */ public function install_mahara() { log_info('Installing Mahara'); db_ignore_sql_exceptions(true); $upgrades = check_upgrades(); db_ignore_sql_exceptions(false); $upgrades['firstcoredata'] = true; $upgrades['lastcoredata'] = true; uksort($upgrades, 'sort_upgrades'); foreach ($upgrades as $name => $data) { if ($name == 'settings') { continue; } log_info('Installing ' . $name); if ($name == 'firstcoredata' || $name == 'lastcoredata') { $funname = 'core_install_' . $name . '_defaults'; $funname(); continue; } else { if ($name == 'core') { $funname = 'upgrade_core'; } else { $funname = 'upgrade_plugin'; } $data->name = $name; $funname($data); } } }