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

fix: PublishedNewsImagesPermissionsV2UpgradePlugin have error when updating from 6.5.4 to 6.5.5 - EXO-75897 #263

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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 @@ -18,6 +18,8 @@

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -50,7 +52,7 @@ public class PublishedNewsImagesPermissionsV2UpgradePlugin extends UpgradeProduc
private static final Log LOG =
ExoLogger.getLogger(PublishedNewsImagesPermissionsV2UpgradePlugin.class.getName());

private static final String IMAGE_SRC_REGEX = "src=\"/portal/rest/images/?(.+)?\"";
private static final String IMAGE_SRC_REGEX = "src=\"/portal/rest/images/([\\w/]+)\"";

private final RepositoryService repositoryService;

Expand Down Expand Up @@ -84,27 +86,38 @@ public void processUpgrade(String s, String s1) {
long startupTime = System.currentTimeMillis();
LOG.info("Start upgrade of published news images permission");
SessionProvider sessionProvider = null;
boolean hasError = false;
List<String> newsWithError = new ArrayList<>();

try {
sessionProvider = sessionProviderService.getSystemSessionProvider(null);
Session session = sessionProvider.getSession(
repositoryService.getCurrentRepository()
.getConfiguration()
.getDefaultWorkspaceName(),
repositoryService.getCurrentRepository());
repositoryService.getCurrentRepository()
.getConfiguration()
.getDefaultWorkspaceName(),
repositoryService.getCurrentRepository());
QueryManager qm = session.getWorkspace().getQueryManager();
int limit = 10, offset = 0;
String stringQuery =
"select * from exo:news WHERE publication:currentState = 'published' AND jcr:path LIKE '/Groups/spaces/%'";
String
stringQuery =
"select * from exo:news WHERE publication:currentState = 'published' AND jcr:path LIKE '/Groups/spaces/%'";
Query jcrQuery = qm.createQuery(stringQuery, Query.SQL);
boolean hasMoreElements = true;

while (hasMoreElements) {
((QueryImpl) jcrQuery).setOffset(offset);
((QueryImpl) jcrQuery).setLimit(limit);
NodeIterator nodeIterator = jcrQuery.execute().getNodes();
if (nodeIterator != null) {
while (nodeIterator.hasNext()) {
Node newsNode = nodeIterator.nextNode();
updateNewsImagesPermissions(newsNode, session);
try {
updateNewsImagesPermissions(newsNode, session);
} catch (Exception e) {
LOG.error("Error when updating news {}", newsNode.getPath(),e);
hasError = true;
newsWithError.add(newsNode.getPath());
}
}
if (nodeIterator.getSize() < limit) {
// no more elements
Expand All @@ -114,17 +127,26 @@ public void processUpgrade(String s, String s1) {
}
}
}
LOG.info("End updating of '{}' images for '{}' published news . It took {} ms.",
this.imageNewsUpdatedCount,
this.newsCount,
(System.currentTimeMillis() - startupTime));
} catch (Exception e) {
LOG.error("An error occurred when upgrading published images news permissions :", e);
hasError = true;
} finally {
if (sessionProvider != null) {
sessionProvider.close();
}
}
if (hasError) {
throw new IllegalStateException(String.format("End updating of %s images for %s published news . There are %s errors for news %s. It took %s ms.",
this.imageNewsUpdatedCount,
this.newsCount,
newsWithError.size(),
newsWithError,
(System.currentTimeMillis() - startupTime)));
} else {
LOG.info("End updating of '{}' images for '{}' published news . It took {} ms.",
this.imageNewsUpdatedCount,
this.newsCount,
(System.currentTimeMillis() - startupTime));
}
}

private void updateNewsImagesPermissions(Node newsNode, Session session) throws RepositoryException {
Expand Down
Loading