Page 1 of 1

Exporter and Cron

PostPosted:Sat Aug 12, 2017 6:37 pm
by alexkcy
Dear all

I am using the scheduler inside openkm to export. However, I found the "com.openkm.core.PathNotFoundException" in the export log. It seems that the path name with specific characters could not be found like ' become amp;#39;. Any clue ?

I am using the following scripts:
Code: Select all
import com.openkm.util.FileLogger;
import com.openkm.bean.ContentInfo;
import com.openkm.api.*;
import com.openkm.util.impexp.*;
import java.io.*;
import java.text.*;
import com.openkm.core.Config;
import java.util.*;
import com.openkm.module.db.stuff.*;

// Configuration parameters
String token = DbSessionManager.getInstance().getSystemToken();
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = "/export/backup/root";
boolean metadata = false;
boolean history = false;

// Start
FileWriter fw = null;
try {
    FileLogger.info(LOG_FILE_NAME, "Started");
    // Open outputstream
    String fileDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String fileName = Config.LOG_DIR + File.separator + LOG_FILE_NAME + "_" + fileDate + ".log";
    File file = new File(fileName);
    fw = new FileWriter(file);
    // Starting the process
    ContentInfo cInfo = OKMFolder.getInstance().getContentInfo(token, repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    ImpExpStats stats = RepositoryExporter.exportDocuments(token, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int) cInfo.getDocuments() + (int) cInfo.getFolders()));
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    try {        if (fw != null) {
            fw.close();        }
    } catch (IOException e1) {        // Ignore
    }
}

Re: Exporter and Cron

PostPosted:Sun Aug 13, 2017 9:02 pm
by jllort
What OpenKM version do you have ?
Do you come from some previous upgrade ?

Re: Exporter and Cron

PostPosted:Mon Aug 14, 2017 7:55 am
by alexkcy
Dear jllort,

I am using 6.3.4, upgraded from 6.3.2 to 6.3.3 to 6.3.4.

I am scratching my head and really have no idea what's happened. According to the source of script, shouldn't have behaved like this.

Regards
Alex

Re: Exporter and Cron

PostPosted:Mon Aug 14, 2017 6:41 pm
by jllort
Try executing this script (https://docs.openkm.com/kcenter/view/ok ... o-630.html) :
Code: Select all
import com.openkm.dao.bean.*;
import com.openkm.dao.*;
import com.openkm.util.*;
import org.hibernate.*;

String qs = "from NodeBase nb where nb.name like '%&%' and nb.uuid NOT IN (select nb.uuid from NodeBase nb where nb.name like '%&%')";
Session session = null;
Transaction tx = null;

try {
    session = HibernateUtil.getSessionFactory().openSession();
    tx = session.beginTransaction();
    Query q = session.createQuery(qs);

    for (NodeBase nBase : q.list()) {
        print(nBase.getUuid() + " -> " + nBase.getName() + "");
        nBase.setName(PathUtils.encodeEntities(nBase.getName()));
        session.update(nBase);
    }

    HibernateUtil.commit(tx);
} catch (Exception e) {
    HibernateUtil.rollback(tx);
    e.printStackTrace();
} finally {
    HibernateUtil.close(session);
}