/**
* A batch install of Elgg
*
* All required parameters must be passed in as an associative array. See
* $requiredParams for a list of them. This creates the necessary files,
* loads the database, configures the site settings, and creates the admin
* account. If it fails, an exception is thrown. It does not check any of
* the requirements as the multiple step web installer does.
*
* If the settings.php file exists, it will use that rather than the parameters
* passed to this function.
*
* @param array $params Array of key value pairs
* @param bool $createHtaccess Should .htaccess be created
*
* @return void
* @throws InstallationException
*/
public function batchInstall(array $params, $createHtaccess = FALSE)
{
global $CONFIG;
restore_error_handler();
restore_exception_handler();
$defaults = array('dbhost' => 'localhost', 'dbprefix' => 'elgg_', 'path' => $CONFIG->path, 'language' => 'en', 'siteaccess' => ACCESS_PUBLIC);
$params = array_merge($defaults, $params);
$requiredParams = array('dbuser', 'dbpassword', 'dbname', 'sitename', 'wwwroot', 'dataroot', 'displayname', 'email', 'username', 'password');
foreach ($requiredParams as $key) {
if (!array_key_exists($key, $params)) {
$msg = elgg_echo('install:error:requiredfield', array($key));
throw new InstallationException($msg);
}
}
// password is passed in once
$params['password1'] = $params['password2'] = $params['password'];
if ($createHtaccess) {
$rewriteTester = new ElggRewriteTester();
if (!$rewriteTester->createHtaccess($CONFIG->path)) {
throw new InstallationException(elgg_echo('install:error:htaccess'));
}
}
$this->setInstallStatus();
if (!$this->status['config']) {
if (!$this->createSettingsFile($params)) {
throw new InstallationException(elgg_echo('install:error:settings'));
}
}
if (!$this->connectToDatabase()) {
throw new InstallationException(elgg_echo('install:error:databasesettings'));
}
if (!$this->status['database']) {
if (!$this->installDatabase()) {
throw new InstallationException(elgg_echo('install:error:cannotloadtables'));
}
}
// load remaining core libraries
$this->finishBootstraping('settings');
if (!$this->saveSiteSettings($params)) {
throw new InstallationException(elgg_echo('install:error:savesitesettings'));
}
if (!$this->createAdminAccount($params)) {
throw new InstallationException(elgg_echo('install:admin:cannot_create'));
}
}