]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15194 adodb separation, dml database creation support
authorskodak <skodak>
Mon, 9 Jun 2008 20:22:11 +0000 (20:22 +0000)
committerskodak <skodak>
Mon, 9 Jun 2008 20:22:11 +0000 (20:22 +0000)
admin/cliupgrade.php
install.php
lib/dml/adodb_moodle_database.php
lib/dml/moodle_database.php
lib/dml/mysqli_adodb_moodle_database.php
lib/dmllib.php
lib/setup.php
lib/simpletest/testbackuplib.php

index a46ab6264b7a0c47b04bc6cdce8bdafaa953dd57..e17821cbea5253866234d50ca607eb451cf70b1f 100644 (file)
@@ -464,6 +464,7 @@ if (!file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
         $errormsg = get_string('dbwronghostserver', 'install');
     }
 
+error('fix cml installer'); //TODO: fix cli installer
     if (empty($errormsg)) {
 
         /// Have the $db object ready because we are going to use it often
index c0b511e1015e4f1235a70d91c453f4c4943fac19..dbece00c0d0d844af6509481f863d433a3e7ccec 100644 (file)
@@ -320,19 +320,11 @@ if ($INSTALL['stage'] == DATABASE) {
         error_reporting(0);  // Hide errors
 
         if (! $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix'])) {
-            $db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
-            if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
-                switch ($INSTALL['dbtype']) {   /// Try to create a database
-                    case 'mysql':
-                    case 'mysqli':
-                        if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
-                            $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
-                        } else {
-                            $errormsg = get_string('dbcreationerror', 'install');
-                            $nextstage = DATABASE;
-                        }
-                        break;
-                }
+            if (!$DB->create_database($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'])) {
+                 $errormsg = get_string('dbcreationerror', 'install');
+                 $nextstage = DATABASE;
+            } else {
+                $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
             }
         } else {
 // TODO: db encoding checks ??
@@ -651,7 +643,7 @@ if ($nextstage == SAVE) {
 //==========================================================================//
 
 function form_table($nextstage, $formaction, $databases) {
-    global $INSTALL, $db;
+    global $INSTALL;
 
     /// Print the standard form if we aren't in the DOWNLOADLANG page
     /// because it has its own form.
index 41bfad660f6f20e6c72c1a6e529c71220588c439..3ab3a0d900963217dca3365be8dddbcb23384eae 100644 (file)
@@ -61,8 +61,6 @@ abstract class adodb_moodle_database extends moodle_database {
 
         $this->db = ADONewConnection($this->get_dbtype());
 
-        global $db; $db = $this->db; // TODO: BC only for now
-
         // See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly,
         // we probably want to change this value to ''.
         $this->db->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \'';
index 40b6b0026d88fded4708aefa1cdaeb8a8c68d8a1..7593d5ffb3b11a7876f46985b7d144b6bf1c79fc 100644 (file)
@@ -108,6 +108,19 @@ abstract class moodle_database {
      */
     public abstract function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null);
 
+    /**
+     * Attempt to create the database
+     * @param string $dbhost
+     * @param string $dbuser
+     * @param string $dbpass
+     * @param string $dbname
+     *
+     * @return bool success
+     */
+    public function create_database($dbhost, $dbuser, $dbpass, $dbname) {
+        return false;
+    }
+
     /**
      * Close database connection and release all resources
      * and memory (especially circular memory references).
index 9b4280b5a7800524f8b7b32e6b559474a031ddd8..176a109776140ac83cebd2b2c644b9815936f1ec 100644 (file)
@@ -9,6 +9,27 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php');
  */
 class mysqli_adodb_moodle_database extends adodb_moodle_database {
 
+    /**
+     * Attempt to create the database
+     * @param string $dbhost
+     * @param string $dbuser
+     * @param string $dbpass
+     * @param string $dbname
+     *
+     * @return bool success
+     */
+    public function create_database($dbhost, $dbuser, $dbpass, $dbname) {
+        $this->db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
+        if ($this->db->Connect($dbhost, $dbuser, $dbpass)) { /// Try to connect without DB
+            if ($this->db->Execute("CREATE DATABASE $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci")) {
+                $this->db->Disconnect();
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
+
     /**
      * Detects if all needed PHP stuff installed.
      * Do not connect to connect to db if this test fails.
index 5e599fe34639421d353dd63d8aeeb0b1fb47b084..f542ae4bd749f2c3045c64a55adc9f715df13512 100644 (file)
@@ -37,8 +37,6 @@
 
 /// GLOBAL CONSTANTS /////////////////////////////////////////////////////////
 
-require_once($CFG->libdir.'/dmllib_todo.php');
-
 /**
  * Bitmask, indicates only :name type parameters are supported by db backend.
  */
index 457cd70118043441de70f4992ea3a975270c1e64..07c20fa687628589fe1c36f6483161a281aca5b9 100644 (file)
@@ -53,11 +53,6 @@ global $MCACHE;
  * @global object(course) $COURSE
  */
 global $COURSE;
-/**
- * Legacy definition of db type TODO: remove in 2.0
- * @global object(db) $db
- */
-global $db;
 /**
  * Database instances
  * @global object(mdb) $DB
index 941a5ddfa527b1decba5c68950316c775e1eb519..59646319210a69491270df75026a98b1a24d8ca9 100644 (file)
@@ -44,7 +44,6 @@ class backuplib_test extends UnitTestCase {
     var $real_dataroot;
     var $rs;   
     var $firstcolumn;
-    var $db;
     var $testfiles = array();
     var $userbasedir;