diff options
Diffstat (limited to 'install')
-rw-r--r-- | install/ElggInstaller.php | 95 | ||||
-rw-r--r-- | install/ElggRewriteTester.php | 2 | ||||
-rw-r--r-- | install/cli/sample_installer.php | 29 | ||||
-rw-r--r-- | install/languages/en.php | 8 |
4 files changed, 130 insertions, 4 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(); + } } diff --git a/install/ElggRewriteTester.php b/install/ElggRewriteTester.php index 6a4d5d16d..69da77721 100644 --- a/install/ElggRewriteTester.php +++ b/install/ElggRewriteTester.php @@ -91,7 +91,7 @@ class ElggRewriteTester { * @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 diff --git a/install/cli/sample_installer.php b/install/cli/sample_installer.php new file mode 100644 index 000000000..10838b562 --- /dev/null +++ b/install/cli/sample_installer.php @@ -0,0 +1,29 @@ +<?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); diff --git a/install/languages/en.php b/install/languages/en.php index 02555c7d3..ff6b7e4a9 100644 --- a/install/languages/en.php +++ b/install/languages/en.php @@ -40,7 +40,7 @@ If you are ready to proceed, click the Next button.", '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: @@ -68,8 +68,6 @@ If you are ready to proceed, click the Next button.", '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', @@ -116,9 +114,12 @@ If you are ready to proceed, click the Next button.", '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', @@ -127,6 +128,7 @@ If you are ready to proceed, click the Next button.", '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.', |