Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/9871] Update version check file to use JSON format #2000

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions phpBB/includes/functions_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3119,8 +3119,7 @@ function obtain_latest_version_info($force_update = false, $warn_fail = false, $
$errstr = '';
$errno = 0;

$info = get_remote_file('version.phpbb.com', '/phpbb',
((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno);
$info = get_remote_file('version.phpbb.com', '/phpbb', 'versions.json', $errstr, $errno);

if (empty($info))
{
Expand All @@ -3132,10 +3131,15 @@ function obtain_latest_version_info($force_update = false, $warn_fail = false, $
return false;
}

$cache->put('versioncheck', $info, $ttl);
$cache->put('versioncheck', json_decode($info), $ttl);
}

return $info;
$version = (defined('PHPBB_QA')) ? '30x_qa' : '30x';

return array(
$info[$version]['current'],
$info[$version]['announcement'],
);
}

/**
Expand Down
13 changes: 9 additions & 4 deletions phpBB/install/install_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -1609,13 +1609,18 @@ function get_file($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);
$info = get_remote_file('version.phpbb.com', '/phpbb', 'versions.json', $errstr, $errno);

if ($info !== false)
{
$info = explode("\n", $info);
$info = trim($info[0]);
$info = json_decode($info);

$version = (defined('PHPBB_QA')) ? '30x_qa' : '30x';

$info = array(
$info[$version]['current'],
$info[$version]['announcement'],
);
}

if ($this->test_update !== false)
Expand Down
16 changes: 8 additions & 8 deletions tests/functions/get_remote_file_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function test_version_phpbb_com()
}

$errstr = $errno = null;
$file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno);
$info = get_remote_file($hostname, '/phpbb', 'versions.json', $errstr, $errno);

$this->assertNotEquals(
0,
strlen($file),
strlen($info),
'Failed asserting that the response is not empty.'
);

Expand All @@ -49,27 +49,27 @@ public function test_version_phpbb_com()
'Failed asserting that the error number is 0 (i.e. no error occurred).'
);

$lines = explode("\n", $file);
$info = json_decode($info);

$this->assertGreaterThanOrEqual(
2,
sizeof($lines),
sizeof($info),
'Failed asserting that the version file has at least two lines.'
);

$this->assertStringStartsWith(
'3.',
$lines[0],
$info['30x']['current'],
"Failed asserting that the first line of the version file starts with '3.'"
);

$this->assertNotSame(
false,
filter_var($lines[1], FILTER_VALIDATE_URL),
filter_var($info['30x']['announcement'], FILTER_VALIDATE_URL),
'Failed asserting that the second line of the version file is a valid URL.'
);

$this->assertContains('http', $lines[1]);
$this->assertContains('phpbb.com', $lines[1], '', true);
$this->assertContains('http', $info['30x']['announcement']);
$this->assertContains('phpbb.com', $info['30x']['announcement'], '', true);
}
}