MDL-57192 dml: Support temporarily disabling query logs during setup

This commit is contained in:
Ankit Agarwal 2016-12-21 13:54:22 +05:30
parent c4cf1c60f5
commit c14fe2cb03

View File

@ -136,6 +136,11 @@ abstract class moodle_database {
*/ */
private $inorequaluniqueindex = 1; private $inorequaluniqueindex = 1;
/**
* @var boolean variable use to temporarily disable logging.
*/
protected $skiplogging = false;
/** /**
* Constructor - Instantiates the database, specifying if it's external (connect to other systems) or not (Moodle DB). * Constructor - Instantiates the database, specifying if it's external (connect to other systems) or not (Moodle DB).
* Note that this affects the decision of whether prefix checks must be performed or not. * Note that this affects the decision of whether prefix checks must be performed or not.
@ -487,6 +492,11 @@ abstract class moodle_database {
* @return void * @return void
*/ */
public function query_log($error=false) { public function query_log($error=false) {
// Logging disabled by the driver.
if ($this->skiplogging) {
return;
}
$logall = !empty($this->dboptions['logall']); $logall = !empty($this->dboptions['logall']);
$logslow = !empty($this->dboptions['logslow']) ? $this->dboptions['logslow'] : false; $logslow = !empty($this->dboptions['logslow']) ? $this->dboptions['logslow'] : false;
$logerrors = !empty($this->dboptions['logerrors']); $logerrors = !empty($this->dboptions['logerrors']);
@ -525,6 +535,20 @@ abstract class moodle_database {
} }
} }
/**
* Disable logging temporarily.
*/
protected function query_log_prevent() {
$this->skiplogging = true;
}
/**
* Restore old logging behavior.
*/
protected function query_log_allow() {
$this->skiplogging = false;
}
/** /**
* Returns the time elapsed since the query started. * Returns the time elapsed since the query started.
* @return float Seconds with microseconds * @return float Seconds with microseconds