Skip to content

Commit

Permalink
Content Sync: add an option to disable recursion and sync a single pa…
Browse files Browse the repository at this point in the history
…ge (#3419)

* Content Sync: Added 'Recursive' option
  • Loading branch information
YegorKozlov authored Oct 1, 2024
1 parent 59c62cf commit 4c2fb59
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
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

0 comments on commit 4c2fb59

Please sign in to comment.