mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
add support for conversion service pass to IndexedDocument()
This commit is contained in:
parent
6d8dcd8125
commit
0f9fa74bbe
|
@ -179,29 +179,39 @@ class SeedDMS_Lucene_IndexedDocument extends Zend_Search_Lucene_Document {
|
|||
if($version && !$nocontent) {
|
||||
$path = $dms->contentDir . $version->getPath();
|
||||
if(file_exists($path)) {
|
||||
$content = '';
|
||||
$mimetype = $version->getMimeType();
|
||||
$this->mimetype = $mimetype;
|
||||
$cmd = '';
|
||||
$mimeparts = explode('/', $mimetype, 2);
|
||||
if(isset($convcmd[$mimetype])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd[$mimeparts[0].'/*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd['*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
}
|
||||
if($cmd) {
|
||||
$this->cmd = $cmd;
|
||||
try {
|
||||
$content = self::execWithTimeout($cmd, $timeout);
|
||||
if($content['stdout']) {
|
||||
$this->addField(Zend_Search_Lucene_Field::UnStored('content', $content['stdout'], 'utf-8'));
|
||||
if(is_object($convcmd) && (get_class($convcmd) == 'SeedDMS_ConversionMgr')) {
|
||||
if($convcmd->hasService($mimetype, 'text/plain')) {
|
||||
$content = $convcmd->convert($path, $mimetype, 'text/plain');
|
||||
if($content) {
|
||||
self::setContent($content);
|
||||
}
|
||||
if($content['stderr']) {
|
||||
$this->errormsg = $content['stderr'];
|
||||
}
|
||||
} else {
|
||||
$content = '';
|
||||
$cmd = '';
|
||||
$mimeparts = explode('/', $mimetype, 2);
|
||||
if(isset($convcmd[$mimetype])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd[$mimeparts[0].'/*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd['*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
}
|
||||
if($cmd) {
|
||||
$this->cmd = $cmd;
|
||||
try {
|
||||
$content = self::execWithTimeout($cmd, $timeout);
|
||||
if($content['stdout']) {
|
||||
self::setContent($content['stdout']);
|
||||
// $this->addField(Zend_Search_Lucene_Field::UnStored('content', $content['stdout'], 'utf-8'));
|
||||
}
|
||||
if($content['stderr']) {
|
||||
$this->errormsg = $content['stderr'];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,9 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
|
|||
/**
|
||||
* Constructor. Creates our indexable document and adds all
|
||||
* necessary fields to it using the passed in document
|
||||
*
|
||||
* $convcmd can either be an array of conversion commands or
|
||||
* an object of class SeedDMS_ConversionMgr
|
||||
*/
|
||||
public function __construct($dms, $document, $convcmd=null, $nocontent=false, $timeout=5) { /* {{{ */
|
||||
$this->errormsg = '';
|
||||
|
@ -176,29 +179,42 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
|
|||
if($version && !$nocontent) {
|
||||
$path = $dms->contentDir . $version->getPath();
|
||||
if(file_exists($path)) {
|
||||
$content = '';
|
||||
$mimetype = $version->getMimeType();
|
||||
$this->mimetype = $mimetype;
|
||||
$cmd = '';
|
||||
$mimeparts = explode('/', $mimetype, 2);
|
||||
if(isset($convcmd[$mimetype])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd[$mimeparts[0].'/*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd['*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
}
|
||||
if($cmd) {
|
||||
$this->cmd = $cmd;
|
||||
try {
|
||||
$content = self::execWithTimeout($cmd, $timeout);
|
||||
if($content['stdout']) {
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::UnStored('content', $content['stdout']));
|
||||
if(is_object($convcmd) && (get_class($convcmd) == 'SeedDMS_ConversionMgr')) {
|
||||
if($convcmd->hasService($mimetype, 'text/plain')) {
|
||||
$content = $convcmd->convert($path, $mimetype, 'text/plain');
|
||||
if($content) {
|
||||
self::setContent($content);
|
||||
}
|
||||
if($content['stderr']) {
|
||||
$this->errormsg = $content['stderr'];
|
||||
$this->cmd = get_class($convcmd);
|
||||
} else {
|
||||
$this->cmd = 'No service to convert '.$mimetype.' to text/plain';
|
||||
}
|
||||
} else {
|
||||
$content = '';
|
||||
$cmd = '';
|
||||
$mimeparts = explode('/', $mimetype, 2);
|
||||
if(isset($convcmd[$mimetype])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd[$mimeparts[0].'/*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
} elseif(isset($convcmd['*'])) {
|
||||
$cmd = sprintf($convcmd[$mimetype], $path);
|
||||
}
|
||||
if($cmd) {
|
||||
$this->cmd = $cmd;
|
||||
try {
|
||||
$content = self::execWithTimeout($cmd, $timeout);
|
||||
if($content['stdout']) {
|
||||
self::setContent($content['stdout']);
|
||||
// $this->addField(SeedDMS_SQLiteFTS_Field::UnStored('content', $content['stdout']));
|
||||
}
|
||||
if($content['stderr']) {
|
||||
$this->errormsg = $content['stderr'];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user