Difference between revisions of "Knowledge:Migration from 6.2.6 to 6.2.7"
From OpenKM Documentation
m |
|||
Line 42: | Line 42: | ||
<source lang="java"> | <source lang="java"> | ||
− | com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath(); | + | // com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath(); |
+ | import org.hibernate.HibernateException; | ||
+ | import org.hibernate.Query; | ||
+ | import org.hibernate.Session; | ||
+ | import org.hibernate.Transaction; | ||
+ | import org.slf4j.Logger; | ||
+ | import org.slf4j.LoggerFactory; | ||
+ | import com.openkm.core.DatabaseException; | ||
+ | import com.openkm.dao.bean.NodeBase; | ||
+ | import com.openkm.dao.HibernateUtil; | ||
+ | import com.openkm.core.Config; | ||
+ | |||
+ | Logger log = LoggerFactory.getLogger("com.openkm.migration"); | ||
+ | log.info("Process BEGIN"); | ||
+ | String qs = "from NodeBase nb where nb.parent=:parent"; | ||
+ | Session session = null; | ||
+ | Transaction tx = null; | ||
+ | |||
+ | try { | ||
+ | session = HibernateUtil.getSessionFactory().openSession(); | ||
+ | tx = session.beginTransaction(); | ||
+ | |||
+ | // First level nodes | ||
+ | Query q = session.createQuery(qs).setCacheable(true); | ||
+ | q.setString("parent", Config.ROOT_NODE_UUID); | ||
+ | |||
+ | for (NodeBase nb : q.list()) { | ||
+ | nb.setPath("/" + nb.getName()); | ||
+ | session.update(nb); | ||
+ | log.info("Updated node: {}", nb.getPath()); | ||
+ | |||
+ | // Process in depth | ||
+ | fixNodePathHelper(session, nb); | ||
+ | } | ||
+ | |||
+ | HibernateUtil.commit(tx); | ||
+ | log.debug("Process END"); | ||
+ | } catch (HibernateException e) { | ||
+ | HibernateUtil.rollback(tx); | ||
+ | throw new DatabaseException(e.getMessage(), e); | ||
+ | } finally { | ||
+ | HibernateUtil.close(session); | ||
+ | } | ||
+ | |||
+ | void fixNodePathHelper(Session session, NodeBase parentNode) throws HibernateException { | ||
+ | String qs = "from NodeBase nb where nb.parent=:parent"; | ||
+ | Query q = session.createQuery(qs).setCacheable(true); | ||
+ | q.setString("parent", parentNode.getUuid()); | ||
+ | |||
+ | for (NodeBase nb : q.list()) { | ||
+ | nb.setPath(parentNode.getPath() + "/" + nb.getName()); | ||
+ | session.update(nb); | ||
+ | log.info("Updated node: {}", nb.getPath()); | ||
+ | |||
+ | // Process in depth | ||
+ | fixNodePathHelper(session, nb); | ||
+ | } | ||
+ | } | ||
</source> | </source> | ||
− | |||
− | <source lang=" | + | |
− | + | To see the progress: | |
+ | |||
+ | <source lang="bash"> | ||
+ | $ tail -f $TOMCAT_HOME/log/catalina.log | ||
</source> | </source> | ||
Revision as of 17:10, 2 January 2013
- Download update from http://openkm.com/download/okm/OpenKM-6.2.7.zip (password eMpg8eIjY5)
- Make a backup!!!
- Stop Tomcat
- Edit OpenKM.cfg and set hibernate.hbm2ddl to update
- Replace the OpenKM.war
- Run from your preferred SQL client these queries:
MySQL
alter table OKM_NODE_NOTE modify NNT_TEXT longtext;
PostgreSQL
alter table OKM_NODE_NOTE alter NNT_TEXT TYPE text;
Oracle
alter table OKM_NODE_NOTE modify (NNT_TEXT clob);
If the ALTER TABLE sentence fails in Oracle with ORA-22858, you have another way:
alter table OKM_NODE_NOTE add NNT_TEXT_TMP CLOB;
update OKM_NODE_NOTE set NNT_TEXT_TMP = NNT_TEXT;
alter table OKM_NODE_NOTE drop NNT_TEXT;
alter table OKM_NODE_NOTE rename NNT_TEXT_TMP to NNT_TEXT;
- Start Tomcat again
- Go to Administration > Scripting and execute this script:
// com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath();
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.core.DatabaseException;
import com.openkm.dao.bean.NodeBase;
import com.openkm.dao.HibernateUtil;
import com.openkm.core.Config;
Logger log = LoggerFactory.getLogger("com.openkm.migration");
log.info("Process BEGIN");
String qs = "from NodeBase nb where nb.parent=:parent";
Session session = null;
Transaction tx = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
tx = session.beginTransaction();
// First level nodes
Query q = session.createQuery(qs).setCacheable(true);
q.setString("parent", Config.ROOT_NODE_UUID);
for (NodeBase nb : q.list()) {
nb.setPath("/" + nb.getName());
session.update(nb);
log.info("Updated node: {}", nb.getPath());
// Process in depth
fixNodePathHelper(session, nb);
}
HibernateUtil.commit(tx);
log.debug("Process END");
} catch (HibernateException e) {
HibernateUtil.rollback(tx);
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}
void fixNodePathHelper(Session session, NodeBase parentNode) throws HibernateException {
String qs = "from NodeBase nb where nb.parent=:parent";
Query q = session.createQuery(qs).setCacheable(true);
q.setString("parent", parentNode.getUuid());
for (NodeBase nb : q.list()) {
nb.setPath(parentNode.getPath() + "/" + nb.getName());
session.update(nb);
log.info("Updated node: {}", nb.getPath());
// Process in depth
fixNodePathHelper(session, nb);
}
}
To see the progress:
$ tail -f $TOMCAT_HOME/log/catalina.log
- Enjoy OpenKM 6.2.7!
If you have any weird problem try to stop Tomcat, delete these folders:
- $TOMCAT_HOME/webapps/OpenKM
- $TOMCAT_HOME/work/Catalina/localhost
And start Tomcat again.
Recommended to clear browser cache and Java Plugin cache |