Commit edaf831d authored by Aaron Wells's avatar Aaron Wells
Browse files

Automatically clear insert_record()'s table column cache

Bug 1430111. When the table structure changes, automatically
clear the cache for that table in insert_record().

Change-Id: I0612755bd5fa6646a26ff51d1d2844df211be61d
parent 27bd7b92
......@@ -3932,9 +3932,6 @@ function xmldb_core_upgrade($oldversion=0) {
$field = new XMLDBField('sortorder');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, null, 100000, 'category');
add_field($table, $field);
// make sure the text blocktype has correct sortorder
execute_sql("UPDATE {blocktype_installed_category} SET sortorder = ? WHERE blocktype = ? AND category = ?", array(1000, 'text', 'shortcut'));
}
if ($oldversion < 2015021000) {
......@@ -3965,5 +3962,17 @@ function xmldb_core_upgrade($oldversion=0) {
delete_records('config', 'field', 'searchusernames');
}
if ($oldversion < 2015032600) {
if ($blocktypes = plugins_installed('blocktype', true)) {
foreach ($blocktypes as $bt) {
// Hack to deal with contactinfo block deletion
if ($bt->name == 'contactinfo') {
continue;
}
install_blocktype_categories_for_plugin(blocktype_single_to_namespaced($bt->name, $bt->artefactplugin));
}
}
}
return $status;
}
......@@ -926,9 +926,9 @@ function rename_table($table, $newname, $continue=true, $feedback=true) {
* @param boolean feedback to specify to show status info (true) or not (false)
* @return boolean true on success, false on error
*/
function add_field($table, $field, $continue=true, $feedback=true) {
function add_field(XMLDBTable $table, $field, $continue=true, $feedback=true) {
global $CFG, $db;
global $CFG, $db, $INSERTRECORD_TABLE_COLUMNS;
$status = true;
......@@ -949,6 +949,7 @@ function add_field($table, $field, $continue=true, $feedback=true) {
return true; //Empty array = nothing to do = no error
}
unset($INSERTRECORD_TABLE_COLUMNS[$table->getName()]);
return execute_sql_arr($sqlarr, $continue, $feedback);
}
......@@ -965,7 +966,7 @@ function add_field($table, $field, $continue=true, $feedback=true) {
*/
function drop_field($table, $field, $continue=true, $feedback=true) {
global $CFG, $db;
global $CFG, $db, $INSERTRECORD_TABLE_COLUMNS;
$status = true;
......@@ -986,6 +987,7 @@ function drop_field($table, $field, $continue=true, $feedback=true) {
return true; //Empty array = nothing to do = no error
}
unset($INSERTRECORD_TABLE_COLUMNS[$table->getName()]);
return execute_sql_arr($sqlarr, $continue, $feedback);
}
......
......@@ -989,26 +989,19 @@ function delete_records_sql($sql, array $values=null) {
* @param bool $returnpk Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @throws SQLException
*/
global $INSERTRECORD_TABLE_COLUMNS;
$INSERTRECORD_TABLE_COLUMNS = array();
function insert_record($table, $dataobject, $primarykey=false, $returnpk=false) {
// $INSERTRECORD_NOCACHE is yet another work around of dmllib/adodb's ineptitude.
// It's all nice to cache the table columns lookup, but what if the table
// columns change over the life of the page load? This happens when an
// upgrade is running. All of a sudden, the table_column cache is out of
// date and we can't insert new data properly.
// Temporary solution: set INSERTRECORD_NOCACHE to true before your calls
// that need a new lookup, and unset it afterwards
global $db, $INSERTRECORD_NOCACHE;
static $table_columns;
global $db, $INSERTRECORD_TABLE_COLUMNS;
// Determine all the fields in the table
if (empty($INSERTRECORD_NOCACHE) && is_array($table_columns) && array_key_exists($table, $table_columns)) {
$columns = $table_columns[$table];
if (array_key_exists($table, $INSERTRECORD_TABLE_COLUMNS)) {
$columns = $INSERTRECORD_TABLE_COLUMNS[$table];
}
else {
if (!$columns = $db->MetaColumns(get_config('dbprefix') . $table)) {
throw new SQLException('Table "' . get_config('dbprefix') . $table . '" does not appear to exist');
}
$table_columns[$table] = $columns;
$INSERTRECORD_TABLE_COLUMNS[$table] = $columns;
}
if (!empty($primarykey)) {
......
......@@ -542,12 +542,7 @@ function upgrade_plugin($upgrade) {
'plugintype' => $plugintype,
'pluginname' => $pluginname,
);
// Work around the fact that insert_record cached the columns that
// _were_ in the activity_type table before it was upgraded
global $INSERTRECORD_NOCACHE;
$INSERTRECORD_NOCACHE = true;
ensure_record_exists('activity_type', $where, $activity);
unset($INSERTRECORD_NOCACHE);
}
}
}
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2015032000;
$config->version = 2015032600;
$config->series = '15.10';
$config->release = '15.10dev';
$config->minupgradefrom = 2009022600;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment