OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

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.

  • Creator
    Topic
  • #34519

    adriwan_kenoby
    Participant

    Hi Oro Team,

    I have a custom doctrine type register in the application via app.yml

    These type are not auditable nor available in email template.
    The @Config and @ConfigField annotaions are present on entity.
    What step Have I forgotten ?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Author
    Replies
  • #34520

    Alexander
    Moderator

    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 this

    and the field annotation should be

    #34521

    adriwan_kenoby
    Participant

    I 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.

    #34522

    Alexander
    Moderator

    Hi,
    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
    User - Entity Management - Entities - System

    firstName - User - EntityManagement - Entities - System

    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

    #34523

    adriwan_kenoby
    Participant

    Thanks for your time @Alexander,

    the output of previous command are :
    for the entity configuration

    list of field they are all auditable

    for the entity field email configuration nothing is shown neither false…

    in prod.log :

    #34524

    Alexander
    Moderator

    >>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.

    #34525

    adriwan_kenoby
    Participant

    I have declared my type in app.yml

    My class BijectifPasswordType :

    I have follow your instruction to register auditable type:

    and follow the documentation:

    But now when I can’t clear the cache

    #34526

    Alexander
    Moderator

    Please 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’“`

    #34527

    Alexander
    Moderator

    And 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');
    }
    }
    }

    #34528

    adriwan_kenoby
    Participant

    I 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 ?

    #34529

    adriwan_kenoby
    Participant

    Sorry I haven’t read the CLASS.

    #34530

    adriwan_kenoby
    Participant

    Huum 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.

    #34531

    adriwan_kenoby
    Participant

    Just added the annotation explicitly works.

    Thank you so much Alexander !

    You resolve both my problem, auditability and available in email template.

Viewing 12 replies - 1 through 12 (of 12 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top