-
-
Notifications
You must be signed in to change notification settings - Fork 552
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
XWIKI-12987: Relative links are made absolute or even broken after moving a page #3553
Changes from all commits
c8f33eb
456e447
60c169a
c8be6ae
4ff12e2
1ac0e3a
efd557d
6409723
0b077f8
96eb739
079bb3c
1d8b51b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,18 +366,16 @@ void renamePageUsedInMacroContentAndParameters(TestUtils setup, TestReference te | |
|
||
setup.rest().delete(testReference); | ||
|
||
ViewPage standardLinkPage = setup.createPage(sourcePageReference1, "Some content to be linked. number 1"); | ||
ViewPage standardMacroLinkPage = | ||
setup.createPage(sourcePageReference2, "Some content to be linked in macro. number 2"); | ||
ViewPage nestedMacroLinkPage = | ||
setup.createPage(sourcePageReference3, "Some content to be linked in nested macro. number 3"); | ||
setup.createPage(sourcePageReference4, "A page with image to be linked. number 4"); | ||
setup.rest().savePage(sourcePageReference1, "Some content to be linked. number 1", "sourcePage1"); | ||
setup.rest().savePage(sourcePageReference2, "Some content to be linked in macro. number 2", "sourcePage2"); | ||
setup.rest().savePage(sourcePageReference3, "Some content to be linked in nested macro. number 3", | ||
"sourcePage3"); | ||
setup.rest().savePage(sourcePageReference4, "A page with image to be linked. number 4", "sourcePage4"); | ||
AttachmentsPane attachmentsPane = new AttachmentsViewPage().openAttachmentsDocExtraPane(); | ||
File image = new File(testConfiguration.getBrowser().getTestResourcesPath(), "AttachmentIT/image.gif"); | ||
attachmentsPane.setFileToUpload(image.getAbsolutePath()); | ||
attachmentsPane.waitForUploadToFinish("image.gif"); | ||
|
||
ViewPage includeLinkPage = setup.createPage(sourcePageReference5, "A page to be included. number 5"); | ||
setup.rest().savePage(sourcePageReference5, "A page to be included. number 5", "sourcePage5"); | ||
|
||
String testPageContent = "Check out this page: [[type the link label>>doc:%1$s]]\n" + "\n" + "{{warning}}\n" | ||
+ "Withing a macro: Check out this page: [[type the link label>>doc:%2$s]]\n" + "\n" + "{{error}}\n" | ||
|
@@ -390,8 +388,9 @@ void renamePageUsedInMacroContentAndParameters(TestUtils setup, TestReference te | |
+ "Withing a macro: Check out this page: [[type the link label>>doc:%1$s]]\n" | ||
+ "{{/warning}}\n\n" | ||
+ "Final line."; | ||
setup.createPage(testReference, | ||
String.format(testPageContent, sourcePage1, sourcePage2, sourcePage3, sourcePage4, sourcePage5)); | ||
setup.rest().savePage(testReference, | ||
String.format(testPageContent, sourcePage1, sourcePage2, sourcePage3, sourcePage4, sourcePage5), | ||
"testPage"); | ||
|
||
// Wait for the solr indexing to be completed before doing any rename | ||
new SolrTestUtils(setup, testConfiguration.getServletEngine()).waitEmptyQueue(); | ||
|
@@ -511,10 +510,10 @@ void renamePageRelativeLinkPageAndTranslation(TestUtils setup, TestReference tes | |
|
||
// Make sure the link was refactored in both the page and its translation | ||
Page newPage = setup.rest().get(new LocalDocumentReference(newSpace, newName)); | ||
assertEquals("[[" + parent + ".OtherPage.WebHome]]", newPage.getContent()); | ||
assertEquals("[[OtherPage]]", newPage.getContent()); | ||
|
||
newPage = setup.rest().get(new LocalDocumentReference(newSpace, newName, Locale.FRENCH)); | ||
assertEquals("fr [[" + parent + ".OtherPage.WebHome]]", newPage.getContent()); | ||
assertEquals("fr [[OtherPage]]", newPage.getContent()); | ||
} | ||
|
||
@Order(6) | ||
|
@@ -668,4 +667,54 @@ void renameWithIndexingWaiting(String strategy, TestUtils setup, TestReference t | |
setup.rest().delete(otherReference); | ||
} | ||
} | ||
|
||
@Order(9) | ||
@Test | ||
void renameWithRelativeLinks(TestUtils testUtils, TestReference testReference, TestConfiguration testConfiguration) | ||
throws Exception | ||
{ | ||
testUtils.rest().savePage(testReference, "[[Alice]]\n[[Bob]]\n[[Eve]]", "Test relative links"); | ||
SpaceReference rootSpaceReference = testReference.getLastSpaceReference(); | ||
SpaceReference aliceSpace = new SpaceReference("Alice", rootSpaceReference); | ||
testUtils.rest().savePage(new DocumentReference("WebHome", aliceSpace), "Alice page", "Alice"); | ||
SpaceReference bobSpace = new SpaceReference("Bob", rootSpaceReference); | ||
testUtils.rest().savePage(new DocumentReference("WebHome", bobSpace), "[[Alice]]", "Bob"); | ||
|
||
// Wait for an empty queue here to ensure that the deleted page has been removed from the index and links | ||
// won't be updated just because the page is still in the index. | ||
new SolrTestUtils(testUtils, testConfiguration.getServletEngine()).waitEmptyQueue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be needed anymore with XWIKI-22323. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually call it to avoid getting a question when performing the rename operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question is supposed to automatically vanish (it's not a blocker question) as soon as the job is done AFAIU. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well what's sure is that I'm getting a timeout when I remove this and the screenshot shows the question... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to update the PO to support non-blocking questions (maybe it does not find what it expects to see to check if the job is still running when a question is displayed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the problem is more that indexing takes quite some time, in particular with the frequent committing of the index with the default parameters, and the page object most likely just doesn't wait long enough. I have an integration test that explicitly triggers the question and there it works to just continue waiting without answering the question. |
||
|
||
ViewPage viewPage = testUtils.gotoPage(testReference); | ||
RenamePage rename = viewPage.rename(); | ||
rename.getDocumentPicker().setName(rootSpaceReference.getName() + "Foo"); | ||
CopyOrRenameOrDeleteStatusPage statusPage = rename.clickRenameButton().waitUntilFinished(); | ||
assertEquals("Done.", statusPage.getInfoMessage()); | ||
|
||
WikiEditPage wikiEditPage = statusPage.gotoNewPage().editWiki(); | ||
assertEquals("[[Alice]]\n[[Bob]]\n[[Eve]]", wikiEditPage.getContent()); | ||
|
||
SpaceReference newRootSpace = | ||
new SpaceReference(rootSpaceReference.getName() + "Foo", rootSpaceReference.getParent()); | ||
SpaceReference newBobSpace = new SpaceReference("Bob", newRootSpace); | ||
wikiEditPage = WikiEditPage.gotoPage(new DocumentReference("WebHome", newBobSpace)); | ||
assertEquals("[[Alice]]", wikiEditPage.getContent()); | ||
|
||
SpaceReference newAliceSpace = new SpaceReference("Alice", newRootSpace); | ||
DocumentReference newAliceReference = new DocumentReference("WebHome", newAliceSpace); | ||
viewPage = testUtils.gotoPage(newAliceReference); | ||
rename = viewPage.rename(); | ||
rename.getDocumentPicker().setName("Alice2"); | ||
statusPage = rename.clickRenameButton().waitUntilFinished(); | ||
assertEquals("Done.", statusPage.getInfoMessage()); | ||
|
||
SpaceReference alice2Space = new SpaceReference("Alice2", newRootSpace); | ||
DocumentReference alice2Reference = new DocumentReference("WebHome", alice2Space); | ||
wikiEditPage = WikiEditPage.gotoPage(new DocumentReference("WebHome", newRootSpace)); | ||
String serializedAlice2Reference = testUtils.serializeLocalReference(alice2Reference); | ||
assertEquals(String.format("[[%s]]%n[[Bob]]%n[[Eve]]", serializedAlice2Reference), wikiEditPage.getContent()); | ||
|
||
// FIXME: ideally this one should be refactored too, however it's not a regression. | ||
//wikiEditPage = WikiEditPage.gotoPage(new DocumentReference("WebHome", newBobSpace)); | ||
//assertEquals(String.format("[[%s]]", serializedAlice2Reference), wikiEditPage.getContent()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ | |
import org.xwiki.extension.job.internal.UninstallJob; | ||
import org.xwiki.extension.repository.CoreExtensionRepository; | ||
import org.xwiki.job.Job; | ||
import org.xwiki.job.JobContext; | ||
import org.xwiki.job.JobException; | ||
import org.xwiki.job.JobExecutor; | ||
import org.xwiki.job.annotation.Serializable; | ||
|
@@ -151,6 +152,7 @@ | |
import org.xwiki.query.QueryFilter; | ||
import org.xwiki.refactoring.batch.BatchOperationExecutor; | ||
import org.xwiki.refactoring.internal.ReferenceUpdater; | ||
import org.xwiki.refactoring.internal.job.AbstractCopyOrMoveJob; | ||
import org.xwiki.rendering.async.AsyncContext; | ||
import org.xwiki.rendering.block.Block; | ||
import org.xwiki.rendering.internal.transformation.MutableRenderingContext; | ||
|
@@ -4968,9 +4970,19 @@ private void updateLinksForRename(XWikiDocument sourceDoc, DocumentReference new | |
List<DocumentReference> backlinkDocumentReferences, List<DocumentReference> childDocumentReferences, | ||
XWikiContext context) throws XWikiException | ||
{ | ||
// FIXME: that's ugly we should use something else. | ||
JobContext jobContext = Utils.getComponent(JobContext.class); | ||
Job currentJob = jobContext.getCurrentJob(); | ||
|
||
Map<EntityReference, EntityReference> updatedReferences = | ||
Map.of(sourceDoc.getDocumentReference(), newDocumentReference); | ||
if (currentJob instanceof AbstractCopyOrMoveJob) { | ||
updatedReferences = ((AbstractCopyOrMoveJob) currentJob).getSelectedEntities(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tmortagne for that one you suggested:
wdyt, the PR is already quite complex, isn't it something we can address later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, it's not a blocker, just a cleaner thing to do eventually for the long run. As long as we don't introduce public API for the current version, it's not adding too much debt. |
||
// Step 1: Refactor the relative links contained in the document to make sure they are relative to the new | ||
// document's location. | ||
getReferenceUpdater().update(newDocumentReference, sourceDoc.getDocumentReference(), newDocumentReference); | ||
getReferenceUpdater().update(newDocumentReference, sourceDoc.getDocumentReference(), newDocumentReference, | ||
updatedReferences); | ||
|
||
// Step 2: For each child document, update its parent reference. | ||
if (childDocumentReferences != null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not good anymore: the
OtherPage
doesn't exist so we just check that the unexisting relative link is not updated. But we don't check anymore that link are refactored in a translation page. We need to improve it.