Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/EventListener/LogRevisionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,10 @@ private function prepareUpdateData(EntityManagerInterface $em, EntityPersister $
continue;
}

if (\in_array($field, $this->config->getGlobalIgnoreColumns(), true)) {
continue;
}

$newVal = $change[1];

if (!isset($classMetadata->associationMappings[$field])) {
Expand Down
67 changes: 67 additions & 0 deletions tests/Fixtures/Issue/IssueGlobalIgnoreColumnsEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\EntityAuditBundle\Tests\Fixtures\Issue;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
* @psalm-suppress ClassMustBeFinal
*/
#[ORM\Entity]
class IssueGlobalIgnoreColumnsEntity
{
/**
* @var int|null
*/
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
private $id;

#[ORM\Column(type: Types::STRING)]
private ?string $ignoreme = null;

#[ORM\Column(type: Types::STRING)]
private ?string $name = null;

public function getId(): ?int
{
return $this->id;
}

public function getIgnoreme(): ?string
{
return $this->ignoreme;
}

public function setIgnoreme(?string $ignoreme): self
{
$this->ignoreme = $ignoreme;

return $this;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(?string $name): self
{
$this->name = $name;

return $this;
}
}
68 changes: 68 additions & 0 deletions tests/Issue/IssueGlobalIgnoreColumns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\EntityAuditBundle\Tests\Issue;

use Sonata\EntityAuditBundle\Tests\BaseTestCase;
use Sonata\EntityAuditBundle\Tests\Fixtures\Issue\IssueGlobalIgnoreColumnsEntity;

final class IssueGlobalIgnoreColumns extends BaseTestCase
{
protected $schemaEntities = [
IssueGlobalIgnoreColumnsEntity::class,
];

protected $auditedEntities = [
IssueGlobalIgnoreColumnsEntity::class,
];

public function testGlobalIgnoreColumns(): void
{
$entity = new IssueGlobalIgnoreColumnsEntity();
$entity->setIgnoreme('test1')
->setName('name1');

$em = $this->getEntityManager();

$em->persist($entity);
$em->flush();
$em->clear();

$entityId = $entity->getId();
static::assertNotNull($entityId);

$persistedEntity = $em->find(IssueGlobalIgnoreColumnsEntity::class, $entityId);
static::assertNotNull($persistedEntity);

$this->getAuditManager();
$cnt = $em->getConnection()->executeQuery('SELECT COUNT(*) FROM revisions')->fetchOne();

$entity = $em->find(IssueGlobalIgnoreColumnsEntity::class, $entityId);
static::assertInstanceOf(IssueGlobalIgnoreColumnsEntity::class, $entity);
$entity->setIgnoreme('test2')->setName('name2');
$em->flush();
$em->clear();

$newCnt = $em->getConnection()->executeQuery('SELECT COUNT(*) FROM revisions')->fetchOne();
static::assertSame($cnt + 1, $newCnt);

$entity = $em->find(IssueGlobalIgnoreColumnsEntity::class, $entityId);
static::assertInstanceOf(IssueGlobalIgnoreColumnsEntity::class, $entity);
$entity->setIgnoreme('test2');
$em->flush();
$em->clear();

$newCnt = $em->getConnection()->executeQuery('SELECT COUNT(*) FROM revisions')->fetchOne();
static::assertSame($cnt + 1, $newCnt);
}
}
Loading