Commit 6823c765 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 1633b07f
......@@ -35,7 +35,7 @@ class Doctrine_AuditLog
'className' => '%CLASS%Version',
'versionColumn' => 'version',
'generateFiles' => false,
'table' => null,
'table' => false,
);
protected $_auditTable;
......@@ -43,6 +43,10 @@ class Doctrine_AuditLog
public function __construct($options)
{
$this->_options = array_merge($this->_options, $options);
$this->_options['className'] = str_replace('%CLASS%',
$this->_options['table']->getComponentName(),
$this->_options['className']);
}
/**
* __get
......@@ -109,13 +113,13 @@ class Doctrine_AuditLog
}
public function getVersion(Doctrine_Record $record, $version)
{
$className = str_replace('%CLASS%', $this->_table->getComponentName(), $this->_options['className']);
{
$className = $this->_options['className'];
$q = new Doctrine_Query();
$values = array();
foreach ((array) $this->_table->getIdentifier() as $id) {
foreach ((array) $this->_options['table']->getIdentifier() as $id) {
$conditions[] = $className . '.' . $id . ' = ?';
$values[] = $record->get($id);
}
......@@ -123,9 +127,10 @@ class Doctrine_AuditLog
$values[] = $version;
return $q->from($className)
->where($where)
->execute($values, Doctrine_HYDRATE::HYDRATE_ARRAY);
$q->from($className)
->where($where);
return $q->execute($values, Doctrine_HYDRATE::HYDRATE_ARRAY);
}
public function buildDefinition(Doctrine_Table $table)
{
......
......@@ -38,22 +38,31 @@ class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
public function __construct(Doctrine_AuditLog $auditLog) {
$this->_auditLog = $auditLog;
}
public function onPreInsert(Doctrine_Record $record)
public function preInsert(Doctrine_Event $event)
{
$versionColumn = $this->_auditLog->getOption('versionColumn');
$record->set($versionColumn, 1);
$event->getInvoker()->set($versionColumn, 1);
}
public function onPreDelete(Doctrine_Record $record)
public function preDelete(Doctrine_Event $event)
{
$class = $this->_auditLog->getOption('className');
$record = $event->getInvoker();
$version = new $class();
$version->merge($record->toArray());
$versionColumn = $this->_auditLog->getOption('versionColumn');
$version = $record->get($versionColumn);
$record->set($versionColumn, ++$version);
}
public function onPreUpdate(Doctrine_Record $record)
public function preUpdate(Doctrine_Event $event)
{
$versionColumn = $this->_auditLog->getOption('versionColumn');
$record = $event->getInvoker();
$version = $record->get($versionColumn);
$record->set($versionColumn, ++$version);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment