$this->autoLogin = $value;
}
+ /**
+ * 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.
+ *
+ * @param array $params Array of key value pairs
+ * @param bool $createHtaccess Should .htaccess be created
+ */
+ 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 = sprintf(elgg_echo('install:error:requiredfield'), $key);
+ throw new InstallationException($msg);
+ }
+ }
+
+ // password is passed in once
+ $params['password1'] = $params['password2'] = $params['password'];
+
+ if ($createHtaccess) {
+ require_once(dirname(__FILE__) . "/ElggRewriteTester.php");
+ $rewriteTester = new ElggRewriteTester();
+ if (!$rewriteTester->createHtaccess($CONFIG->path)) {
+ throw new InstallationException(elgg_echo('install:error:htaccess'));
+ }
+ }
+
+ 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->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'));
+ }
+ }
+
/**
* Renders the data passed by a controller
*
}
}
+ $this->initGlobals();
+
set_default_config();
trigger_elgg_event('boot', 'system');
return TRUE;
}
+
+ /**
+ * Init globals because engine loaded within a function
+ */
+ protected function initGlobals() {
+ global $DB_QUERY_CACHE, $DB_DELAYED_QUERIES;
+ $DB_QUERY_CACHE = array();
+ $DB_DELAYED_QUERIES = array();
+
+ global $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
+ $METASTRINGS_CACHE = array();
+ $METASTRINGS_DEADNAME_CACHE = array();
+ }
}
* @param string $path Elgg's root directory with trailing slash
* @return bool
*/
- protected function createHtaccess($path) {
+ public function createHtaccess($path) {
$filename = "{$path}.htaccess";
if (file_exists($filename)) {
// check that this is the Elgg .htaccess
--- /dev/null
+<?php
+/**
+ * Sample cli installer script
+ */
+
+require_once(dirname(dirname(__FILE__)) . "/ElggInstaller.php");
+
+$installer = new ElggInstaller();
+
+$params = array(
+ // database parameters
+ 'dbuser' => '',
+ 'dbpassword' => '',
+ 'dbname' => '',
+
+ // site settings
+ 'sitename' => '',
+ 'wwwroot' => '',
+ 'dataroot' => '',
+
+ // admin account
+ 'displayname' => '',
+ 'email' => '',
+ 'username' => '',
+ 'password' => '',
+);
+
+// install and create the .htaccess file
+$installer->batchInstall($params, TRUE);
'install:check:php:extension:recommend' => 'It is recommended that the PHP extension %s is installed.',
'install:check:php:open_basedir' => 'The open_basedir PHP directive may prevent Elgg from saving files to its data directory.',
'install:check:php:safe_mode' => 'Running PHP in safe mode is not recommened and may cause problems with Elgg.',
- 'install:check:php:arg_separator' => 'arg_separator.output must be & for Elgg to work and your server\'s value is %s ',
+ 'install:check:php:arg_separator' => 'arg_separator.output must be & for Elgg to work and your server\'s value is %s',
'install:check:enginedir' => 'Your web server does not have permission to create the settings.php file in the engine directory. You have two choices:
'install:database:help:dbhost' => 'Hostname of the MySQL server (usually localhost)',
'install:database:help:dbprefix' => "The prefix given to all of Elgg's tables (usually elgg_)",
- 'install:dbuser' => '',
-
'install:settings:instructions' => "We need some information about the site as we configure Elgg. If you haven't created a data directory for Elgg, please do so before completing this step.",
'install:settings:label:sitename' => 'Site Name',
'install:success:settings' => 'Site settings have been saved.',
'install:success:admin' => 'Admin account has been created.',
+ 'install:error:htaccess' => 'Unable to create an .htaccess',
+ 'install:error:settings' => 'Unable to create the settings file',
'install:error:databasesettings' => 'Unable to connect to the database with these settings.',
'install:error:oldmysql' => 'MySQL must be version 5.0 or above. Your server is using %s.',
'install:error:nodatabase' => 'Unable to use database %s. It may not exist.',
+ 'install:error:cannotloadtables' => 'Cannot load the database tables',
'install:error:tables_exist' => 'There are already Elgg tables in the database. You need to either drop those tables or restart the installer and we will attempt to use them. To restart the installer, remove \'?step=database\' from the URL in your browser\'s address bar and press Enter.',
'install:error:readsettingsphp' => 'Unable to read engine/settings.example.php',
'install:error:writesettingphp' => 'Unable to write engine/settings.php',
'install:error:locationdatadirectory' => 'Your data directory %s must be outside of your install path for security.',
'install:error:emailaddress' => '%s is not a valid email address',
'install:error:createsite' => 'Unable to create the site.',
+ 'install:error:savesitesettings' => 'Unable to save site settings',
'install:error:loadadmin' => 'Unable to load admin user.',
'install:error:adminaccess' => 'Unable to give new user account admin privileges.',
'install:error:adminlogin' => 'Unable to login the new admin user automatically.',