Skip to content

Cannot completely remove object relation attribute #228

@SalvatorePollaci

Description

@SalvatorePollaci

I have run the following migration to remove the 'product_categories' object relation list attribute(list of 'product_category' content type objects) from my 'recipe' content type:

-
    type: content_type
    mode: update
    content_type_group: Content
    identifier: recipe
    remove_attributes: [product_categories]

Now if I view the 'recipe' content type definition from eZ's backoffice I no longer see the 'product_categories' object relation list attribute, BUT, from a recipe content objects 'Relations' tab I still see the relation with the previously associated product category.

recipe_product_category_related_objects

So now If I try to update such recipe content via eZ's ContentService(eZ\Publish\Core\Repository\ContentService) updateContent method I get the following notice 'Notice: Trying to get property of non-object' from
vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/RelationProcessor.php processFieldRelations method.

public function processFieldRelations(
        array $inputRelations,
        $sourceContentId,
        $sourceContentVersionNo,
        ContentType $contentType,
        array $existingRelations = array()
    ) {
        // Map existing relations for easier handling
        $mappedRelations = array();
        foreach ($existingRelations as $relation) {
            if ($relation->type === Relation::FIELD) {
                $fieldDefinitionId = $contentType->getFieldDefinition($relation->sourceFieldDefinitionIdentifier)->id;
                $mappedRelations[$relation->type][$fieldDefinitionId][$relation->destinationContentInfo->id] = $relation;
            }
            // Using bitwise AND as Legacy Stack stores COMMON, LINK and EMBED relation types
            // in the same entry using bitmask
            if ($relation->type & Relation::LINK) {
                $mappedRelations[Relation::LINK][$relation->destinationContentInfo->id] = $relation;
            }
            if ($relation->type & Relation::EMBED) {
                $mappedRelations[Relation::EMBED][$relation->destinationContentInfo->id] = $relation;
            }
        }

Simply put, the previous version of the 'recipe' content still contains the 'product_categories' relation, but now the relation's 'sourceFieldDefinitionIdentifier'

$relation->sourceFieldDefinitionIdentifier

is null, resulting in the highlighted notice.
On the other hand, if I re-publish the recipe content from eZ's backoffice, all goes well, and the relation is no longer visible from the 'Relations' tab.

Is this a bug in eZ Migration Bundle? If so, how can I programmatically re-publish the recipe contents without such notices?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions