2009-05-21 10:08:58 +00:00
< ? php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
2008-01-07 01:54:28 +00:00
/**
2008-06-15 12:23:53 +00:00
* Functions to support installation process
2009-05-21 10:08:58 +00:00
*
2010-07-30 11:58:02 +00:00
* @ package core
2009-05-21 10:08:58 +00:00
* @ subpackage install
* @ copyright 2009 Petr Skoda ( http :// skodak . org )
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2008-01-07 01:54:28 +00:00
*/
2010-07-26 20:17:36 +00:00
defined ( 'MOODLE_INTERNAL' ) || die ();
2009-05-26 02:17:06 +00:00
/** INSTALL_WELCOME = 0 */
2009-02-07 10:20:33 +00:00
define ( 'INSTALL_WELCOME' , 0 );
2009-05-26 02:17:06 +00:00
/** INSTALL_ENVIRONMENT = 1 */
2009-02-07 20:03:25 +00:00
define ( 'INSTALL_ENVIRONMENT' , 1 );
2009-05-26 02:17:06 +00:00
/** INSTALL_PATHS = 2 */
2009-02-07 20:03:25 +00:00
define ( 'INSTALL_PATHS' , 2 );
2009-05-26 02:17:06 +00:00
/** INSTALL_DOWNLOADLANG = 3 */
2009-02-07 20:03:25 +00:00
define ( 'INSTALL_DOWNLOADLANG' , 3 );
2009-05-26 02:17:06 +00:00
/** INSTALL_DATABASETYPE = 4 */
2009-02-07 20:03:25 +00:00
define ( 'INSTALL_DATABASETYPE' , 4 );
2009-05-26 02:17:06 +00:00
/** INSTALL_DATABASE = 5 */
2009-02-07 20:03:25 +00:00
define ( 'INSTALL_DATABASE' , 5 );
2009-05-26 02:17:06 +00:00
/** INSTALL_SAVE = 6 */
2009-02-07 20:03:25 +00:00
define ( 'INSTALL_SAVE' , 6 );
2009-02-07 10:20:33 +00:00
2009-01-05 21:37:20 +00:00
/**
2009-05-26 02:17:06 +00:00
* Tries to detect the right www root setting .
2009-01-05 21:37:20 +00:00
* @ return string detected www root
*/
function install_guess_wwwroot () {
$wwwroot = '' ;
if ( empty ( $_SERVER [ 'HTTPS' ]) or $_SERVER [ 'HTTPS' ] == 'off' ) {
$wwwroot .= 'http://' ;
} else {
$wwwroot .= 'https://' ;
}
$hostport = explode ( ':' , $_SERVER [ 'HTTP_HOST' ]);
$wwwroot .= reset ( $hostport );
if ( $_SERVER [ 'SERVER_PORT' ] != 80 and $_SERVER [ 'SERVER_PORT' ] != '443' ) {
$wwwroot .= ':' . $_SERVER [ 'SERVER_PORT' ];
}
$wwwroot .= $_SERVER [ 'SCRIPT_NAME' ];
list ( $wwwroot , $xtra ) = explode ( '/install.php' , $wwwroot );
return $wwwroot ;
}
2009-05-21 10:08:58 +00:00
/**
* Copy of @ see { ini_get_bool ()}
* @ param string $ini_get_arg
* @ return bool
*/
2009-02-07 10:20:33 +00:00
function install_ini_get_bool ( $ini_get_arg ) {
$temp = ini_get ( $ini_get_arg );
if ( $temp == '1' or strtolower ( $temp ) == 'on' ) {
return true ;
}
return false ;
}
2010-08-29 11:33:04 +00:00
/**
* Creates dataroot if not exists yet ,
* makes sure it is writable , add lang directory
* and add . htaccess just in case it works .
*
* @ param string $dataroot full path to dataroot
* @ param int $dirpermissions
* @ return bool success
*/
function install_init_dataroot ( $dataroot , $dirpermissions ) {
if ( file_exists ( $dataroot ) and ! is_dir ( $dataroot )) {
// file with the same name exists
return false ;
}
2013-07-13 19:54:50 +02:00
umask ( 0000 ); // $CFG->umaskpermissions is not set yet.
2010-08-29 11:33:04 +00:00
if ( ! file_exists ( $dataroot )) {
if ( ! mkdir ( $dataroot , $dirpermissions , true )) {
// most probably this does not work, but anyway
return false ;
}
}
@ chmod ( $dataroot , $dirpermissions );
if ( ! is_writable ( $dataroot )) {
return false ; // we can not continue
}
2011-11-21 16:49:40 +01:00
// create the directory for $CFG->tempdir
if ( ! is_dir ( " $dataroot /temp " )) {
if ( ! mkdir ( " $dataroot /temp " , $dirpermissions , true )) {
return false ;
}
}
if ( ! is_writable ( " $dataroot /temp " )) {
return false ; // we can not continue
}
// create the directory for $CFG->cachedir
if ( ! is_dir ( " $dataroot /cache " )) {
if ( ! mkdir ( " $dataroot /cache " , $dirpermissions , true )) {
return false ;
}
}
if ( ! is_writable ( " $dataroot /cache " )) {
return false ; // we can not continue
}
// create the directory for $CFG->langotherroot
2010-08-29 11:33:04 +00:00
if ( ! is_dir ( " $dataroot /lang " )) {
if ( ! mkdir ( " $dataroot /lang " , $dirpermissions , true )) {
return false ;
}
}
if ( ! is_writable ( " $dataroot /lang " )) {
return false ; // we can not continue
}
// finally just in case some broken .htaccess that prevents access just in case it is allowed
if ( ! file_exists ( " $dataroot /.htaccess " )) {
if ( $handle = fopen ( " $dataroot /.htaccess " , 'w' )) {
fwrite ( $handle , " deny from all \r \n AllowOverride None \r \n Note: this file is broken intentionally, we do not want anybody to undo it in subdirectory! \r \n " );
fclose ( $handle );
} else {
return false ;
}
}
return true ;
}
2009-05-21 10:08:58 +00:00
/**
* Print help button
* @ param string $url
* @ param string $titel
* @ return void
*/
2009-02-07 10:20:33 +00:00
function install_helpbutton ( $url , $title = '' ) {
if ( $title == '' ) {
$title = get_string ( 'help' );
}
echo " <a href= \" javascript:void(0) \" " ;
echo " onclick= \" return window.open(' $url ','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400') \" " ;
echo " > " ;
echo " <img src= \" pix/help.gif \" class= \" iconhelp \" alt= \" $title\ " title = \ " $title\ " /> " ;
echo " </a> \n " ;
}
2009-05-21 10:08:58 +00:00
/**
* This is in function because we want the / install . php to parse in PHP4
2009-05-26 02:17:06 +00:00
*
* @ param object $database
* @ param string $dbhsot
* @ param string $dbuser
* @ param string $dbpass
* @ param string $dbname
* @ param string $prefix
* @ param mixed $dboptions
* @ return string
2009-05-21 10:08:58 +00:00
*/
2009-02-09 19:35:57 +00:00
function install_db_validate ( $database , $dbhost , $dbuser , $dbpass , $dbname , $prefix , $dboptions ) {
2019-07-08 15:58:56 +10:00
if ( ! preg_match ( '/^[a-z_]*$/' , $prefix )) {
return get_string ( 'invaliddbprefix' , 'install' );
}
2009-02-07 10:20:33 +00:00
try {
try {
$database -> connect ( $dbhost , $dbuser , $dbpass , $dbname , $prefix , $dboptions );
} catch ( moodle_exception $e ) {
// let's try to create new database
if ( $database -> create_database ( $dbhost , $dbuser , $dbpass , $dbname , $dboptions )) {
$database -> connect ( $dbhost , $dbuser , $dbpass , $dbname , $prefix , $dboptions );
} else {
throw $e ;
}
}
return '' ;
} catch ( dml_exception $ex ) {
2013-05-10 17:28:31 +12:00
$stringmanager = get_string_manager ();
$errorstring = $ex -> errorcode . 'oninstall' ;
$legacystring = $ex -> errorcode ;
if ( $stringmanager -> string_exists ( $errorstring , $ex -> module )) {
// By using a different string id from the error code we are separating exception handling and output.
2014-04-30 15:21:41 +08:00
$returnstring = $stringmanager -> get_string ( $errorstring , $ex -> module , $ex -> a );
if ( $ex -> debuginfo ) {
$returnstring .= '<br />' . $ex -> debuginfo ;
}
return $returnstring ;
2013-05-10 17:28:31 +12:00
} else if ( $stringmanager -> string_exists ( $legacystring , $ex -> module )) {
// There are some DML exceptions that may be thrown here as well as during normal operation.
// If we have a translated message already we still want to serve it here.
// However it is not the preferred way.
2014-04-30 15:21:41 +08:00
$returnstring = $stringmanager -> get_string ( $legacystring , $ex -> module , $ex -> a );
if ( $ex -> debuginfo ) {
$returnstring .= '<br />' . $ex -> debuginfo ;
}
return $returnstring ;
2013-05-10 17:28:31 +12:00
}
// No specific translation. Deliver a generic error message.
return $stringmanager -> get_string ( 'dmlexceptiononinstall' , 'error' , $ex );
2009-02-07 10:20:33 +00:00
}
}
2009-05-25 17:17:33 +00:00
/**
* Returns content of config . php file .
2010-05-10 12:51:49 +00:00
*
* Uses PHP_EOL for generating proper end of lines for the given platform .
*
2009-05-25 17:17:33 +00:00
* @ param moodle_database $database database instance
* @ param object $cfg copy of $CFG
* @ return string
*/
2010-05-21 17:32:15 +00:00
function install_generate_configphp ( $database , $cfg ) {
2010-05-10 15:59:21 +00:00
$configphp = '<?php // Moodle configuration file' . PHP_EOL . PHP_EOL ;
2009-05-25 17:17:33 +00:00
2010-05-10 12:51:49 +00:00
$configphp .= 'unset($CFG);' . PHP_EOL ;
2010-08-26 15:31:18 +00:00
$configphp .= 'global $CFG;' . PHP_EOL ;
2010-05-10 12:51:49 +00:00
$configphp .= '$CFG = new stdClass();' . PHP_EOL . PHP_EOL ; // prevent PHP5 strict warnings
2009-05-25 17:17:33 +00:00
$dbconfig = $database -> export_dbconfig ();
foreach ( $dbconfig as $key => $value ) {
$key = str_pad ( $key , 9 );
2010-05-10 12:51:49 +00:00
$configphp .= '$CFG->' . $key . ' = ' . var_export ( $value , true ) . ';' . PHP_EOL ;
2009-05-25 17:17:33 +00:00
}
2010-05-10 12:51:49 +00:00
$configphp .= PHP_EOL ;
2009-05-25 17:17:33 +00:00
2010-05-10 12:51:49 +00:00
$configphp .= '$CFG->wwwroot = ' . var_export ( $cfg -> wwwroot , true ) . ';' . PHP_EOL ;
2009-05-25 17:17:33 +00:00
2010-05-21 17:32:15 +00:00
$configphp .= '$CFG->dataroot = ' . var_export ( $cfg -> dataroot , true ) . ';' . PHP_EOL ;
2009-05-25 17:17:33 +00:00
2010-05-10 12:51:49 +00:00
$configphp .= '$CFG->admin = ' . var_export ( $cfg -> admin , true ) . ';' . PHP_EOL . PHP_EOL ;
2009-05-25 17:17:33 +00:00
2010-05-20 13:40:45 +00:00
if ( empty ( $cfg -> directorypermissions )) {
$chmod = '02777' ;
} else {
$chmod = '0' . decoct ( $cfg -> directorypermissions );
}
$configphp .= '$CFG->directorypermissions = ' . $chmod . ';' . PHP_EOL . PHP_EOL ;
2009-05-25 17:17:33 +00:00
2015-09-16 00:18:06 +02:00
if ( isset ( $cfg -> upgradekey ) and $cfg -> upgradekey !== '' ) {
$configphp .= '$CFG->upgradekey = ' . var_export ( $cfg -> upgradekey , true ) . ';' . PHP_EOL . PHP_EOL ;
}
2016-02-26 17:47:58 +11:00
$configphp .= 'require_once(__DIR__ . \'/lib/setup.php\');' . PHP_EOL . PHP_EOL ;
2010-05-10 12:51:49 +00:00
$configphp .= '// There is no php closing tag in this file,' . PHP_EOL ;
$configphp .= '// it is intentional because it prevents trailing whitespace problems!' . PHP_EOL ;
2009-05-25 17:17:33 +00:00
return $configphp ;
}
2009-05-21 10:08:58 +00:00
/**
* Prints complete help page used during installation .
* Does not return .
2009-05-26 02:17:06 +00:00
*
* @ global object
2009-05-21 10:08:58 +00:00
* @ param string $help
*/
2009-02-07 10:20:33 +00:00
function install_print_help_page ( $help ) {
2010-04-10 07:24:56 +00:00
global $CFG , $OUTPUT ; //TODO: MUST NOT USE $OUTPUT HERE!!!
2009-02-07 10:20:33 +00:00
@ header ( 'Content-Type: text/html; charset=UTF-8' );
2012-11-09 17:27:29 +01:00
@ header ( 'X-UA-Compatible: IE=edge' );
2009-02-07 10:20:33 +00:00
@ header ( 'Cache-Control: no-store, no-cache, must-revalidate' );
@ header ( 'Cache-Control: post-check=0, pre-check=0' , false );
@ header ( 'Pragma: no-cache' );
@ header ( 'Expires: Mon, 20 Aug 1969 09:23:00 GMT' );
@ header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' );
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ;
echo '<html dir="' . ( right_to_left () ? 'rtl' : 'ltr' ) . ' " >
< head >
2014-01-30 11:42:36 +08:00
< link rel = " shortcut icon " href = " theme/clean/pix/favicon.ico " />
2011-07-23 00:45:17 +02:00
< link rel = " stylesheet " type = " text/css " href = " '. $CFG->wwwroot .'/install/css.php " />
2009-02-07 10:20:33 +00:00
< title > '.get_string(' installation ',' install ').' </ title >
< meta http - equiv = " content-type " content = " text/html; charset=UTF-8 " />
2014-03-14 18:31:29 -03:00
</ head >< body > ' ;
2009-02-07 10:20:33 +00:00
switch ( $help ) {
case 'phpversionhelp' :
print_string ( $help , 'install' , phpversion ());
break ;
case 'memorylimithelp' :
2010-09-18 11:14:09 +00:00
print_string ( $help , 'install' , @ ini_get ( 'memory_limit' ));
2009-02-07 10:20:33 +00:00
break ;
default :
print_string ( $help , 'install' );
2008-01-07 01:54:28 +00:00
}
2010-04-10 07:24:56 +00:00
echo $OUTPUT -> close_window_button (); //TODO: MUST NOT USE $OUTPUT HERE!!!
2009-02-07 10:20:33 +00:00
echo '</body></html>' ;
die ;
2008-01-07 01:54:28 +00:00
}
2009-05-21 10:08:58 +00:00
/**
2010-05-21 17:40:28 +00:00
* Prints installation page header , we can no use weblib yet in installer .
2009-05-26 02:17:06 +00:00
*
* @ global object
2009-05-21 10:08:58 +00:00
* @ param array $config
* @ param string $stagename
* @ param string $heading
* @ param string $stagetext
2014-04-30 15:21:41 +08:00
* @ param string $stageclass
2009-05-21 10:08:58 +00:00
* @ return void
*/
2014-04-30 15:21:41 +08:00
function install_print_header ( $config , $stagename , $heading , $stagetext , $stageclass = " alert-info " ) {
2009-02-07 10:20:33 +00:00
global $CFG ;
2008-01-07 01:54:28 +00:00
2009-02-07 10:20:33 +00:00
@ header ( 'Content-Type: text/html; charset=UTF-8' );
2012-11-09 17:27:29 +01:00
@ header ( 'X-UA-Compatible: IE=edge' );
2009-02-07 10:20:33 +00:00
@ header ( 'Cache-Control: no-store, no-cache, must-revalidate' );
@ header ( 'Cache-Control: post-check=0, pre-check=0' , false );
@ header ( 'Pragma: no-cache' );
@ header ( 'Expires: Mon, 20 Aug 1969 09:23:00 GMT' );
@ header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' );
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ;
echo '<html dir="' . ( right_to_left () ? 'rtl' : 'ltr' ) . ' " >
< head >
2014-01-30 11:42:36 +08:00
< link rel = " shortcut icon " href = " theme/clean/pix/favicon.ico " /> ' ;
2009-02-07 10:20:33 +00:00
2011-07-23 00:45:17 +02:00
echo '<link rel="stylesheet" type="text/css" href="' . $CFG -> wwwroot . ' / install / css . php " />
2009-02-07 17:56:40 +00:00
< title > '.get_string(' installation ',' install ').' - Moodle '.$CFG->target_release.' </ title >
2015-11-23 10:14:15 +00:00
< meta name = " robots " content = " noindex " >
2009-02-07 10:20:33 +00:00
< meta http - equiv = " content-type " content = " text/html; charset=UTF-8 " />
< meta http - equiv = " pragma " content = " no-cache " />
< meta http - equiv = " expires " content = " 0 " /> ' ;
echo ' </ head >< body class = " notloggedin " >
2019-05-02 16:47:35 +02:00
< div id = " page " class = " mt-0 container stage'. $config->stage .' " >
2010-03-25 06:38:21 +00:00
< div id = " page-header " >
< div id = " header " class = " clearfix " >
< h1 class = " headermain " > '.get_string(' installation ',' install ').' </ h1 >
< div class = " headermenu " >& nbsp ; </ div >
</ div >
2019-05-02 16:47:35 +02:00
< div class = " bg-light p-3 mb-3 " >< h3 class = " m-0 " > '.$stagename.' </ h3 ></ div >
2009-02-07 10:20:33 +00:00
</ div >
<!-- END OF HEADER -->
< div id = " installdiv " > ' ;
2008-01-07 01:54:28 +00:00
2009-02-07 10:20:33 +00:00
echo '<h2>' . $heading . '</h2>' ;
if ( $stagetext !== '' ) {
2014-04-30 15:21:41 +08:00
echo '<div class="alert ' . $stageclass . '">' ;
2009-02-07 10:20:33 +00:00
echo $stagetext ;
echo '</div>' ;
}
// main
echo '<form id="installform" method="post" action="install.php"><fieldset>' ;
foreach ( $config as $name => $value ) {
echo '<input type="hidden" name="' . $name . '" value="' . s ( $value ) . '" />' ;
}
2008-01-07 01:54:28 +00:00
}
2009-05-21 10:08:58 +00:00
/**
* Prints installation page header , we can no use weblib yet in isntaller .
2009-05-26 02:17:06 +00:00
*
* @ global object
2009-05-21 10:08:58 +00:00
* @ param array $config
* @ param bool $reload print reload button instead of next
* @ return void
*/
2009-02-07 10:20:33 +00:00
function install_print_footer ( $config , $reload = false ) {
global $CFG ;
if ( $config -> stage > INSTALL_WELCOME ) {
2019-06-25 13:26:15 +08:00
$first = '<input type="submit" id="previousbutton" class="btn btn-secondary flex-grow-0 ml-auto" name="previous" value="« ' . s ( get_string ( 'previous' )) . '" />' ;
2009-02-07 10:20:33 +00:00
} else {
2019-06-25 13:26:15 +08:00
$first = '<input type="submit" id="previousbutton" class="btn btn-secondary flex-grow-0 ml-auto" name="next" value="' . s ( get_string ( 'reload' )) . '" />' ;
2009-02-07 13:35:01 +00:00
$first .= ' < script type = " text/javascript " >
//<![CDATA[
var first = document . getElementById ( " previousbutton " );
first . style . visibility = " hidden " ;
//]]>
</ script >
' ;
2009-02-07 10:20:33 +00:00
}
if ( $reload ) {
2019-06-25 13:26:15 +08:00
$next = '<input type="submit" id="nextbutton" class="btn btn-primary ml-1 flex-grow-0 mr-auto" name="next" value="' . s ( get_string ( 'reload' )) . '" />' ;
2009-02-07 10:20:33 +00:00
} else {
2019-06-25 13:26:15 +08:00
$next = '<input type="submit" id="nextbutton" class="btn btn-primary ml-1 flex-grow-0 mr-auto" name="next" value="' . s ( get_string ( 'next' )) . ' »" />' ;
2009-02-07 10:20:33 +00:00
}
2019-06-25 13:26:15 +08:00
echo '</fieldset><div id="nav_buttons" class="mb-3 btn-group w-100 flex-row-reverse">' . $next . $first . '</div>' ;
2009-02-07 10:20:33 +00:00
$homelink = '<div class="sitelink">' .
2009-02-07 17:56:40 +00:00
'<a title="Moodle ' . $CFG -> target_release . '" href="http://docs.moodle.org/en/Administrator_documentation" onclick="this.target=\'_blank\'">' .
2015-10-30 16:51:51 +00:00
'<img src="pix/moodlelogo.png" alt="' . get_string ( 'moodlelogo' ) . '" /></a></div>' ;
2009-02-07 10:20:33 +00:00
echo '</form></div>' ;
2014-04-30 15:21:41 +08:00
echo '<div id="page-footer">' . $homelink . '</div>' ;
2009-02-07 10:20:33 +00:00
echo '</div></body></html>' ;
}
2010-07-30 11:58:02 +00:00
/**
* Install Moodle DB ,
* config . php must exist , there must not be any tables in db yet .
*
* @ param array $options adminpass is mandatory
* @ param bool $interactive
* @ return void
*/
function install_cli_database ( array $options , $interactive ) {
global $CFG , $DB ;
require_once ( $CFG -> libdir . '/environmentlib.php' );
require_once ( $CFG -> libdir . '/upgradelib.php' );
// show as much debug as possible
2012-03-30 19:19:06 +02:00
@ error_reporting ( E_ALL | E_STRICT );
2010-07-30 11:58:02 +00:00
@ ini_set ( 'display_errors' , '1' );
2012-03-30 19:19:06 +02:00
$CFG -> debug = ( E_ALL | E_STRICT );
2010-07-30 11:58:02 +00:00
$CFG -> debugdisplay = true ;
2013-08-10 22:46:49 +02:00
$CFG -> debugdeveloper = true ;
2010-07-30 11:58:02 +00:00
$CFG -> version = '' ;
$CFG -> release = '' ;
2012-05-10 15:43:52 +08:00
$CFG -> branch = '' ;
2010-09-18 11:29:10 +00:00
$version = null ;
2010-09-18 11:29:45 +00:00
$release = null ;
2012-05-10 15:43:52 +08:00
$branch = null ;
2010-07-30 11:58:02 +00:00
// read $version and $release
require ( $CFG -> dirroot . '/version.php' );
if ( $DB -> get_tables () ) {
cli_error ( get_string ( 'clitablesexist' , 'install' ));
}
if ( empty ( $options [ 'adminpass' ])) {
cli_error ( 'Missing required admin password' );
}
// test environment first
2011-10-19 13:24:11 +01:00
list ( $envstatus , $environment_results ) = check_moodle_environment ( normalize_version ( $release ), ENV_SELECT_RELEASE );
if ( ! $envstatus ) {
2010-07-30 11:58:02 +00:00
$errors = environment_get_errors ( $environment_results );
cli_heading ( get_string ( 'environment' , 'admin' ));
foreach ( $errors as $error ) {
list ( $info , $report ) = $error ;
echo " !! $info !! \n $report\n\n " ;
}
exit ( 1 );
}
if ( ! $DB -> setup_is_unicodedb ()) {
if ( ! $DB -> change_db_encoding ()) {
// If could not convert successfully, throw error, and prevent installation
cli_error ( get_string ( 'unicoderequired' , 'admin' ));
}
}
if ( $interactive ) {
cli_separator ();
cli_heading ( get_string ( 'databasesetup' ));
}
// install core
install_core ( $version , true );
set_config ( 'release' , $release );
2012-05-03 14:05:40 +08:00
set_config ( 'branch' , $branch );
2010-07-30 11:58:02 +00:00
2012-05-25 10:21:12 +02:00
if ( PHPUNIT_TEST ) {
// mark as test database as soon as possible
set_config ( 'phpunittest' , 'na' );
}
2010-07-30 11:58:02 +00:00
// install all plugins types, local, etc.
upgrade_noncore ( true );
// set up admin user password
$DB -> set_field ( 'user' , 'password' , hash_internal_user_password ( $options [ 'adminpass' ]), array ( 'username' => 'admin' ));
2015-01-09 14:08:33 +08:00
// Set the admin email address if specified.
if ( isset ( $options [ 'adminemail' ])) {
$DB -> set_field ( 'user' , 'email' , $options [ 'adminemail' ], array ( 'username' => 'admin' ));
}
2010-07-30 11:58:02 +00:00
// rename admin username if needed
if ( isset ( $options [ 'adminuser' ]) and $options [ 'adminuser' ] !== 'admin' and $options [ 'adminuser' ] !== 'guest' ) {
$DB -> set_field ( 'user' , 'username' , $options [ 'adminuser' ], array ( 'username' => 'admin' ));
}
// indicate that this site is fully configured
set_config ( 'rolesactive' , 1 );
upgrade_finished ();
// log in as admin - we need do anything when applying defaults
2013-09-08 08:38:52 +02:00
\core\session\manager :: set_user ( get_admin ());
2010-07-30 11:58:02 +00:00
2018-10-22 13:09:58 +11:00
// Apply all default settings.
2010-07-30 11:58:02 +00:00
admin_apply_default_settings ( NULL , true );
set_config ( 'registerauth' , '' );
2010-10-27 19:18:45 +00:00
// set the site name
if ( isset ( $options [ 'shortname' ]) and $options [ 'shortname' ] !== '' ) {
$DB -> set_field ( 'course' , 'shortname' , $options [ 'shortname' ], array ( 'format' => 'site' ));
}
if ( isset ( $options [ 'fullname' ]) and $options [ 'fullname' ] !== '' ) {
$DB -> set_field ( 'course' , 'fullname' , $options [ 'fullname' ], array ( 'format' => 'site' ));
}
2015-04-15 10:33:14 +08:00
if ( isset ( $options [ 'summary' ])) {
$DB -> set_field ( 'course' , 'summary' , $options [ 'summary' ], array ( 'format' => 'site' ));
}
2017-09-22 13:16:57 +08:00
// Redirect to site registration on first login.
set_config ( 'registrationpending' , 1 );
2010-10-27 19:18:45 +00:00
}