Skip to content

Commit

Permalink
MDL-17036 dml: dbpersist moved into dboptions
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Oct 27, 2008
1 parent 298d925 commit beaa43d
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 46 deletions.
2 changes: 1 addition & 1 deletion admin/cliupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@
$str .= "\r\n";

$database = $databases[$CONFFILE['dbtype']];
$dbconfig = $database->export_dbconfig($CONFFILE['dbhost'], $CONFFILE['dbuser'], $CONFFILE['dbpass'], $CONFFILE['dbname'], false, $CONFFILE['prefix']);
$dbconfig = $database->export_dbconfig($CONFFILE['dbhost'], $CONFFILE['dbuser'], $CONFFILE['dbpass'], $CONFFILE['dbname'], $CONFFILE['prefix']);

foreach ($dbconfig as $key=>$value) {
$key = str_pad($key, 9);
Expand Down
10 changes: 5 additions & 5 deletions admin/report/unittest/dbtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
if (!isset($CFG->$name)) {
continue;
}
list($library, $driver, $dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions) = $CFG->$name;
list($library, $driver, $dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions) = $CFG->$name;
$dbinfos[$i] = array('name'=>"External database $i ($library/$driver/$dbhost/$dbname/$prefix)", 'installed'=>false, 'configured'=>false);

$classname = "{$driver}_{$library}_moodle_database";
Expand All @@ -55,7 +55,7 @@
}
$dbinfos[$i]['installed'] = true;

if ($d->connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions)) {
if ($d->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions)) {
$dbinfos[$i]['configured'] = true;
if (data_submitted() and !empty($selected[$i])) {
$tests[$i] = $d;
Expand Down Expand Up @@ -123,10 +123,10 @@
echo '</ul></p>';
echo '<p>External databases are configured in config.php, add lines:
<pre>
$CFG->func_test_db_1 = array("adodb", "postgres7", "localhost", "moodleuser", "password", "moodle", false, "test", null);
$CFG->func_test_db_2 = array("adodb", "mssql", "localhost", "moodleuser", "password", "moodle", false, "test", null);
$CFG->func_test_db_1 = array("adodb", "postgres7", "localhost", "moodleuser", "password", "moodle", "test", null);
$CFG->func_test_db_2 = array("adodb", "mssql", "localhost", "moodleuser", "password", "moodle", "test", null);
</pre>
where order of parameters is: dblibrary, dbtype, dbhost, dbuser, dbpass, dbname, dbpersist, prefix, dboptions
where order of parameters is: dblibrary, dbtype, dbhost, dbuser, dbpass, dbname, prefix, dboptions
</p>';
echo '<p><input type="submit" value="' . get_string('runtests', 'simpletest') . '" /></p>';
echo '</div>';
Expand Down
3 changes: 1 addition & 2 deletions admin/report/unittest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
$CFG->dbuser = $real_cfg->dbuser;
$CFG->dbpass = $real_cfg->dbpass;
$CFG->dbname = $real_cfg->dbname;
$CFG->dbpersist = $real_cfg->dbpersist;
$CFG->unittestprefix = $real_cfg->unittestprefix;
$CFG->wwwroot = $real_cfg->wwwroot;
$CFG->dirroot = $real_cfg->dirroot;
Expand All @@ -131,7 +130,7 @@
$CFG->debug = $real_cfg->debug;

$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->unittestprefix);
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);

