Initial import
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
class ImportOCRJob extends Job {
|
||||
|
||||
public static function jobs() { return 1; }
|
||||
|
||||
public $upload_id;
|
||||
|
||||
public function __construct($upload_id) {
|
||||
parent::__construct("upload:" . $upload_id);
|
||||
$this->upload_id = $upload_id;
|
||||
}
|
||||
|
||||
public function run() {
|
||||
|
||||
$pdf = false;
|
||||
|
||||
$doc = new Upload($this->upload_id);
|
||||
$doc->ocr = "P";
|
||||
$doc->save();
|
||||
$pdf = $doc->getPDF();
|
||||
|
||||
if (!$pdf) {
|
||||
$this->fail();
|
||||
$doc->ocr = "F";
|
||||
$this->status("PDF File Missing");
|
||||
$doc->save();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->status("Processing " . $doc->filename . " with OCR");
|
||||
|
||||
$body = $pdf->text()->get_text();
|
||||
if ($body == "") {
|
||||
$this->status("Running OCR on PDF file");
|
||||
$ocr = new PDF($pdf->path() . "-ocr.pdf");
|
||||
$pdf->ocr($ocr);
|
||||
$ocr->rename($pdf->path(), true);
|
||||
$pdf = $doc->getPDF();
|
||||
$body = $pdf->text()->get_text();
|
||||
}
|
||||
|
||||
$doc->body = $body;
|
||||
|
||||
$docid = IDMatch::find_docid($doc->filename . " " . $body);
|
||||
if ($docid) {
|
||||
$doc->ocr_docid = $docid[0];
|
||||
}
|
||||
|
||||
$doc->ocr = "Y";
|
||||
$doc->save();
|
||||
|
||||
$this->status("Finished");
|
||||
$this->finish();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public function uploadcb($percent) {
|
||||
$this->status("Uploading: " . $percent . "% complete");
|
||||
}
|
||||
|
||||
public function processcb($message) {
|
||||
$this->status($message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user