Code for 4.1.6

This commit is contained in:
James Cole
2016-11-06 16:17:22 +01:00
parent 124ecb1372
commit 69422cc796
233 changed files with 2307 additions and 1889 deletions

View File

@@ -26,6 +26,8 @@ use Route;
*/
class Help implements HelpInterface
{
/** @var string */
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36';
/**
* @param string $route
@@ -35,7 +37,9 @@ class Help implements HelpInterface
*/
public function getFromCache(string $route, string $language): string
{
return Cache::get('help.' . $route . '.' . $language);
$line = sprintf('help.%s.%s', $route, $language);
return Cache::get($line);
}
/**
@@ -49,9 +53,10 @@ class Help implements HelpInterface
$uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
Log::debug(sprintf('Trying to get %s...', $uri));
$opt = ['useragent' => $this->userAgent];
$content = '';
try {
$result = Requests::get($uri);
$result = Requests::get($uri, [], $opt);
} catch (Requests_Exception $e) {
Log::error($e);
@@ -69,6 +74,9 @@ class Help implements HelpInterface
$converter = new CommonMarkConverter();
$content = $converter->convertToHtml($content);
}
if (strlen($content) === 0) {
Log::warning('Raw content length is zero.');
}
return $content;
@@ -93,7 +101,8 @@ class Help implements HelpInterface
*/
public function inCache(string $route, string $language):bool
{
$result = Cache::has('help.' . $route . '.' . $language);
$line = sprintf('help.%s.%s', $route, $language);
$result = Cache::has($line);
if ($result) {
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
}
@@ -115,8 +124,12 @@ class Help implements HelpInterface
*/
public function putInCache(string $route, string $language, string $content)
{
$key = 'help.' . $route . '.' . $language;
Log::debug(sprintf('Will store entry in cache: %s', $key));
Cache::put($key, $content, 10080); // a week.
$key = sprintf('help.%s.%s', $route, $language);
if (strlen($content) > 0) {
Log::debug(sprintf('Will store entry in cache: %s', $key));
Cache::put($key, $content, 10080); // a week.
return;
}
Log::info(sprintf('Will not cache %s because content is empty.', $key));
}
}