Skip to content

Commit 2316e2f

Browse files
committed
fix(PageresBookmarkPreviewer): Use IBinaryFinder
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 7319e34 commit 2316e2f

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

lib/Service/Previewers/PageresBookmarkPreviewer.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
use OCA\Bookmarks\Contract\IImage;
1414
use OCA\Bookmarks\Db\Bookmark;
1515
use OCA\Bookmarks\Image;
16+
use OCP\IBinaryFinder;
1617
use OCP\IConfig;
1718
use OCP\ITempManager;
1819
use Psr\Log\LoggerInterface;
20+
use function exec;
1921

2022
class PageresBookmarkPreviewer implements IBookmarkPreviewer {
2123
public const CACHE_PREFIX = 'bookmarks.PageresPreviewService';
@@ -32,11 +34,18 @@ class PageresBookmarkPreviewer implements IBookmarkPreviewer {
3234
* @var IConfig
3335
*/
3436
private $config;
35-
36-
public function __construct(ITempManager $tempManager, LoggerInterface $logger, IConfig $config) {
37+
private IBinaryFinder $binaryFinder;
38+
39+
public function __construct(
40+
ITempManager $tempManager,
41+
LoggerInterface $logger,
42+
IConfig $config,
43+
IBinaryFinder $binaryFinder,
44+
) {
3745
$this->tempManager = $tempManager;
3846
$this->logger = $logger;
3947
$this->config = $config;
48+
$this->binaryFinder = $binaryFinder;
4049
}
4150

4251
/**
@@ -49,8 +58,8 @@ public function getImage($bookmark, $cacheOnly = false): ?IImage {
4958
return null;
5059
}
5160

52-
$serverPath = self::getPageresPath();
53-
if ($serverPath === null || $cacheOnly) {
61+
$serverPath = $this->binaryFinder->findBinaryPath('pageres');
62+
if ($serverPath === false || $cacheOnly) {
5463
return null;
5564
}
5665

@@ -100,17 +109,4 @@ protected function fetchImage(string $serverPath, string $url): Image {
100109

101110
throw new Exception("Pageres Error\nCommand: {$cmd}\nOutput: " . implode(' ' . PHP_EOL, $output) . PHP_EOL);
102111
}
103-
104-
/**
105-
* @return null|string
106-
*/
107-
public static function getPageresPath(): ?string {
108-
@exec('which pageres', $serverPath);
109-
$path = trim(implode("\n", $serverPath));
110-
if (!empty($path) && is_readable($path)) {
111-
return $path;
112-
}
113-
114-
return null;
115-
}
116112
}

0 commit comments

Comments
 (0)