Skip to content

Commit

Permalink
Merge branch 'w25_MDL-26455_m26_installport' of git://github.com/skod…
Browse files Browse the repository at this point in the history
…ak/moodle

Conflicts:
	admin/cli/install.php
  • Loading branch information
Sam Hemelryk committed Jun 18, 2013
2 parents 1b194c9 + 1826d0e commit 5c8cfcc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
41 changes: 36 additions & 5 deletions admin/cli/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
--dbname=NAME Database name. Default is moodle
--dbuser=USERNAME Database user. Default is root
--dbpass=PASSWORD Database password. Default is blank
--dbsocket Use database sockets. Available for some databases only.
--dbport=NUMBER Use database port.
--dbsocket=PATH Use database socket, 1 means default. Available for some databases only.
--prefix=STRING Table prefix for above database tables. Default is mdl_
--fullname=STRING The fullname of the site
--shortname=STRING The shortname of the site
Expand Down Expand Up @@ -151,6 +152,7 @@
$CFG->early_install_lang = true;
$CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
$CFG->developerdebug = true;
$CFG->dboptions = array();

$parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__))));
$CFG->admin = array_pop($parts);
Expand Down Expand Up @@ -205,7 +207,8 @@
'dbname' => 'moodle',
'dbuser' => empty($distro->dbuser) ? 'root' : $distro->dbuser, // let distros set dbuser
'dbpass' => '',
'dbsocket' => false,
'dbport' => '',
'dbsocket' => '',
'prefix' => 'mdl_',
'fullname' => '',
'shortname' => '',
Expand Down Expand Up @@ -498,6 +501,34 @@
$CFG->prefix = $options['prefix'];
}

// ask for db port
if ($interactive) {
cli_separator();
cli_heading(get_string('databaseport', 'install'));
$prompt = get_string('clitypevaluedefault', 'admin', $options['dbport']);
$CFG->dboptions['dbport'] = (int)cli_input($prompt, $options['dbport']);

} else {
$CFG->dboptions['dbport'] = (int)$options['dbport'];
}
if ($CFG->dboptions['dbport'] <= 0) {
$CFG->dboptions['dbport'] = '';
}

// ask for db socket
if ($CFG->ostype === 'WINDOWS') {
$CFG->dboptions['dbsocket'] = '';

} else if ($interactive and empty($CFG->dboptions['dbport'])) {
cli_separator();
cli_heading(get_string('databasesocket', 'install'));
$prompt = get_string('clitypevaluedefault', 'admin', $options['dbsocket']);
$CFG->dboptions['dbsocket'] = cli_input($prompt, $options['dbsocket']);

} else {
$CFG->dboptions['dbsocket'] = $options['dbsocket'];
}

// ask for db user
if ($interactive) {
cli_separator();
Expand Down Expand Up @@ -526,14 +557,14 @@

$CFG->dbpass = cli_input($prompt, $options['dbpass']);
if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
$distro = distro_pre_create_db($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbsocket'=>$options['dbsocket']), $distro);
$distro = distro_pre_create_db($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbport'=>$CFG->dboptions['dbport'], 'dbsocket'=>$CFG->dboptions['dbsocket']), $distro);
}
$hint_database = install_db_validate($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbsocket'=>$options['dbsocket']));
$hint_database = install_db_validate($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbport'=>$CFG->dboptions['dbport'], 'dbsocket'=>$CFG->dboptions['dbsocket']));
} while ($hint_database !== '');

} else {
$CFG->dbpass = $options['dbpass'];
$hint_database = install_db_validate($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbsocket'=>$options['dbsocket']));
$hint_database = install_db_validate($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbport'=>$CFG->dboptions['dbport'], 'dbsocket'=>$CFG->dboptions['dbsocket']));
if ($hint_database !== '') {
cli_error(get_string('dbconnectionerror', 'install'));
}
Expand Down
23 changes: 16 additions & 7 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@
$config->dbpass = trim($_POST['dbpass']);
$config->dbname = trim($_POST['dbname']);
$config->prefix = trim($_POST['prefix']);
$config->dbsocket = (int)(!empty($_POST['dbsocket']));
$config->dbport = (int)trim($_POST['dbport']);
$config->dbsocket = trim($_POST['dbsocket']);

if ($config->dbport <= 0) {
$config->dbport = '';
}

$config->admin = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']);

Expand All @@ -144,7 +149,8 @@
$config->dbpass = '';
$config->dbname = 'moodle';
$config->prefix = 'mdl_';
$config->dbsocket = 0;
$config->dbport = empty($distro->dbport) ? '' : $distro->dbport;
$config->dbsocket = empty($distro->dbsocket) ? '' : $distro->dbsocket;

$config->admin = 'admin';

Expand Down Expand Up @@ -264,9 +270,9 @@
$config->stage = INSTALL_DATABASETYPE;
} else {
if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
$distro = distro_pre_create_db($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbsocket'=>$config->dbsocket), $distro);
$distro = distro_pre_create_db($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbport'=>$config->dbport, 'dbsocket'=>$config->dbsocket), $distro);
}
$hint_database = install_db_validate($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbsocket'=>$config->dbsocket));
$hint_database = install_db_validate($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbport'=>$config->dbport, 'dbsocket'=>$config->dbsocket));

if ($hint_database === '') {
$configphp = install_generate_configphp($database, $CFG);
Expand Down Expand Up @@ -406,6 +412,7 @@
$strdbuser = get_string('databaseuser', 'install');
$strdbpass = get_string('databasepass', 'install');
$strprefix = get_string('dbprefix', 'install');
$strdbport = get_string('databaseport', 'install');
$strdbsocket = get_string('databasesocket', 'install');

echo '<div class="userinput">';
Expand Down Expand Up @@ -433,11 +440,13 @@
echo '<input id="id_prefix" name="prefix" type="text" value="'.s($config->prefix).'" size="10" class="forminput" />';
echo '</div>';

echo '<div class="formrow"><label for="id_prefix" class="formlabel">'.$strdbport.'</label>';
echo '<input id="id_dbport" name="dbport" type="text" value="'.s($config->dbport).'" size="10" class="forminput" />';
echo '</div>';

if (!(stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin'))) {
$checked = $config->dbsocket ? 'checked="checked' : '';
echo '<div class="formrow"><label for="id_dbsocket" class="formlabel">'.$strdbsocket.'</label>';
echo '<input type="hidden" value="0" name="dbsocket" />';
echo '<input type="checkbox" id="id_dbsocket" value="1" name="dbsocket" '.$checked.' class="forminput" />';
echo '<input id="id_dbsocket" name="dbsocket" type="text" value="'.s($config->dbsocket).'" size="50" class="forminput" />';
echo '</div>';
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
$string['databasehost'] = 'Database host';
$string['databasename'] = 'Database name';
$string['databasepass'] = 'Database password';
$string['databaseport'] = 'Database port';
$string['databasesettings'] = 'Now you need to configure the database where most Moodle data
will be stored. This database must already have been created
and a username and password created to access it.<br />
Expand Down

0 comments on commit 5c8cfcc

Please sign in to comment.