Files
decpdf.site/app/jobs/IndexJob.php
T
2026-06-04 11:13:34 +01:00

48 lines
904 B
PHP

<?php
class IndexJob extends Job {
public static function jobs() { return 5; }
public $revision;
public function __construct($rev) {
parent::__construct("revision:" . $rev);
$this->revision = $rev;
}
public function run() {
$db = DB::getInstance();
$rev = new Revision($this->revision);
$rev->load("body");
$body = $rev->body;
if ($body) {
$body->counted = 'P';
$body->save();
$db->query("DELETE FROM word_index WHERE revision=:rev", ["rev" => $rev->id]);
$words = $body->count_words();
foreach ($words as $word=>$hits) {
$db->query("INSERT INTO word_index (revision, word, hits) VALUES (:rev, :word, :hits)", [
"rev" => $rev->id,
"word" => substr($word, 0, 20),
"hits" => $hits
]);
}
$body->counted = 'Y';
$body->save();
$this->finish();
} else {
$this->fail();
$this->status("No body to count");
}
}
}