/** * @return boolean */ public function checkFilePermission() { return $this->_file->isReadable(); }
/** * returns the extracted fulltext of the given file or an exception in * case of errors * * @param Opus_File $file * @throws Opus_SolrSearch_Index_Exception * @return extracted fulltext */ private function getFileContent(Opus_File $file) { $this->log->debug('extracting fulltext from ' . $file->getPath()); if (!$file->exists()) { $this->log->err($file->getPath() . ' does not exist.'); throw new Opus_SolrSearch_Index_Exception($file->getPath() . ' does not exist.'); } if (!$file->isReadable()) { $this->log->err($file->getPath() . ' is not readable.'); throw new Opus_SolrSearch_Index_Exception($file->getPath() . ' is not readable.'); } if (!$this->hasSupportedMimeType($file)) { $this->log->err($file->getPath() . ' has MIME type ' . $file->getMimeType() . ' which is not supported'); throw new Opus_SolrSearch_Index_Exception($file->getPath() . ' has MIME type ' . $file->getMimeType() . ' which is not supported'); } // Check for cached ... $fulltext = $this->getCachedFileContent($file); if ($fulltext !== false and is_string($fulltext)) { $this->log->info('Found cached fulltext for file ' . $file->getPath()); return $fulltext; } $params = array('extractOnly' => 'true', 'extractFormat' => 'text'); try { $response = $this->getSolrServer('extract')->extract($file->getPath(), $params); // TODO add mime type information $jsonResponse = Zend_Json_Decoder::decode($response->getRawResponse()); if (array_key_exists('', $jsonResponse)) { $fulltext = trim($jsonResponse['']); $this->setCachedFileContent($file, $fulltext); return $fulltext; // TODO evaluate additional data in json response } } catch (Exception $e) { $this->log->err('error while extracting fulltext from file ' . $file->getPath()); throw new Opus_SolrSearch_Index_Exception('error while extracting fulltext from file ' . $file->getPath(), null, $e); } return ''; }