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

[ERM-13] Revert changes upon unsuccessfull rollout #26

Merged
merged 1 commit into from
Oct 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.commons.lang3.time.StopWatch;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
Expand Down Expand Up @@ -188,10 +190,18 @@ private RolloutStatus rollout(RolloutItem targetItem, PageManager pageManager, b
status.setSuccess(false);
String message = String.format("Item rollout failed, master: %s, target: %s", masterPath, targetPath);
LOG.error(message, e);
discardUnsavedChanges(masterPage.get());
}
return status;
}

private static void discardUnsavedChanges(Page masterPage) {
Optional.of(masterPage)
.map(page -> page.adaptTo(Resource.class))
.map(Resource::getResourceResolver)
.ifPresent(ResourceResolver::revert);
}

private RolloutManager.RolloutParams toRolloutParams(Page masterPage, String targetPath, boolean isDeep) {
RolloutManager.RolloutParams params = new RolloutManager.RolloutParams();
params.master = masterPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RolloutServletTest {
"/content/we-retail/ch/ca-es-ch-livecopy/experience"
);

private final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
private final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK);

@Mock
private RolloutManager rolloutManager;
Expand Down
Loading