Skip to content

Commit

Permalink
Merge branch 'MDL-51245' of git://github.com/stronk7/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Sep 8, 2015
2 parents ebdfde7 + 48657a6 commit fd23f8e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
$string['movecategorynotpossible'] = 'You cannot move category \'{$a}\' into the selected category.';
$string['movecategoryownparent'] = 'You cannot make category \'{$a}\' a parent of itself.';
$string['movecategoryparentconflict'] = 'You cannot make category \'{$a}\' a subcategory of one of its own subcategories.';
$string['mssqlrcsmodemissing'] = 'The database is not using the expected READ_COMMITTED_SNAPSHOT mode which can lead to wrong results, especially under high concurrency scenarios. Please enable it for correct behaviour. You can find more information in the <a href="https://docs.moodle.org/en/Installing_MSSQL_for_PHP#Configuration">Moodle Docs</a>.';
$string['multiplerecordsfound'] = 'Multiple records found, only one record expected.';
$string['multiplerestorenotallow'] = 'Multiple restore execution not allowed!';
$string['mustbeloggedin'] = 'You must be logged in to do this';
Expand Down
31 changes: 31 additions & 0 deletions lib/dml/mssql_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ public function get_configuration_help() {
return get_string('nativemssqlhelp', 'install');
}

/**
* Diagnose database and tables, this function is used
* to verify database and driver settings, db engine types, etc.
*
* @return string null means everything ok, string means problem found.
*/
public function diagnose() {
// Verify the database is running with READ_COMMITTED_SNAPSHOT enabled.
// (that's required to get snapshots/row versioning on READ_COMMITED mode).
$correctrcsmode = false;
$sql = "SELECT is_read_committed_snapshot_on
FROM sys.databases
WHERE name = '{$this->dbname}'";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = mssql_query($sql, $this->mssql);
$this->query_end($result);
if ($result) {
if ($row = mssql_fetch_assoc($result)) {
$correctrcsmode = (bool)reset($row);
}
}
$this->free_result($result);

if (!$correctrcsmode) {
return get_string('mssqlrcsmodemissing', 'error');
}

// Arrived here, all right.
return null;
}

/**
* Connect to db
* Must be called before other methods.
Expand Down
31 changes: 31 additions & 0 deletions lib/dml/sqlsrv_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,37 @@ public function get_configuration_help() {
return get_string('nativesqlsrvhelp', 'install');
}

/**
* Diagnose database and tables, this function is used
* to verify database and driver settings, db engine types, etc.
*
* @return string null means everything ok, string means problem found.
*/
public function diagnose() {
// Verify the database is running with READ_COMMITTED_SNAPSHOT enabled.
// (that's required to get snapshots/row versioning on READ_COMMITED mode).
$correctrcsmode = false;
$sql = "SELECT is_read_committed_snapshot_on
FROM sys.databases
WHERE name = '{$this->dbname}'";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = sqlsrv_query($this->sqlsrv, $sql);
$this->query_end($result);
if ($result) {
if ($row = sqlsrv_fetch_array($result)) {
$correctrcsmode = (bool)reset($row);
}
}
$this->free_result($result);

if (!$correctrcsmode) {
return get_string('mssqlrcsmodemissing', 'error');
}

// Arrived here, all right.
return null;
}

/**
* Connect to db
* Must be called before most other methods. (you can call methods that return connection configuration parameters)
Expand Down

0 comments on commit fd23f8e

Please sign in to comment.