if ($DB->get_manager()->table_exists(new xmldb_table('config')) && $config = $DB->get_records('config')) {
foreach ($config as $conf) {
Expand Down
2 changes: 1 addition & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
$str .= "\r\n";

$DB = $databases[$INSTALL['dbtype']];
$dbconfig = $DB->export_dbconfig($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
$dbconfig = $DB->export_dbconfig($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], $INSTALL['prefix']);

foreach ($dbconfig as $key=>$value) {
$key = str_pad($key, 9);
Expand Down
6 changes: 3 additions & 3 deletions lib/dml/adodb_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function get_name() {
*/
protected abstract function preconfigure_dbconnection();

public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
global $CFG;

$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);

$this->preconfigure_dbconnection();

Expand All @@ -50,7 +50,7 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix,
// we probably want to change this value to ''.
$this->adodb->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \'';

if (!isset($this->dbpersist) or !empty($this->dbpersist)) { // Use persistent connection (default)
if (!empty($this->dboptions['dbpersist'])) { // Use persistent connection
if (!$this->adodb->PConnect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname)) {
return false;
}
Expand Down
12 changes: 4 additions & 8 deletions lib/dml/moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ abstract class moodle_database {
protected $dbuser;
protected $dbpass;
protected $dbname;
protected $dbpersist;
protected $prefix;

/**
Expand Down Expand Up @@ -146,8 +145,8 @@ public abstract function get_configuration_hints();
* Note: can be used before connect()
* @return string
*/
public function export_dbconfig($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
public function export_dbconfig($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);

$cfg = new stdClass();
$cfg->dbtype = $this->get_dbtype();
Expand All @@ -171,30 +170,27 @@ public function export_dbconfig($dbhost, $dbuser, $dbpass, $dbname, $dbpersist,
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param bool $dbpersist
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
* @param array $dboptions driver specific options
* @return bool success
*/
public abstract function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null);
public abstract function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null);

/**
* Store various database settings
* @param string $dbhost
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param bool $dbpersist
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
* @param array $dboptions driver specific options
* @return void
*/
protected function store_settings($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
protected function store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbname = $dbname;
$this->dbpersist = $dbpersist;
$this->prefix = $prefix;
$this->dboptions = (array)$dboptions;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/dml/mssql_adodb_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
*/
public $temptables;

public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
if ($prefix == '' and !$this->external) {
//Enforce prefixes for everybody but mysql
throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily());
}
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions lib/dml/mysqli_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ public function get_configuration_hints() {
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param bool $dbpersist
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
* @param array $dboptions driver specific options
* @return bool success
*/
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
global $CFG;

$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, false, $prefix, $dboptions);
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);

$this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($this->mysqli->connect_error) {
Expand Down
4 changes: 2 additions & 2 deletions lib/dml/oci8po_adodb_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class oci8po_adodb_moodle_database extends adodb_moodle_database {

public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
if ($prefix == '' and !$this->external) {
//Enforce prefixes for everybody but mysql
throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily());
Expand All @@ -20,7 +20,7 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix,
$a = (object)array('dbfamily'=>'oracle', 'maxlength'=>2);
throw new dml_exception('prefixtoolong', $a);
}
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions lib/dml/pdo_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ public function __construct($external=false) {
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param bool $dbpersist
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
* @param array $dboptions driver specific options
* @return bool success
*/
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);

try {
$this->pdb = new PDO($this->get_dsn(), $this->dbuser, $this->dbpass, $this->get_pdooptions());
Expand Down Expand Up @@ -64,7 +63,7 @@ protected function get_dsn() {
* @return array A key=>value array of PDO driver-specific connection options
*/
protected function get_pdooptions() {
return array(PDO::ATTR_PERSISTENT => $this->dbpersist);
return array(PDO::ATTR_PERSISTENT => !empty($this->dboptions['dbpersist']));
}

protected function configure_dbconnection() {
Expand Down
5 changes: 2 additions & 3 deletions lib/dml/pgsql_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,14 @@ public function get_configuration_hints() {
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param bool $dbpersist
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
* @param array $dboptions driver specific options
* @return bool success
*/
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
global $CFG;

$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, false, $prefix, $dboptions);
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);

//TODO: handle both port and socket connection
$this->pgsql = pg_connect("host='{$this->dbhost}' user='{$this->dbuser}' password='{$this->dbpass}' dbname='{$this->dbname}'");
Expand Down
8 changes: 4 additions & 4 deletions lib/dml/postgres7_adodb_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
class postgres7_adodb_moodle_database extends adodb_moodle_database {

public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
if ($prefix == '' and !$this->external) {
//Enforce prefixes for everybody but mysql
throw new dml_exception('prefixcannotbeempty', $this->get_dbfamily());
}
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
}

/**
Expand Down Expand Up @@ -72,8 +72,8 @@ public function get_configuration_hints() {
* Note: can be used before connect()
* @return string
*/
public function export_dbconfig($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
public function export_dbconfig($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null) {
$this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);

$cfg = new stdClass();
$cfg->dbtype = $this->get_dbtype();
Expand Down
2 changes: 1 addition & 1 deletion lib/dml/simpletest/testdml.php
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ protected function get_dbtype(){}
protected function get_dblibrary(){}
public function get_name(){}
public function get_configuration_hints(){}
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null){}
public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dboptions=null){}
public function get_server_info(){}
protected function allowed_param_types(){}
public function get_last_error(){}
Expand Down
11 changes: 6 additions & 5 deletions lib/dmllib.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ function setup_DB() {
$CFG->dbname = '';
}

if (!isset($CFG->dbpersist)) {
$CFG->dbpersist = false;
}

if (!isset($CFG->dblibrary)) {
$CFG->dblibrary = 'adodb';
}
Expand All @@ -81,6 +77,11 @@ function setup_DB() {
$CFG->dboptions = array();
}

if (isset($CFG->dbpersist)) {
$CFG->dboptions['dbpersist'] = $CFG->dbpersist;
}


$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);

$CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now
Expand All @@ -97,7 +98,7 @@ function setup_DB() {
} else {
$prevdebug = error_reporting(0);
}
if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix, $CFG->dboptions)) {
if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions)) {
if (debugging('', DEBUG_ALL)) {
if ($dberr = ob_get_contents()) {
$dberr = '<p><em>'.$dberr.'</em></p>';
Expand Down
2 changes: 1 addition & 1 deletion lib/simpletest/testeventslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function setUp() {
if (is_null($DB)) {
$this->realdb = $DB;
$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix);
$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix);
}

events_uninstall('unittest');
Expand Down
2 changes: 1 addition & 1 deletion lib/simpletestlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public static function instantiate() {

if (empty(UnitTestDB::$DB)) {
UnitTestDB::$DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
UnitTestDB::$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->unittestprefix);
UnitTestDB::$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
}

$manager = UnitTestDB::$DB->get_manager();
Expand Down

0 comments on commit beaa43d

Please sign in to comment.