Merge branch 'wip-mdl-52605-m29' of https://github.com/rajeshtaneja/moodle into MOODLE_29_STABLE
This commit is contained in:
@@ -577,6 +577,11 @@ abstract class moodle_database {
|
||||
protected function where_clause($table, array $conditions=null) {
|
||||
// We accept nulls in conditions
|
||||
$conditions = is_null($conditions) ? array() : $conditions;
|
||||
|
||||
if (empty($conditions)) {
|
||||
return array('', array());
|
||||
}
|
||||
|
||||
// Some checks performed under debugging only
|
||||
if (debugging()) {
|
||||
$columns = $this->get_columns($table);
|
||||
@@ -600,9 +605,6 @@ abstract class moodle_database {
|
||||
}
|
||||
|
||||
$allowed_types = $this->allowed_param_types();
|
||||
if (empty($conditions)) {
|
||||
return array('', array());
|
||||
}
|
||||
$where = array();
|
||||
$params = array();
|
||||
|
||||
|
||||
@@ -1432,9 +1432,9 @@ class core_dml_testcase extends database_driver_testcase {
|
||||
$this->assertSame('ddltablenotexist', $e->errorcode);
|
||||
}
|
||||
}
|
||||
// And without params.
|
||||
|
||||
try {
|
||||
$records = $DB->get_records('xxxx', array());
|
||||
$records = $DB->get_records('xxxx', array('id' => '1'));
|
||||
$this->fail('An Exception is missing, expected due to query against non-existing table');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertInstanceOf('dml_exception', $e);
|
||||
@@ -5347,7 +5347,7 @@ class core_dml_testcase extends database_driver_testcase {
|
||||
|
||||
// The get_records() method generates 2 queries the first time is called
|
||||
// as it is fetching the table structure.
|
||||
$whatever = $DB->get_records($tablename);
|
||||
$whatever = $DB->get_records($tablename, array('id' => '1'));
|
||||
$this->assertEquals($initreads + 3, $DB->perf_get_reads());
|
||||
$this->assertEquals($initwrites, $DB->perf_get_writes());
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ class phpunit_util extends testing_util {
|
||||
reset_text_filters_cache(true);
|
||||
events_get_handlers('reset');
|
||||
core_text::reset_caches();
|
||||
get_message_processors(false, true);
|
||||
get_message_processors(false, true, true);
|
||||
filter_manager::reset_caches();
|
||||
core_filetypes::reset_caches();
|
||||
|
||||
|
||||
@@ -59,6 +59,11 @@ abstract class testing_util {
|
||||
*/
|
||||
protected static $tablestructure = null;
|
||||
|
||||
/**
|
||||
* @var array keep list of sequenceid used in a table.
|
||||
*/
|
||||
private static $tablesequences = array();
|
||||
|
||||
/**
|
||||
* @var array original structure of all database tables
|
||||
*/
|
||||
@@ -78,6 +83,7 @@ abstract class testing_util {
|
||||
* @var int next sequence value for a single test cycle.
|
||||
*/
|
||||
protected static $sequencenextstartingid = null;
|
||||
|
||||
/**
|
||||
* Return the name of the JSON file containing the init filenames.
|
||||
*
|
||||
@@ -263,17 +269,15 @@ abstract class testing_util {
|
||||
* @return array $table=>$records
|
||||
*/
|
||||
protected static function get_tabledata() {
|
||||
global $CFG;
|
||||
|
||||
$framework = self::get_framework();
|
||||
|
||||
$datafile = self::get_dataroot() . '/' . $framework . '/tabledata.ser';
|
||||
if (!file_exists($datafile)) {
|
||||
// Not initialised yet.
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!isset(self::$tabledata)) {
|
||||
$framework = self::get_framework();
|
||||
|
||||
$datafile = self::get_dataroot() . '/' . $framework . '/tabledata.ser';
|
||||
if (!file_exists($datafile)) {
|
||||
// Not initialised yet.
|
||||
return array();
|
||||
}
|
||||
|
||||
$data = file_get_contents($datafile);
|
||||
self::$tabledata = unserialize($data);
|
||||
}
|
||||
@@ -291,17 +295,15 @@ abstract class testing_util {
|
||||
* @return array $table=>$records
|
||||
*/
|
||||
public static function get_tablestructure() {
|
||||
global $CFG;
|
||||
|
||||
$framework = self::get_framework();
|
||||
|
||||
$structurefile = self::get_dataroot() . '/' . $framework . '/tablestructure.ser';
|
||||
if (!file_exists($structurefile)) {
|
||||
// Not initialised yet.
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!isset(self::$tablestructure)) {
|
||||
$framework = self::get_framework();
|
||||
|
||||
$structurefile = self::get_dataroot() . '/' . $framework . '/tablestructure.ser';
|
||||
if (!file_exists($structurefile)) {
|
||||
// Not initialised yet.
|
||||
return array();
|
||||
}
|
||||
|
||||
$data = file_get_contents($structurefile);
|
||||
self::$tablestructure = unserialize($data);
|
||||
}
|
||||
@@ -361,9 +363,10 @@ abstract class testing_util {
|
||||
// incorrect table match caused by _
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_null($info->auto_increment)) {
|
||||
$table = preg_replace('/^'.preg_quote($prefix, '/').'/', '', $table);
|
||||
if ($info->auto_increment == 1) {
|
||||
if (isset(self::$tablesequences[$table]) && ($info->auto_increment == self::$tablesequences[$table])) {
|
||||
$empties[$table] = $table;
|
||||
}
|
||||
}
|
||||
@@ -418,9 +421,14 @@ abstract class testing_util {
|
||||
*
|
||||
* @static
|
||||
* @param array $records The records to use to determine the starting value for the table.
|
||||
* @param string $table table name.
|
||||
* @return int The value the sequence should be set to.
|
||||
*/
|
||||
private static function get_next_sequence_starting_value($records) {
|
||||
private static function get_next_sequence_starting_value($records, $table) {
|
||||
if (isset(self::$tablesequences[$table])) {
|
||||
return self::$tablesequences[$table];
|
||||
}
|
||||
|
||||
$id = self::$sequencenextstartingid;
|
||||
|
||||
// If there are records, calculate the minimum id we can use.
|
||||
@@ -431,6 +439,9 @@ abstract class testing_util {
|
||||
}
|
||||
|
||||
self::$sequencenextstartingid = $id + 1000;
|
||||
|
||||
self::$tablesequences[$table] = $id;
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
@@ -470,7 +481,7 @@ abstract class testing_util {
|
||||
$prefix = $DB->get_prefix();
|
||||
foreach ($data as $table => $records) {
|
||||
if (isset($structure[$table]['id']) and $structure[$table]['id']->auto_increment) {
|
||||
$nextid = self::get_next_sequence_starting_value($records);
|
||||
$nextid = self::get_next_sequence_starting_value($records, $table);
|
||||
$queries[] = "ALTER SEQUENCE {$prefix}{$table}_id_seq RESTART WITH $nextid";
|
||||
}
|
||||
}
|
||||
@@ -498,11 +509,10 @@ abstract class testing_util {
|
||||
foreach ($data as $table => $records) {
|
||||
if (isset($structure[$table]['id']) and $structure[$table]['id']->auto_increment) {
|
||||
if (isset($sequences[$table])) {
|
||||
$nextid = self::get_next_sequence_starting_value($records);
|
||||
$nextid = self::get_next_sequence_starting_value($records, $table);
|
||||
if ($sequences[$table] != $nextid) {
|
||||
$DB->change_database_structure("ALTER TABLE {$prefix}{$table} AUTO_INCREMENT = $nextid");
|
||||
}
|
||||
|
||||
} else {
|
||||
// some problem exists, fallback to standard code
|
||||
$DB->get_manager()->reset_sequence($table);
|
||||
|
||||
+6
-1
@@ -2441,14 +2441,19 @@ function message_mark_message_read($message, $timeread, $messageworkingempty=fal
|
||||
*
|
||||
* @param bool $ready only return ready-to-use processors
|
||||
* @param bool $reset Reset list of message processors (used in unit tests)
|
||||
* @param bool $resetonly Just reset, then exit
|
||||
* @return mixed $processors array of objects containing information on message processors
|
||||
*/
|
||||
function get_message_processors($ready = false, $reset = false) {
|
||||
function get_message_processors($ready = false, $reset = false, $resetonly = false) {
|
||||
global $DB, $CFG;
|
||||
|
||||
static $processors;
|
||||
if ($reset) {
|
||||
$processors = array();
|
||||
|
||||
if ($resetonly) {
|
||||
return $processors;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($processors)) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
This files describes API changes in /message/ messaging system,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.1 ===
|
||||
* get_message_processors accepts an addition parameter for testing, which will just reset processor and exit.
|
||||
|
||||
=== 2.9 ===
|
||||
* Renderer method \core_message_renderer::manage_messagingoptions now accepts a user id parameter as well.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user