How to change or remove ownership scope in OroCRM entity configuration

Every OroCRM developer can face with a situation when there is a necessity to change a configuration for the entity config in the bundle. And it is no problem if we have an ability to remove a full bundle with the database tables. Recently, we’ve tried to change the ownership scope for the existing entity, but we could not delete the tables because there were a lot of data.

So, we’ve tried to change a code for ownership scope and run the following command:

 php app/console oro:entity-config:update --force

Unfortunately, it has been failed – as a result, the config for the entity was not changed. So, we had to spend much time to find the way out and finally we could do it. Therefore, continue reading our article to see the recommendations on how it works.

Let’s say, we have an entity’s config:

/** 
* Atwixentity
 *
 * @ORM\Table(name="atwix_entity")
 * @ORM\Entity()
 * @ORM\HasLifecycleCallbacks
 * @Config(
 *     routeName="atwix_entity_index",
 *     defaultValues={
 *        "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"
 *         },
 *         "security"={
 *            "type"="ACL",
 *             "group_name"=""
 *         },
 *         "note"={
 *             "immutable"=true
 *        }
 *     }
 * )
 */

We need to change the ownership scope – for this, just remove a full ownership scope. Note that first of all, we should remove it from the config.

/** 
* Atwixentity
 *
 * @ORM\Table(name="atwix_entity")
 * @ORM\Entity()
 * @ORM\HasLifecycleCallbacks
 * @Config(
 *     routeName="atwix_entity_index",
 *     defaultValues={
 *         "security"={
 *            "type"="ACL",
 *             "group_name"=""
 *         },
 *         "note"={
 *             "immutable"=true
 *        }
 *     }
 * )
 */

And then run this command:

  php app/console oro:entity-config:cache:clear

Proceed with one more command:

 php app/console oro:entity-config:debug "Atwix\Bundle\TestBundle\Entity\Atwixentity" --scope ownership --remove

where “Atwix\Bundle\TestBundle\Entity\Atwixentity” is our own entity. On the next step, we need to update the config for our ORO platform:

 php app/console oro:entity-config:update --force

And clear a cache

 php app/console cache:clear

That’s all for this case – our entity’s config has been changed.

Also, we can change some parts of the ownership scope.
For example, remove “organization_field_name” and “organization_column_name” items from this scope.

/**
...
* "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"
 * },
...
*/

When we removed the “organization_field_name” and “organization_column_name” items, we should see:

/**
...
* "ownership"={
 *     "owner_type"="BUSINESS_UNIT",
 *     "owner_field_name"="owner",
 *     "owner_column_name"="business_unit_owner_id"
 * },
...
*/

After that, run the command:

 php app/console oro:entity-config:cache:clear

And then one more command:

php app/console oro:entity-config:debug "Atwix\Bundle\TestBundle\Entity\Atwixentity" --scope ownership --remove

where “Atwix\Bundle\TestBundle\Entity\Atwixentity” is our entity.
On the next stage, we update the config.

 php app/console oro:entity-config:update --force.

And clear a cache

 php app/console cache:clear

Furthermore, to see the result run this debug command:

 php app/console oro:entity-config:debug "Atwix\Bundle\TestBundle\Entity\Atwixentity" --scope ownership

Afterwards, you should see:

 
Class: Atwix\Bundle\TestBundle\Entity\Atwixentity
Mode: default
Values:
Array
(
 [ownership] => Array
 (
 [owner_type] => BUSINESS_UNIT
 [owner_field_name] => owner
 [owner_column_name] => business_unit_owner_id
 )
)

That’s all, now you know how to change the config of your entity by yourself.

Clients

Smart Brands Choose Us.

From startups backed by Mark Cuban and Sir Richard Branson, to some of the biggest eCommerce operations in the world, Atwix helps our clients deliver unparalleled eСommerce experiences. We’re proud to work with the following companies: