MDL-51374 core_dml: change database layer to pass table name as parameter

This commit is contained in:
Simey Lameze 2016-03-15 14:41:48 +08:00
parent 26e7eceefc
commit 87a3e50192
11 changed files with 165 additions and 65 deletions

View file

@ -1049,13 +1049,32 @@ abstract class moodle_database {
/**
* Resets the internal column details cache
*
* @param array|null $tablenames an array of xmldb table names affected by this request.
* @return void
*/
public function reset_caches() {
$this->tables = null;
// Purge MUC as well.
$this->get_metacache()->purge();
$this->metacache = null;
public function reset_caches($tablenames = null) {
if (!empty($tablenames)) {
$temptablepurged = false;
$dbmetapurged = false;
foreach ($tablenames as $tablename) {
if ($temptablepurged === false && $this->temptables->is_temptable($tablename)) {
$this->get_temp_tables_cache()->purge();
$temptablepurged = true;
} else if ($dbmetapurged === false) {
$this->tables = null;
$this->get_metacache()->purge();
$this->metacache = null;
$dbmetapurged = true;
}
}
} else {
$this->get_temp_tables_cache()->purge();
$this->tables = null;
// Purge MUC as well.
$this->get_metacache()->purge();
$this->metacache = null;
}
}
/**
@ -1124,10 +1143,11 @@ abstract class moodle_database {
/**
* Do NOT use in code, this is for use by database_manager only!
* @param string|array $sql query or array of queries
* @param array|null $tablenames an array of xmldb table names affected by this request.
* @return bool true
* @throws ddl_change_structure_exception A DDL specific exception is thrown for any errors.
*/
public abstract function change_database_structure($sql);
public abstract function change_database_structure($sql, $tablenames = null);
/**
* Executes a general sql query. Should be used only when no other method suitable.