RE: Slide locks lost with upgrade to Jahia 4.1
"Fabrice Marchon" <[email protected]>
| Newsgroups | gmane.comp.cms.jahia.install |
|---|---|
| Message-ID | <[email protected]> |
Thanks Thomas. The script in attachment is working great (all locks were restored) but with a small problem: it seems that the call to "file.lock(true)" works only in memory. In fact, it is "volatile", the locking of a DAVFileAccess object is not saved in the jahia database, because when the server is restarted, every lock is lost! So my question is how to save the modification of the DAVFileAccess ? Using the commit mehtod or anything else ? Fabrice > -----Message d'origine----- > De : Thomas Draier [mailto:[email protected]] > Envoyé : mercredi, 26. juillet 2006 11:03 > À : [email protected] > Objet : Re: Slide locks lost with upgrade to Jahia 4.1 > > Hi Fabrice, > the script looks good to me - just be careful on the fact > that you iterate on all sites, but you check that the user is > an administrator of the current site only. you may rather use > isRoot() instead of isAdminMember(). but anyway, this should work. > thomas
slidelocks_fix.jsp
(text/html, 5.6 KB)
<%@ page language="java" contentType="text/plain"%>
<%@ page import="org.jahia.registries.ServicesRegistry,org.jahia.services.webdav.JahiaWebdavBaseService,org.jahia.services.webdav.DAVFileAccess,org.jahia.services.sites.JahiaSite,org.jahia.params.ParamBean,org.jahia.bin.Jahia,org.jahia.params.AdminParamBean,org.jahia.services.pages.ContentPage,org.jahia.data.JahiaData,org.jahia.services.usermanager.JahiaUser"%>
<%@ page import="java.util.List,java.util.Calendar,java.util.Enumeration,java.util.ArrayList,java.util.HashMap,java.util.Iterator,java.io.PrintWriter,java.io.Writer,javax.servlet.jsp.JspWriter,java.io.IOException"%>
<%!/** lock a WevDAV file if any usage is found */
private void lockDAVFile(DAVFileAccess file, ParamBean jParams) {
if (file != null && jParams != null) {
synchronized (file) {
if (!file.isLocked()) {
if (!file.isCollection()) {
//get usages
List usages = JahiaWebdavBaseService.getInstance()
.findUsages(file.getPath(), jParams, true);
if (usages != null && !usages.isEmpty()) {
//lock file
if (file.lockFile(true)) {
System.out.println("File locked: "
+ file.getPath());
} else {
System.out.println("Cannot lock file: "
+ file.getPath());
}
} else {
//no usage
}
} else {
//file is a collection
}
} else {
//file is already locked
}
}
}//null
}
/** lock a WevDAV file tree */
private void lockDAVCollection(DAVFileAccess file, ParamBean jParams) {
if (file != null && jParams != null) {
//top-down and left-right approach to traverse the file tree
if (!file.isCollection()) {
//file is a real one => try to lock it
lockDAVFile(file, jParams);
} else {
//sanity check in order to exclude some paths
if ((!file.getPath().startsWith("/groups"))
|| ((!file.getPath().startsWith("/users")) && (!file
.getPath().endsWith("/mygroups")))) {
//file is a collection => get its children
List children = file.getChildren();
if (children != null && !children.isEmpty()) {
//iterate over children
Iterator iterator = children.iterator();
while (iterator.hasNext()) {
DAVFileAccess child = (DAVFileAccess) iterator
.next();
if (child != null) {
//recursive call over the child
lockDAVCollection(child, jParams);
}
}
} else {
//no children
}
} else {
//bad file path for the recursion => no iteration over children
System.out.print("Bad file path for the recursion: "
+ file.getPath() + "\n");
}
}
}//null
}
%>
<%//title
out.write("Fix for slide locks on active/published files \n");
out.write("-----------------------------------------------\n\n");
out
.write("Warning: some webdav files may be modified by this script!!!\n");
//jData
JahiaData jData = (JahiaData) request
.getAttribute("org.jahia.data.JahiaData");
if (jData == null) {
HashMap tempEngineMap = (HashMap) request
.getAttribute("org.jahia.engines.EngineHashMap");
if (tempEngineMap != null) {
jData = (JahiaData) tempEngineMap.get("jData");
}
}
//construct the JahiaData objet for the first time
if (jData == null) {
int siteId = 9;//ci
int currentPageId = 20;//homepage
JahiaUser user = (JahiaUser) request.getSession().getAttribute(
ParamBean.SESSION_USER);
JahiaSite site = ServicesRegistry.getInstance()
.getJahiaSitesService().getSite(siteId);
AdminParamBean jParams = new AdminParamBean(request, response,
getServletConfig().getServletContext(), Jahia
.getSettings(), System.currentTimeMillis(),
ParamBean.GET_METHOD, site, user, ContentPage
.getPage(currentPageId));
jParams.setUser(user);
jParams.setOperationMode(ParamBean.EDIT);
jData = new JahiaData(jParams);
}
//user
JahiaUser user = jData.params().getUser();
boolean isRoot = user.isRoot();
if (isRoot) {
out.write("User is the Jahia administrator!\n");
//gets all sites
Enumeration enumSites = ServicesRegistry.getInstance()
.getJahiaSitesService().getSites();
try {
out.write("Script is starting...\n");
out.write("at time: "
+ Calendar.getInstance().getTime().toLocaleString()
+ " \n");
while (enumSites.hasMoreElements()) {
JahiaSite site = (JahiaSite) enumSites.nextElement();
out.write("Processing the site " + site.getSiteKey()
+ "...\n");
//construct the JahiaData objet for each site
int siteId = site.getID();
int currentPageId = site.getHomePageID();
user = (JahiaUser) request.getSession().getAttribute(
ParamBean.SESSION_USER);
AdminParamBean jParams = new AdminParamBean(request,
response, getServletConfig()
.getServletContext(), Jahia
.getSettings(), System
.currentTimeMillis(),
ParamBean.GET_METHOD, site, user, ContentPage
.getPage(currentPageId));
jParams.setUser(user);
jParams.setOperationMode(ParamBean.EDIT);
jData = new JahiaData(jParams);
//create dav file for "/shared" folder
DAVFileAccess collection = new DAVFileAccess(jParams,
site, user, "/shared");
//try to lock the /shared tree
lockDAVCollection(collection, jParams);
//idem for the "/users" folder
collection = new DAVFileAccess(jParams, site, user,
"/users");
//try to lock the /users tree
lockDAVCollection(collection, jParams);
}
out.write("Script successfully ended!\n");
out.write("at time: "
+ Calendar.getInstance().getTime().toLocaleString()
+ " \n");
} catch (Exception e) {
out.write("Exception " + e
+ " occured during processing : \n");
e.printStackTrace(new PrintWriter(out));
}
} else {
//no action
out
.write("User is not the Jahia administrator. The script is not started.\n");
}
%>