mogilvie / EncryptBundle

Encryption bundle
82 stars 27 forks source link

Entity creation requires at least one property with the "Encrypted" attribute to have a non-null value #47

Closed barca-barca closed 3 weeks ago

barca-barca commented 11 months ago

Description: I encountered an issue while creating a new entity with properties that have the "Encrypted" attribute. The problem is that the entity creation process requires at least one property with the "Encrypted" attribute to have a non-null value, even when other non-encrypted properties have default null values.

Steps to reproduce:

Define a new entity with multiple properties, including at least one property annotated with the "Encrypted" attribute (e.g., @Encrypted). Set default values for non-encrypted properties to null in the entity definition. Attempt to create a new instance of the entity, providing values only for non-encrypted properties while leaving the property with the "Encrypted" attribute as null. Expected behavior: The system should allow the creation of the entity with null values for non-encrypted properties and automatically handle the encryption process when a value is provided for the "Encrypted" property during the entity creation process.

Actual behavior: Currently, when trying to create the entity without a value for the property with the "Encrypted" attribute, the system throws an error or exception, indicating that at least one property with the "Encrypted" attribute should have a non-null value.

Error message and stackTrace: Undefined array key 2760

/app/vendor/specshaper/encrypt-bundle/src/Subscribers/DoctrineEncryptSubscriber.php:201 /app/vendor/specshaper/encrypt-bundle/src/Subscribers/DoctrineEncryptSubscriber.php:100 /app/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:63 /app/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3587 /app/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:420 /app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:403 /app/tests/DataFixtures/Common/CommonAccountFixture.php:71 /app/vendor/doctrine/data-fixtures/src/Executor/AbstractExecutor.php:123 /app/vendor/doctrine/data-fixtures/src/Executor/ORMExecutor.php:26 /app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:272

so to fix this issue I changed method processFields in DoctrineEncryptSubscriber

..... if ($isInsert && isset($this->rawValues[$oid])) { foreach ($this->rawValues[$oid] as $prop => $rawValue) { $refProperty = $meta->getReflectionProperty($prop); $refProperty->setValue($entity, $rawValue); } unset($this->rawValues[$oid]); } ........

mogilvie commented 1 month ago

Resolved in dev-master, will push to v3.2 in next few days.