예제 #1
0
function reconnect_db()
{
    global $db;
    // Reconnect db
    $db->Close();
    while (!$db->NConnect()) {
        sleep(5);
    }
    configure_dbconnection();
}
예제 #2
0
파일: setup.php 프로젝트: r007/PMoodle
// Events functions
require_once $CFG->libdir . '/grouplib.php';
// Groups functions
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
//the problem is that we need specific version of quickforms and hacked excel files :-(
ini_set('include_path', $CFG->libdir . '/pear' . PATH_SEPARATOR . ini_get('include_path'));
/// Disable errors for now - needed for installation when debug enabled in config.php
if (isset($CFG->debug)) {
    $originalconfigdebug = $CFG->debug;
    unset($CFG->debug);
} else {
    $originalconfigdebug = -1;
}
/// Set the client/server and connection to utf8
/// and configure some other specific variables for each db
configure_dbconnection();
/// Load up any configuration from the config table
$CFG = get_config();
/// Turn on SQL logging if required
if (!empty($CFG->logsql)) {
    $db->LogSQL();
}
/// Prevent warnings from roles when upgrading with debug on
if (isset($CFG->debug)) {
    $originaldatabasedebug = $CFG->debug;
    unset($CFG->debug);
} else {
    $originaldatabasedebug = -1;
}
/// For now, only needed under apache (and probably unstable in other contexts)
if (function_exists('register_shutdown_function')) {
예제 #3
0
 /**
  * clean out all the test data
  */
 protected function tearDown()
 {
     // fix the connection - this gets lost because of the tests
     configure_dbconnection();
     // clean down the institution
     $this->clean_institution();
     // delete test token
     if ($this->testtoken) {
         delete_records('external_tokens', 'token', $this->testtoken);
     }
     // remove the web service descriptions
     $dbservice = get_record('external_services', 'name', $this->servicename);
     if ($dbservice) {
         $dbregistry = get_record('oauth_server_registry', 'externalserviceid', $dbservice->id);
         if ($dbregistry) {
             delete_records('oauth_server_token', 'osr_id_ref', $dbregistry->id);
         }
         delete_records('oauth_server_registry', 'externalserviceid', $dbservice->id);
         delete_records('external_services_users', 'externalserviceid', $dbservice->id);
         delete_records('external_tokens', 'externalserviceid', $dbservice->id);
         delete_records('external_services_functions', 'externalserviceid', $dbservice->id);
         delete_records('external_services', 'id', $dbservice->id);
     }
     // remove the test user
     $dbuser = get_record('usr', 'username', $this->testuser);
     if ($dbuser) {
         $this->created_users[] = $dbuser->id;
     }
     // remove all left over users
     if ($this->created_users) {
         foreach ($this->created_users as $userid) {
             delete_user($userid);
         }
     }
     // remove left over groups
     $dbgroup = get_record('group', 'shortname', 'mytestgroup1', 'institution', 'mahara');
     if ($dbgroup) {
         $this->created_groups[] = $dbgroup->id;
     }
     if ($this->created_groups) {
         foreach ($this->created_groups as $groupid) {
             group_delete($groupid);
         }
     }
 }
예제 #4
0
function change_db_encoding()
{
    global $CFG, $db;
    // try forcing utf8 collation, if mysql db and no tables present
    if ($CFG->dbfamily == 'mysql' && !$db->Metatables()) {
        $SQL = 'ALTER DATABASE ' . $CFG->dbname . ' CHARACTER SET utf8';
        execute_sql($SQL, false);
        // silent, if it fails it fails
        if (setup_is_unicodedb()) {
            configure_dbconnection();
        }
    }
}
예제 #5
0
 /**
  * Superclass setUp method
  *
  * Takes care of setting up the database correctly as this doesn't
  * happen in unit test through init.php properly.
  *
  * parent::setUp() must always be called if it is overriden in
  * subclasses
  *
  * @return void
  */
 protected function setUp()
 {
     configure_dbconnection();
 }