Commit 4ab87f7e authored by Dries's avatar Dries
Browse files

Issue #2004350 by Berdir, Dean Reilly: Fixed Unserialised database connection...

Issue #2004350 by Berdir, Dean Reilly: Fixed Unserialised database connection objects don't use Drupal's PDO Statement class.
parent 9e354fa9
......@@ -1265,6 +1265,11 @@ public function unserialize($serialized) {
}
// Re-establish the PDO connection using the original options.
$this->connection = static::open($this->connectionOptions);
// Re-set a Statement class if necessary.
if (!empty($this->statementClass)) {
$this->connection->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this)));
}
}
}
......@@ -247,14 +247,21 @@ public function testConnectionSerialization() {
$db_reflection = new \ReflectionObject($db);
$unserialized_reflection = new \ReflectionObject($unserialized);
foreach ($db_reflection->getProperties() as $value) {
// Skip the pdo connection object.
if ($value->getName() == 'connection') {
continue;
}
$value->setAccessible(TRUE);
$unserialized_property = $unserialized_reflection->getProperty($value->getName());
$unserialized_property->setAccessible(TRUE);
$this->assertEqual($unserialized_property->getValue($unserialized), $value->getValue($db));
// For the PDO object, just check the statement class attribute.
if ($value->getName() == 'connection') {
$db_statement_class = $unserialized_property->getValue($db)->getAttribute(\PDO::ATTR_STATEMENT_CLASS);
$unserialized_statement_class = $unserialized_property->getValue($unserialized)->getAttribute(\PDO::ATTR_STATEMENT_CLASS);
// Assert the statement class.
$this->assertEqual($unserialized_statement_class[0], $db_statement_class[0]);
// Assert the connection argument that is passed into the statement.
$this->assertEqual(get_class($unserialized_statement_class[1][0]), get_class($db_statement_class[1][0]));
}
else {
$this->assertEqual($unserialized_property->getValue($unserialized), $value->getValue($db));
}
}
}
......
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