aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/extension
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/extension')
-rw-r--r--phpBB/phpbb/extension/manager.php40
-rw-r--r--phpBB/phpbb/extension/metadata_manager.php76
2 files changed, 65 insertions, 51 deletions
diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php
index 98d2d27278..ca0ff31d5d 100644
--- a/phpBB/phpbb/extension/manager.php
+++ b/phpBB/phpbb/extension/manager.php
@@ -13,6 +13,8 @@
namespace phpbb\extension;
+use phpbb\exception\runtime_exception;
+use phpbb\file_downloader;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -42,10 +44,10 @@ class manager
* @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, defaults to php
- * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null
+ * @param \phpbb\cache\service $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_interface $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_interface $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\service $cache = null, $cache_name = '_ext')
{
$this->cache = $cache;
$this->cache_name = $cache_name;
@@ -146,12 +148,11 @@ class manager
* Instantiates the metadata manager for the extension with the given name
*
* @param string $name The extension name
- * @param \phpbb\template\template $template The template manager
* @return \phpbb\extension\metadata_manager Instance of the metadata manager
*/
- public function create_extension_metadata_manager($name, \phpbb\template\template $template)
+ public function create_extension_metadata_manager($name)
{
- 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, $this->phpbb_root_path);
}
/**
@@ -566,6 +567,35 @@ class manager
}
/**
+ * Check the version and return the available updates (for an extension).
+ *
+ * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check.
+ * @param bool $force_update Ignores cached data. Defaults to false.
+ * @param bool $force_cache Force the use of the cache. Override $force_update.
+ * @param string $stability Force the stability (null by default).
+ * @return string
+ * @throws runtime_exception
+ */
+ public function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false, $stability = null)
+ {
+ $meta = $md_manager->get_metadata('all');
+
+ if (!isset($meta['extra']['version-check']))
+ {
+ throw new runtime_exception('NO_VERSIONCHECK');
+ }
+
+ $version_check = $meta['extra']['version-check'];
+
+ $version_helper = new \phpbb\version_helper($this->cache, $this->config, new file_downloader());
+ $version_helper->set_current_version($meta['version']);
+ $version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename'], isset($version_check['ssl']) ? $version_check['ssl'] : false);
+ $version_helper->force_stability($stability);
+
+ return $updates = $version_helper->get_suggested_updates($force_update, $force_cache);
+ }
+
+ /**
* Check to see if a given extension is purged
*
* An extension is purged if it is available, not enabled and not disabled.
diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php
index 4f080647c8..6fc6dc9891 100644
--- a/phpBB/phpbb/extension/metadata_manager.php
+++ b/phpBB/phpbb/extension/metadata_manager.php
@@ -31,12 +31,6 @@ class metadata_manager
protected $extension_manager;
/**
- * phpBB Template instance
- * @var \phpbb\template\template
- */
- protected $template;
-
- /**
* phpBB root path
* @var string
*/
@@ -66,14 +60,12 @@ 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 phpBB extension manager
- * @param \phpbb\template\template $template phpBB Template 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_root_path)
{
$this->config = $config;
$this->extension_manager = $extension_manager;
- $this->template = $template;
$this->phpbb_root_path = $phpbb_root_path;
$this->ext_name = $ext_name;
@@ -101,28 +93,18 @@ class metadata_manager
{
case 'all':
default:
- // Validate the metadata
- if (!$this->validate())
- {
- return false;
- }
-
+ $this->validate();
return $this->metadata;
break;
+ case 'version':
case 'name':
- return ($this->validate('name')) ? $this->metadata['name'] : false;
+ $this->validate($element);
+ return $this->metadata[$element];
break;
case 'display-name':
- if (isset($this->metadata['extra']['display-name']))
- {
- return $this->metadata['extra']['display-name'];
- }
- else
- {
- return ($this->validate('name')) ? $this->metadata['name'] : false;
- }
+ return (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : $this->get_metadata('name');
break;
}
}
@@ -219,10 +201,8 @@ class metadata_manager
switch ($name)
{
case 'all':
- $this->validate('display');
-
$this->validate_enable();
- break;
+ // no break
case 'display':
foreach ($fields as $field => $data)
@@ -279,40 +259,43 @@ class metadata_manager
/**
* This array handles the verification that this extension can be enabled on this board
*
- * @return bool True if validation succeeded, False if failed
+ * @return bool True if validation succeeded, throws an exception if invalid
+ * @throws \phpbb\extension\exception
*/
public function validate_enable()
{
// Check for valid directory & phpBB, PHP versions
- if (!$this->validate_dir() || !$this->validate_require_phpbb() || !$this->validate_require_php())
- {
- return false;
- }
-
- return true;
+ return $this->validate_dir() && $this->validate_require_phpbb() && $this->validate_require_php();
}
/**
* Validates the most basic directory structure to ensure it follows <vendor>/<ext> convention.
*
- * @return boolean True when passes validation
+ * @return boolean True when passes validation, throws an exception if invalid
+ * @throws \phpbb\extension\exception
*/
public function validate_dir()
{
- return (substr_count($this->ext_name, '/') === 1 && $this->ext_name == $this->get_metadata('name'));
+ if (substr_count($this->ext_name, '/') !== 1 || $this->ext_name != $this->get_metadata('name'))
+ {
+ throw new \phpbb\extension\exception('EXTENSION_DIR_INVALID');
+ }
+
+ return true;
}
/**
* Validates the contents of the phpbb requirement field
*
- * @return boolean True when passes validation
+ * @return boolean True when passes validation, throws an exception if invalid
+ * @throws \phpbb\extension\exception
*/
public function validate_require_phpbb()
{
if (!isset($this->metadata['extra']['soft-require']['phpbb/phpbb']))
{
- return false;
+ throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('soft-require'));
}
return true;
@@ -321,13 +304,14 @@ class metadata_manager
/**
* Validates the contents of the php requirement field
*
- * @return boolean True when passes validation
+ * @return boolean True when passes validation, throws an exception if invalid
+ * @throws \phpbb\extension\exception
*/
public function validate_require_php()
{
if (!isset($this->metadata['require']['php']))
{
- return false;
+ throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('require php'));
}
return true;
@@ -336,11 +320,11 @@ class metadata_manager
/**
* Outputs the metadata into the template
*
- * @return null
+ * @param \phpbb\template\template $template phpBB Template instance
*/
- public function output_template_data()
+ public function output_template_data(\phpbb\template\template $template)
{
- $this->template->assign_vars(array(
+ $template->assign_vars(array(
'META_NAME' => $this->metadata['name'],
'META_TYPE' => $this->metadata['type'],
'META_DESCRIPTION' => (isset($this->metadata['description'])) ? $this->metadata['description'] : '',
@@ -350,17 +334,17 @@ class metadata_manager
'META_LICENSE' => $this->metadata['license'],
'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '',
- 'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(),
+ 'META_REQUIRE_PHP_FAIL' => (isset($this->metadata['require']['php'])) ? false : true,
'META_REQUIRE_PHPBB' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? $this->metadata['extra']['soft-require']['phpbb/phpbb'] : '',
- 'META_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(),
+ 'META_REQUIRE_PHPBB_FAIL' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,
'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '',
));
foreach ($this->metadata['authors'] as $author)
{
- $this->template->assign_block_vars('meta_authors', array(
+ $template->assign_block_vars('meta_authors', array(
'AUTHOR_NAME' => $author['name'],
'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '',
'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '',