/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.celements.web.plugin.cmd;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;

public class ResetProgrammingRightsCommand {

  private static Log mLogger = LogFactory.getFactory().getInstance(
      ResetProgrammingRightsCommand.class);

  public boolean resetCelements2webRigths(XWikiContext context) {
    int result = 0;
    if (context.getUser().startsWith("xwiki:")) {
      String tenantDbName = context.getDatabase();
      try {
        context.setDatabase("celements2web");
        Session sess = getNewHibSession(context);
        Transaction transaction = sess.beginTransaction();
        Query query = sess.createQuery("update com.xpn.xwiki.doc.XWikiDocument"
            + " set contentAuthor = :username");
        query.setParameter("username", context.getUser());
        result = query.executeUpdate();
        mLogger.info("updated [" + result + "] documents. Set to content author ["
            + context.getUser() + "] in database [" + context.getDatabase() + "].");
        transaction.commit();
      } catch (XWikiException exp) {
        mLogger.error("resetCelements2webRights: failed to get a hibernate session: ", exp);
      } finally {
        context.setDatabase(tenantDbName);
      }
    }
    return (result > 0);
  }

  private Session getNewHibSession(XWikiContext context) throws XWikiException {
    Session session = context.getWiki().getHibernateStore().getSessionFactory().openSession();
    context.getWiki().getHibernateStore().setDatabase(session, context);
    return session;
  }

}

@@ -930,93 +930,8 @@
 d;%0A%0A
-import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A
 impo
@@ -1017,16 +1017,73 @@
 saction;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -1205,16 +1205,22 @@
 private 
+final 
 static L
@@ -1225,22 +1225,27 @@
  Log
- mLogger
+ger LOGGER
  = Log
+ger
 Fact
@@ -1255,37 +1255,15 @@
 .get
-Factory().getInstance(%0A      
+Logger(
 Rese
@@ -1887,23 +1887,22 @@
         
-mLogger
+LOGGER
 .info(%22u
@@ -1913,22 +1913,10 @@
 ed %5B
-%22 + result + %22
+%7B%7D
 %5D do
@@ -1947,19 +1947,48 @@
 author %5B
-%22%0A 
+%7B%7D%5D in database %5B%7B%7D%5D.%22, result,%0A
         
@@ -1990,17 +1990,16 @@
         
-+
  context
@@ -2012,30 +2012,9 @@
 er()
- + %22%5D in database %5B%22 +
+,
  con
@@ -2035,15 +2035,8 @@
 se()
- + %22%5D.%22
 );%0A 
@@ -2113,15 +2113,14 @@
     
-mLogger
+LOGGER
 .err
@@ -2182,17 +2182,17 @@
  session
-:
+.
  %22, exp)

refactor logger to slf4j in ResetProgrammingRightsCommand