damienharper / auditor-bundle Goto Github PK
View Code? Open in Web Editor NEWThe missing audit log library
License: MIT License
The missing audit log library
License: MIT License
Hello!
I have been using your package since v1.2 and I like it a lot, but I had a problem with the routes because the characters '' are in the namespace of my entities and the URLs.
The package creates routes such as:
http://localhost/myproject/public/audit/App\Entity\MyEntity
And I can not reach them.
In the version 1.2, I modified the controller and the routes of the views changing the \ in favour of ##, and the trick succeded. But I've updated the bundle and I should make the change again (what is more I lack the DependencyInjector and my Custom Controller haven't the reader in the container).
It would be possible make the change in future versions (I guess that I could implement it, or you can implement a better solution if you wish), but I would prefer that I don't have to make changes about this in the next updates.
I'm sorry for my poor english, I want you to understand what I'm talking about, and thank you for this amazing bundle. ๐
We are using PostgreSQL database. We have tables in schema 'scheme' which must be audited. With default bundle configuration audit tables creating in correct table's schema, but on insert changes to audit tables the schema is ignored and doctrine trying save to default 'public' scheme.
I install the package with
composer require damienharper/doctrine-audit-bundle
After that I setup my dh_doctrine_audit.yaml
dh_doctrine_audit:
# Configuration reference available at:
# https://github.com/DamienHarper/DoctrineAuditBundle#configuration
entities:
App\Entity\ServiceTemplate: ~
# MyBundle\Entity\MyAuditedEntity1: ~ # all MyAuditedEntity1 properties are audited
# MyBundle\Entity\MyAuditedEntity2:
# ignored_columns: # MyAuditedEntity2 properties to be ignored by the audit process
# - createdAt
# - updatedAt
php bin/console doctrine:schema:update --dump-sql
When I update my database after that it says there aren't any changes. The package doesn't add views or entity's or something to my project. How can I install it on the right way?
Hello,
I would like to know the best way to store in the audit table more informations about the user, like the first name, last name and avatar (I use default userprovider). What is the best way ?
Thank you.
Hi,
Can we have audit logs to be stored in a separate DB through another DB connection and entityManager? From the first look seems that is not possible by simple reassign other entityManager to related services. But not sure how much work would be needed to add such functionality.
UPD:
Just want to share the idea behind.
When the entities are used actively, the _audit tables are growing rather fast. Also this data is not the most important to have.
The one solution would be to implement some rotation policy and move old data to another db. But better would be to store this audit data directly to a "secondary" database
I have only been using Symfony for about 6 months now, and so I might be wrong with this but...
I would get an error when trying to use $this->container->get('dh_doctrine_audit.reader');
I had to put this in my services.yaml
DH\DoctrineAuditBundle\AuditReader:
alias: dh_doctrine_audit.reader
DH\DoctrineAuditBundle\AuditConfiguration:
alias: dh_doctrine_audit.configuration
and then my controller
use DH\DoctrineAuditBundle\AuditReader;
class AuditViewController extends AbstractController
{
/**
* @Route("/audit/view/{entity}/{id?0}", name="audit_view")
*/
public function index(AuditReader $reader, $entity, $id)
{
$entity = 'App\Entity\\'.$entity;
$data = $reader->getAudits($entity);
dump($data);
return $this->render('@DHDoctrineAudit/Audit/entity_audit_details.html.twig', [
'entity' => $entity,
'entry' => $data[$id],
]);
}
}
Would this be the correct approach? and if so, might be worth putting in the readme!
Thanks for this, so far I think it will work. I am having a couple issues with updated entities not getting tracked, but I have a lot more experimenting to do! Damn complex forms.
Hi there. First of all thanks for the bundle.
Having an issue with a specific use case:
Getting an Undefined index: Y , in src/DoctrineAuditBundle/AuditConfiguration.php:95 . Checked the code there and I think it's because isAudited return true due to Y instanceof X being true.
Don't have time to push a PR currently :(
Q | A |
---|---|
DoctrineAuditBundle version | 3.0.0 |
PHP version | 7.2.12 |
Database | MySQL |
I just upgraded to DoctrineAuditBundle v3.0.0 from v2.3.1 and I haven't changed any configuration.
I'm also only using one entity manager for everything.
I tried testing a simple insertion and I'm not getting any audit data persisted after the onFlush event.
Doing some investigation by setting up breakpoints, I think the bug is in the onFlush method of DoctrineSubscriber.
public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$transaction = new AuditTransaction($this->manager->getHelper());
...
// Populate transaction
$transaction->collect();
}
The EntityManager $em which is passed by the parameter of the callback correctly contains the unit of work which has the entity to be inserted in the table, but inspecting the EntityManager via $transaction->getEntityManager() shows an empty unit of work and therefore nothing to be audited.
A snapshot of the two different EntityManager instances right after $transaction is initialized.
Then in the following code block, $uow->getScheduledEntityInsertions() returns an empty array and we don't collect any changes.
/**
* @param UnitOfWork $uow
*/
public function collectScheduledInsertions(UnitOfWork $uow): void
{
foreach ($uow->getScheduledEntityInsertions() as $entity) {
if ($this->configuration->isAudited($entity)) {
$this->inserted[] = [
$entity,
$uow->getEntityChangeSet($entity),
];
}
}
}
Any ideas? Thanks
Helllo!
Metadata initialization very early and its break my loadClassMetadata listener, because there are no listernes in eventManager at this moment and metadata initialized once..
what about change direct access to AuditConfiguration::$entities and use AuditConfiguration::getEntities() everywhere and make update entities list by annotation loader once here?
or may be make service are lazy but lazy params dont work in my hands:(
what do you think ?
As the readme says its the bundle is not tracking the deletion of entries, is this going to take place in the future?
Whats the reason why its not a feature?
Hi @DamienHarper i'm getting the following exception with SF3.4 on latest master ba53186 .
Type error: Argument 2 passed to Symfony\Component\EventDispatcher\EventDispatcher::dispatch() must be an instance of Symfony\Component\EventDispatcher\Event or null, instance of DH\DoctrineAuditBundle\Event\LifecycleEvent given, called in [...]/vendor/damienharper/doctrine-audit-bundle/src/DoctrineAuditBundle/Manager/AuditManager.php on line 49 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 2 passed to Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch() must be an instance of Symfony\\Component\\EventDispatcher\\Event or null, instance of DH\\DoctrineAuditBundle\\Event\\LifecycleEvent given, called in [...]/vendor/damienharper/doctrine-audit-bundle/src/DoctrineAuditBundle/Manager/AuditManager.php on line 49 at [...]/vendor/symfony/event-dispatcher/EventDispatcher.php:37)"} []
when viewing example.com/audit
and entities with config enabled: false
do not show up in the list.
ex;
# config/packages/dh_doctrine_audit.yaml
dh_doctrine_audit:
entities:
App\Entity\ContactAddress:
enabled: false
Contact Address will be omitted from the list even though you may have enabled audit at run time
Float entries detected as update even if there is no change.
Dissociate id source was wrong.
What I did (as stated in the readme.md):
ignored_columns:
- created_at
- modified_at
What happened:
These columns were not ignored.
What I expected:
For these columns to be ignored.
What I found out:
ignored_columns:
- createdAt
- modifiedAt
Actually worked.
Because audited entities are not "real" entity i can't tell (as I know) ApiPlatform to expose it.
I try to find a way but any help will be appreciated.
I found a way to expose vendor entities here api-platform/api-platform#891 but with you bundle I don't know yet.
We have an use case where an Entity can be changed by an automated process and also by the user. We want to audit changes made to this Entity only when it's made by the user and not the automated process.
I think that we can add some methods/options in AuditConfiguration
class to allow disabling audit for an Entity. Then, we can inject the configuration service in our controllers and disable/enable the audit manually. The isAudited
method would return false
while the audit for that Entity is disabled.
What do you think of this approach? If it's okay, I can work on a PR.
Hello!
i have two entity with @ORM\InheritanceType("JOINED")
/**
* @ORM\Entity()
* @Auditable()
*/
class Child extends Base
/**
* @ORM\Entity()
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="kind", type="string")
* @ORM\DiscriminatorMap({"child" = "App\Entity\Child"})
*/
abstract class Base
When i add @Auditable
annotation, bundle want to create two tables.
child_audit and base_audit
Why ?
is it necessary for what?
There is also descriminator column and its always null if inheritance type === joined
Can you check is it bug or not ?
I use version 3. When I execute the "audit: clean" command, it does not delete the data from the audit tables.
Please, your support.
Note: Sorry for my bad English. I use Symfony 4.3.
My solution to this will be just to add an ID as per normal, but it is actually unnecessary from a data integrity point of view.
The entity is part of a ManyToMay table. [App\Entity\FamilyBrBeneficiaryProfilePerson] It is a "family" record that links a "beneficiary profile" to a "person" and contains a couple of extra data points.
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity="App\Entity\BeneficiaryProfile", inversedBy="family")
* @ORM\JoinColumn(nullable=false)
*/
private $beneficiaryProfile;
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity="App\Entity\Person", inversedBy="dependantProfiles")
* @ORM\JoinColumn(nullable=false)
*/
private $person;
in PostgreSql this is simply a PRIMARY KEY (beneficiary_profile_id, person_id)
As I said, my work around will be to add the usual single id
key and then add a unique constraint on the other id's.
Not sure if this is worth trying to support or not, but I thought I'd share.
Hello, is it possible to add custom data to audit entry ?
for example uid http request .
can we create a json field to audit table and do dispatch event before insert payload to table ?
When loading doctrine fixtures, the following code in the onFlush method of the AuditSubscriber seems to be buggy:
$this->loggerBackup = $em->getConnection()->getConfiguration()->getSQLLogger();
$loggerChain = new LoggerChain();
$loggerChain->addLogger(new AuditLogger(function () use ($em) {
// flushes pending data
$em->getConnection()->getConfiguration()->setSQLLogger($this->loggerBackup);
$uow = $em->getUnitOfWork();
$this->manager->processInsertions($em, $uow);
$this->manager->processUpdates($em, $uow);
$this->manager->processAssociations($em);
$this->manager->processDissociations($em);
$this->manager->processDeletions($em);
$this->manager->reset();
}));
if ($this->loggerBackup instanceof SQLLogger) {
$loggerChain->addLogger($this->loggerBackup);
}
$em->getConnection()->getConfiguration()->setSQLLogger($loggerChain);
The loggerBackup
variable is of type Doctrine\DBAL\Logging\LoggerChain
(which implements SQLLogger). In the code above a new LoggerChain is created and an AuditLogger is added to it. But then the loggerBackup is also added to the new LoggerChain since LoggerChain implements SQLLogger. So now we have a LoggerChain inside a LoggerChain.
Below is the startQuery
method of the LoggerChain:
/**
* {@inheritdoc}
*/
public function startQuery($sql, array $params = null, array $types = null)
{
foreach ($this->loggers as $logger) {
$logger->startQuery($sql, $params, $types);
}
}
The method will recurse infinitely, and with xdebug enabled, you'll get a max_nesting_level error. Not exactly sure if this issue is being caused by something else, or if I'm missing something, but these are my initial findings.
Any and all help is greatly appreciated.
Hello again,
I have some boolean nullable fields inside my entities. If I change one of these fields from false to null, the change is not tracked. If I change it from true to false, or from true to null, the change is tracked in both cases but I cannot see the difference inside the diff (in both cases I see from: 1 - to: {empty}
.
The audit table shows:
// (true => null)
{
"theField": {
"new": null,
"old": true
}
}
// (true => false)
{
"theField": {
"new": false,
"old": true
}
}
I think this is because false == NULL
( http://php.net/manual/en/types.comparisons.php#types.comparisions-loose ).
I would submit a PR but I'm not entirely sure about the implications of changing the loose ifs inside https://github.com/DamienHarper/DoctrineAuditBundle/blob/master/src/DoctrineAuditBundle/EventSubscriber/AuditSubscriber.php#L276 && https://github.com/DamienHarper/DoctrineAuditBundle/blob/master/src/DoctrineAuditBundle/EventSubscriber/AuditSubscriber.php#L284 for other types
What do you think about having a configuration option for whether the bundle should record changes on insert and update, or only update? I'm guessing this could also technically be applied to any ORM operation.
Currently, it is logging the 'changes' on initial flush when an entity is created; the previous value is null and the new value is whatever the property is set to when created. We have 'created' and 'updated' properties on the entity itself so this initial audit trail is not really necessary.
hi,
I try to install through composer but I received this message error:
Could not find package damienharper/doctrine-audit-bundle at any version matching your PHP version 7.0.32.0
What can I do?
thanks a lot
Paolo
hi, I use uuid for primary keys, and therefore cannot use your bundle, how difficult is to change the code to support non-integer ids?
thanks
Because here it is not planned DATA-DOG/DataDogAuditBundle#43 do you ?
Especially revert behaviour.
When I have any decimal type in my entity, upon updating the entity a new audit record is saved in which it seems the value was changed. This is even the case when I set the scale in my form to 1. For example, if I have a number saved as 5.0 in my database, when I edit the entity and do not touch this number, for this value "{"old":"5.0","new":"5"}" is saved.
I am using MariaDB version 10.3.15 on an Apache server 2.4.39 with PHP 7.3.6.
My entity field looks like this:
/**
* @ORM\Column(type="decimal", precision=3, scale=1, nullable=true)
*/
private $credits;
Thanks!
Since 1.4.0 and this commit (c839ee8), the "is_subclass_of" test added makes "isAudited" return false if the argument is a proxy (because the proxy is a subclass of the enity)
if (\is_object($entity) && $entity instanceof $auditedEntity && !is_subclass_of($entity, $auditedEntity)) {
But when working with Doctrine, we often get a proxy instead of the entity.
In my case, we have users linked to orders.
When calling the getUser() method of the order, we get a proxy on the User (class is Proxies_CG_\App\Entity\User).
But then making changes on the user, the proxy class is considered as not audited
The same code works fine with 1.3.0.
Hi, thanks for the great bundle. It seems that after a recent change we can't save changes to arrays and JSON array fields as it throws the following error:
In ArrayType.php line 65:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: unserialize() expects parameter 1 to be string, array given
Exception trace:
Doctrine\DBAL\Types\ArrayType->convertToPHPValue() at D:\project\vendor\damienharper\doctrine-audit-bundle\src\DoctrineAuditBundle\EventSubscriber\AuditSubscriber.php:458
DH\DoctrineAuditBundle\EventSubscriber\AuditSubscriber->value() at D:\project\vendor\damienharper\doctrine-audit-bundle\src\DoctrineAuditBundle\EventSubscriber\AuditSubscriber.php:383
DH\DoctrineAuditBundle\EventSubscriber\AuditSubscriber->diff() at D:\project\vendor\damienharper\doctrine-audit-bundle\src\DoctrineAuditBundle\EventSubscriber\AuditSubscriber.php:190
DH\DoctrineAuditBundle\EventSubscriber\AuditSubscriber->insert() at D:\project\vendor\damienharper\doctrine-audit-bundle\src\DoctrineAuditBundle\EventSubscriber\AuditSubscriber.php:146
DH\DoctrineAuditBundle\EventSubscriber\AuditSubscriber->flush() at D:\project\vendor\damienharper\doctrine-audit-bundle\src\DoctrineAuditBundle\EventSubscriber\AuditSubscriber.php:56
DH\DoctrineAuditBundle\EventSubscriber\AuditSubscriber->DH\DoctrineAuditBundle\EventSubscriber\{closure}() at n/a:n/a
call_user_func() at D:\project\vendor\damienharper\doctrine-audit-bundle\src\DoctrineAuditBundle\DBAL\AuditLogger.php:26
DH\DoctrineAuditBundle\DBAL\AuditLogger->startQuery() at D:\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Logging\LoggerChain.php:54
Doctrine\DBAL\Logging\LoggerChain->startQuery() at D:\project\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php:1311
Doctrine\DBAL\Connection->commit() at D:\project\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php:237
Doctrine\ORM\EntityManager->transactional() at D:\project\vendor\doctrine\data-fixtures\lib\Doctrine\Common\DataFixtures\Executor\ORMExecutor.php:73
Doctrine\Common\DataFixtures\Executor\ORMExecutor->execute() at D:\project\vendor\doctrine\doctrine-fixtures-bundle\Command\LoadDataFixturesDoctrineCommand.php:105
Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() at D:\project\vendor\symfony\console\Command\Command.php:251
Symfony\Component\Console\Command\Command->run() at D:\project\vendor\symfony\console\Application.php:964
Symfony\Component\Console\Application->doRunCommand() at D:\project\vendor\symfony\framework-bundle\Console\Application.php:86
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at D:\project\vendor\symfony\console\Application.php:248
Symfony\Component\Console\Application->doRun() at D:\project\vendor\symfony\framework-bundle\Console\Application.php:74
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at D:\project\vendor\symfony\console\Application.php:148
Symfony\Component\Console\Application->run() at D:\project\bin\console:39
I looked at the convertToPHPValue
method and it doesn't seem to be particular useful in this case, as it seems to expect the given value to come directly from the database, not from the entity, hopefully that helps.
Thanks!
Because i use api-platform as backend (correct me if i'm wrong) it doesn't require sensio/framework-extra-bundle
which is needed to load @Tempalte
annotation which is in your AudiController
I think of 2 solutions:
1- Add requirement in you composer.json
2- Remove the annotations in you controller (in fact you use $this->render
)
For me the second solution seems better
Hello again,
I'm experimenting with the bundle, and I have a few questions about associations tracking.
I have some associations mapped as:
// EntityOne.php
class EntityOne
{
/* [...] */
/**
* @ORM\OneToOne(targetEntity="AppBundle\Entity\CorrelatedEntity",
* inversedBy="entityOne",
* fetch="LAZY",
* cascade={"persist"})
*/
private $correlatedEntity;
/* [...] */
}
// CorrelatedEntity.php
/*
* @Entity
*/
class CorrelatedEntity
{
/* [...] */
/**
* @ORM\OneToOne(targetEntity="AppBundle\Entity\EntityOne", mappedBy="correlatedEntity")
* @ORM\JoinColumn(name="entity_one_id", referencedColumnName="id")
*/
private $entityOne;
/* [...] */
}
After adding a CorrelatedEntity
to an existing EntityOne
, I can see a change tracked inside EntityOne
:
Properties | Old value | New value |
---|---|---|
correlatedEntity | label: AppBundle\Entity\CorrelatedEntity#3 class: AppBundle\Entity\CorrelatedEntity table: correlated_entity id: 3 |
And an insertion inside CorrelatedEntity
:
Properties | Old value | New value |
---|---|---|
id | 3 | |
data | test_test | |
entityOne | label: AppBundle\Entity\EntityOne#1 class: AppBundle\Entity\EntityOne table: entity_one id: 1 |
Inside the bundle code I saw that there is a "associated" / "disassociated" change type, so I'm wondering:
I have some associations mapped as:
// EntityOne.php
/**
* @ORM\Entity
*/
class EntityOne
{
/* [...] */
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\EntityTwo",
* mappedBy="entityOne", cascade={"persist"})
*/
private $entityTwos;
/* [...] */
}
// EntityTwo.php
/**
* @ORM\Entity
*/
class EntityTwo
{
/* [...] */
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\EntityOne",
* inversedBy="entityTwos", cascade={"persist"})
* @ORM\JoinColumn(name="entity_one_id", referencedColumnName="id")
*/
private $entityOne;
/* [...] */
}
After adding one or more EntityTwo
to an existing EntityOne
, I can see an insert tracked inside EntityTwo
:
Properties | Old value | New value |
---|---|---|
id | 6 | |
additional_data | datatest | |
entityOne | label: Proxies_CG_\AppBundle\Entity\EntityOne#8 class: AppBundle\Entity\EntityOne table: entity_one id: 8 |
But on EntityOne
I don't see any change.
I have some associations mapped as:
// EntityOne.php
/**
* @ORM\Entity
*/
class EntityOne
{
/* [...] */
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\EntityThree", cascade={"persist"})
* @ORM\JoinTable(schema="my_schema", name="entity_three")
*
*/
private $entityThrees;
/* [...] */
}
// EntityThree.php
/**
* @ORM\Entity
*/
class EntityThree
{
/* [...] */
}
After adding one or more EntityThree
to an existing EntityOne
, I'm not able to see the association anywhere.
Thanks in advance,
Marco
When using DoctrineAuditBundle on an entity that has a property of a custom Doctrine type (CrEOF doctrine2-spatial 'point'), I got an error during comparison of the old and new objects:
Cannot use object of type CrEOF\Spatial\PHP\Types\Geometry\Point as array
Looking into it, I found that the error was fixed by changing line 465 of AuditSubscriber.php from:
$convertedValue = $type->convertToPHPValue($value, $platform);
to:
$convertedValue = $type->convertToDatabaseValue($value, $platform);
Maybe converting to a database value for string comparison makes sense here?
Hi!
It would be nice to have some way by configuring to replace the AuditEntry entity with some other entity. Since AuditReader always returns instances of AuditEntry and it is not possible to give behavior to this class unless it is its own.
Something like:
`
dh_doctrine_audit:
audit_entry:
class: App\Entity\CustomAuditEntry
`
So I am trying to launch command ang I get "Unable to display the estimated time if the maximum number of steps is not set.". where do I set them?
php bin/console audit:schema:update
Introspecting schema...
Unable to display the estimated time if the maximum number of steps is not
set.
Thank you very much for this bundle @DamienHarper .
Is it possible to have a revision number which bundles all changes made in one transaction? i.E. when updating a entity with many relations it would be nice to get all these changes without relying on user and timestamp.
I use UUID as identifier for User entity. Your code assumes that id
is integer https://github.com/DamienHarper/DoctrineAuditBundle/blob/master/src/DoctrineAuditBundle/User/UserInterface.php#L7
Application throws error
Notice: A non well formed numeric value encountered
Hello,
I'm currently mapping my entities using annotations, my database is PostgreSQL.
My entities are annotated as:
/**
* @ORM\Entity
* @ORM\Table(schema="my_schema", name="entity_name")
*/
I tried adding a table_prefix to my configuration, and doctrine:schema:update --dump-sql
showed the following:
CREATE SCHEMA audit_my_schema;
CREATE TABLE audit_my_schema.entity_name (id SERIAL NOT NULL, type VARCHAR(10) NOT NULL, object_id INT NOT NULL, diffs JSON DEFAULT NULL, blame_id INT DEFAULT NULL, blame_user VARCHAR(100) DEFAULT NULL, ip VARCHAR(45) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id));
Is this expected behaviour? Is there a way to set a table_prefix while conserving the original schema?
Hello,
How do you enable auditing for all entities ?
Another question: Is it possible to use the views for DATA-DOG/DataDogAuditBundle ?
Note: Also I see that in the README it is said that this bundle is inspired by DATA-DOG/DataDogAuditBundle, it would be nice to mention the key differences.
Thanks
Hello! I face some trouble, having many to many relation when you remove last association there is no dissociative event record in audit table for that entity
Everything else seems working fine
Hello
Audit does not work.
How i can fix it?
I installed this bundle on Symfony 4.2, the mentioned below issue is occurring.
Unknown "spaceless" filter.
if I remove it from twig file, then works fine.
Please provide the solution or tell me how to override the twig.
I noticed another weird bug, not critical but weird. Every time when I execute doctrine:schema:update --force
it will drop all audit indexes and create them again.
SF3.4
10.1.38-MariaDB-0+deb9u1
./bin/console doctrine:schema:update --force --dump-sql
DROP INDEX object_id_922a2e2fde8c24f7943de9485a005b9f_idx ON country_audit;
DROP INDEX discriminator_922a2e2fde8c24f7943de9485a005b9f_idx ON country_audit;
DROP INDEX blame_id_922a2e2fde8c24f7943de9485a005b9f_idx ON country_audit;
CREATE INDEX object_id_922a2e2fde8c24f7943de9485a005b9f_idx ON country_audit (object_id);
CREATE INDEX discriminator_922a2e2fde8c24f7943de9485a005b9f_idx ON country_audit (discriminator);
CREATE INDEX blame_id_922a2e2fde8c24f7943de9485a005b9f_idx ON country_audit (blame_id);
DROP INDEX object_id_044baacb2e72a0e8016709888314abd2_idx ON charge_audit;
DROP INDEX discriminator_044baacb2e72a0e8016709888314abd2_idx ON charge_audit;
DROP INDEX blame_id_044baacb2e72a0e8016709888314abd2_idx ON charge_audit;
CREATE INDEX object_id_044baacb2e72a0e8016709888314abd2_idx ON charge_audit (object_id);
CREATE INDEX discriminator_044baacb2e72a0e8016709888314abd2_idx ON charge_audit (discriminator);
CREATE INDEX blame_id_044baacb2e72a0e8016709888314abd2_idx ON charge_audit (blame_id);
The AuditViewer depends on Pagerfanta bundle which is not loaded by default in Symfony 3. So in AppKernel.php i have to enable the bundle, otherwise we have the error:
Unknown "pagerfanta" function.
In AppKernel.php:
public function registerBundles()
{
$bundles = array(
// ...
new DH\DoctrineAuditBundle\DHDoctrineAuditBundle(),
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
);
}
Hi!
Why do you create an extra table for each entity? You could store all of the audits into the only one table "audit", that contains an additional field "entity" with the name of the correspondent entity. Can you add this option to the config?
Hi, thanks for the bundle. I just intalled it with Symfony 4 and would have some minor improvements recommendation for the README.md related to Symfony 4 specifically:
Great work!
When adding the storage_entity_manager
option symfony returns the following error
Unrecognized option" storage_entity_manager "under" dh_doctrine_audit
I have the entity
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="case_core")
*/
class CoreCase {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", name="type", length=50)
*/
private $type;
/**
* @ORM\Column(type="string", name="status", length=50)
*/
private $status;
}
and the entity
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="case_diesel")
*/
class DieselCase {
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="CoreCase", cascade={"persist"})
* @ORM\JoinColumn(name="core_case", referencedColumnName="id")
*/
private $coreCase;
}
If I try to run this code, I get the exception
CRITICAL13:00:09 | request | Uncaught PHP Exception ErrorException: "Notice: Undefined index: coreCase" at /home/alexander/projects/lawbutler/vendor/damienharper/doctrine-audit-bundle/src/DoctrineAuditBundle/EventSubscriber/AuditSubscriber.php line 384
$dieselCase = $em->getRepository(DieselCase::class)->find(1);
$dieselCase->setCreatedAt(new \DateTime('now'));
$em->flush();
What is the problem? Can the bundle properly work with related entities?
Currently, this bundle only supports getting the user from Symfony's TokenStorage
. Is it possible to add something like getting the user from a custom service? We are using Symfony in a microservices architecture and we don't use TokenStorage
to save the current user. With this bundle we have no way to implement a custom logic for getting the user.
I think that replacing the direct usage of TokenStorage
with something like an AuditUserProviderInterface
will provide the required flexibility, and this bundle could provide a default implementation that still uses TokenStorage
. I'm afraid that for this to work we have to change the AuditConfiguration
constructor and possibly break compatibility. But, if it is ok I can work on a PR.
I have an abstract entity which uses single table inheritance. Using a discriminator map, I'm mapping 3 entities that extend my abstract entity.
In my dh_doctrine_audit.yaml
under entities, I've put my parent class. Whenever I change one of the subclasses, no audits are created. I also did try splitting my audit config out by including the 3 entities individually.
Here is my yaml config:
dh_doctrine_audit:
table_prefix: 'audit_'
table_suffix: ''
ignored_columns:
- created
- updated
- createdBy
- updatedBy
entities:
App\Entity\AbstractFooBar: ~
Here is the parent class:
/**
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "example_one" = "ExampleOne",
* "example_two" = "ExampleTwo",
* "example_three" = "ExampleThree"
* })
* @ORM\Entity()
* @ORM\InheritanceType("SINGLE_TABLE")
*/
abstract class AbstractFooBar
{
// ...
}
And then my three entities look like this:
/**
* @Entity()
*/
class ExampleOne extends AbstractFooBar
{
// ...
}
Looking through the source code, there appears to be logic to audit these entities.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.