• Automatic import

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #11546  by ocaselvaggia
 
jllort wrote:ocaselvaggia can share the script on wiki ? could be useful to other users
Yes, sure!
Where and how to make it?
 #11744  by joako
 
I still haven't forgotten, but I hate to give a script that isn't working 100%.

Right now the OCR will start to write the file, the import script won't check if the file is being written, so what happens is a 0 bytes file is imported and deleted -- before the OCR can finish writing the file. At this point the OCR fails. I will tweak the script and test. At that point I believe it will be ready for normal use.
 #11762  by pavila
 
Please, post here the modified script once completed and I will update the wiki.
 #12424  by rmm
 
I have tried this..I've encountered an error..

Fatal error: Class 'SoapClient' not found in /opt/OpenKM/autoimport.php on line 6

I have checked my php configuration..I have SOAP installed. Anyway, i am running on a proxy server could this be the issue? Thanks a lot.
 #12449  by pavila
 
SoapClient should be in any PHP5 installation, AFAIK.
 #12456  by joako
 
Sorry I never got around to posting this before, been very busy and currently we have paused in-house OpenKM development, but here's what I promised:

My cron script:
Code: Select all
#!/bin/bash
if [ -f /var/run/okmScanCron.pid ]; then
        echo "`date` Scan Cron: Already running, skipping this cycle!"
        exit 2
fi
touch /var/run/okmScanCron.pid
for file in /opt/openkm/IMPORT/NEW-Scan/*.pdf; do
if [ -d "$file" ]; then
        echo "`date` Scan Cron: Dazed and consufed,  \"$file\" is a directory!"
fi

if [ -z "$file" ]; then
        rm -rf /var/run/okmScanCron.pid
        exit 0
fi

if [ ! -f "$file" ]; then
        rm -rf /var/run/okmScanCron.pid
        exit 0
fi
        if [  -s "$file" ];then
                                if [ $(/usr/sbin/lsof -t $file | wc -l) -ge 1 ];then
                        echo "File $file still being written, skipping"
                else
                        hash1=$(md5sum $file)
                        sleep 5
                        hash2=$(md5sum $file)
                        if [ ! "$hash1" = "$hash2" ];then
                                echo "File $file still being written, skipping"
                        else
                                                 /opt/openkm/import.sh "$file" NEW-Scan
                        fi
                fi
                else
                        echo "`date` Scan Cron:  $file is empty!"
                fi
done;
rm -rf /var/run/okmScanCron.pid
import.sh script:
Code: Select all
#!/bin/bash
# JOAKO Import 1.0.2 - Copyright 2011 Andrew Joakimsen
# Distributed under the terms of the GNU General Public
# License Version 2 and no future versions.
#
# Script to import files into OpenKM and report error/success.
# Requires the PHP import script written by snowman, with a
# few small tweaks.

###################################
###                             ###
###  C O N F I G U R A T I O N  ###
###                             ###
###################################


# OpenKM directory where files are imported to
OKM_IMPORT_DIR=NEW

# Filesystem directory (no trailing slash) where we put imported files (it will be created)
STORE_DIR=/opt/openkm/IMPORT/Archive

# Filesystem directory (no trailing slash) where we put files that encountered import errors
ERROR_STORE_DIR=/opt/openkm/IMPORT/Error

####################################

# First let's see if the runtime condition is sane
if [ -z "$1" ]; then
        echo "JOAKO Import: Missing file name"
        echo "Usage: import.sh [filename] <[target-directory]>"
        exit 1
fi


# If ARG1 is a real file
if [ -d "$1" ]; then
        echo "ERROR: \"$1\" is a directory!"
        exit 1
fi

if [ ! -f "$1" ]; then
        echo "ERROR: \"$1\" Invalid file name "
        exit 1
else
        INFILE=$1
fi

# Check if OKM_IMPORT_DIR was passed as argument
if [ -z "$2" ]; then
        OKM_DIR=$OKM_IMPORT_DIR
else
        OKM_DIR=$2
fi

# Check if the imported files directory exsists
if [ ! -d $STORE_DIR/$OKM_DIR ]; then
        if [ ! -d $STORE_DIR ]; then
                mkdir $STORE_DIR
        fi
        mkdir $STORE_DIR/$OKM_DIR
fi
import.php script:
Code: Select all
<?php

$okmurl="http://doc-server/OpenKM/";
$okmid="okmAdmin";
$okmpw="admin";
$impfile = $argv[1];
$filename =  $argv[2];
$folder =  $argv[3];

$OKMAuth = new SoapClient($okmurl."OKMAuth?wsdl");
$OKMDocument = new SoapClient($okmurl."OKMDocument?wsdl");

// open file and encode if necessary
$handle = fopen($impfile,'rb');
$file_content = fread($handle,filesize($impfile));
fclose($handle);
$encoded = base64_encode($file_content);

// Login
$token = $OKMAuth->login($okmid, $okmpw);
$OKMDocument->createSimple($token,"/okm:root/$folder/$filename",$file_content);

// Logout
$OKMAuth->logout($token);
?>
Working well for me currently. I still feel there's the possibility for issues but I haven't seen much of those lately.
 #17227  by shaardu
 
Can anyone please let me know how to auto import ? I tried with the php script, it didnt work. Also I was wondering how ll php script work with java cron? Anyway can anyone please shed some light on this. Its very urgent/
 #17235  by jllort
 
I suggest you test step my step the joako example starting with php, you can execute from terminal if you have installed php5 ( you're on windows or on linux ? )
 #17241  by shaardu
 
I am on windows. You mean the above version works perfectly? Only I have to install PHP5?
 #17246  by dsc68
 
Here is a BeanShell script that imports files from a directory on the server. Save it as a file with the extention '.bsh' and install it as an OpenKM cron job to run every couple of minutes.
Code: Select all
import javax.jcr.*;
import com.openkm.core.*;
import com.openkm.api.OKMDocument;
import java.io.*;

String token = JcrSessionManager.getInstance().getSystemToken();
Session session = JcrSessionManager.getInstance().get(token);
OKMDocument document = OKMDocument.getInstance();


public class OnlyExt implements FilenameFilter {
  String ext;

  public OnlyExt(String ext) {
    this.ext = "." + ext;
  }

  public boolean accept(File dir, String name) {
    return name.endsWith(ext);
  }
}


File scans = new File("/home/scanner");
Thread.sleep(10000);  // Sleep 10 seconds in case files are still being written
try {
  for (File scan : scans.listFiles(new OnlyExt("pdf"))) {
    
    try {
      document.createSimple(token, "/okm:root/Scans/" + scan.getName(), new FileInputStream(scan));
      scan.delete();
    }catch (Exception e) {
      print("Exception: " + e);
    }
  }
  
} catch (Exception e) {
  print("Exception: " + e);
}
I use this with my network connected scanner. The scanner saves scans as pdfs to a shared folder ('/home/scanner') on the server then this script picks them up, loads them into an OpenKM folder ('/okm:root/Scans') and deletes the originals. I am also going to set up a CUPS print to PDF file queue that will print documents into OpenKM using the same method.

Note: This script only loads PDF files. If you want other files loaded then change the OnlyExt class to accept other file types.
 #17257  by shaardu
 
dude dsc68, fantastic piece of work there....Hats off to yo man, keep it up....As always, thanks jllort and pavila for this wonderful product, you guys are awesome!!!
 #18286  by pavila
 
Glad to read it 8)
  • 1
  • 3
  • 4
  • 5
  • 6
  • 7

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.