aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/config/services.yml2
-rw-r--r--phpBB/phpbb/file_downloader.php25
-rw-r--r--phpBB/phpbb/version_helper.php8
-rw-r--r--tests/version/version_fetch_test.php1
-rw-r--r--tests/version/version_test.php3
5 files changed, 17 insertions, 22 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index 8a58a078f8..8667cbbf84 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -111,8 +111,6 @@ services:
file_downloader:
class: phpbb\file_downloader
- arguments:
- - @user
http_kernel:
class: Symfony\Component\HttpKernel\HttpKernel
diff --git a/phpBB/phpbb/file_downloader.php b/phpBB/phpbb/file_downloader.php
index 0f33ae9941..2d5d9a7516 100644
--- a/phpBB/phpbb/file_downloader.php
+++ b/phpBB/phpbb/file_downloader.php
@@ -15,9 +15,6 @@ namespace phpbb;
class file_downloader
{
- /** @var \phpbb\user */
- protected $user;
-
/** @var string Error string */
public $error_string = '';
@@ -25,16 +22,6 @@ class file_downloader
public $error_number = 0;
/**
- * Constructor
- *
- * @param \phpbb\user $user phpBB user object
- */
- public function __construct(user $user)
- {
- $this->user = $user;
- }
-
- /**
* Retrieve contents from remotely stored file
*
* @param string $host File host
@@ -45,6 +32,9 @@ class file_downloader
*
* @return mixed File data as string if file can be read and there is no
* timeout, false if there were errors or the connection timed out
+ *
+ * @throws \RuntimeException If data can't be retrieved and no error
+ * message is returned
*/
function get($host, $directory, $filename, $port = 80, $timeout = 6)
{
@@ -75,8 +65,7 @@ class file_downloader
}
else if (stripos($line, '404 not found') !== false)
{
- $this->error_string = $this->user->lang('FILE_NOT_FOUND', $filename);
- return false;
+ throw new \RuntimeException(array('FILE_NOT_FOUND', $filename));
}
}
@@ -84,8 +73,7 @@ class file_downloader
if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
{
- $this->error_string = $this->user->lang['FSOCK_TIMEOUT'];
- return false;
+ throw new \RuntimeException('FSOCK_TIMEOUT');
}
}
@fclose($socket);
@@ -99,8 +87,7 @@ class file_downloader
}
else
{
- $this->error_string = $this->user->lang['FSOCK_DISABLED'];
- return false;
+ throw new \RuntimeException('FSOCK_DISABLED');
}
}
diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php
index 3b455ec5ba..d7f1f02678 100644
--- a/phpBB/phpbb/version_helper.php
+++ b/phpBB/phpbb/version_helper.php
@@ -257,7 +257,13 @@ class version_helper
$errstr = $errno = '';
$this->file_downloader->set_error_number($errno)
->set_error_string($errstr);
- $info = $this->file_downloader->get($this->host, $this->path, $this->file);
+ try {
+ $info = $this->file_downloader->get($this->host, $this->path, $this->file);
+ }
+ catch (\RuntimeException $exception)
+ {
+ throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage()));
+ }
if (!empty($errstr))
{
diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php
index 05eac58a52..cfc87183cf 100644
--- a/tests/version/version_fetch_test.php
+++ b/tests/version/version_fetch_test.php
@@ -33,6 +33,7 @@ class phpbb_version_helper_fetch_test extends phpbb_test_case
new \phpbb\config\config(array(
'version' => '3.1.0',
)),
+ new \phpbb\file_downloader(),
new \phpbb\user('\phpbb\datetime')
);
}
diff --git a/tests/version/version_test.php b/tests/version/version_test.php
index ba31c79a79..528f1602d6 100644
--- a/tests/version/version_test.php
+++ b/tests/version/version_test.php
@@ -30,6 +30,7 @@ class phpbb_version_helper_test extends phpbb_test_case
new \phpbb\config\config(array(
'version' => '3.1.0',
)),
+ new \phpbb\file_downloader(),
new \phpbb\user('\phpbb\datetime')
);
}
@@ -208,6 +209,7 @@ class phpbb_version_helper_test extends phpbb_test_case
new \phpbb\config\config(array(
'version' => $current_version,
)),
+ new \phpbb\file_downloader(),
new \phpbb\user('\phpbb\datetime'),
))
->getMock()
@@ -318,6 +320,7 @@ class phpbb_version_helper_test extends phpbb_test_case
new \phpbb\config\config(array(
'version' => $current_version,
)),
+ new \phpbb\file_downloader(),
new \phpbb\user('\phpbb\datetime'),
))
->getMock()