[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This installs Moodle into empty database, config.php must already exist. 20 * 21 * This script is intended for advanced usage such as in Debian packages. 22 * - sudo to www-data (apache account) before 23 * - not compatible with Windows platform 24 * 25 * @package core 26 * @subpackage cli 27 * @copyright 2010 Petr Skoda (http://skodak.org) 28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 */ 30 31 define('CLI_SCRIPT', true); 32 define('CACHE_DISABLE_ALL', true); 33 34 // extra execution prevention - we can not just require config.php here 35 if (isset($_SERVER['REMOTE_ADDR'])) { 36 exit(1); 37 } 38 39 // Force OPcache reset if used, we do not want any stale caches 40 // when preparing test environment. 41 if (function_exists('opcache_reset')) { 42 opcache_reset(); 43 } 44 45 $help = 46 "Advanced command line Moodle database installer. 47 Please note you must execute this script with the same uid as apache. 48 49 Site defaults may be changed via local/defaults.php. 50 51 Options: 52 --lang=CODE Installation and default site language. Default is en. 53 --adminuser=USERNAME Username for the moodle admin account. Default is admin. 54 --adminpass=PASSWORD Password for the moodle admin account. 55 --agree-license Indicates agreement with software license. 56 --fullname=STRING Name of the site 57 --shortname=STRING Name of the site 58 -h, --help Print out this help 59 60 Example: 61 \$sudo -u www-data /usr/bin/php admin/cli/install_database.php --lang=cs --adminpass=soMePass123 --agree-license 62 "; 63 64 // Check that PHP is of a sufficient version 65 if (version_compare(phpversion(), "5.4.4") < 0) { 66 $phpversion = phpversion(); 67 // do NOT localise - lang strings would not work here and we CAN NOT move it after installib 68 fwrite(STDERR, "Moodle 2.7 or later requires at least PHP 5.4.4 (currently using version $phpversion).\n"); 69 fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n"); 70 exit(1); 71 } 72 73 // Nothing to do if config.php does not exist 74 $configfile = dirname(dirname(dirname(__FILE__))).'/config.php'; 75 if (!file_exists($configfile)) { 76 fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize 77 fwrite(STDERR, "\n"); 78 exit(1); 79 } 80 81 // Include necessary libs 82 require($configfile); 83 84 require_once($CFG->libdir.'/clilib.php'); 85 require_once($CFG->libdir.'/installlib.php'); 86 require_once($CFG->libdir.'/adminlib.php'); 87 require_once($CFG->libdir.'/componentlib.class.php'); 88 89 // make sure no tables are installed yet 90 if ($DB->get_tables() ) { 91 cli_error(get_string('clitablesexist', 'install')); 92 } 93 94 $CFG->early_install_lang = true; 95 get_string_manager(true); 96 97 raise_memory_limit(MEMORY_EXTRA); 98 99 // now get cli options 100 list($options, $unrecognized) = cli_get_params( 101 array( 102 'lang' => 'en', 103 'adminuser' => 'admin', 104 'adminpass' => '', 105 'fullname' => '', 106 'shortname' => '', 107 'agree-license' => false, 108 'help' => false 109 ), 110 array( 111 'h' => 'help' 112 ) 113 ); 114 115 116 if ($options['help']) { 117 echo $help; 118 die; 119 } 120 121 if (!$options['agree-license']) { 122 cli_error('You have to agree to the license. --help prints out the help'); // TODO: localize 123 } 124 125 if ($options['adminpass'] === true or $options['adminpass'] === '') { 126 cli_error('You have to specify admin password. --help prints out the help'); // TODO: localize 127 } 128 129 $options['lang'] = clean_param($options['lang'], PARAM_SAFEDIR); 130 if (!file_exists($CFG->dirroot.'/install/lang/'.$options['lang'])) { 131 $options['lang'] = 'en'; 132 } 133 $CFG->lang = $options['lang']; 134 135 // download required lang packs 136 if ($CFG->lang !== 'en') { 137 make_upload_directory('lang'); 138 $installer = new lang_installer($CFG->lang); 139 $results = $installer->run(); 140 foreach ($results as $langcode => $langstatus) { 141 if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) { 142 $a = new stdClass(); 143 $a->url = $installer->lang_pack_url($langcode); 144 $a->dest = $CFG->dataroot.'/lang'; 145 cli_problem(get_string('remotedownloaderror', 'error', $a)); 146 } 147 } 148 } 149 150 // switch the string_manager instance to stop using install/lang/ 151 $CFG->early_install_lang = false; 152 get_string_manager(true); 153 154 require("$CFG->dirroot/version.php"); 155 156 // Test environment first. 157 require_once($CFG->libdir . '/environmentlib.php'); 158 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); 159 if (!$envstatus) { 160 $errors = environment_get_errors($environment_results); 161 cli_heading(get_string('environment', 'admin')); 162 foreach ($errors as $error) { 163 list($info, $report) = $error; 164 echo "!! $info !!\n$report\n\n"; 165 } 166 exit(1); 167 } 168 169 // Test plugin dependencies. 170 $failed = array(); 171 if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { 172 cli_problem(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed))))); 173 cli_error(get_string('pluginschecktodo', 'admin')); 174 } 175 176 install_cli_database($options, true); 177 178 echo get_string('cliinstallfinished', 'install')."\n"; 179 exit(0); // 0 means success
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |