Skip to content

Instantly share code, notes, and snippets.

@tai2
Last active December 14, 2015 18:28
Show Gist options
  • Save tai2/5129172 to your computer and use it in GitHub Desktop.
Save tai2/5129172 to your computer and use it in GitHub Desktop.
A patch to ADODB Active Record cache bug. c.f. http://phplens.com/lens/lensforum/msgs.php?id=18288&x=1
diff --git a/src/concrete/libraries/3rdparty/adodb/adodb-active-record.inc.php b/src/concrete/libraries/3rdparty/adodb/adodb-active-record.inc.php
index 474f2a7..4a214ed 100644
--- a/src/concrete/libraries/3rdparty/adodb/adodb-active-record.inc.php
+++ b/src/concrete/libraries/3rdparty/adodb/adodb-active-record.inc.php
@@ -343,20 +343,11 @@ class ADODB_Active_Record {
$table = $this->_table;
$tables = $activedb->tables;
$tableat = $this->_tableat;
- if (!$forceUpdate && !empty($tables[$tableat])) {
-
- $tobj = $tables[$tableat];
- foreach($tobj->flds as $name => $fld) {
- if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
- $this->$name = $fld->default_value;
- else
- $this->$name = null;
- }
- return;
- }
$db = $activedb->db;
$fname = $ADODB_CACHE_DIR . '/adodb_' . $db->databaseType . '_active_'. $table . '.cache';
- if (!$forceUpdate && $ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR && file_exists($fname)) {
+ if (!$forceUpdate && !empty($tables[$tableat])) {
+
+ if ($ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR && file_exists($fname)) {
$fp = fopen($fname,'r');
@flock($fp, LOCK_SH);
$acttab = unserialize(fread($fp,100000));
@@ -364,13 +355,25 @@ class ADODB_Active_Record {
if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) {
// abs(rand()) randomizes deletion, reducing contention to delete/refresh file
// ideally, you should cache at least 32 secs
- $activedb->tables[$table] = $acttab;
+ $tables[$table] = $acttab;
//if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
- return;
} else if ($db->debug) {
ADOConnection::outp("Refreshing cached active record file: $fname");
}
+ }
+
+ if (!empty($tables[$tableat])) {
+
+ $tobj = $tables[$tableat];
+ foreach($tobj->flds as $name => $fld) {
+ if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
+ $this->$name = $fld->default_value;
+ else
+ $this->$name = null;
+ }
+ return;
+ }
}
$activetab = new ADODB_Active_Table();
$activetab->name = $table;
@@ -974,4 +977,4 @@ global $_ADODB_ACTIVE_DBS;
return $arr;
}
-?>
\ No newline at end of file
+?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment