This commit is contained in:
parent
1633b07f1d
commit
6823c76544
2 changed files with 27 additions and 13 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue