From 43af7b69f2bfad4657b9291fde8f48098ac678af Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 11 Jun 2007 15:33:59 +0000 Subject: [PATCH] --- lib/Doctrine/AuditLog/Listener.php | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lib/Doctrine/AuditLog/Listener.php diff --git a/lib/Doctrine/AuditLog/Listener.php b/lib/Doctrine/AuditLog/Listener.php new file mode 100644 index 000000000..404f10cae --- /dev/null +++ b/lib/Doctrine/AuditLog/Listener.php @@ -0,0 +1,60 @@ +. + */ +/** + * Doctrine_AuditLog_Listener + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ +class Doctrine_AuditLog_Listener extends Doctrine_EventListener +{ + + protected $_auditLog; + + public function __construct(Doctrine_AuditLog $auditLog) { + $this->_auditLog = $auditLog; + } + public function onPreInsert(Doctrine_Record $record) + { + $versionColumn = $this->_auditLog->getOption('versionColumn'); + + $record->set($versionColumn, 1); + } + public function onPreDelete(Doctrine_Record $record) + { + $versionColumn = $this->_auditLog->getOption('versionColumn'); + $version = $record->get($versionColumn); + + $record->set($versionColumn, ++$version); + } + public function onPreUpdate(Doctrine_Record $record) + { + $versionColumn = $this->_auditLog->getOption('versionColumn'); + $version = $record->get($versionColumn); + + $record->set($versionColumn, ++$version); + } +}