summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/Memcached_DataObject.php27
-rw-r--r--classes/Session.php43
2 files changed, 64 insertions, 6 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 2cc6377f8..f4dfe6314 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -147,6 +147,7 @@ class Memcached_DataObject extends DB_DataObject
{
$result = parent::insert();
if ($result) {
+ $this->fixupTimestamps();
$this->encache(); // in case of cached negative lookups
}
return $result;
@@ -159,6 +160,7 @@ class Memcached_DataObject extends DB_DataObject
}
$result = parent::update($orig);
if ($result) {
+ $this->fixupTimestamps();
$this->encache();
}
return $result;
@@ -366,7 +368,7 @@ class Memcached_DataObject extends DB_DataObject
}
/**
- * sends query to database - this is the private one that must work
+ * sends query to database - this is the private one that must work
* - internal functions use this rather than $this->query()
*
* Overridden to do logging.
@@ -428,7 +430,7 @@ class Memcached_DataObject extends DB_DataObject
//
// WARNING WARNING if we end up actually using multiple DBs at a time
// we'll need some fancier logic here.
- if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS'])) {
+ if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS']) && php_sapi_name() == 'cli') {
foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $index => $conn) {
if (!empty($conn)) {
$conn->disconnect();
@@ -529,4 +531,25 @@ class Memcached_DataObject extends DB_DataObject
return $c->delete($cacheKey);
}
+
+ function fixupTimestamps()
+ {
+ // Fake up timestamp columns
+ $columns = $this->table();
+ foreach ($columns as $name => $type) {
+ if ($type & DB_DATAOBJECT_MYSQLTIMESTAMP) {
+ $this->$name = common_sql_now();
+ }
+ }
+ }
+
+ function debugDump()
+ {
+ common_debug("debugDump: " . common_log_objstring($this));
+ }
+
+ function raiseError($message, $type = null, $behaviour = null)
+ {
+ throw new ServerException("DB_DataObject error [$type]: $message");
+ }
}
diff --git a/classes/Session.php b/classes/Session.php
index 79a69a96e..2422f8b68 100644
--- a/classes/Session.php
+++ b/classes/Session.php
@@ -64,8 +64,12 @@ class Session extends Memcached_DataObject
$session = Session::staticGet('id', $id);
if (empty($session)) {
+ self::logdeb("Couldn't find '$id'");
return '';
} else {
+ self::logdeb("Found '$id', returning " .
+ strlen($session->session_data) .
+ " chars of data");
return (string)$session->session_data;
}
}
@@ -77,14 +81,24 @@ class Session extends Memcached_DataObject
$session = Session::staticGet('id', $id);
if (empty($session)) {
+ self::logdeb("'$id' doesn't yet exist; inserting.");
$session = new Session();
$session->id = $id;
$session->session_data = $session_data;
$session->created = common_sql_now();
- return $session->insert();
+ $result = $session->insert();
+
+ if (!$result) {
+ common_log_db_error($session, 'INSERT', __FILE__);
+ self::logdeb("Failed to insert '$id'.");
+ } else {
+ self::logdeb("Successfully inserted '$id' (result = $result).");
+ }
+ return $result;
} else {
+ self::logdeb("'$id' already exists; updating.");
if (strcmp($session->session_data, $session_data) == 0) {
self::logdeb("Not writing session '$id'; unchanged");
return true;
@@ -95,7 +109,16 @@ class Session extends Memcached_DataObject
$session->session_data = $session_data;
- return $session->update($orig);
+ $result = $session->update($orig);
+
+ if (!$result) {
+ common_log_db_error($session, 'UPDATE', __FILE__);
+ self::logdeb("Failed to update '$id'.");
+ } else {
+ self::logdeb("Successfully updated '$id' (result = $result).");
+ }
+
+ return $result;
}
}
}
@@ -106,8 +129,17 @@ class Session extends Memcached_DataObject
$session = Session::staticGet('id', $id);
- if (!empty($session)) {
- return $session->delete();
+ if (empty($session)) {
+ self::logdeb("Can't find '$id' to delete.");
+ } else {
+ $result = $session->delete();
+ if (!$result) {
+ common_log_db_error($session, 'DELETE', __FILE__);
+ self::logdeb("Failed to delete '$id'.");
+ } else {
+ self::logdeb("Successfully deleted '$id' (result = $result).");
+ }
+ return $result;
}
}
@@ -132,7 +164,10 @@ class Session extends Memcached_DataObject
$session->free();
+ self::logdeb("Found " . count($ids) . " ids to delete.");
+
foreach ($ids as $id) {
+ self::logdeb("Destroying session '$id'.");
self::destroy($id);
}
}