mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
This update will make the help method fall back to the English content, if it is available.
This commit is contained in:
@@ -14,7 +14,9 @@ namespace FireflyIII\Helpers\Help;
|
||||
|
||||
use Cache;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use Log;
|
||||
use Requests;
|
||||
use Requests_Exception;
|
||||
use Route;
|
||||
|
||||
/**
|
||||
@@ -45,20 +47,28 @@ class Help implements HelpInterface
|
||||
public function getFromGithub(string $language, string $route): string
|
||||
{
|
||||
|
||||
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
|
||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||
$result = Requests::get($uri);
|
||||
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
|
||||
Log::debug(sprintf('Trying to get %s...', $uri));
|
||||
$content = '';
|
||||
try {
|
||||
$result = Requests::get($uri);
|
||||
} catch (Requests_Exception $e) {
|
||||
Log::error($e);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
Log::debug(sprintf('Status code is %d', $result->status_code));
|
||||
|
||||
if ($result->status_code === 200) {
|
||||
$content = $result->body;
|
||||
$content = trim($result->body);
|
||||
}
|
||||
|
||||
|
||||
if (strlen(trim($content)) == 0) {
|
||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||
if (strlen($content) > 0) {
|
||||
Log::debug('Content is longer than zero. Expect something.');
|
||||
$converter = new CommonMarkConverter();
|
||||
$content = $converter->convertToHtml($content);
|
||||
}
|
||||
$converter = new CommonMarkConverter();
|
||||
$content = $converter->convertToHtml($content);
|
||||
|
||||
return $content;
|
||||
|
||||
@@ -83,7 +93,16 @@ class Help implements HelpInterface
|
||||
*/
|
||||
public function inCache(string $route, string $language):bool
|
||||
{
|
||||
return Cache::has('help.' . $route . '.' . $language);
|
||||
$result = Cache::has('help.' . $route . '.' . $language);
|
||||
if ($result) {
|
||||
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
|
||||
}
|
||||
if (!$result) {
|
||||
Log::debug(sprintf('Cache does not have this entry: %s', 'help.' . $route . '.' . $language));
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +115,8 @@ class Help implements HelpInterface
|
||||
*/
|
||||
public function putInCache(string $route, string $language, string $content)
|
||||
{
|
||||
Cache::put('help.' . $route . '.' . $language, $content, 10080); // a week.
|
||||
$key = 'help.' . $route . '.' . $language;
|
||||
Log::debug(sprintf('Will store entry in cache: %s', $key));
|
||||
Cache::put($key, $content, 10080); // a week.
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user