forked from opencats/OpenCATS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild_old_docs.php
61 lines (52 loc) · 2.02 KB
/
rebuild_old_docs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
// This tool will reindex your *.odt, *.rtf and *.docx formats
// Feature to reindex those files has nbeen added by patch on 2011 July, 08
// by Inuits Company. Email: [email protected]
//
// If you used version 0.9.2 or earlier for a while all your RTF, DOCX and ODT
// candidate attachments are not indexed. By running this script once you may
// index all such attachments.
//
// Please run this from CATS root directory.
//
require_once 'config.php';
function rebuild_old_docs() {
$result = mysql_query('SELECT * FROM `attachment` WHERE `text` IS NULL');
include_once('./lib/DocumentToText.php');
$countOK = 0;
$countError = 0;
while ($attachment = mysql_fetch_object($result)) {
$doc2txt = new DocumentToText();
$doc2txt->convert('attachments/' . $attachment->directory_name . $attachment->stored_filename,
$doc2txt->getDocumentType('attachments/' . $attachment->directory_name . $attachment->stored_filename));
if ($doc2txt->isError())
{
$countError++;
print('Error while converting ' . $attachment->stored_filename . " file\n");
}
else
{
$extractedText = $doc2txt->getString();
print('File ' . $attachment->stored_filename." reindexed.\n");
$sql = 'UPDATE `attachment` SET `text` = \'' . addslashes($extractedText) . '\', `md5_sum_text` = \'' . md5($extractedText) . '\' WHERE `attachment_id` = ' . $attachment->attachment_id;
$upd = mysql_query($sql);
if (!$upd) {
$countError++;
print('DB error: ' . mysql_error());
} else {
$countOK++;
}
}
unset($doc2txt);
}
print('Success/Fail counters:' . $countOK . '/' . $countError);
}
//$con = mysql_connect("localhost","root","root");
$con = mysql_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASS);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(DATABASE_NAME, $con);
rebuild_old_docs();
?>