Skip to content

Commit

Permalink
MDL-31501 fake requried globals in both installers
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 23, 2013
1 parent cbbaffc commit 1a4621d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
21 changes: 21 additions & 0 deletions admin/cli/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
}

// set up configuration
global $CFG;
$CFG = new stdClass();
$CFG->lang = 'en';
$CFG->dirroot = dirname(dirname(dirname(__FILE__)));
Expand Down Expand Up @@ -200,6 +201,26 @@
require($CFG->dirroot.'/version.php');
$CFG->target_release = $release;

$_SESSION = array();
$_SESSION['SESSION'] = new stdClass();
$_SESSION['SESSION']->lang = $CFG->lang;
$_SESSION['USER'] = new stdClass();
$_SESSION['USER']->id = 0;
$_SESSION['USER']->mnethostid = 1;

global $SESSION;
global $USER;
$SESSION = &$_SESSION['SESSION'];
$USER = &$_SESSION['USER'];

global $COURSE;
$COURSE = new stdClass();
$COURSE->id = 1;

global $SITE;
$SITE = $COURSE;
define('SITEID', 1);

//Database types
$databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
Expand Down
21 changes: 15 additions & 6 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
}

// Fake some settings so that we can use selected functions from moodlelib.php, weblib.php and filelib.php.
global $CFG;
$CFG = new stdClass();
$CFG->lang = $config->lang;
$CFG->dirroot = dirname(__FILE__);
Expand Down Expand Up @@ -232,17 +233,25 @@
require('version.php');
$CFG->target_release = $release;

$SESSION = new stdClass();
$SESSION->lang = $CFG->lang;
$_SESSION = array();
$_SESSION['SESSION'] = new stdClass();
$_SESSION['SESSION']->lang = $CFG->lang;
$_SESSION['USER'] = new stdClass();
$_SESSION['USER']->id = 0;
$_SESSION['USER']->mnethostid = 1;

$USER = new stdClass();
$USER->id = 0;
global $SESSION;
global $USER;
$SESSION = &$_SESSION['SESSION'];
$USER = &$_SESSION['USER'];

global $COURSE;
$COURSE = new stdClass();
$COURSE->id = 0;
$COURSE->id = 1;

global $SITE;
$SITE = $COURSE;
define('SITEID', 0);
define('SITEID', 1);

$hint_dataroot = '';
$hint_admindir = '';
Expand Down

0 comments on commit 1a4621d

Please sign in to comment.