Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GeneraleCauchemar opened this issue Nov 6, 2020 · 1 comment

Comments

@GeneraleCauchemar
Copy link
Collaborator

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

@DjLeChuck
Copy link
Member

I have made some changes in the Doctrine event subscriber and I have move the pool management in a new service.

Let me know if it's OK for your use case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants