Skip to content

Historization: dependencies not found by looping through route parameters #17

@GeneraleCauchemar

Description

@GeneraleCauchemar
  • Version: develop

I have these two entities, with a ManyToOne relationship, bidirectionnal:

/**
 * @ORM\Entity(repositoryClass=MenuElementRepository::class)
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="site", type="string")
 * @ORM\DiscriminatorMap({
 *     "site_instit" = "MenuElementInstit",
 *     "site_loc" = "MenuElementLoc"
 * })
 */
abstract class MenuElement implements RoutableModelInterface, HistorizableUrlModelInterface, HasSeoMetadataInterface
{
    use HistorizableUrlTrait, SeoMetadataTrait;

    /**
     * @ORM\OneToMany(targetEntity=Page::class, mappedBy="menuElement")
     */
    private $pages;

    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $slug;

    ...
}
/**
 * @ORM\Entity(repositoryClass=PageRepository::class)
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="site", type="string")
 * @ORM\DiscriminatorMap({
 *     "site_instit" = "PageInstit",
 *     "site_prog" = "PageProg",
 *     "site_loc" = "PageLoc"
 * })
 */
abstract class Page implements RoutableModelInterface, HistorizableUrlModelInterface, HasSeoMetadataInterface
{
    use HistorizableUrlTrait, SeoMetadataTrait;

    /**
     * @ORM\ManyToOne(targetEntity=MenuElement::class, inversedBy="pages")
     */
    private $menuElement;

    /**
     * @ORM\Column(type="string", length=255)
     */
    protected $slug;

    ...
}

The route scheme for Page is /{menuElement.slug}/{slug} (and just /{slug} for MenuElement). So, when I modify the $slug on a MenuElement instance, I need a redirection to be added to umanit_seo_url_history for both my MenuElement and the Pages linked to it.

I've looked at the UrlHistoryWriter->postLoad() method that adds entities related to the entity being updated to the cache, to allow historization of dependencies on onFlush event and I'm not quite sure the way it's written now allows it to work.

From what I gather, using my example:

  • we get the Route for the current entity (MenuElement, or rather MenuElementInstit in my case) and create a reflection entity
  • we then loop on the route parameters (in my case, for MenuElementInstit, it's just slug), get the reflection property for each one from the reflection entity
  • for each annotation on $slug, we look for the targetEntity property...

Which $slug doesn't have, because the targetEntity is on the $pages property.
I'm not sure why we are looking for a dependency through the route parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions