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

Content Sync: add an option to disable recursion and sync a single page #3419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
- #3423 - Redirect Manager - status code is not retaining its value in the dialog after authoring

## 6.6.4 - 2024-08-14
- #3417 - Configurable recursion in Content Sync

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ public List<CatalogItem> getItems(SlingHttpServletRequest request) {
if (rootPath == null) {
throw new IllegalArgumentException("root request parameter is required");
}
boolean recursive = "true".equals(request.getParameter("recursive"));

Resource root = request.getResourceResolver().getResource(rootPath);
if (root == null) {
return Collections.emptyList();
}

List<CatalogItem> items = new ArrayList<>();
new AbstractResourceVisitor() {
@Override
public void visit(Resource res) {
if (!accepts(res)) {
if ((!recursive && !res.getPath().equals(root.getPath())) || !accepts(res)) {
return;
}
JsonObjectBuilder json = Json.createObjectBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,42 @@ public void testCustomExporter() {
assertEquals(path + ".infinity.json", item.getContentUri());
assertEquals(customExporter, item.getCustomExporter());
}

@Test
public void testRecursive() {
doAnswer(invocation -> {
GenericServlet servlet = mock(GenericServlet.class);
doReturn(REDIRECT_SERVLET).when(servlet).getServletName();
return servlet;
}).when(servletResolver).resolveServlet(any(SlingHttpServletRequest.class));

context.create().page("/content/wknd");
context.create().page("/content/wknd/en");
context.create().page("/content/wknd/en/home");
MockSlingHttpServletRequest request = context.request();

request.addRequestParameter("root", "/content/wknd");
request.addRequestParameter("recursive", "true");

List<CatalogItem> items = updateStrategy.getItems(request);
assertEquals(3, items.size());
}

@Test
public void testNonRecursive() {
doAnswer(invocation -> {
GenericServlet servlet = mock(GenericServlet.class);
doReturn(REDIRECT_SERVLET).when(servlet).getServletName();
return servlet;
}).when(servletResolver).resolveServlet(any(SlingHttpServletRequest.class));

context.create().page("/content/wknd");
context.create().page("/content/wknd/en");
context.create().page("/content/wknd/en/home");
MockSlingHttpServletRequest request = context.request();
request.addRequestParameter("root", "/content/wknd");

List<CatalogItem> items = updateStrategy.getItems(request);
assertEquals(1, items.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@
name="delete"
text="Delete resources that exist in the destination but not in the source"
value="true"/>
<recursive
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
name="recursive"
text="Recursive"
checked="{Boolean}true"
value="true"/>
</items>
</checkboxes>
<submit
Expand Down
Loading