mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/9871] Allow setting the host/file to load for the version class
PHPBB3-9871
This commit is contained in:
parent
1f7c891da2
commit
00d86a4af1
2 changed files with 45 additions and 3 deletions
|
@ -318,6 +318,7 @@ services:
|
|||
|
||||
version_helper:
|
||||
class: phpbb\version_helper
|
||||
scope: prototype
|
||||
arguments:
|
||||
- @cache
|
||||
- @config
|
||||
|
|
|
@ -14,6 +14,21 @@ namespace phpbb;
|
|||
*/
|
||||
class version_helper
|
||||
{
|
||||
/**
|
||||
* @var string Host
|
||||
*/
|
||||
protected $host = 'version.phpbb.com';
|
||||
|
||||
/**
|
||||
* @var string Path to file
|
||||
*/
|
||||
protected $path = '/phpbb';
|
||||
|
||||
/**
|
||||
* @var string File name
|
||||
*/
|
||||
protected $file = 'versions.json';
|
||||
|
||||
/** @var \phpbb\cache\service */
|
||||
protected $cache;
|
||||
|
||||
|
@ -23,6 +38,13 @@ class version_helper
|
|||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\cache\service $cache
|
||||
* @param \phpbb\config\config $config
|
||||
* @param \phpbb\user $user
|
||||
*/
|
||||
public function __construct(\phpbb\cache\service $cache, \phpbb\config\config $config, \phpbb\user $user)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
|
@ -30,6 +52,23 @@ class version_helper
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set location to the file
|
||||
*
|
||||
* @param string $host Host (e.g. version.phpbb.com)
|
||||
* @param string $path Path to file (e.g. /phpbb)
|
||||
* @param string $file File name (Default: versions.json)
|
||||
* @return version_helper
|
||||
*/
|
||||
public function set_file_location($host, $path, $file = 'versions.json')
|
||||
{
|
||||
$this->host = $host;
|
||||
$this->path = $path;
|
||||
$this->file = $file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for version_compare() that allows using uppercase A and B
|
||||
* for alpha and beta releases.
|
||||
|
@ -142,12 +181,14 @@ class version_helper
|
|||
*/
|
||||
public function get_versions($force_update = false)
|
||||
{
|
||||
$info = $this->cache->get('versioncheck');
|
||||
$cache_file = 'versioncheck_' . $this->host . $this->path . $this->file;
|
||||
|
||||
$info = $this->cache->get($cache_file);
|
||||
|
||||
if ($info === false || $force_update)
|
||||
{
|
||||
$errstr = $errno = '';
|
||||
$info = get_remote_file('version.phpbb.com', '/phpbb', 'versions.json', $errstr, $errno);
|
||||
$info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno);
|
||||
|
||||
if (!empty($errstr))
|
||||
{
|
||||
|
@ -172,7 +213,7 @@ class version_helper
|
|||
}
|
||||
}
|
||||
|
||||
$this->cache->put('versioncheck', $info, 86400); // 24 hours
|
||||
$this->cache->put($cache_file, $info, 86400); // 24 hours
|
||||
}
|
||||
|
||||
return $info;
|
||||
|
|
Loading…
Add table
Reference in a new issue