diff options
Diffstat (limited to 'includes/database/query.inc')
-rw-r--r-- | includes/database/query.inc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/includes/database/query.inc b/includes/database/query.inc index d7e688eb5..7c590c220 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -242,6 +242,20 @@ abstract class Query implements QueryPlaceholderInterface { protected $connection; /** + * The target of the connection object. + * + * @var string + */ + protected $connectionTarget; + + /** + * The key of the connection object. + * + * @var string + */ + protected $connectionKey; + + /** * The query options to pass on to the connection object. * * @var array @@ -270,10 +284,29 @@ abstract class Query implements QueryPlaceholderInterface { */ public function __construct(DatabaseConnection $connection, $options) { $this->connection = $connection; + $this->connectionKey = $this->connection->getKey(); + $this->connectionTarget = $this->connection->getTarget(); + $this->queryOptions = $options; } /** + * Implements the magic __sleep function to disconnect from the database. + */ + public function __sleep() { + $keys = get_object_vars($this); + unset($keys['connection']); + return array_keys($keys); + } + + /** + * Implements the magic __wakeup function to reconnect to the database. + */ + public function __wakeup() { + $this->connection = Database::getConnection($this->connectionTarget, $this->connectionKey); + } + + /** * Runs the query against the database. */ abstract protected function execute(); |