Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit a007d34

Browse files
committed
Merge pull request #1247 from owncloud/mimetypeicon-version-hack
Add version hack to support mimeTypeIcon on different core versions
2 parents eae55ca + 26ffdf3 commit a007d34

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

appinfo/application.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public function __construct (array $urlParams=array()) {
9696
$c->getServer()->getUserFolder(),
9797
$c->query('ContactsIntegration'),
9898
$c->query('Logger'),
99-
$c->getServer()->getL10N('mail'),
100-
$c->getServer()->getMimeTypeDetector()
99+
$c->getServer()->getL10N('mail')
101100
);
102101
});
103102

lib/controller/messagescontroller.php

+20-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use OCP\AppFramework\Http\ContentSecurityPolicy;
2626
use OCP\AppFramework\Http\JSONResponse;
2727
use OCP\AppFramework\Http\TemplateResponse;
28-
use OCP\Files\IMimeTypeDetector;
2928
use OCP\IL10N;
3029
use OCP\Util;
3130

@@ -59,11 +58,6 @@ class MessagesController extends Controller {
5958
*/
6059
private $l10n;
6160

62-
/**
63-
* @var IMimeTypeDetector
64-
*/
65-
private $mimeTypeDetector;
66-
6761
/**
6862
* @var IAccount[]
6963
*/
@@ -78,7 +72,6 @@ class MessagesController extends Controller {
7872
* @param $contactsIntegration
7973
* @param $logger
8074
* @param $l10n
81-
* @param IMimeTypeDetector $mimeTypeDetector
8275
*/
8376
public function __construct($appName,
8477
$request,
@@ -87,16 +80,14 @@ public function __construct($appName,
8780
$userFolder,
8881
$contactsIntegration,
8982
$logger,
90-
$l10n,
91-
IMimeTypeDetector $mimeTypeDetector) {
83+
$l10n) {
9284
parent::__construct($appName, $request);
9385
$this->accountService = $accountService;
9486
$this->currentUserId = $currentUserId;
9587
$this->userFolder = $userFolder;
9688
$this->contactsIntegration = $contactsIntegration;
9789
$this->logger = $logger;
9890
$this->l10n = $l10n;
99-
$this->mimeTypeDetector = $mimeTypeDetector;
10091
}
10192

10293
/**
@@ -384,7 +375,7 @@ private function enrichDownloadUrl($accountId, $folderId, $messageId, $attachmen
384375
]);
385376
$downloadUrl = \OC::$server->getURLGenerator()->getAbsoluteURL($downloadUrl);
386377
$attachment['downloadUrl'] = $downloadUrl;
387-
$attachment['mimeUrl'] = $this->mimeTypeDetector->mimeTypeIcon($attachment['mime']);
378+
$attachment['mimeUrl'] = $this->mimeTypeIcon($attachment['mime']);
388379

389380
if ($this->attachmentIsImage($attachment)) {
390381
$attachment['isImage'] = true;
@@ -469,4 +460,22 @@ private function enhanceMessage($accountId, $folderId, $id, $m, IAccount $accoun
469460
return $json;
470461
}
471462

463+
/**
464+
* Get path to the icon of a file type
465+
*
466+
* @todo Inject IMimeTypeDetector once core 8.2+ is supported
467+
*
468+
* @param string $mimeType the MIME type
469+
*/
470+
private function mimeTypeIcon($mimeType) {
471+
$ocVersion = \OC::$server->getConfig()->getSystemValue('version', '0.0.0');
472+
if (version_compare($ocVersion, '8.2.0', '<')) {
473+
// Version-hack for 8.1 and lower
474+
return \OC_Helper::mimetypeIcon($mimeType);
475+
}
476+
/* @var IMimeTypeDetector */
477+
$mimeTypeDetector = \OC::$server->getMimeTypeDetector();
478+
return $mimeTypeDetector->mimeTypeIcon($mimeType);
479+
}
480+
472481
}

0 commit comments

Comments
 (0)