Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/cli/install_database.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00031 define('CLI_SCRIPT', true);
00032 
00033 // extra execution prevention - we can not just require config.php here
00034 if (isset($_SERVER['REMOTE_ADDR'])) {
00035     exit(1);
00036 }
00037 
00038 $help =
00039 "Advanced command line Moodle database installer.
00040 Please note you must execute this script with the same uid as apache.
00041 
00042 Site defaults may be changed via local/defaults.php.
00043 
00044 Options:
00045 --lang=CODE           Installation and default site language. Default is en.
00046 --adminuser=USERNAME  Username for the moodle admin account. Default is admin.
00047 --adminpass=PASSWORD  Password for the moodle admin account.
00048 --agree-license       Indicates agreement with software license.
00049 --fullname=STRING     Name of the site
00050 --shortname=STRING    Name of the site
00051 -h, --help            Print out this help
00052 
00053 Example:
00054 \$sudo -u www-data /usr/bin/php admin/cli/install_database.php --lang=cs --adminpass=soMePass123 --agree-license
00055 ";
00056 
00057 // Check that PHP is of a sufficient version
00058 if (version_compare(phpversion(), "5.3.2") < 0) {
00059     $phpversion = phpversion();
00060     // do NOT localise - lang strings would not work here and we CAN NOT move it after installib
00061     fwrite(STDERR, "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).\n");
00062     fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
00063     exit(1);
00064 }
00065 
00066 // Nothing to do if config.php does not exist
00067 $configfile = dirname(dirname(dirname(__FILE__))).'/config.php';
00068 if (!file_exists($configfile)) {
00069     fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize
00070     fwrite(STDERR, "\n");
00071     exit(1);
00072 }
00073 
00074 // Include necessary libs
00075 require($configfile);
00076 
00077 require_once($CFG->libdir.'/clilib.php');
00078 require_once($CFG->libdir.'/installlib.php');
00079 require_once($CFG->libdir.'/adminlib.php');
00080 require_once($CFG->libdir.'/componentlib.class.php');
00081 
00082 // make sure no tables are installed yet
00083 if ($DB->get_tables() ) {
00084     cli_error(get_string('clitablesexist', 'install'));
00085 }
00086 
00087 $CFG->early_install_lang = true;
00088 get_string_manager(true);
00089 
00090 raise_memory_limit(MEMORY_EXTRA);
00091 
00092 // now get cli options
00093 list($options, $unrecognized) = cli_get_params(
00094     array(
00095         'lang'              => 'en',
00096         'adminuser'         => 'admin',
00097         'adminpass'         => '',
00098         'fullname'          => '',
00099         'shortname'         => '',
00100         'agree-license'     => false,
00101         'help'              => false
00102     ),
00103     array(
00104         'h' => 'help'
00105     )
00106 );
00107 
00108 
00109 if ($options['help']) {
00110     echo $help;
00111     die;
00112 }
00113 
00114 if (!$options['agree-license']) {
00115     cli_error('You have to agree to the license. --help prints out the help'); // TODO: localize
00116 }
00117 
00118 if ($options['adminpass'] === true or $options['adminpass'] === '') {
00119     cli_error('You have to specify admin password. --help prints out the help'); // TODO: localize
00120 }
00121 
00122 $options['lang'] = clean_param($options['lang'], PARAM_SAFEDIR);
00123 if (!file_exists($CFG->dirroot.'/install/lang/'.$options['lang'])) {
00124     $options['lang'] = 'en';
00125 }
00126 $CFG->lang = $options['lang'];
00127 
00128 // download required lang packs
00129 if ($CFG->lang !== 'en') {
00130     make_upload_directory('lang');
00131     $installer = new lang_installer($CFG->lang);
00132     $results = $installer->run();
00133     foreach ($results as $langcode => $langstatus) {
00134         if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
00135             $a       = new stdClass();
00136             $a->url  = $installer->lang_pack_url($langcode);
00137             $a->dest = $CFG->dataroot.'/lang';
00138             cli_problem(get_string('remotedownloaderror', 'error', $a));
00139         }
00140     }
00141 }
00142 
00143 // switch the string_manager instance to stop using install/lang/
00144 $CFG->early_install_lang = false;
00145 get_string_manager(true);
00146 
00147 require("$CFG->dirroot/version.php");
00148 
00149 // Test environment first.
00150 require_once($CFG->libdir . '/environmentlib.php');
00151 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
00152 if (!$envstatus) {
00153     $errors = environment_get_errors($environment_results);
00154     cli_heading(get_string('environment', 'admin'));
00155     foreach ($errors as $error) {
00156         list($info, $report) = $error;
00157         echo "!! $info !!\n$report\n\n";
00158     }
00159     exit(1);
00160 }
00161 
00162 // Test plugin dependencies.
00163 require_once($CFG->libdir . '/pluginlib.php');
00164 if (!plugin_manager::instance()->all_plugins_ok($version)) {
00165     cli_error(get_string('pluginschecktodo', 'admin'));
00166 }
00167 
00168 install_cli_database($options, true);
00169 
00170 echo get_string('cliinstallfinished', 'install')."\n";
00171 exit(0); // 0 means success
 All Data Structures Namespaces Files Functions Variables Enumerations