mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-18 22:58:10 +01:00
Merge remote-tracking branch 'EXreaction/ticket/9871-2' into develop
* EXreaction/ticket/9871-2: [ticket/9871] Can set current version to use instead of the phpBB version [ticket/9871] Fix indentation on comment [ticket/9871] Fix test name [ticket/9871] Split fast and slow version tests [ticket/9871] Option to force the stability when checking for updates [ticket/9871] Allow setting the host/file to load for the version class [ticket/9871] Restore get_remote_file_test [ticket/9871] Fix tests [ticket/9871] Typehint and comment on var types [ticket/9871] Mark test as slow [ticket/9871] Restore phpbb_version_compare [ticket/9871] Restore get_remote_file [ticket/9871] Use $request->variable instead of request_var [ticket/9871] Update version check file to use json format
This commit is contained in:
commit
0aa23d203e
@ -17,6 +17,7 @@
|
||||
<!-- IF S_VERSIONCHECK_FAIL -->
|
||||
<div class="errorbox notice">
|
||||
<p>{L_VERSIONCHECK_FAIL}</p>
|
||||
<p>{VERSIONCHECK_FAIL_REASON}</p>
|
||||
<p><a href="{U_VERSIONCHECK_FORCE}">{L_VERSIONCHECK_FORCE_UPDATE}</a> · <a href="{U_VERSIONCHECK}">{L_MORE_INFORMATION}</a></p>
|
||||
</div>
|
||||
<!-- ELSEIF not S_VERSION_UP_TO_DATE -->
|
||||
|
@ -1,52 +1,46 @@
|
||||
<!-- INCLUDE overall_header.html -->
|
||||
|
||||
<a id="maincontent"></a>
|
||||
|
||||
<!-- IF S_VERSION_CHECK -->
|
||||
|
||||
<h1>{L_VERSION_CHECK}</h1>
|
||||
<h1>{L_VERSION_CHECK}</h1>
|
||||
|
||||
<p>{L_VERSION_CHECK_EXPLAIN}</p>
|
||||
<p>{L_VERSION_CHECK_EXPLAIN}</p>
|
||||
|
||||
<!-- IF S_UP_TO_DATE and S_UP_TO_DATE_AUTO -->
|
||||
<div class="successbox">
|
||||
<p>{L_VERSION_UP_TO_DATE_ACP} - <a href="{U_VERSIONCHECK_FORCE}">{L_VERSIONCHECK_FORCE_UPDATE}</a></p>
|
||||
</div>
|
||||
<!-- ELSE -->
|
||||
<div class="errorbox">
|
||||
<p>{L_VERSION_NOT_UP_TO_DATE_ACP} - <a href="{U_VERSIONCHECK_FORCE}">{L_VERSIONCHECK_FORCE_UPDATE}</a></p>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
<!-- IF S_UP_TO_DATE -->
|
||||
<div class="successbox">
|
||||
<p>{L_VERSION_UP_TO_DATE_ACP} - <a href="{U_VERSIONCHECK_FORCE}">{L_VERSIONCHECK_FORCE_UPDATE}</a></p>
|
||||
</div>
|
||||
<!-- ELSE -->
|
||||
<div class="errorbox">
|
||||
<p>{L_VERSION_NOT_UP_TO_DATE_ACP} - <a href="{U_VERSIONCHECK_FORCE}">{L_VERSIONCHECK_FORCE_UPDATE}</a></p>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF NEXT_FEATURE_VERSION -->
|
||||
<div class="errorbox">
|
||||
<p>{UPGRADE_INSTRUCTIONS}</p>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<fieldset>
|
||||
<legend></legend>
|
||||
<fieldset>
|
||||
<legend></legend>
|
||||
<dl>
|
||||
<dt><label>{L_CURRENT_VERSION}</label></dt>
|
||||
<dd><strong><!-- IF S_UP_TO_DATE and not S_UP_TO_DATE_AUTO -->{AUTO_VERSION}<!-- ELSE -->{CURRENT_VERSION}<!-- ENDIF --></strong></dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt><label>{L_LATEST_VERSION}</label></dt>
|
||||
<dd><strong>{LATEST_VERSION}</strong></dd>
|
||||
<dd><strong>{CURRENT_VERSION}</strong></dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<!-- BEGIN updates_available -->
|
||||
<fieldset>
|
||||
<legend></legend>
|
||||
<dl>
|
||||
<dt><label>{L_LATEST_VERSION}</label></dt>
|
||||
<dd><strong>{updates_available.current}</strong></dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt><label>{L_RELEASE_ANNOUNCEMENT}</label></dt>
|
||||
<dd><strong><a href="{updates_available.announcement}">{updates_available.announcement}</a></strong></dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<!-- END updates_available -->
|
||||
|
||||
<!-- IF S_UP_TO_DATE and not S_UP_TO_DATE_AUTO -->
|
||||
{L_UPDATE_INSTRUCTIONS_INCOMPLETE}
|
||||
<br /><br />
|
||||
{UPDATE_INSTRUCTIONS}
|
||||
<br /><br />
|
||||
<!-- ENDIF -->
|
||||
<!-- IF not S_UP_TO_DATE -->
|
||||
{UPDATE_INSTRUCTIONS}
|
||||
<br /><br />
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF not S_UP_TO_DATE -->
|
||||
{UPDATE_INSTRUCTIONS}
|
||||
<br /><br />
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- INCLUDE overall_footer.html -->
|
||||
|
@ -324,3 +324,11 @@ services:
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- %tables.users%
|
||||
|
||||
version_helper:
|
||||
class: phpbb\version_helper
|
||||
scope: prototype
|
||||
arguments:
|
||||
- @cache
|
||||
- @config
|
||||
- @user
|
||||
|
@ -25,7 +25,7 @@ class acp_main
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $config, $db, $cache, $user, $auth, $template, $request;
|
||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
|
||||
|
||||
// Show restore permissions notice
|
||||
if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
|
||||
@ -432,17 +432,19 @@ class acp_main
|
||||
));
|
||||
}
|
||||
|
||||
$latest_version_info = false;
|
||||
if (($latest_version_info = obtain_latest_version_info(request_var('versioncheck_force', false))) === false)
|
||||
$version_helper = $phpbb_container->get('version_helper');
|
||||
try
|
||||
{
|
||||
$template->assign_var('S_VERSIONCHECK_FAIL', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$latest_version_info = explode("\n", $latest_version_info);
|
||||
$recheck = $request->variable('versioncheck_force', false);
|
||||
$updates_available = $version_helper->get_suggested_updates($recheck);
|
||||
|
||||
$template->assign_var('S_VERSION_UP_TO_DATE', empty($updates_available));
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'S_VERSION_UP_TO_DATE' => phpbb_version_compare(trim($latest_version_info[0]), $config['version'], '<='),
|
||||
'S_VERSIONCHECK_FAIL' => true,
|
||||
'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '',
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -24,64 +24,42 @@ class acp_update
|
||||
|
||||
function main($id, $mode)
|
||||
{
|
||||
global $config, $db, $user, $auth, $template, $cache;
|
||||
global $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
||||
global $config, $user, $template, $request;
|
||||
global $phpbb_root_path, $phpEx, $phpbb_container;
|
||||
|
||||
$user->add_lang('install');
|
||||
|
||||
$this->tpl_name = 'acp_update';
|
||||
$this->page_title = 'ACP_VERSION_CHECK';
|
||||
|
||||
// Get current and latest version
|
||||
$errstr = '';
|
||||
$errno = 0;
|
||||
|
||||
$info = obtain_latest_version_info(request_var('versioncheck_force', false));
|
||||
|
||||
if (empty($info))
|
||||
$version_helper = $phpbb_container->get('version_helper');
|
||||
try
|
||||
{
|
||||
trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING);
|
||||
$recheck = $request->variable('versioncheck_force', false);
|
||||
$updates_available = $version_helper->get_suggested_updates($recheck);
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$template->assign_var('S_VERSIONCHECK_FAIL', true);
|
||||
|
||||
$updates_available = array();
|
||||
}
|
||||
|
||||
$info = explode("\n", $info);
|
||||
$latest_version = trim($info[0]);
|
||||
foreach ($updates_available as $branch => $version_data)
|
||||
{
|
||||
$template->assign_block_vars('updates_available', $version_data);
|
||||
}
|
||||
|
||||
$announcement_url = trim($info[1]);
|
||||
$announcement_url = (strpos($announcement_url, '&') === false) ? str_replace('&', '&', $announcement_url) : $announcement_url;
|
||||
$update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update');
|
||||
|
||||
// next feature release
|
||||
$next_feature_version = $next_feature_announcement_url = false;
|
||||
if (isset($info[2]) && trim($info[2]) !== '')
|
||||
{
|
||||
$next_feature_version = trim($info[2]);
|
||||
$next_feature_announcement_url = trim($info[3]);
|
||||
}
|
||||
|
||||
// Determine automatic update...
|
||||
$sql = 'SELECT config_value
|
||||
FROM ' . CONFIG_TABLE . "
|
||||
WHERE config_name = 'version_update_from'";
|
||||
$result = $db->sql_query($sql);
|
||||
$version_update_from = (string) $db->sql_fetchfield('config_value');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$current_version = (!empty($version_update_from)) ? $version_update_from : $config['version'];
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_UP_TO_DATE' => phpbb_version_compare($latest_version, $config['version'], '<='),
|
||||
'S_UP_TO_DATE_AUTO' => phpbb_version_compare($latest_version, $current_version, '<='),
|
||||
'S_VERSION_CHECK' => true,
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&versioncheck_force=1'),
|
||||
'S_UP_TO_DATE' => empty($updates_available),
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&versioncheck_force=1'),
|
||||
|
||||
'LATEST_VERSION' => $latest_version,
|
||||
'CURRENT_VERSION' => $config['version'],
|
||||
'AUTO_VERSION' => $version_update_from,
|
||||
'NEXT_FEATURE_VERSION' => $next_feature_version,
|
||||
'CURRENT_VERSION' => $config['version'],
|
||||
|
||||
'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $announcement_url, $update_link),
|
||||
'UPGRADE_INSTRUCTIONS' => $next_feature_version ? $user->lang('UPGRADE_INSTRUCTIONS', $next_feature_version, $next_feature_announcement_url) : false,
|
||||
'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $update_link),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -3041,7 +3041,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port
|
||||
return $file_info;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Tidy Warnings
|
||||
* Remove all warnings which have now expired from the database
|
||||
* The duration of a warning can be defined by the administrator
|
||||
@ -3150,45 +3150,6 @@ function add_permission_language()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the latest version information
|
||||
*
|
||||
* @param bool $force_update Ignores cached data. Defaults to false.
|
||||
* @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false.
|
||||
* @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours).
|
||||
*
|
||||
* @return string | false Version info on success, false on failure.
|
||||
*/
|
||||
function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400)
|
||||
{
|
||||
global $cache;
|
||||
|
||||
$info = $cache->get('versioncheck');
|
||||
|
||||
if ($info === false || $force_update)
|
||||
{
|
||||
$errstr = '';
|
||||
$errno = 0;
|
||||
|
||||
$info = get_remote_file('version.phpbb.com', '/phpbb',
|
||||
((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
|
||||
|
||||
if (empty($info))
|
||||
{
|
||||
$cache->destroy('versioncheck');
|
||||
if ($warn_fail)
|
||||
{
|
||||
trigger_error($errstr, E_USER_WARNING);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache->put('versioncheck', $info, $ttl);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a particular flag in a bitfield column of a given table.
|
||||
*
|
||||
|
@ -154,14 +154,23 @@ class install_update extends module
|
||||
));
|
||||
|
||||
// Get current and latest version
|
||||
if (($latest_version = $cache->get('_version_info')) === false)
|
||||
$version_helper = $phpbb_container->get('version_helper');
|
||||
try
|
||||
{
|
||||
$this->latest_version = $this->get_file('version_info');
|
||||
$cache->put('_version_info', $this->latest_version);
|
||||
$this->latest_version = $version_helper->get_latest_on_current_branch(true);
|
||||
}
|
||||
else
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
$this->latest_version = $latest_version;
|
||||
$this->latest_version = false;
|
||||
|
||||
$update_info = array();
|
||||
include($phpbb_root_path . 'install/update/index.' . $phpEx);
|
||||
$info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;
|
||||
|
||||
if ($info !== false)
|
||||
{
|
||||
$this->latest_version = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false;
|
||||
}
|
||||
}
|
||||
|
||||
// For the current version we trick a bit. ;)
|
||||
@ -1606,37 +1615,6 @@ class install_update extends module
|
||||
|
||||
switch ($mode)
|
||||
{
|
||||
case 'version_info':
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$info = get_remote_file('version.phpbb.com', '/phpbb',
|
||||
((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
|
||||
|
||||
if ($info !== false)
|
||||
{
|
||||
$info = explode("\n", $info);
|
||||
$info = trim($info[0]);
|
||||
}
|
||||
|
||||
if ($this->test_update !== false)
|
||||
{
|
||||
$info = $this->test_update;
|
||||
}
|
||||
|
||||
// If info is false the fsockopen function may not be working. Instead get the latest version from our update file (and pray it is up-to-date)
|
||||
if ($info === false)
|
||||
{
|
||||
$update_info = array();
|
||||
include($phpbb_root_path . 'install/update/index.' . $phpEx);
|
||||
$info = (empty($update_info) || !is_array($update_info)) ? false : $update_info;
|
||||
|
||||
if ($info !== false)
|
||||
{
|
||||
$info = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'update_info':
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
|
@ -490,6 +490,7 @@ $lang = array_merge($lang, array(
|
||||
'PREVIOUS_VERSION' => 'Previous version',
|
||||
'PROGRESS' => 'Progress',
|
||||
|
||||
'RELEASE_ANNOUNCEMENT' => 'Announcement',
|
||||
'RESULT' => 'Result',
|
||||
'RUN_DATABASE_SCRIPT' => 'Update my database now',
|
||||
|
||||
@ -532,7 +533,7 @@ $lang = array_merge($lang, array(
|
||||
|
||||
<h1>Release announcement</h1>
|
||||
|
||||
<p>Please read <a href="%1$s" title="%1$s"><strong>the release announcement for the latest version</strong></a> before you continue your update process, it may contain useful information. It also contains full download links as well as the change log.</p>
|
||||
<p>Please read the release announcement for the latest version before you continue your update process, it may contain useful information. It also contains full download links as well as the change log.</p>
|
||||
|
||||
<br />
|
||||
|
||||
@ -547,17 +548,11 @@ $lang = array_merge($lang, array(
|
||||
</ul>
|
||||
|
||||
<p>Once uploaded your board will be offline for normal users due to the install directory you uploaded now present.<br /><br />
|
||||
<strong><a href="%2$s" title="%2$s">Now start the update process by pointing your browser to the install folder</a>.</strong><br />
|
||||
<strong><a href="%1$s" title="%1$s">Now start the update process by pointing your browser to the install folder</a>.</strong><br />
|
||||
<br />
|
||||
You will then be guided through the update process. You will be notified once the update is complete.
|
||||
</p>
|
||||
',
|
||||
'UPDATE_INSTRUCTIONS_INCOMPLETE' => '
|
||||
|
||||
<h1>Incomplete update detected</h1>
|
||||
|
||||
<p>phpBB detected an incomplete automatic update. Please make sure you followed every step within the automatic update tool. Below you will find the link again, or go directly to your install directory.</p>
|
||||
',
|
||||
'UPDATE_METHOD' => 'Update method',
|
||||
'UPDATE_METHOD_EXPLAIN' => 'You are now able to choose your preferred update method. Using the FTP upload will present you with a form you need to enter your FTP account details into. With this method the files will be automatically moved to the new location and backups of the old files being created by appending .bak to the filename. If you choose to download the modified files you are able to unpack and upload them to their correct location manually later.',
|
||||
'UPDATE_REQUIRES_FILE' => 'The updater requires that the following file is present: %s',
|
||||
@ -567,7 +562,6 @@ $lang = array_merge($lang, array(
|
||||
'UPDATING_DATA' => 'Updating data',
|
||||
'UPDATING_TO_LATEST_STABLE' => 'Updating database to latest stable release',
|
||||
'UPDATED_VERSION' => 'Updated version',
|
||||
'UPGRADE_INSTRUCTIONS' => 'A new feature release <strong>%1$s</strong> is available. Please read <a href="%2$s" title="%2$s"><strong>the release announcement</strong></a> to learn about what it has to offer, and how to upgrade.',
|
||||
'UPLOAD_METHOD' => 'Upload method',
|
||||
|
||||
'UPDATE_DB_SUCCESS' => 'Database update was successful.',
|
||||
|
271
phpBB/phpbb/version_helper.php
Normal file
271
phpBB/phpbb/version_helper.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb;
|
||||
|
||||
/**
|
||||
* Class to handle version checking and comparison
|
||||
*/
|
||||
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 string Current version installed
|
||||
*/
|
||||
protected $current_version;
|
||||
|
||||
/**
|
||||
* @var null|string Null to not force stability, 'unstable' or 'stable' to
|
||||
* force the corresponding stability
|
||||
*/
|
||||
protected $force_stability;
|
||||
|
||||
/** @var \phpbb\cache\service */
|
||||
protected $cache;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @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;
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
|
||||
if (defined('PHPBB_QA'))
|
||||
{
|
||||
$this->force_stability = 'unstable';
|
||||
}
|
||||
|
||||
$this->current_version = $this->config['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current version
|
||||
*
|
||||
* @param string $version The current version
|
||||
* @return version_helper
|
||||
*/
|
||||
public function set_current_version($version)
|
||||
{
|
||||
$this->current_version = $version;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Over-ride the stability to force check to include unstable versions
|
||||
*
|
||||
* @param null|string Null to not force stability, 'unstable' or 'stable' to
|
||||
* force the corresponding stability
|
||||
* @return version_helper
|
||||
*/
|
||||
public function force_stability($stability)
|
||||
{
|
||||
$this->force_stability = $stability;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for version_compare() that allows using uppercase A and B
|
||||
* for alpha and beta releases.
|
||||
*
|
||||
* See http://www.php.net/manual/en/function.version-compare.php
|
||||
*
|
||||
* @param string $version1 First version number
|
||||
* @param string $version2 Second version number
|
||||
* @param string $operator Comparison operator (optional)
|
||||
*
|
||||
* @return mixed Boolean (true, false) if comparison operator is specified.
|
||||
* Integer (-1, 0, 1) otherwise.
|
||||
*/
|
||||
public function compare($version1, $version2, $operator = null)
|
||||
{
|
||||
return phpbb_version_compare($version1, $version2, $operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not a version is "stable"
|
||||
*
|
||||
* Stable means only numbers OR a pl release
|
||||
*
|
||||
* @param string $version
|
||||
* @return bool Bool true or false
|
||||
*/
|
||||
public function is_stable($version)
|
||||
{
|
||||
$matches = false;
|
||||
preg_match('/^[\d\.]+/', $version, $matches);
|
||||
|
||||
if (empty($matches[0]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->compare($version, $matches[0], '>=');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the latest version for the current branch the user is on
|
||||
*
|
||||
* @param bool $force_update Ignores cached data. Defaults to false.
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function get_latest_on_current_branch($force_update = false)
|
||||
{
|
||||
$versions = $this->get_versions_matching_stability($force_update);
|
||||
|
||||
$self = $this;
|
||||
$current_version = $this->current_version;
|
||||
|
||||
// Filter out any versions less than to the current version
|
||||
$versions = array_filter($versions, function($data) use ($self, $current_version) {
|
||||
return $self->compare($data['current'], $current_version, '>=');
|
||||
});
|
||||
|
||||
// Get the lowest version from the previous list.
|
||||
return array_reduce($versions, function($value, $data) use ($self) {
|
||||
if ($value === null || $self->compare($data['current'], $value, '<'))
|
||||
{
|
||||
return $data['current'];
|
||||
}
|
||||
|
||||
return $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the latest version information
|
||||
*
|
||||
* @param bool $force_update Ignores cached data. Defaults to false.
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function get_suggested_updates($force_update = false)
|
||||
{
|
||||
$versions = $this->get_versions_matching_stability($force_update);
|
||||
|
||||
$self = $this;
|
||||
$current_version = $this->current_version;
|
||||
|
||||
// Filter out any versions less than or equal to the current version
|
||||
return array_filter($versions, function($data) use ($self, $current_version) {
|
||||
return $self->compare($data['current'], $current_version, '>');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the latest version information matching the stability of the current install
|
||||
*
|
||||
* @param bool $force_update Ignores cached data. Defaults to false.
|
||||
* @return string Version info
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function get_versions_matching_stability($force_update = false)
|
||||
{
|
||||
$info = $this->get_versions($force_update);
|
||||
|
||||
if ($this->force_stability !== null)
|
||||
{
|
||||
return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable'];
|
||||
}
|
||||
|
||||
return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the latest version information
|
||||
*
|
||||
* @param bool $force_update Ignores cached data. Defaults to false.
|
||||
* @return string Version info, includes stable and unstable data
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function get_versions($force_update = false)
|
||||
{
|
||||
$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($this->host, $this->path, $this->file, $errstr, $errno);
|
||||
|
||||
if (!empty($errstr))
|
||||
{
|
||||
throw new \RuntimeException($errstr);
|
||||
}
|
||||
|
||||
$info = json_decode($info, true);
|
||||
|
||||
if (empty($info['stable']) || empty($info['unstable']))
|
||||
{
|
||||
$this->user->add_lang('acp/common');
|
||||
|
||||
throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL'));
|
||||
}
|
||||
|
||||
// Replace & with & on announcement links
|
||||
foreach ($info as $stability => $branches)
|
||||
{
|
||||
foreach ($branches as $branch => $branch_data)
|
||||
{
|
||||
$info[$stability][$branch]['announcement'] = str_replace('&', '&', $branch_data['announcement']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->put($cache_file, $info, 86400); // 24 hours
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
}
|
58
tests/version/version_fetch_test.php
Normal file
58
tests/version/version_fetch_test.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* @group slow
|
||||
*/
|
||||
class phpbb_version_helper_fetch_test extends phpbb_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
|
||||
$this->cache = $this->getMockBuilder('\phpbb\cache\service')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->version_helper = new \phpbb\version_helper(
|
||||
$this->cache,
|
||||
new \phpbb\config\config(array(
|
||||
'version' => '3.1.0',
|
||||
)),
|
||||
new \phpbb\user()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_version_phpbb_com()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
|
||||
if (!phpbb_checkdnsrr('version.phpbb.com', 'A'))
|
||||
{
|
||||
$this->markTestSkipped(sprintf(
|
||||
'Could not find a DNS record for hostname %s. ' .
|
||||
'Assuming network is down.',
|
||||
'version.phpbb.com'
|
||||
));
|
||||
}
|
||||
|
||||
$this->version_helper->get_versions();
|
||||
|
||||
// get_versions checks to make sure we got a valid versions file or
|
||||
// throws an exception if we did not. We don't need to test anything
|
||||
// here, but adding an assertion so we do not get a warning about no
|
||||
// assertions in this test
|
||||
$this->assertSame(true, true);
|
||||
}
|
||||
}
|
318
tests/version/version_test.php
Normal file
318
tests/version/version_test.php
Normal file
@ -0,0 +1,318 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_version_helper_test extends phpbb_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
include_once($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
|
||||
$this->cache = $this->getMockBuilder('\phpbb\cache\service')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->version_helper = new \phpbb\version_helper(
|
||||
$this->cache,
|
||||
new \phpbb\config\config(array(
|
||||
'version' => '3.1.0',
|
||||
)),
|
||||
new \phpbb\user()
|
||||
);
|
||||
}
|
||||
|
||||
public function is_stable_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'3.0.0-a1',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'3.0.0-b1',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'3.0.0-rc1',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'3.0.0-RC1',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'3.0.0',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'3.0.0-pl1',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'3.0.0.1-pl1',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'3.1-dev',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
'foobar',
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider is_stable_data
|
||||
*/
|
||||
public function test_is_stable($version, $expected)
|
||||
{
|
||||
$this->assertSame($expected, $this->version_helper->is_stable($version));
|
||||
}
|
||||
|
||||
public function get_suggested_updates_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'1.0.0',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.0.1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.0.1-a1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1-a2',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1-a2',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.0',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.1.0',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.1.1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
array(),
|
||||
),
|
||||
array(
|
||||
'1.1.0-a1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.0-a2',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'1.1' => array(
|
||||
'current' => '1.1.0-a2',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_suggested_updates_data
|
||||
*/
|
||||
public function test_get_suggested_updates($current_version, $versions, $expected)
|
||||
{
|
||||
$version_helper = $this
|
||||
->getMockBuilder('\phpbb\version_helper')
|
||||
->setMethods(array(
|
||||
'get_versions_matching_stability',
|
||||
))
|
||||
->setConstructorArgs(array(
|
||||
$this->cache,
|
||||
new \phpbb\config\config(array(
|
||||
'version' => $current_version,
|
||||
)),
|
||||
new \phpbb\user(),
|
||||
))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$version_helper->expects($this->any())
|
||||
->method('get_versions_matching_stability')
|
||||
->will($this->returnValue($versions));
|
||||
|
||||
$this->assertSame($expected, $version_helper->get_suggested_updates());
|
||||
}
|
||||
|
||||
public function get_latest_on_current_branch_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'1.0.0',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
'1.0.1',
|
||||
),
|
||||
array(
|
||||
'1.0.1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
'1.0.1',
|
||||
),
|
||||
array(
|
||||
'1.0.1-a1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1-a2',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.0',
|
||||
),
|
||||
),
|
||||
'1.0.1-a2',
|
||||
),
|
||||
array(
|
||||
'1.1.0',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
'1.1.1',
|
||||
),
|
||||
array(
|
||||
'1.1.1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.1',
|
||||
),
|
||||
),
|
||||
'1.1.1',
|
||||
),
|
||||
array(
|
||||
'1.1.0-a1',
|
||||
array(
|
||||
'1.0' => array(
|
||||
'current' => '1.0.1',
|
||||
),
|
||||
'1.1' => array(
|
||||
'current' => '1.1.0-a2',
|
||||
),
|
||||
),
|
||||
'1.1.0-a2',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_latest_on_current_branch_data
|
||||
*/
|
||||
public function test_get_latest_on_current_branch($current_version, $versions, $expected)
|
||||
{
|
||||
$version_helper = $this
|
||||
->getMockBuilder('\phpbb\version_helper')
|
||||
->setMethods(array(
|
||||
'get_versions_matching_stability',
|
||||
))
|
||||
->setConstructorArgs(array(
|
||||
$this->cache,
|
||||
new \phpbb\config\config(array(
|
||||
'version' => $current_version,
|
||||
)),
|
||||
new \phpbb\user(),
|
||||
))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$version_helper->expects($this->any())
|
||||
->method('get_versions_matching_stability')
|
||||
->will($this->returnValue($versions));
|
||||
|
||||
$this->assertSame($expected, $version_helper->get_latest_on_current_branch());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user