[TASK] DatabaseConnection::isConnected() should use ping() 47/26447/3
authorMarkus Klein <klein.t3@mfc-linz.at>
Mon, 16 Dec 2013 11:22:37 +0000 (12:22 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 3 Feb 2014 22:49:39 +0000 (23:49 +0100)
In some rare cases the database connection might be down, but
DatabaseConnection still has isConnected set to TRUE.
A call to isConnected() simply returns the member variable's value.

Improve the getter to also ping() the database if the class thinks
it is connected to verify the connection state.

The other methods of the class will still use the member variable
and not the getter method to avoid a ping() to the database on every
database interaction.

Resolves: #54323
Releases: 6.2, 6.1
Change-Id: I6bf090e5ab5f1d5539319ff10a1fb224036c4634
Reviewed-on: https://review.typo3.org/26447
Reviewed-by: Bill Dagou
Tested-by: Bill Dagou
Reviewed-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Database/DatabaseConnection.php

index 23fc313..f714095 100644 (file)
@@ -1629,6 +1629,11 @@ class DatabaseConnection {
         * @return boolean
         */
        public function isConnected() {
+               // We think we're still connected
+               if ($this->isConnected) {
+                       // Check if this is really the case or if the database server has gone away for some reason
+                       $this->isConnected = $this->link->ping();
+               }
                return $this->isConnected;
        }
 
@@ -1714,7 +1719,7 @@ class DatabaseConnection {
         * @return void
         */
        protected function disconnectIfConnected() {
-               if ($this->isConnected()) {
+               if ($this->isConnected) {
                        $this->link->close();
                        $this->isConnected = FALSE;
                }