ElggInstaller::batchInstall PHP Method

batchInstall() public method

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.
public batchInstall ( array $params, boolean $createHtaccess = FALSE ) : void
$params array Array of key value pairs
$createHtaccess boolean Should .htaccess be created
return void
    public function batchInstall(array $params, $createHtaccess = FALSE)
    {
        restore_error_handler();
        restore_exception_handler();
        $defaults = array('dbhost' => 'localhost', 'dbprefix' => 'elgg_', 'language' => 'en', 'siteaccess' => ACCESS_PUBLIC, 'site_guid' => 1);
        $params = array_merge($defaults, $params);
        $requiredParams = array('dbuser', 'dbpassword', 'dbname', 'sitename', 'wwwroot', 'dataroot', 'displayname', 'email', 'username', 'password');
        foreach ($requiredParams as $key) {
            if (empty($params[$key])) {
                $msg = _elgg_services()->translator->translate('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($params['wwwroot'], Directory\Local::root()->getPath())) {
                throw new InstallationException(_elgg_services()->translator->translate('install:error:htaccess'));
            }
        }
        $this->setInstallStatus();
        if (!$this->status['config']) {
            if (!$this->createSettingsFile($params)) {
                throw new InstallationException(_elgg_services()->translator->translate('install:error:settings'));
            }
        }
        if (!$this->connectToDatabase()) {
            throw new InstallationException(_elgg_services()->translator->translate('install:error:databasesettings'));
        }
        if (!$this->status['database']) {
            if (!$this->installDatabase()) {
                throw new InstallationException(_elgg_services()->translator->translate('install:error:cannotloadtables'));
            }
        }
        // load remaining core libraries
        $this->finishBootstraping('settings');
        if (!$this->saveSiteSettings($params)) {
            throw new InstallationException(_elgg_services()->translator->translate('install:error:savesitesettings'));
        }
        if (!$this->createAdminAccount($params)) {
            throw new InstallationException(_elgg_services()->translator->translate('install:admin:cannot_create'));
        }
    }

Usage Example

示例#1
0
<?php

/**
 * Sample cli installer script
 */
require_once dirname(dirname(__FILE__)) . "/ElggInstaller.php";
$installer = new ElggInstaller();
$params = array('dbuser' => '', 'dbpassword' => '', 'dbname' => '', 'sitename' => '', 'wwwroot' => '', 'dataroot' => '', 'displayname' => '', 'email' => '', 'username' => '', 'password' => '');
// install and create the .htaccess file
$installer->batchInstall($params, TRUE);
All Usage Examples Of ElggInstaller::batchInstall