return $cached;
}
- if (!$context = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM))) {
+ try {
+ $context = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM));
+ } catch (dml_read_exception $e) {
+ //table does not exist yet, sorry
+ return null;
+ }
+
+ if (!$context) {
$context = new object();
$context->contextlevel = CONTEXT_SYSTEM;
$context->instanceid = 0;
*/
protected $writes = 0;
- // TODO: do we really need record caching??
+ protected $last_sql;
+ protected $last_params;
+ protected $last_type;
+ protected $last_extrainfo;
/**
* Contructor - instantiates the database, specifying if it's external (connect to other systems) or no (Moodle DB)
* @return void
*/
protected function query_start($sql, array $params=null, $type, $extrainfo=null) {
+ $this->last_sql = $sql;
+ $this->last_params = $params;
+ $this->last_type = $type;
+ $this->last_extrainfo = $extrainfo;
+
switch ($type) {
case SQL_QUERY_SELECT:
case SQL_QUERY_AUX:
case SQL_QUERY_STRUCTURE:
$this->writes++;
}
- //TODO
+
+ $this->print_debug($sql, $params);
}
/**
* @return void
*/
protected function query_end($result) {
- //TODO
+ if ($result !== false) {
+ return;
+ }
+
+ switch ($this->last_type) {
+ case SQL_QUERY_SELECT:
+ case SQL_QUERY_AUX:
+ throw new dml_read_exception($this->get_last_error(), $this->last_sql, $this->last_params);
+ case SQL_QUERY_INSERT:
+ case SQL_QUERY_UPDATE:
+ case SQL_QUERY_STRUCTURE:
+ throw new dml_write_exception($this->get_last_error(), $this->last_sql, $this->last_params);
+ }
}
/**
}
/// Load up any configuration from the config table
- $CFG = get_config();
+ try {
+ $CFG = get_config();
+ } catch (dml_read_exception $e) {
+ // most probably empty db, going to install soon
+ }
/// Verify upgrade is not running unless we are in a script that needs to execute in any case
if (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) {
}
/// Defining the site
- if ($SITE = get_site()) {
+ try {
+ $SITE = get_site();
+ } catch (dml_read_exception $e) {
+ $SITE = null;
+ }
+
+ if ($SITE) {
/**
* If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
*/
// define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
if (!defined('SYSCONTEXTID')) {
- get_system_context();
+ try {
+ get_system_context();
+ } catch (dml_read_exception $e) {
+ // not available yet
+ }
}
/// Set error reporting back to normal
* @return mixed string or void
*/
function print_footer($course=NULL, $usercourse=NULL, $return=false) {
- global $USER, $CFG, $THEME, $COURSE;
+ global $USER, $CFG, $THEME, $COURSE, $SITE;
if (defined('ADMIN_EXT_HEADER_PRINTED') and !defined('ADMIN_EXT_FOOTER_PRINTED')) {
admin_externalpage_print_footer();
$home = false;
} else if ($course === 'home') { // special case for site home page - please do not remove
- $course = get_site();
+ $course = $SITE;
$homelink = '<div class="sitelink">'.
'<a title="Moodle '. $CFG->release .'" href="http://moodle.org/">'.
'<img style="width:100px;height:30px" src="pix/moodlelogo.gif" alt="moodlelogo" /></a></div>';
}
} else {
- $course = get_site(); // Set course as site course by default
+ $course = $SITE; // Set course as site course by default
$homelink = '<div class="homelink"><a '.$CFG->frametarget.' href="'.$CFG->wwwroot.'/">'.get_string('home').'</a></div>';
$home = false;
}
* @param boolean $return False to echo the breadcrumb string (default), true to return it.
*/
function print_navigation ($navigation, $separator=0, $return=false) {
- global $CFG, $THEME;
+ global $CFG, $THEME, $SITE;
$output = '';
if (0 === $separator) {
}
}
- if (! $site = get_site()) {
+ if (!$SITE) {
$site = new object();
$site->shortname = get_string('home');
+ } else {
+ $site = $SITE;
}
//Accessibility: breadcrumb links now in a list, » replaced with a 'silent' character.
* navigation strings.
*/
function build_navigation($extranavlinks, $cm = null) {
- global $CFG, $COURSE, $DB;
+ global $CFG, $COURSE, $DB, $SITE;
if (is_string($extranavlinks)) {
if ($extranavlinks == '') {
$navlinks = array();
//Site name
- if ($site = get_site()) {
+ if ($SITE) {
$navlinks[] = array(
- 'name' => format_string($site->shortname),
+ 'name' => format_string($SITE->shortname),
'link' => "$CFG->wwwroot/",
'type' => 'home');
}