Commit e1c17aea authored by Nigel McNie's avatar Nigel McNie
Browse files

Work around a bug in insert_record, where the table columns were cached for a...

Work around a bug in insert_record, where the table columns were cached for a table the first time the table was inserted into, making it impossible to do inserts into the table in the same request if the table is changed.

Added a global variable, $INSERTRECORD_NOCACHE, that can be set in order to force re-looking up the table columns.

Use this feature to fix the installation of the forum interaction activity type "new post" when upgrading.
parent 93100de4
......@@ -931,11 +931,18 @@ function delete_records_sql($sql, $values=null) {
* @throws SQLException
*/
function insert_record($table, $dataobject, $primarykey=false, $returnpk=false) {
global $db;
// $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;
// Determine all the fields in the table
if (is_array($table_columns) && array_key_exists($table, $table_columns)) {
if (empty($INSERTRECORD_NOCACHE) && is_array($table_columns) && array_key_exists($table, $table_columns)) {
$columns = $table_columns[$table];
}
else {
......
......@@ -422,7 +422,12 @@ function upgrade_plugin($upgrade) {
$where = $activity;
unset($where->admin);
unset($where->delay);
// 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);
}
}
......
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