[icinga-checkins] icinga.org: icinga-web/mhein/testing: * Provded oracle fix for session garbage collector

git at icinga.org git at icinga.org
Sat Jun 25 15:01:23 CEST 2011


Module: icinga-web
Branch: mhein/testing
Commit: 9ab4e4f3f4ae24b0472761181fdbc2416f3ec069
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=9ab4e4f3f4ae24b0472761181fdbc2416f3ec069

Author: Marius Hein <marius.hein at netways.de>
Date:   Sat Jun 25 13:20:52 2011 +0200

* Provded oracle fix for session garbage collector

---

 .../storage/AppKitDoctrineSessionStorage.class.php |  213 ++++++++++----------
 1 files changed, 104 insertions(+), 109 deletions(-)

diff --git a/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php b/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php
index 4a87afe..b45bfef 100644
--- a/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php
+++ b/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php
@@ -1,115 +1,110 @@
 <?php
 
 class AppKitDoctrineSessionStorage extends AgaviSessionStorage {
-
-    /**
-     * @var NsmSession
-     */
-    private $NsmSession = null;
-  
-    public function initialize(AgaviContext $context, array $parameters = array()) {
-
-        // initialize the parent
-        parent::initialize($context, $parameters);
-         
-        session_set_save_handler(
-            array(&$this, 'sessionOpen'),
-            array(&$this, 'sessionClose'),
-            array(&$this, 'sessionRead'),
-            array(&$this, 'sessionWrite'),
-            array(&$this, 'sessionDestroy'),
-            array(&$this, 'sessionGC')
-        );
-
-    }
-
-    public function sessionClose() {
-        // Hm, the same as sessionOpen?!
-
-    }
-
-    public function sessionDestroy($id) {
-        $connection = AppKitSQLConstants::getInternalDB();
-        $result = Doctrine_Query::create($connection)
-                  ->delete('NsmSession')
-                  ->andWhere('session_name=? and session_id=?', array($this->getParameter('session_name'), 'id'))
-                  ->execute();
-
-        if ($result > 0) {
-            return true;
-        }
-
-        return false;
-
-    }
-
-    public function sessionGC($lifetime) {
-        $maxlifetime = time()-$lifetime;
-        $connection = AppKitSQLConstants::getInternalDB();
-        $result = Doctrine_Query::create($connection)
-                  ->andWhere('session_created < ?', array(date("c",$maxlifetime)))
-                  ->delete('NsmSession')
-                  ->execute();
-
-        if ($result > 0) {
-            $this->getContext()->getLoggerManager()
-            ->log(sprintf('Session garbage collector, deleted %d old sessions.', $result), AgaviLogger::INFO);
-        }
-
-        if ($result > 0) {
-            return true;
-        }
-
-        return false;
-    }
-
-    public function sessionOpen($path, $name) {
-        // Hm should we do anything here?
-    }
-
-    public function sessionRead($id) {
-        $session_name = $this->getParameter('session_name');
-
-        $connection = AppKitSQLConstants::getInternalDB();
-        $result = Doctrine_Query::create($connection)
-                  ->select('*')
-                  ->from('NsmSession n')
-                  ->andWhere('session_id=? and session_name=?', array($id, $session_name))
-                  ->execute();
-
-        if ($result->count() == 0) {
-            $this->NsmSession = new NsmSession();
-            $this->NsmSession->session_id = $id;
-            $this->NsmSession->session_name = $session_name;
-
-            return '';
-        } else {
-
-            $this->NsmSession = $result->getFirst();
-            $data = $this->NsmSession->get('session_data');
-
-            if (is_resource($data)) {
-                $data = stream_get_contents($this->NsmSession->get('session_data'));
-            }
-
-            if (md5($data) == $this->NsmSession->session_checksum) {
-                return $data;
-            }
-
-            $this->NsmSession->delete();
-            throw new AppKitDoctrineSessionStorageException('Sessiondata integrity error, should be: '. $this->NsmSession->session_checksum);
-        }
-
-    }
-
-    public function sessionWrite($id, &$data) {
-        $this->NsmSession->session_data = $data;//, $this->getParameter('gzip_level', 6)));
-        $this->NsmSession->session_checksum = md5($data);
-
-        $this->NsmSession->save();
-
-    }
-
+	
+	/**
+	 * @var NsmSession
+	 */
+	private $NsmSession = null;
+	
+	public function initialize(AgaviContext $context, array $parameters = array()) {
+		
+		// initialize the parent
+		parent::initialize($context, $parameters);
+		
+		session_set_save_handler(
+			array(&$this, 'sessionOpen'),
+			array(&$this, 'sessionClose'),
+			array(&$this, 'sessionRead'),
+			array(&$this, 'sessionWrite'),
+			array(&$this, 'sessionDestroy'),
+			array(&$this, 'sessionGC')
+		);
+		
+	}
+	
+	public function sessionClose() {
+		// Hm, the same as sessionOpen?!
+
+	}
+	
+	public function sessionDestroy($id) {
+		
+		$result = Doctrine_Query::create()
+		->delete('NsmSession')
+		->andWhere('session_name=? and session_id=?', array($this->getParameter('session_name'), 'id'))
+		->execute();
+		
+		if ($result > 0) return true;
+		
+		return false;
+		
+	}
+	
+	public function sessionGC($lifetime) {
+		$date = new DateTime();
+		$date->sub(new DateInterval(sprintf('PT%dS', $lifetime)));
+
+		$this->getContext()->getLoggerManager()->log('Deleting sessions older that '. $date->format('c'), AgaviLogger::DEBUG);
+
+		$result = Doctrine_Query::create()
+		->andWhere('session_created < ?', array($date->format('Y-m-d H:i:s')))
+		->delete('NsmSession')
+		->execute();
+		
+		if ($result > 0) {
+			$this->getContext()->getLoggerManager()
+			->log(sprintf('Session garbage collector, deleted %d old sessions.', $result), AgaviLogger::INFO);
+		}
+		
+		if ($result > 0) return true;
+		
+		return false;
+	}
+	
+	public function sessionOpen($path, $name) {
+		// Hm should we do anything here?
+	}
+	
+	public function sessionRead($id) {
+		$session_name = $this->getParameter('session_name');
+		
+		$result = Doctrine_Query::create()
+		->select('*')
+		->from('NsmSession n')
+		->andWhere('session_id=? and session_name=?', array($id, $session_name))
+		->execute();
+	
+		if ($result->count() == 0) {
+			$this->NsmSession = new NsmSession();
+			$this->NsmSession->session_id = $id;
+			$this->NsmSession->session_name = $session_name;
+
+			return '';
+		}
+		else {
+			
+			$this->NsmSession = $result->getFirst();
+			$data = $this->NsmSession->get('session_data');
+			if(is_resource($data))
+				$data = stream_get_contents($this->NsmSession->get('session_data'));
+			if (md5($data) == $this->NsmSession->session_checksum) {
+				return $data;
+			}
+			$this->NsmSession->delete();
+			throw new AppKitDoctrineSessionStorageException('Sessiondata integrity error, should be: '. $this->NsmSession->session_checksum);
+		}
+	
+	}
+	
+	public function sessionWrite($id, &$data) {
+		$this->NsmSession->session_data = $data;//, $this->getParameter('gzip_level', 6)));
+		$this->NsmSession->session_checksum = md5($data);
+
+		$this->NsmSession->save();
+
+	}
+	
 }
 
 class AppKitDoctrineSessionStorageException extends AppKitException {}





More information about the icinga-checkins mailing list