Commit b48e9d187ce6a2a35ea90b4b63c5c971562b68f2
1 parent
022f1f74
Save time and only try unzip files that have the correct OpenDocument
file extensions. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5076 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
24 additions
and
3 deletions
plugins/ktstandard/contents/OpenDocumentIndexer.php
| ... | ... | @@ -42,15 +42,36 @@ class KTOpenDocumentIndexerTrigger extends KTBaseIndexerTrigger { |
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | 44 | function transform() { |
| 45 | + global $default; | |
| 45 | 46 | $iMimeTypeId = $this->oDocument->getMimeTypeId(); |
| 46 | 47 | $sMimeType = KTMime::getMimeTypeName($iMimeTypeId); |
| 47 | 48 | $sFileName = $this->oDocument->getFileName(); |
| 48 | - if (in_array($sMimeType, array('application/octet-stream', 'application/zip', 'application/x-zip'))) { | |
| 49 | + $aTestTypes = array('application/octet-stream', 'application/zip', 'application/x-zip'); | |
| 50 | + if (in_array($sMimeType, $aTestTypes)) { | |
| 49 | 51 | $sExtension = KTMime::stripAllButExtension($sFileName); |
| 50 | 52 | $sTable = KTUtil::getTableName('mimetypes'); |
| 51 | - $sQuery = "SELECT id FROM $sTable WHERE LOWER(filetypes) = ?"; | |
| 53 | + $sQuery = "SELECT id, mimetypes FROM $sTable WHERE LOWER(filetypes) = ?"; | |
| 52 | 54 | $aParams = array($sExtension); |
| 53 | - $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); | |
| 55 | + $aRow = DBUtil::getOneResult(array($sQuery, $aParams)); | |
| 56 | + | |
| 57 | + if (PEAR::isError($aRow)) { | |
| 58 | + $default->log->debug("ODI: error in query: " . print_r($aRow, true)); | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + if (empty($aRow)) { | |
| 62 | + $default->log->debug("ODI: query returned entry"); | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + | |
| 66 | + $id = $aRow['id']; | |
| 67 | + $mimetype = $aRow['mimetypes']; | |
| 68 | + $default->log->debug("ODI: query returned: " . print_r($aRow, true)); | |
| 69 | + | |
| 70 | + if (in_array($mimetype, $aTestTypes)) { | |
| 71 | + // Haven't changed, really not an OpenDocument file... | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + | |
| 54 | 75 | if ($id) { |
| 55 | 76 | $this->oDocument->setMimeTypeId($id); |
| 56 | 77 | $this->oDocument->update(); | ... | ... |