use of org.xwiki.query.QueryException in project celements-blog by celements.
the class ArticleNullDatesMigrator method migrate.
@Override
public void migrate(SubSystemHibernateMigrationManager manager, XWikiContext context) throws XWikiException {
try {
List<String> results = queryManager.createQuery(getXWQL(), Query.XWQL).execute();
LOGGER.debug("Got results for xwql '" + getXWQL() + "': " + results);
if (results != null) {
for (String fullName : results) {
DocumentReference docRef = webUtilsService.resolveDocumentReference(fullName);
context.getWiki().saveDocument(context.getWiki().getDocument(docRef, context), "article null dates migration", context);
}
}
} catch (QueryException qexc) {
LOGGER.error("Exception executing query: " + getXWQL(), qexc);
}
}
use of org.xwiki.query.QueryException in project celements-blog by celements.
the class NewsletterReceiversRemoveDoublesMigrator method migrate.
@Override
public void migrate(SubSystemHibernateMigrationManager manager, XWikiContext context) throws XWikiException {
DocumentReference recObjRef = new DocumentReference(context.getDatabase(), "Celements", "NewsletterReceiverClass");
String xwql = "from doc.object(Celements.NewsletterReceiverClass) as obj";
try {
List<String> receivers = queryManager.createQuery(xwql, Query.XWQL).execute();
Map<String, Object[]> receiversMap = new HashMap<>();
if (receivers != null) {
for (String docName : receivers) {
if (docName != null) {
XWikiDocument recDoc = context.getWiki().getDocument(getWebUtils().resolveDocumentReference(docName), context);
BaseObject recObj = recDoc.getXObject(recObjRef);
String recMail = recObj.getStringValue("email");
int isActive = recObj.getIntValue("isactive", 0);
if (!"".equals(recMail)) {
String recSubscr = recObj.getStringValue("subscribed");
String recKey = recMail + "," + recSubscr;
if (receiversMap.containsKey(recKey)) {
int duplActive = (Integer) receiversMap.get(recKey)[0];
XWikiDocument duplDoc = (XWikiDocument) receiversMap.get(recKey)[1];
if (!recDoc.getDocumentReference().equals(duplDoc.getDocumentReference())) {
if ((isActive == 1) || (duplActive != 1)) {
recDoc.removeXObject(recObj);
context.getWiki().saveDocument(recDoc, "Removed douplicate", context);
} else {
duplDoc.removeXObject((BaseObject) receiversMap.get(recKey)[2]);
context.getWiki().saveDocument(duplDoc, "Removed douplicate", context);
receiversMap.put(recMail + "," + recSubscr, new Object[] { isActive, recDoc, recObj });
}
}
LOGGER.info("Remove duplicate of " + recMail + " - " + recSubscr);
} else {
receiversMap.put(recMail + "," + recSubscr, new Object[] { isActive, recDoc, recObj });
}
} else {
LOGGER.info("Empty NewsletterReceiver found on doc " + recDoc.getDocumentReference());
}
}
}
}
} catch (QueryException qe) {
LOGGER.error("Exception cleaning duplicate newsletter receivers", qe);
}
}
Aggregations