From beaa43db85e1bfda11de1394ec682b3c66e73f9f Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 27 Oct 2008 22:21:34 +0000 Subject: [PATCH] MDL-17036 dml: dbpersist moved into dboptions --- admin/cliupgrade.php | 2 +- admin/report/unittest/dbtest.php | 10 +++++----- admin/report/unittest/index.php | 3 +-- install.php | 2 +- lib/dml/adodb_moodle_database.php | 6 +++--- lib/dml/moodle_database.php | 12 ++++-------- lib/dml/mssql_adodb_moodle_database.php | 4 ++-- lib/dml/mysqli_native_moodle_database.php | 5 ++--- lib/dml/oci8po_adodb_moodle_database.php | 4 ++-- lib/dml/pdo_moodle_database.php | 7 +++---- lib/dml/pgsql_native_moodle_database.php | 5 ++--- lib/dml/postgres7_adodb_moodle_database.php | 8 ++++---- lib/dml/simpletest/testdml.php | 2 +- lib/dmllib.php | 11 ++++++----- lib/simpletest/testeventslib.php | 2 +- lib/simpletestlib.php | 2 +- 16 files changed, 39 insertions(+), 46 deletions(-) diff --git a/admin/cliupgrade.php b/admin/cliupgrade.php index 99db2d4789e..a4c81aa7c2b 100644 --- a/admin/cliupgrade.php +++ b/admin/cliupgrade.php @@ -599,7 +599,7 @@ if (!file_exists(dirname(dirname(__FILE__)) . '/config.php')) { $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); diff --git a/admin/report/unittest/dbtest.php b/admin/report/unittest/dbtest.php index 4d8c4246ef3..506b9d00513 100644 --- a/admin/report/unittest/dbtest.php +++ b/admin/report/unittest/dbtest.php @@ -44,7 +44,7 @@ for ($i=1; $i<=10; $i++) { 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"; @@ -55,7 +55,7 @@ for ($i=1; $i<=10; $i++) { } $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; @@ -123,10 +123,10 @@ foreach ($dbinfos as $i=>$dbinfo) { echo '

'; echo '

External databases are configured in config.php, add lines:

-$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);
 
-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

'; echo '

'; echo ''; diff --git a/admin/report/unittest/index.php b/admin/report/unittest/index.php index a1003df1549..10adcfd6b9b 100644 --- a/admin/report/unittest/index.php +++ b/admin/report/unittest/index.php @@ -115,7 +115,6 @@ $CFG->dblibrary = $real_cfg->dblibrary; $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; @@ -131,7 +130,7 @@ $CFG->footer = $real_cfg->footer; $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) { diff --git a/install.php b/install.php index f2028a253a4..60e5a30c2f9 100644 --- a/install.php +++ b/install.php @@ -465,7 +465,7 @@ if ($nextstage == SAVE) { $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); diff --git a/lib/dml/adodb_moodle_database.php b/lib/dml/adodb_moodle_database.php index 8117853dffd..e8898aa687b 100644 --- a/lib/dml/adodb_moodle_database.php +++ b/lib/dml/adodb_moodle_database.php @@ -35,10 +35,10 @@ abstract class adodb_moodle_database extends moodle_database { */ 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(); @@ -50,7 +50,7 @@ abstract class adodb_moodle_database extends moodle_database { // 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; } diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index cedb15eacef..b569c196cee 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -36,7 +36,6 @@ abstract class moodle_database { protected $dbuser; protected $dbpass; protected $dbname; - protected $dbpersist; protected $prefix; /** @@ -146,8 +145,8 @@ abstract class moodle_database { * 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(); @@ -171,12 +170,11 @@ abstract class moodle_database { * @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 @@ -184,17 +182,15 @@ abstract class moodle_database { * @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; } diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index e3157164d65..bfb6886a8a9 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -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); } /** diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 1f95cf265cf..7c3696ba739 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -76,15 +76,14 @@ class mysqli_native_moodle_database extends moodle_database { * @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) { diff --git a/lib/dml/oci8po_adodb_moodle_database.php b/lib/dml/oci8po_adodb_moodle_database.php index 77dcbbb1843..73d8ee295b0 100644 --- a/lib/dml/oci8po_adodb_moodle_database.php +++ b/lib/dml/oci8po_adodb_moodle_database.php @@ -10,7 +10,7 @@ require_once($CFG->libdir.'/dml/oci8po_adodb_moodle_recordset.php'); */ 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()); @@ -20,7 +20,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database { $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); } /** diff --git a/lib/dml/pdo_moodle_database.php b/lib/dml/pdo_moodle_database.php index 4cc0c9ecf99..ace30423ef1 100644 --- a/lib/dml/pdo_moodle_database.php +++ b/lib/dml/pdo_moodle_database.php @@ -29,13 +29,12 @@ abstract class pdo_moodle_database extends moodle_database { * @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()); @@ -64,7 +63,7 @@ abstract class pdo_moodle_database extends moodle_database { * @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() { diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index 94b3d07ec3f..e0634b81072 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -77,15 +77,14 @@ class pgsql_native_moodle_database extends moodle_database { * @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}'"); diff --git a/lib/dml/postgres7_adodb_moodle_database.php b/lib/dml/postgres7_adodb_moodle_database.php index d11f9f4a86f..2e2a17ec5e0 100644 --- a/lib/dml/postgres7_adodb_moodle_database.php +++ b/lib/dml/postgres7_adodb_moodle_database.php @@ -9,12 +9,12 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php'); */ 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); } /** @@ -72,8 +72,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database { * 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(); diff --git a/lib/dml/simpletest/testdml.php b/lib/dml/simpletest/testdml.php index 3be5bad67c9..935a1f22351 100755 --- a/lib/dml/simpletest/testdml.php +++ b/lib/dml/simpletest/testdml.php @@ -1477,7 +1477,7 @@ class moodle_database_for_testing extends moodle_database { 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(){} diff --git a/lib/dmllib.php b/lib/dmllib.php index cf876d88ca9..d53f52740d3 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -69,10 +69,6 @@ function setup_DB() { $CFG->dbname = ''; } - if (!isset($CFG->dbpersist)) { - $CFG->dbpersist = false; - } - if (!isset($CFG->dblibrary)) { $CFG->dblibrary = 'adodb'; } @@ -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 @@ -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 = '

'.$dberr.'

'; diff --git a/lib/simpletest/testeventslib.php b/lib/simpletest/testeventslib.php index 5eddc25e14b..679c6d34649 100755 --- a/lib/simpletest/testeventslib.php +++ b/lib/simpletest/testeventslib.php @@ -89,7 +89,7 @@ class eventslib_test extends MoodleUnitTestCase { 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'); diff --git a/lib/simpletestlib.php b/lib/simpletestlib.php index 814b7beb765..a75031b1643 100644 --- a/lib/simpletestlib.php +++ b/lib/simpletestlib.php @@ -308,7 +308,7 @@ class UnitTestDB { 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();