aboutsummaryrefslogtreecommitdiff
path: root/install/ElggInstaller.php
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-13 11:01:16 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-13 11:01:16 +0000
commitcd33e6a791409bf0898d6d1db5938b09415289fb (patch)
treeec33c1463d8fdff09bdb897ba21f5066c3899fbb /install/ElggInstaller.php
parentea320e206be4f99c9a5819306ec1b284b1085ed4 (diff)
downloadelgg-cd33e6a791409bf0898d6d1db5938b09415289fb.tar.gz
elgg-cd33e6a791409bf0898d6d1db5938b09415289fb.tar.bz2
Fixes #2556 - one step install now supported with sample cli script
git-svn-id: http://code.elgg.org/elgg/trunk@7067 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'install/ElggInstaller.php')
-rw-r--r--install/ElggInstaller.php95
1 files changed, 95 insertions, 0 deletions
diff --git a/install/ElggInstaller.php b/install/ElggInstaller.php
index 0ed081a9a..304eb18b7 100644
--- a/install/ElggInstaller.php
+++ b/install/ElggInstaller.php
@@ -87,6 +87,86 @@ class ElggInstaller {
}
/**
+ * 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
*
* @param string $step
@@ -641,6 +721,8 @@ class ElggInstaller {
}
}
+ $this->initGlobals();
+
set_default_config();
trigger_elgg_event('boot', 'system');
@@ -1275,4 +1357,17 @@ class ElggInstaller {
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();
+ }
}