Fixes #427, now the AuditLog component should work
This commit is contained in:
parent
1f1fef741c
commit
8fb82c2f65
@ -74,13 +74,20 @@ class Doctrine_AuditLog extends Doctrine_Plugin
|
|||||||
$name = $table->getComponentName();
|
$name = $table->getComponentName();
|
||||||
|
|
||||||
$className = $name . 'Version';
|
$className = $name . 'Version';
|
||||||
|
|
||||||
|
// check that class doesn't exist (otherwise we cannot create it)
|
||||||
if (class_exists($className)) {
|
if (class_exists($className)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$columns = $table->getColumns();
|
$columns = $table->getColumns();
|
||||||
|
|
||||||
|
// remove all sequential and autoincrement definitions
|
||||||
|
foreach ($columns as $column => $definition) {
|
||||||
|
unset($columns[$column]['autoincrement']);
|
||||||
|
unset($columns[$column]['sequence']);
|
||||||
|
}
|
||||||
|
|
||||||
// the version column should be part of the primary key definition
|
// the version column should be part of the primary key definition
|
||||||
$columns[$this->_options['versionColumn']]['primary'] = true;
|
$columns[$this->_options['versionColumn']]['primary'] = true;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
|
|||||||
|
|
||||||
$event->getInvoker()->set($versionColumn, 1);
|
$event->getInvoker()->set($versionColumn, 1);
|
||||||
}
|
}
|
||||||
public function preDelete(Doctrine_Event $event)
|
public function postInsert(Doctrine_Event $event)
|
||||||
{
|
{
|
||||||
$class = $this->_auditLog->getOption('className');
|
$class = $this->_auditLog->getOption('className');
|
||||||
|
|
||||||
@ -53,25 +53,35 @@ class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
|
|||||||
$version = new $class();
|
$version = new $class();
|
||||||
$version->merge($record->toArray());
|
$version->merge($record->toArray());
|
||||||
$version->save();
|
$version->save();
|
||||||
|
}
|
||||||
|
public function preDelete(Doctrine_Event $event)
|
||||||
|
{
|
||||||
|
$class = $this->_auditLog->getOption('className');
|
||||||
|
|
||||||
|
$record = $event->getInvoker();
|
||||||
|
|
||||||
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
||||||
$version = $record->get($versionColumn);
|
$version = $record->get($versionColumn);
|
||||||
|
|
||||||
$record->set($versionColumn, ++$version);
|
$record->set($versionColumn, ++$version);
|
||||||
|
|
||||||
|
$version = new $class();
|
||||||
|
$version->merge($record->toArray());
|
||||||
|
$version->save();
|
||||||
}
|
}
|
||||||
public function preUpdate(Doctrine_Event $event)
|
public function preUpdate(Doctrine_Event $event)
|
||||||
{
|
{
|
||||||
$class = $this->_auditLog->getOption('className');
|
$class = $this->_auditLog->getOption('className');
|
||||||
$record = $event->getInvoker();
|
$record = $event->getInvoker();
|
||||||
|
|
||||||
$version = new $class();
|
|
||||||
$version->merge($record->toArray());
|
|
||||||
$version->save();
|
|
||||||
|
|
||||||
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
$versionColumn = $this->_auditLog->getOption('versionColumn');
|
||||||
|
|
||||||
$version = $record->get($versionColumn);
|
$version = $record->get($versionColumn);
|
||||||
|
|
||||||
$record->set($versionColumn, ++$version);
|
$record->set($versionColumn, ++$version);
|
||||||
|
|
||||||
|
$version = new $class();
|
||||||
|
$version->merge($record->toArray());
|
||||||
|
$version->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user