44 lines
884 B
PHP
44 lines
884 B
PHP
<?php
|
|
|
|
class OCRJob extends Job {
|
|
|
|
public static function jobs() { return 1; }
|
|
public $revision;
|
|
|
|
public function __construct($rev) {
|
|
parent::__construct("revision:" . $rev);
|
|
$this->revision = $rev;
|
|
}
|
|
|
|
public function run() {
|
|
$ocr = OCR::find([["revision", "=", $this->revision]])->first();
|
|
if (!$ocr) {
|
|
$ocr = new OCR;
|
|
$ocr->revision = $this->revision;
|
|
$ocr->save();
|
|
}
|
|
|
|
$this->status("Processing");
|
|
|
|
$rev = new Revision($this->revision);
|
|
$pdf = $rev->getPDF();
|
|
$text = $pdf->text()->get_text();
|
|
|
|
print("[" . $text . "]\n");
|
|
|
|
if ($text == "") {
|
|
$this->status("Running OCR on PDF");
|
|
$newpdf = new PDF($pdf->parent() . "/ocr.pdf");
|
|
$pdf->ocr($newpdf);
|
|
$text = $newpdf->text()->get_text();
|
|
}
|
|
|
|
$ocr->body = $text;
|
|
$ocr->save();
|
|
$j = new IndexJob($this->revision);
|
|
$j->queue();
|
|
$this->status("Complete");
|
|
$this->finish();
|
|
}
|
|
}
|