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); + } +}