From e24b01bdd62ff1b34d6da3d56e8cfce7c4be9b04 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 23 Jan 2015 18:34:58 +0300 Subject: [PATCH] Skip non-supported mimes --- lib/db/session.php | 6 ++++++ lib/filter.php | 25 +++++++++++++++++-------- lib/storage.php | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/db/session.php b/lib/db/session.php index ffb79bfc..04bdbe84 100644 --- a/lib/db/session.php +++ b/lib/db/session.php @@ -12,6 +12,8 @@ namespace OCA\Documents\Db; +use OCA\Documents\Filter; + /** * Session management * @@ -47,6 +49,10 @@ class Session extends \OCA\Documents\Db { $genesis = new \OCA\Documents\Genesis($file); list($ownerView, $path) = $file->getOwnerViewAndPath(); + $mimetype = $ownerView->getMimeType($path); + if (!Filter::isSupportedMimetype($mimetype)){ + throw new \Exception( $path . ' is ' . $mimetype . ' and is not supported by Documents app'); + } $oldSession = new Session(); $oldSession->loadBy('file_id', $file->getFileId()); diff --git a/lib/filter.php b/lib/filter.php index e7ef4833..bfd6b598 100644 --- a/lib/filter.php +++ b/lib/filter.php @@ -13,9 +13,9 @@ namespace OCA\Documents; class Filter { - protected static $filters = array(); + protected static $filters = array(); - public static function add($mimetype, $class){ + public static function add($mimetype, $class){ self::$filters[$mimetype] = $class; } @@ -36,9 +36,9 @@ namespace OCA\Documents; } return $data; - } + } - public static function write($content, $mimetype){ + public static function write($content, $mimetype){ $data = array( 'mimetype' => $mimetype, 'content' => $content @@ -55,11 +55,20 @@ namespace OCA\Documents; } return $data; - } + } - public static function getAll(){ + public static function getAll(){ return array_keys(self::$filters); - } + } - } + /** + * Checks if mimetype is supported by the app + * @param string $mimetype - checked mimetype + * @return bool + */ + public static function isSupportedMimetype($mimetype){ + return in_array($mimetype, Storage::getSupportedMimetypes()); + } +} + \ No newline at end of file diff --git a/lib/storage.php b/lib/storage.php index 91a1d240..dc39122f 100644 --- a/lib/storage.php +++ b/lib/storage.php @@ -97,7 +97,7 @@ class Storage { return $documents; } - protected static function getSupportedMimetypes(){ + public static function getSupportedMimetypes(){ return array_merge( array(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), Filter::getAll()