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

Audit field type registry bug #1074

Open
andriusvo opened this issue Nov 16, 2021 · 7 comments
Open

Audit field type registry bug #1074

andriusvo opened this issue Nov 16, 2021 · 7 comments

Comments

@andriusvo
Copy link

Summary
In class AuditFieldTypeRegistry method validateAuditType works incorrectly.

Method validateAuditType checks whether provided audit type exists and if it's exist -> exception is raised:

        if (!empty(static::$auditTypes[$auditType])) {
            throw new \LogicException(sprintf('Unknown audit type %s.', $auditType));
        }

Should be:

        if (empty(static::$auditTypes[$auditType])) {
            throw new \LogicException(sprintf('Unknown audit type %s.', $auditType));
        }

Steps to reproduce
Use method addType to add new type to auditable fields.

Actual Result
Exception Unknown audit type is raised

Expected Result
New audit type should be added

Details about your environment

  • OroPlatform version: 4.2.6
  • PHP version: 8.0
@anyt
Copy link
Contributor

anyt commented Nov 16, 2021

Hi @andriusvo,
You can extend the Oro\Bundle\DataAuditBundle\Model\AuditFieldTypeRegistry to override the maps as they are stored in protected properties

@andriusvo
Copy link
Author

@anyt yes, but this is a bug and in any case should be fixed ;)

@anyt
Copy link
Contributor

anyt commented Nov 16, 2021

The data audit feature in the oro/platform package supports the limited list of field types. If you add an unsupported type - the validation triggers an error, that is, as I understand, expected behavior.

@andriusvo
Copy link
Author

@anyt Please check if statement one more time. In Oro code this if statement says that: If provided $auditType is not empty (== is found) - thrown an exception) And there should be exactly the opposite - `If provided $auditType is empty (== found) - thrown an exception.

@anyt
Copy link
Contributor

anyt commented Nov 16, 2021

I see there is a unit test for this method
\Oro\Bundle\DataAuditBundle\Tests\Unit\Model\AuditFieldTypeRegistryTest::testAuditFieldTypeRegistry.
Could you, please, change it to reproduce the bug?

@anyt
Copy link
Contributor

anyt commented Nov 16, 2021

It seems the validation message is missliding. According to the test, it throws an exception if you add the type that is already in the map.

@andriusvo
Copy link
Author

andriusvo commented Nov 16, 2021

Ok, let me give a real example for you. In AuditFieldTypeRegistry we have $typesMap where doctrine type is mapped to audit type. And now, f.e. I want to add integer_array (Doctrine type) to as simplearray (audit type). How I will achieve this? By writing this code:

        if (false === AuditFieldTypeRegistry::hasType(IntegerArrayType::TYPE)) {
            AuditFieldTypeRegistry::addType(IntegerArrayType::TYPE, 'simplearray');
        }

Now, method validateAuditType will be called and will be checked if audit type simplearray exists, and if exists -> the exception is thrown <---- Here is a bug! Should be the opposite, if the audit type is not found, only then the exception should be thrown. We are not checking duplicates of mapping here, we are checking only if this audit type exists. So in line 209 the exclamation mark should be removed, because it acts wrongly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants