]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Session/Handler/Database.php
Reverted some changes that won't work with PHP7.3
[friendica.git] / src / Core / Session / Handler / Database.php
index b18d55db7ceb2b49d23ce97a77c89960a20de26f..41ccb6b33f834e4f315fef4b6b78a5f2813bebff 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Core\Session\Handler;
 
-use Friendica\Core\Session;
 use Friendica\Database\Database as DBA;
 use Psr\Log\LoggerInterface;
-use SessionHandlerInterface;
 
 /**
  * SessionHandler using database
  */
-class Database implements SessionHandlerInterface
+class Database extends AbstractSessionHandler
 {
        /** @var DBA */
        private $dba;
@@ -37,6 +35,8 @@ class Database implements SessionHandlerInterface
        private $logger;
        /** @var array The $_SERVER variable */
        private $server;
+       /** @var bool global check, if the current Session exists */
+       private $sessionExists = false;
 
        /**
         * DatabaseSessionHandler constructor.
@@ -66,11 +66,11 @@ class Database implements SessionHandlerInterface
                try {
                        $session = $this->dba->selectFirst('session', ['data'], ['sid' => $id]);
                        if ($this->dba->isResult($session)) {
-                               Session::$exists = true;
+                               $this->sessionExists = true;
                                return $session['data'];
                        }
                } catch (\Exception $exception) {
-                       $this->logger->warning('Cannot read session.'. ['id' => $id, 'exception' => $exception]);
+                       $this->logger->warning('Cannot read session.', ['id' => $id, 'exception' => $exception]);
                        return '';
                }
 
@@ -101,11 +101,11 @@ class Database implements SessionHandlerInterface
                        return $this->destroy($id);
                }
 
-               $expire         = time() + Session::$expire;
+               $expire         = time() + static::EXPIRE;
                $default_expire = time() + 300;
 
                try {
-                       if (Session::$exists) {
+                       if ($this->sessionExists) {
                                $fields    = ['data' => $data, 'expire' => $expire];
                                $condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $id, $data, $expire];
                                $this->dba->update('session', $fields, $condition);
@@ -114,7 +114,7 @@ class Database implements SessionHandlerInterface
                                $this->dba->insert('session', $fields);
                        }
                } catch (\Exception $exception) {
-                       $this->logger->warning('Cannot write session.'. ['id' => $id, 'exception' => $exception]);
+                       $this->logger->warning('Cannot write session.', ['id' => $id, 'exception' => $exception]);
                        return false;
                }
 
@@ -131,7 +131,7 @@ class Database implements SessionHandlerInterface
                try {
                        return $this->dba->delete('session', ['sid' => $id]);
                } catch (\Exception $exception) {
-                       $this->logger->warning('Cannot destroy session.'. ['id' => $id, 'exception' => $exception]);
+                       $this->logger->warning('Cannot destroy session.', ['id' => $id, 'exception' => $exception]);
                        return false;
                }
        }
@@ -141,7 +141,7 @@ class Database implements SessionHandlerInterface
                try {
                        return $this->dba->delete('session', ["`expire` < ?", time()]);
                } catch (\Exception $exception) {
-                       $this->logger->warning('Cannot use garbage collector.'. ['exception' => $exception]);
+                       $this->logger->warning('Cannot use garbage collector.', ['exception' => $exception]);
                        return false;
                }
        }