Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception while creating audit table schema when using single table inheritance #132

Closed
nalxnet opened this issue Nov 30, 2022 · 8 comments · Fixed by #133
Closed

exception while creating audit table schema when using single table inheritance #132

nalxnet opened this issue Nov 30, 2022 · 8 comments · Fixed by #133
Labels
bug Something isn't working

Comments

@nalxnet
Copy link

nalxnet commented Nov 30, 2022

Q A
auditor version 2.3.0
PHP version 8.1.8
Database MySQL / SQLite

Summary

I have an abstract parent entity which is not audited, but uses doctrine/orm inheritance type "SINGLE_TABLE" and defines the database table for its child entities. Some child entities are configured to be audited.

With auditor 2.3.0, creating the audit database schema throws an exception.

Current behavior

When the database schema is created for this abstract parent entity, the CreateSchemaListener wants to create the corresponding audit table. This throws an exception while trying to determine the table name from the configuration with the new logic introduced in auditor 2.3.0, as the parent entity does not have any configuration: Undefined array key "App\AbstractParentEntity"

$auditTablename = $this->resolveAuditTableName($entities[$entity], $configuration, $connection->getDatabasePlatform());

In versions before 2.3.0, the table name from the event was being used, which is independent of the configuration.

How to reproduce

Define an abstract parent entity and an audited child entity:

namespace App;

/**
 * @ORM\Table(name="entities")
 * @ORM\Entity()
 * @ORM\InheritanceType("SINGLE_TABLE")
 */
abstract class AbstractParentEntity {}

/**
 * @ORM\Entity
 */
class Entity {}

Configure auditing for the child entity:

dh_auditor:
    enabled: true
    providers:
        doctrine:
            table_prefix: ~
            table_suffix: '_audit'
            entities:
                App\Entity: ~

Create the database schema using Doctrine\ORM\Tools\SchemaTool::createSchema for the parent entity to create an Doctrine\ORM\Tools\ToolEvents::postGenerateSchemaTable event.

Expected behavior

Creating the database schema for the abstract parent entity and its child entities does not throw an exception and creates the corresponding audit table schema.

@nalxnet nalxnet added the bug Something isn't working label Nov 30, 2022
dmitryuk pushed a commit to dmitryuk/auditor that referenced this issue Dec 2, 2022
DamienHarper pushed a commit that referenced this issue Dec 2, 2022
…e table inheritance (#133)

* fix #132

* entity

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>
@DamienHarper
Copy link
Owner

@nalxnet should be fixed now with 2.3.1, thanks for the feedback!

DamienHarper pushed a commit that referenced this issue Dec 2, 2022
…e table inheritance (#133)

* fix #132

* entity

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>
DamienHarper added a commit that referenced this issue Dec 2, 2022
* Fix bug: exception while creating audit table schema when using single table inheritance (#133)

* fix #132

* entity

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* Fixed annotations in tests

* Removed annotations from cherrypicked commits

Co-authored-by: Alexander Dmitryuk <xakzona@bk.ru>
Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>
@nalxnet
Copy link
Author

nalxnet commented Dec 2, 2022

Thanks for the quick fix, will test this in my code once its used by https://github.com/DamienHarper/auditor-bundle

@DamienHarper
Copy link
Owner

It should already be the case, auditor-bundle version 5.2.0 targets auditor version ^2.3 which means >= 2.3.0 and < 2.4.0
Just run composer update and it should do the trick

@nalxnet
Copy link
Author

nalxnet commented Dec 5, 2022

You're absolutely right, thanks. Tested it but unfortunately the exception is still thrown because SchemaManager::createAuditTable is still called with the untracked parent entity and not the tracked child entity. Looks like #139 will fix this.

@DamienHarper
Copy link
Owner

@nalxnet 2.4.0 is out and fixes this issue. Sorry for the inconvenience and kudos to @dmitryuk.

@nalxnet
Copy link
Author

nalxnet commented Dec 5, 2022

Thanks, but since it's a new minor release I'll have to wait for a new auditor-bundle release this time. 😄

@dmitryuk
Copy link
Contributor

dmitryuk commented Dec 5, 2022

@nalxnet kindly run ’composer u damienharper/auditor’

^2.3 which means >= 2.3.0 and < 3.0.0 as I know

@nalxnet
Copy link
Author

nalxnet commented Dec 5, 2022

You're absolutely right, I got confused by @DamienHarper 's comment above. It's working again without errors. Again, thanks a lot for the quick fix! 👍

DamienHarper added a commit that referenced this issue Jul 14, 2024
* Fix bug: exception while creating audit table schema when using single table inheritance (#133)

* fix #132

* entity

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* Updated README.md

* Updated CI

* Fixed annotations in tests

* Regression fix.

Fixes DamienHarper/auditor-bundle#334

* Updated CI

* Performance issues with metadatas (#137)

* Cache DH Annotations
* speed
* remove getOwner call

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* CreateSchemaListener not updating inheritance tables (#139)

* Fix: Attempted to call an undefined method named "getMetadataCache" of class "Doctrine\ORM\Configuration". (#144)

* Fix: Attempted to call an undefined method named "introspectSchema" of class "Doctrine\DBAL\Schema\PostgreSQLSchemaManager" (#143)

* Fixed invokable storage mapper (see #146) (#148)

* Fixed broken annotation registration since doctrine/orm 2.14

* improved the TransactionProcessor to convert encoding of diff properly (#152)

* improved the TransactionProcessor to convert encoding of diff properly

* adapted quotes in TransactionProcessor to single quotes

* Fixed compatibility issue with doctrine/event-manager ^2.0 (#157)

* PHP-CS-Fixer

* Validate that diff is a string before passing to mb_convert_encoding (#156)

* PHP-CS-Fixer

* Support  doctrine annotations 2.0 (#158)

* topic 344  doctrine annotations 2.0

---------

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* PHP-CS-Fixer

* Fix failing CI (lock related)

* PHP-CS-Fixer

* Fixes `diffs` column type when JSON type is supported

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fix 185 (#186)

* fixes #185

* PHP-CS-Fixer

---------

Co-authored-by: Damien Harper <damien.harper@gmail.com>

* skip embedded class from schema listener (#189)

Co-authored-by: Guillaume Sainthillier <guillaume.sainthillier@gmail.com>

* Fixed CI (2.x)

* Typo

* PHP-CS-Fixer

* Update deps + PHP-CS-Fixer

* PHP-CS-Fixer

* PHP-CS-Fixer (3.48.0)

* Detected wrapped driver (#195)

* - updated DHDriver and use parent::connect instead of dedicated field
- added getWrappedDriver to extract wrapped driver.
- tests

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* Fixed PHPStan error

---------

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>
Co-authored-by: Damien Harper <damien.harper@gmail.com>

* fix

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* php-cs-fixer

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* removed getSubscribedEvents from CreateSchemaListener

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* phpstan

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* fix DoctrineSubscriber + tests

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* fix Issue174Test

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* removed duplicate code, fixed test

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

---------

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>
Co-authored-by: Alexander Dmitryuk <xakzona@bk.ru>
Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>
Co-authored-by: damienharper <damien.harper@gmail.com>
Co-authored-by: Jörn Dyherrn <joern@dyherrn.dev>
Co-authored-by: Martijn Boers <2955898+martijnboers@users.noreply.github.com>
Co-authored-by: Guillaume Sainthillier <guillaume.sainthillier@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants