Skip to content

Commit

Permalink
Merge branch 'wip-mdl-52605-m29' of https://github.com/rajeshtaneja/m…
Browse files Browse the repository at this point in the history
…oodle into MOODLE_29_STABLE
  • Loading branch information
danpoltawski committed Jan 4, 2016
2 parents 82470d8 + 0d8ad43 commit d9ddd1d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
8 changes: 5 additions & 3 deletions lib/dml/moodle_database.php
Expand Up @@ -577,6 +577,11 @@ protected function print_debug_time() {
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);
Expand All @@ -600,9 +605,6 @@ protected function where_clause($table, array $conditions=null) {
}

$allowed_types = $this->allowed_param_types();
if (empty($conditions)) {
return array('', array());
}
$where = array();
$params = array();

Expand Down
6 changes: 3 additions & 3 deletions lib/dml/tests/dml_test.php
Expand Up @@ -1432,9 +1432,9 @@ public function test_get_records() {
$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);
Expand Down Expand Up @@ -5347,7 +5347,7 @@ public function test_queries_counter() {

// 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());

Expand Down
2 changes: 1 addition & 1 deletion lib/phpunit/classes/util.php
Expand Up @@ -207,7 +207,7 @@ public static function reset_all_data($detectchanges = false) {
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();

Expand Down
56 changes: 33 additions & 23 deletions lib/testing/classes/util.php
Expand Up @@ -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
*/
Expand All @@ -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.
*
Expand Down Expand Up @@ -263,17 +269,15 @@ protected static function store_versions_hash() {
* @return array $table=>$records
*/
protected static function get_tabledata() {
global $CFG;

$framework = self::get_framework();
if (!isset(self::$tabledata)) {
$framework = self::get_framework();

$datafile = self::get_dataroot() . '/' . $framework . '/tabledata.ser';
if (!file_exists($datafile)) {
// Not initialised yet.
return array();
}
$datafile = self::get_dataroot() . '/' . $framework . '/tabledata.ser';
if (!file_exists($datafile)) {
// Not initialised yet.
return array();
}

if (!isset(self::$tabledata)) {
$data = file_get_contents($datafile);
self::$tabledata = unserialize($data);
}
Expand All @@ -291,17 +295,15 @@ protected static function get_tabledata() {
* @return array $table=>$records
*/
public static function get_tablestructure() {
global $CFG;

$framework = self::get_framework();
if (!isset(self::$tablestructure)) {
$framework = self::get_framework();

$structurefile = self::get_dataroot() . '/' . $framework . '/tablestructure.ser';
if (!file_exists($structurefile)) {
// Not initialised yet.
return array();
}
$structurefile = self::get_dataroot() . '/' . $framework . '/tablestructure.ser';
if (!file_exists($structurefile)) {
// Not initialised yet.
return array();
}

if (!isset(self::$tablestructure)) {
$data = file_get_contents($structurefile);
self::$tablestructure = unserialize($data);
}
Expand Down Expand Up @@ -361,9 +363,10 @@ protected static function guess_unmodified_empty_tables() {
// 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;
}
}
Expand Down Expand Up @@ -418,9 +421,14 @@ protected static function guess_unmodified_empty_tables() {
*
* @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.
Expand All @@ -431,6 +439,9 @@ private static function get_next_sequence_starting_value($records) {
}

self::$sequencenextstartingid = $id + 1000;

self::$tablesequences[$table] = $id;

return $id;
}

Expand Down Expand Up @@ -470,7 +481,7 @@ public static function reset_all_database_sequences(array $empties = null) {
$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";
}
}
Expand Down Expand Up @@ -498,11 +509,10 @@ public static function reset_all_database_sequences(array $empties = null) {
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);
Expand Down
7 changes: 6 additions & 1 deletion message/lib.php
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions message/upgrade.txt
@@ -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.

Expand Down

0 comments on commit d9ddd1d

Please sign in to comment.