From 8fae10a971e982771e59dc60811b7cc5add57d1e Mon Sep 17 00:00:00 2001 From: Graeme Tait Date: Mon, 21 Sep 2015 14:05:56 +0100 Subject: [PATCH 1/3] Set DboSource::$_connection to null on disconnect --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index a41e88cef..e66ff49c1 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -284,7 +284,7 @@ class DboSource extends DataSource { if ($this->_result instanceof PDOStatement) { $this->_result->closeCursor(); } - unset($this->_connection); + $this->_connection = null; $this->connected = false; return true; } From 1b33efaad3b3e9af87074552127839375d3cedee Mon Sep 17 00:00:00 2001 From: Graeme Tait Date: Mon, 21 Sep 2015 14:08:07 +0100 Subject: [PATCH 2/3] Check $_connection is not null before trying to use it Stops a fatal error if calling isConnected() after disconnect(). --- lib/Cake/Model/Datasource/DboSource.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index e66ff49c1..135dfe055 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -857,10 +857,14 @@ class DboSource extends DataSource { * @return bool True if the database is connected, else false */ public function isConnected() { - try { - $connected = $this->_connection->query('SELECT 1'); - } catch (Exception $e) { + if (is_null($this->_connection)) { $connected = false; + } else { + try { + $connected = $this->_connection->query('SELECT 1'); + } catch (Exception $e) { + $connected = false; + } } $this->connected = ! empty($connected); return $this->connected; From dc856b850865589f9810cf93bc12187902174bc9 Mon Sep 17 00:00:00 2001 From: Graeme Tait Date: Mon, 21 Sep 2015 17:00:20 +0100 Subject: [PATCH 3/3] Switch out is_null() --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 135dfe055..b3ae8d814 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -857,7 +857,7 @@ class DboSource extends DataSource { * @return bool True if the database is connected, else false */ public function isConnected() { - if (is_null($this->_connection)) { + if ($this->_connection === null) { $connected = false; } else { try {