diff options
| -rw-r--r-- | phpBB/config/services.yml | 1 | ||||
| -rw-r--r-- | phpBB/includes/acp/acp_extensions.php | 2 | ||||
| -rw-r--r-- | phpBB/includes/functions_admin.php | 2 | ||||
| -rw-r--r-- | phpBB/language/en/acp/extensions.php | 3 | ||||
| -rw-r--r-- | phpBB/language/en/common.php | 2 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/manager.php | 21 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 30 | ||||
| -rw-r--r-- | tests/dbal/migrator_test.php | 2 | ||||
| -rw-r--r-- | tests/extension/manager_test.php | 2 | ||||
| -rw-r--r-- | tests/extension/metadata_manager_test.php | 24 | ||||
| -rw-r--r-- | tests/functional/extension_acp_test.php | 2 | ||||
| -rw-r--r-- | tests/functional/metadata_manager_test.php | 2 | ||||
| -rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 2 | 
13 files changed, 60 insertions, 35 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 4de47f750f..3bd9182924 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -170,6 +170,7 @@ services:              - @dbal.conn              - @config              - @filesystem +            - @user              - %tables.ext%              - %core.root_path%              - %core.php_ext% diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 88b6a9c270..3d3cfb7f16 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -70,7 +70,7 @@ class acp_extensions  		// If they've specified an extension, let's load the metadata manager and validate it.  		if ($ext_name)  		{ -			$md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $phpbb_root_path); +			$md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);  			try  			{ diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 3000a18668..2d3ac62f86 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3030,7 +3030,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port  				}  				else if (stripos($line, '404 not found') !== false)  				{ -					$errstr = $user->lang('FILE_NOT_FOUND',  $filename); +					$errstr = $user->lang('FILE_NOT_FOUND', $filename);  					return false;  				}  			} diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index e9f1c3ac5c..6ec722bb78 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -117,4 +117,7 @@ $lang = array_merge($lang, array(  	'VERSIONCHECK_FORCE_UPDATE_ALL'		=> 'Re-Check all versions',  	'FORCE_UNSTABLE'					=> 'Always check for unstable versions',  	'EXTENSIONS_VERSION_CHECK_SETTINGS'	=> 'Version check settings', + +	'META_FIELD_NOT_SET'	=> 'Required meta field %s has not been set.', +	'META_FIELD_INVALID'	=> 'Meta field %s is invalid.',  )); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 5e524a6164..2020783100 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -231,6 +231,8 @@ $lang = array_merge($lang, array(  	'FILESIZE'				=> 'File size',  	'FILEDATE'				=> 'File date',  	'FILE_COMMENT'			=> 'File comment', +	'FILE_CONTENT_ERR'		=> 'Could not read the contents of file: %s', +	'FILE_JSON_DECODE_ERR'	=> 'Failed to decode json file: %s',  	'FILE_NOT_FOUND'		=> 'The requested file could not be found: %s',  	'FIND_USERNAME'			=> 'Find a member',  	'FOLDER'				=> 'Folder', diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 0bfec23573..cd7289e085 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -26,6 +26,7 @@ class manager  	protected $db;  	protected $config;  	protected $cache; +	protected $user;  	protected $php_ext;  	protected $extensions;  	protected $extension_table; @@ -37,25 +38,27 @@ class manager  	*  	* @param ContainerInterface $container A container  	* @param \phpbb\db\driver\driver_interface $db A database connection -	* @param \phpbb\config\config $config \phpbb\config\config +	* @param \phpbb\config\config $config Config object  	* @param \phpbb\filesystem $filesystem +	* @param \phpbb\user $user User object  	* @param string $extension_table The name of the table holding extensions  	* @param string $phpbb_root_path Path to the phpbb includes directory. -	* @param string $php_ext php file extension +	* @param string $php_ext php file extension, defaults to php  	* @param \phpbb\cache\driver\driver_interface $cache A cache instance or null  	* @param string $cache_name The name of the cache variable, defaults to _ext  	*/ -	public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') +	public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, \phpbb\user $user, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext')  	{ +		$this->cache = $cache; +		$this->cache_name = $cache_name; +		$this->config = $config;  		$this->container = $container; -		$this->phpbb_root_path = $phpbb_root_path;  		$this->db = $db; -		$this->config = $config; -		$this->cache = $cache; +		$this->extension_table = $extension_table;  		$this->filesystem = $filesystem; +		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; -		$this->extension_table = $extension_table; -		$this->cache_name = $cache_name; +		$this->user = $user;  		$this->extensions = ($this->cache) ? $this->cache->get($this->cache_name) : false; @@ -150,7 +153,7 @@ class manager  	*/  	public function create_extension_metadata_manager($name, \phpbb\template\template $template)  	{ -		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path); +		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->user, $this->phpbb_root_path);  	}  	/** diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 047f0ca54c..5c4e8fbf00 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -37,6 +37,12 @@ class metadata_manager  	protected $template;  	/** +	* phpBB User instance +	* @var \phpbb\user +	*/ +	protected $user; + +	/**  	* phpBB root path  	* @var string  	*/ @@ -65,15 +71,17 @@ class metadata_manager  	*  	* @param string				$ext_name			Name (including vendor) of the extension  	* @param \phpbb\config\config		$config				phpBB Config instance -	* @param \phpbb\extension\manager	$extension_manager An instance of the phpBBb extension manager -	* @param \phpbb\template\template		$template			phpBB Template instance +	* @param \phpbb\extension\manager	$extension_manager	An instance of the phpBB extension manager +	* @param \phpbb\template\template	$template			phpBB Template instance +	* @param \phpbb\user 		$user 				User instance  	* @param string				$phpbb_root_path	Path to the phpbb includes directory.  	*/ -	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, $phpbb_root_path) +	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, \phpbb\user $user, $phpbb_root_path)  	{  		$this->config = $config;  		$this->extension_manager = $extension_manager;  		$this->template = $template; +		$this->user = $user;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->ext_name = $ext_name; @@ -141,7 +149,7 @@ class metadata_manager  		if (!file_exists($this->metadata_file))  		{ -			throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); +			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));  		}  	} @@ -154,18 +162,18 @@ class metadata_manager  	{  		if (!file_exists($this->metadata_file))  		{ -			throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); +			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file));  		}  		else  		{  			if (!($file_contents = file_get_contents($this->metadata_file)))  			{ -				throw new \phpbb\extension\exception('file_get_contents failed on ' . $this->metadata_file); +				throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file));  			}  			if (($metadata = json_decode($file_contents, true)) === null)  			{ -				throw new \phpbb\extension\exception('json_decode failed on ' . $this->metadata_file); +				throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file));  			}  			$this->metadata = $metadata; @@ -224,12 +232,12 @@ class metadata_manager  				{  					if (!isset($this->metadata[$name]))  					{ -						throw new \phpbb\extension\exception("Required meta field '$name' has not been set."); +						throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', $name));  					}  					if (!preg_match($fields[$name], $this->metadata[$name]))  					{ -						throw new \phpbb\extension\exception("Meta field '$name' is invalid."); +						throw new \phpbb\extension\exception($this->user->lang('META_FIELD_INVALID', $name));  					}  				}  			break; @@ -247,14 +255,14 @@ class metadata_manager  	{  		if (empty($this->metadata['authors']))  		{ -			throw new \phpbb\extension\exception("Required meta field 'authors' has not been set."); +			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'authors'));  		}  		foreach ($this->metadata['authors'] as $author)  		{  			if (!isset($author['name']))  			{ -				throw new \phpbb\extension\exception("Required meta field 'author name' has not been set."); +				throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'author name'));  			}  		} diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 381fe16115..4a1d15aea4 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,12 +60,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case  		$container = new phpbb_mock_container_builder();  		$container->set('migrator', $migrator); +		$user = new \phpbb\user();  		$this->extension_manager = new \phpbb\extension\manager(  			$container,  			$this->db,  			$this->config,  			new phpbb\filesystem(), +			$user,  			'phpbb_ext',  			dirname(__FILE__) . '/../../phpBB/',  			'php', diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 6acade1e87..d9f8fbd1a4 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -101,6 +101,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case  		$phpbb_root_path = __DIR__ . './../../phpBB/';  		$php_ext = 'php';  		$table_prefix = 'phpbb_'; +		$user = new \phpbb\user();  		$migrator = new \phpbb\db\migrator(  			$config, @@ -121,6 +122,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case  			$db,  			$config,  			new \phpbb\filesystem(), +			$user,  			'phpbb_ext',  			dirname(__FILE__) . '/',  			$php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 95544a6f7c..3678ac0a3f 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -77,6 +77,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			$this->db,  			$this->config,  			new \phpbb\filesystem(), +			$this->user,  			'phpbb_ext',  			$this->phpbb_root_path,  			$this->phpEx, @@ -97,7 +98,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e){} -		$this->assertEquals((string) $e, 'The required file does not exist: ' . $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'); +		$this->assertEquals((string) $e, $this->user->lang('FILE_NOT_FOUND', $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'));  	}  	// Should be the same as a direct json_decode of the composer.json file @@ -136,7 +137,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'name'));  		}  		try @@ -147,7 +148,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'type'));  		}  		try @@ -158,7 +159,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Required meta field \'license\' has not been set.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'license'));  		}  		try @@ -169,7 +170,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'version'));  		}  		try @@ -180,7 +181,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'authors'));  		}  		$manager->merge_metadata(array( @@ -197,7 +198,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_NOT_SET', 'author name'));  		}  	} @@ -224,7 +225,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'name'));  		}  		try @@ -235,7 +236,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'type'));  		}  		try @@ -246,7 +247,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Meta field \'license\' is invalid.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'license'));  		}  		try @@ -257,7 +258,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  		}  		catch(\phpbb\extension\exception $e)  		{ -			$this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); +			$this->assertEquals((string) $e, $this->user->lang('META_FIELD_INVALID', 'version'));  		}  	} @@ -437,6 +438,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case  			$this->config,  			$this->extension_manager,  			$this->template, +			$this->user,  			$this->phpbb_root_path  		);  	} diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 8f0f9c6700..b6dd5db708 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -180,7 +180,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case  	{  		// test2 is not available (error)  		$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=test2&sid=' . $this->sid); -		$this->assertContains('The required file does not exist', $crawler->filter('.errorbox')->text()); +		$this->assertContains($this->lang('FILE_NOT_FOUND', ''), $crawler->filter('.errorbox')->text());  		// foo is not disabled (redirect to list)  		$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=vendor2%2Ffoo&sid=' . $this->sid); diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 020e9cd142..080822d249 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -82,6 +82,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case  		$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid);  		// Error message because the files do not exist -		$this->assertContains('The required file does not exist:', $crawler->filter('#main')->text()); +		$this->assertContains($this->lang('FILE_NOT_FOUND', ''), $crawler->filter('#main')->text());  	}  } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 0bfdfa57ac..182ffaaaf7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -203,12 +203,14 @@ class phpbb_functional_test_case extends phpbb_test_case  		);  		$container = new phpbb_mock_container_builder();  		$container->set('migrator', $migrator); +		$user = new \phpbb\user();  		$extension_manager = new \phpbb\extension\manager(  			$container,  			$db,  			$config,  			new phpbb\filesystem(), +			$user,  			self::$config['table_prefix'] . 'ext',  			dirname(__FILE__) . '/',  			$phpEx,  | 
