Skip to content

Commit

Permalink
Add operation type constants
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienHarper committed Apr 27, 2020
1 parent 5749bab commit e3cc043
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/DoctrineAuditBundle/Manager/AuditManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

class AuditManager
{
public const OPERATION_TYPE_INSERT = 'insert';
public const OPERATION_TYPE_UPDATE = 'update';
public const OPERATION_TYPE_REMOVE = 'remove';
public const OPERATION_TYPE_ASSOCIATE = 'associate';
public const OPERATION_TYPE_DISSOCIATE = 'dissociate';

/**
* @var \DH\DoctrineAuditBundle\AuditConfiguration
*/
Expand Down Expand Up @@ -85,7 +91,7 @@ public function insert(EntityManagerInterface $em, $entity, array $ch, string $t
/** @var ClassMetadata $meta */
$meta = $em->getClassMetadata(DoctrineHelper::getRealClassName($entity));
$this->audit([
'action' => 'insert',
'action' => self::OPERATION_TYPE_INSERT,
'blame' => $this->helper->blame(),
'diff' => $this->helper->diff($em, $entity, $ch),
'table' => $meta->getTableName(),
Expand Down Expand Up @@ -117,7 +123,7 @@ public function update(EntityManagerInterface $em, $entity, array $ch, string $t
/** @var ClassMetadata $meta */
$meta = $em->getClassMetadata(DoctrineHelper::getRealClassName($entity));
$this->audit([
'action' => 'update',
'action' => self::OPERATION_TYPE_UPDATE,
'blame' => $this->helper->blame(),
'diff' => $diff,
'table' => $meta->getTableName(),
Expand Down Expand Up @@ -145,7 +151,7 @@ public function remove(EntityManagerInterface $em, $entity, $id, string $transac
/** @var ClassMetadata $meta */
$meta = $em->getClassMetadata(DoctrineHelper::getRealClassName($entity));
$this->audit([
'action' => 'remove',
'action' => self::OPERATION_TYPE_REMOVE,
'blame' => $this->helper->blame(),
'diff' => $this->helper->summarize($em, $entity, $id),
'table' => $meta->getTableName(),
Expand All @@ -171,7 +177,7 @@ public function remove(EntityManagerInterface $em, $entity, $id, string $transac
*/
public function associate(EntityManagerInterface $em, $source, $target, array $mapping, string $transactionHash): void
{
$this->associateOrDissociate('associate', $em, $source, $target, $mapping, $transactionHash);
$this->associateOrDissociate(self::OPERATION_TYPE_ASSOCIATE, $em, $source, $target, $mapping, $transactionHash);
}

/**
Expand All @@ -188,7 +194,7 @@ public function associate(EntityManagerInterface $em, $source, $target, array $m
*/
public function dissociate(EntityManagerInterface $em, $source, $target, array $mapping, string $transactionHash): void
{
$this->associateOrDissociate('dissociate', $em, $source, $target, $mapping, $transactionHash);
$this->associateOrDissociate(self::OPERATION_TYPE_DISSOCIATE, $em, $source, $target, $mapping, $transactionHash);
}

/**
Expand Down

0 comments on commit e3cc043

Please sign in to comment.