48 lines
904 B
PHP
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");
|
|
}
|
|
}
|
|
}
|