Forums › Forums › OroPlatform › OroPlatform – Programming Questions › custom doctrine Type, field not auditable or available in email template
This topic contains 12 replies, has 2 voices, and was last updated by adriwan_kenoby 6 years, 1 month ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- February 26, 2018 at 1:04 am #34519
Hi Oro Team,
I have a custom doctrine type register in the application via app.yml
YAML12345678doctrine:dbal:types:b_password: Sinabs\Bundle\EntityBundle\DBAL\Type\BijectifPasswordTypephone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberTypemapping_types:b_password: stringphone_number: stringThese type are not auditable nor available in email template.
The @Config and @ConfigField annotaions are present on entity.
What step Have I forgotten ? - CreatorTopic
- AuthorReplies
- February 26, 2018 at 9:36 am #34520
Hi, @adriwan_kenoby
Can you please provide us with the value of your ‘@Config’ and ‘@ConfigField’ annotaions?
Also please take a look into e.g. UserEntity, so the Entity annotation should be like thisPHP123456@Config(...defaultValues={..."dataaudit"={"auditable"=true},...and the field annotation should be
PHP1234567* @ConfigField(* defaultValues={* "dataaudit"={"auditable"=true}* }* )*/protected $yourField;February 27, 2018 at 1:48 am #34521I have already this annotation on my entity and my fields. Maybe that I have to add JMS serializer annotation to make it work. I have seen a message error in prod.log, I dont retrieve it but it was something like type b_password not auditable.
12345678910111213141516171819202122232425@Config(* defaultValues={* "entity"={* "icon"="fa-user-circle"* },* "form"={* "form_type"="sinabs_hosting_user_select",* "grid_name"="sinabs-hosting-users-select-grid",* },* "security"={* "type"="ACL",* "permissions"="All"* },* "ownership"={* "owner_type"="BUSINESS_UNIT",* "owner_field_name"="owner",* "owner_column_name"="business_unit_owner_id",* "organization_field_name"="organization",* "organization_column_name"="organization_id"* },* "dataaudit"={* "auditable"=true* }* }* )123456789101112131415/*** @var string** @ORM\Column(name="unix_password", type="b_password")* @Assert\Type("string")* @Assert\NotBlank()* @ConfigField(* defaultValues={* "dataaudit"={* "auditable"=true* }* }* )*/protected $unixPassword;February 27, 2018 at 3:58 am #34522Hi,
it will help if you could provide error log, because it’s still hard to suggest something.
Also, please double check audit settings for Entity and its field from UI (System/Entities/Entity Management), as an example
The same check can be performed from CLI, e.g.
– entity configuration
./app/console oro:entity-config:debug "Oro\Bundle\ZendeskBundle\Entity\User" --env=prod | grep audit
it should output something like
[dataaudit] => Array
[auditable] => true
- list entity fields./app/console oro:entity-config:debug "Oro\Bundle\ZendeskBundle\Entity\User" -l --env=prod
– entity field audit configuration./app/console oro:entity-config:debug "Oro\Bundle\ZendeskBundle\Entity\User" fieldName --env=prod | grep audit
it should output something like
[dataaudit] => Array
[auditable] => true
- entity field email template configuration./app/console oro:entity-config:debug "Oro\Bundle\ZendeskBundle\Entity\User" fieldName --env=prod | grep template
it should output something like
[available_in_template] => true
February 27, 2018 at 6:03 am #34523Thanks for your time @Alexander,
the output of previous command are :
for the entity configuration12345[dataaudit] => Array[auditable] => truelist of field they are all auditable
123456789101112createdAt, Type: datetime, Mode: defaultdriver, Type: string, Mode: defaulthost, Type: ref-one, Mode: defaultid, Type: integer, Mode: defaultlogin, Type: b_password, Mode: defaultorganization, Type: ref-one, Mode: defaultowner, Type: ref-one, Mode: defaultpassword, Type: b_password, Mode: defaultserialized_data, Type: array, Mode: hiddenupdatedAt, Type: datetime, Mode: defaultfor the entity field email configuration nothing is shown neither false…
in prod.log :
1234app.ERROR: Consuming interrupted by exception. "Unsupported audit data type "b_password"" {"exception":"[object] (Oro\\Bundle\\DataAuditBundle\\Exception\\UnsupportedDataTypeException(code: 0): Unsupported audit data type \"b_password\" at /home/sinabs/sites/dev.orocrm.sinabs.fr/vendor/oro/platform/src/Oro/Bundle/DataAuditBundle/Model/AuditFieldTypeRegistry.php:98)"} {"processor":"Oro\\Bundle\\DataAuditBundle\\Async\\AuditChangedEntitiesProcessor","message_id":"oro.5a955c3202f8b6.66646835","message_body":"{\"entities_inserted\":[{\"entity_class\":\"Sinabs\\\\Bundle\\\\HostingBundle\\\\Entity\\\\Sqlserver\",\"entity_id\":1,\"change_set\":{\"login\":[null,\"root\"],\"password\":[null,\"mysql_emile128#\"],\"driver\":[null,\"mysql\"],\"createdAt\":[null,\"2018-02-27T13:25:05+0000\"],\"host\":[null,{\"entity_class\":\"Sinabs\\\\Bundle\\\\HostingBundle\\\\Entity\\\\Host\",\"entity_id\":1,\"change_set\":[],\"additional_fields\":[]}],\"owner\":[null,{\"entity_class\":\"Oro\\\\Bundle\\\\OrganizationBundle\\\\Entity\\\\BusinessUnit\",\"entity_id\":1,\"change_set\":[],\"additional_fields\":[]}],\"organization\":[null,{\"entity_class\":\"Oro\\\\Bundle\\\\OrganizationBundle\\\\Entity\\\\Organization\",\"entity_id\":1,\"change_set\":[],\"additional_fields\":[]}]},\"additional_fields\":[]}],\"entities_updated\":[{\"entity_class\":\"Sinabs\\\\Bundle\\\\HostingBundle\\\\Entity\\\\Host\",\"entity_id\":1,\"change_set\":{\"sqlserver\":[null,{\"entity_class\":\"Sinabs\\\\Bundle\\\\HostingBundle\\\\Entity\\\\Sqlserver\",\"entity_id\":1,\"change_set\":[],\"additional_fields\":[]}],\"updatedAt\":[\"2018-02-27T13:24:20+0000\",\"2018-02-27T13:25:05+0000\"]},\"additional_fields\":[]}],\"entities_deleted\":[],\"collections_updated\":[],\"timestamp\":1519737906,\"transaction_id\":\"90e46a55-75bb-4d64-9e19-49d190526a7e\",\"user_id\":1,\"user_class\":\"Oro\\\\Bundle\\\\UserBundle\\\\Entity\\\\User\",\"organization_id\":1}","message_properties":{"oro.message_queue.client.topic_name":"oro.data_audit.entities_changed","oro.message_queue.client.processor_name":"oro_dataaudit.async.audit_changed_entities","oro.message_queue.client.queue_name":"oro.default","oro.security.token":"organizationId=1;userId=1;userClass=Oro\\Bundle\\UserBundle\\Entity\\User;roles=ROLE_ADMINISTRATOR","oro-redeliver-count":110},"message_headers":{"content_type":null,"message_id":"oro.5a955c3202f8b6.66646835","timestamp":0},"message_priority":0}[2018-02-27 14:51:01] console.ERROR: An error occurred while running command "'oro:message-queue:consume' --env=prod". Unsupported audit data type "b_password" {"exit_code":0,"exception":"[object] (Oro\\Bundle\\DataAuditBundle\\Exception\\UnsupportedDataTypeException(code: 0): Unsupported audit data type \"b_password\" at /home/sinabs/sites/dev.orocrm.sinabs.fr/vendor/oro/platform/src/Oro/Bundle/DataAuditBundle/Model/AuditFieldTypeRegistry.php:98)","arguments":{"command":"oro:message-queue:consume"},"options":{"env":"prod"}} []February 27, 2018 at 7:16 am #34524>>for the entity field email configuration nothing is shown neither false…
this means that your fields email configuration is not explicitly set and the default value will be taken.
the default value for ‘available_in_template’ option is ‘true’, so it should be available in email templates, please recheck from UI that option ‘Available In Email Templates’ is really set to ‘Yes’.
Also you can configure you field explicitly, e.g.
/**
* @var string
*
* @ORM\Column(name="unix_password", type="b_password")
* @Assert\Type("string")
* @Assert\NotBlank()
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* },
* "email"={
* "available_in_template"=true
* }
* }
* )
*/
protected $unixPassword;
And about auditing custom types, please refer to documentation in DataAuditBaundle
So, as your new type extends string type, try the first part
you need to register new type in your bundle's boot method
<?php
use Oro\Bundle\DataAuditBundle\Model\AuditFieldTypeRegistry;
class MyBundle extends Bundle
{
public function boot() {
AuditFieldTypeRegistry::addType($doctrineType = 'b_password', $auditType = 'text');
}
}
And please take a note, that the audit option will not be available for such custom field types on UI because of configuration, see. But it is still possible to change its value with ‘oro:entity-config:debug’ command, just run it with ‘–help’ option for more details.
Hope, this will help.
And if no – please provide me the code of ‘Sinabs\Bundle\EntityBundle\DBAL\Type\BijectifPasswordType’, so i will be able to recheck your case locally.February 27, 2018 at 8:27 am #34525I have declared my type in app.yml
YAML12345678doctrine:dbal:types:b_password: Sinabs\Bundle\EntityBundle\DBAL\Type\BijectifPasswordTypephone_number: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberTypemapping_types:b_password: stringphone_number: stringMy class BijectifPasswordType :
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364<?php/*** Created by PhpStorm.* User: adrien* Date: 09/02/18* Time: 13:53*/namespace Sinabs\Bundle\EntityBundle\DBAL\Type;use Doctrine\DBAL\Types\Type;use Doctrine\DBAL\Platforms\AbstractPlatform;use Corley\Generator\Base62;class BijectifPasswordType extends Type{/*** @var string*/const NAME = 'b_password';/*** {@inheritdoc}** @param array $fieldDeclaration* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform*/public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform){return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);}/*** {@inheritdoc}** @param string|null $value* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform*/public function convertToPHPValue($value, AbstractPlatform $platform){return (new Base62())->decode($value);}/*** {@inheritdoc}** @param Uuid|null $value* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform*/public function convertToDatabaseValue($value, AbstractPlatform $platform){return (new Base62())->encode($value);}/*** {@inheritdoc}** @return string*/public function getName(){return self::NAME;}}I have follow your instruction to register auditable type:
1234567891011121314151617181920<?php/*** Created by PhpStorm.* User: adrien* Date: 09/02/18* Time: 13:35*/namespace Sinabs\Bundle\EntityBundle;use Symfony\Component\HttpKernel\Bundle\Bundle;use Oro\Bundle\DataAuditBundle\Model\AuditFieldTypeRegistry;class SinabsEntityBundle extends Bundle{public function boot(){AuditFieldTypeRegistry::addType($doctrineType = 'b_password', $auditType = 'string');}}and follow the documentation:
12345678910111213141516171819202122232425262728293031<?php/*** Created by PhpStorm.* User: adrien* Date: 27/02/18* Time: 17:14*/namespace Sinabs\Bundle\EntityBundle\Migrations\Schema\v1_0;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\DataAuditBundle\Migration\Extension\AuditFieldExtension;use Oro\Bundle\DataAuditBundle\Migration\Extension\AuditFieldExtensionAwareInterface;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;class SinabsEntityBundle implements Migration, AuditFieldExtensionAwareInterface{/** @var AuditFieldExtension */private $auditFieldExtension;public function setAuditFieldExtension(AuditFieldExtension $extension){$this->auditFieldExtension = $extension;}public function up(Schema $schema, QueryBag $queries){$this->auditFieldExtension->addType($schema, $doctrineType = 'b_password', $auditType = 'string');}}But now when I can’t clear the cache
1234[LogicException]Type b_password already exists.February 27, 2018 at 8:49 am #34526Please take a look into AuditFieldTypeRegistry – so, you do not need a migration because your ‘b_password’ field is based on ‘string’ type and its changes will be stored in ‘old_text’ & ‘new_text’ columns that is already exists in DB (‘oro_audit_field’ table), the only thing that is needed
public function boot()
{
AuditFieldTypeRegistry::addType($doctrineType = 'b_password', $auditType = 'text');
}
please pay attention to “$auditType = ‘text’“`February 27, 2018 at 9:22 am #34527And as for
[LogicException]
Type b_password already exists.
try to wrap the ‘addType’ with ‘hasType’ check, the documentation is pretty old and may miss something.
So the final example:
class SinabsEntityBundle extends Bundle
{
public function boot()
{
if (!AuditFieldTypeRegistry::hasType('b_password')) {
AuditFieldTypeRegistry::addType($doctrineType = 'b_password', $auditType = 'text');
}
}
}
February 27, 2018 at 11:14 am #34528I haven’ play the migration below, so just try the addType method in boot method of my bundle but I still got a LogicException ?
I missing something ?
PHP123456789101112131415161718192021222324<?php/*** Created by PhpStorm.* User: adrien* Date: 09/02/18* Time: 13:35*/namespace Sinabs\Bundle\EntityBundle;use Symfony\Component\HttpKernel\Bundle\Bundle;use Oro\Bundle\DataAuditBundle\Model\AuditFieldTypeRegistry;class SinabsEntityBundle extends Bundle{/*** {@inheritdoc}*/public function boot(){AuditFieldTypeRegistry::addType($doctrineType = 'b_password', $auditType = 'text');AuditFieldTypeRegistry::addType($doctrineType = 'phone_number', $auditType = 'text');}}1234[LogicException]Type b_password already exists.February 27, 2018 at 11:49 am #34529Sorry I haven’t read the CLASS.
PHP12345678910111213141516/*** {@inheritdoc}*/public function boot(){$types = ['b_password' => 'text','phone_number' => 'text'];foreach ($types as $doctrineType => $auditType) {if (!AuditFieldTypeRegistry::hasType($doctrineType)) {AuditFieldTypeRegistry::addType($doctrineType, $auditType);}}}February 27, 2018 at 12:03 pm #34530Huum my fields still not available in email template. On the view page of entity management fieds, those one with my custom type have nothing in the Other section, no options auditable or available in template are shown.
February 27, 2018 at 12:53 pm #34531Just added the annotation explicitly works.
Thank you so much Alexander !
You resolve both my problem, auditability and available in email template.
- AuthorReplies
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.