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

Links in the diagram content are not updated when the linked page is moved/renamed #110

Closed
CamiAndrei opened this issue Jan 27, 2020 · 4 comments

Comments

@CamiAndrei
Copy link

The links from the diagram content are not updated when the linked content is moved or renamed.
Steps to reproduce:

  • Create a page A1
  • Insert a link to A1 in a diagram
  • Rename/move A1 page
    Results:
    The links in the diagram are not updated.
@mflorea
Copy link
Collaborator

mflorea commented Feb 12, 2020

First we need to detect when a page is renamed. For this we need to write an event listener. On XWiki 11.1RC1+ we can use the dedicated page rename events. On older versions we need to do some hacks. @lucaa might be able to help us with that. Note that if we want to use the dedicated rename events without increasing the minimum XWiki version we need to use reflection and do some hacks.

Once we are notified when a page is renamed we need to determine which diagram pages have links to the renamed page. This can be done on each rename with a database query, or we could try to use the backlinks table, but for this we would need another event listener that updates the backlinks whenever a diagram is saved (by adding the links from the saved diagram).

Once we know which diagrams have to be updated we need to modify their XML content. The best for this would be to use a stream-based XML parser / serializer because we don't need to load the entire diagram XML in memory, we just need to get to the XML element that holds the link and modify some attribute value.

In any case, this processing should be done asynchronously. It shouldn't block the page rename. It's fine if the diagrams are updated "slowly" in a background thread.

@lucaa
Copy link

lucaa commented Feb 12, 2020

@mflorea Here is how @slauriere (and myself?) hacked this in the past https://github.com/xwiki-contrib/application-page-relations/blob/application-page-relations-2.4/application-page-relations-api/src/main/java/org/xwiki/contrib/pagerelations/internal/PageRelationsRenameEventListener.java#L69 (listening to create and then checking the context by the name or something). I think it was somewhat validated that it's the good way to know if the creation is part of a rename or a regular create.

@mflorea
Copy link
Collaborator

mflorea commented Feb 14, 2020

Thanks @lucaa , this is very helpful.

oanalavinia added a commit to oanalavinia/application-diagram that referenced this issue Mar 17, 2020
oanalavinia added a commit to oanalavinia/application-diagram that referenced this issue Mar 20, 2020
oanalavinia added a commit to oanalavinia/application-diagram that referenced this issue Mar 25, 2020
oanalavinia added a commit to oanalavinia/application-diagram that referenced this issue Mar 27, 2020
oanalavinia added a commit that referenced this issue Mar 27, 2020
@oanalavinia oanalavinia added this to the 1.13 milestone Mar 27, 2020
@oanalavinia
Copy link

For diagrams created before the fix version, an additional save on each diagram page will be needed (to mark the page as a backlink)

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

No branches or pull requests

4 participants