From b48e9d187ce6a2a35ea90b4b63c5c971562b68f2 Mon Sep 17 00:00:00 2001 From: nbm Date: Fri, 10 Mar 2006 10:50:56 +0000 Subject: [PATCH] Save time and only try unzip files that have the correct OpenDocument file extensions. --- plugins/ktstandard/contents/OpenDocumentIndexer.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/ktstandard/contents/OpenDocumentIndexer.php b/plugins/ktstandard/contents/OpenDocumentIndexer.php index e4075bd..55fbb6c 100644 --- a/plugins/ktstandard/contents/OpenDocumentIndexer.php +++ b/plugins/ktstandard/contents/OpenDocumentIndexer.php @@ -42,15 +42,36 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger { ); function transform() { + global $default; $iMimeTypeId = $this->oDocument->getMimeTypeId(); $sMimeType = KTMime::getMimeTypeName($iMimeTypeId); $sFileName = $this->oDocument->getFileName(); - if (in_array($sMimeType, array('application/octet-stream', 'application/zip', 'application/x-zip'))) { + $aTestTypes = array('application/octet-stream', 'application/zip', 'application/x-zip'); + if (in_array($sMimeType, $aTestTypes)) { $sExtension = KTMime::stripAllButExtension($sFileName); $sTable = KTUtil::getTableName('mimetypes'); - $sQuery = "SELECT id FROM $sTable WHERE LOWER(filetypes) = ?"; + $sQuery = "SELECT id, mimetypes FROM $sTable WHERE LOWER(filetypes) = ?"; $aParams = array($sExtension); - $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); + $aRow = DBUtil::getOneResult(array($sQuery, $aParams)); + + if (PEAR::isError($aRow)) { + $default->log->debug("ODI: error in query: " . print_r($aRow, true)); + return; + } + if (empty($aRow)) { + $default->log->debug("ODI: query returned entry"); + return; + } + + $id = $aRow['id']; + $mimetype = $aRow['mimetypes']; + $default->log->debug("ODI: query returned: " . print_r($aRow, true)); + + if (in_array($mimetype, $aTestTypes)) { + // Haven't changed, really not an OpenDocument file... + return; + } + if ($id) { $this->oDocument->setMimeTypeId($id); $this->oDocument->update(); -- libgit2 0.21.4