aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorNicofuma <github@nicofuma.fr>2014-04-14 06:56:04 +0200
committerTristan Darricau <github@nicofuma.fr>2014-05-28 22:15:47 +0200
commite0b2ceef833dee55a1701216d4f0823375e8fa74 (patch)
treef3db259b786638897e90a009db10009171ac8941 /phpBB/includes
parent47b240660b688fab7a3dc57c46392506f1350daa (diff)
downloadforums-e0b2ceef833dee55a1701216d4f0823375e8fa74.tar
forums-e0b2ceef833dee55a1701216d4f0823375e8fa74.tar.gz
forums-e0b2ceef833dee55a1701216d4f0823375e8fa74.tar.bz2
forums-e0b2ceef833dee55a1701216d4f0823375e8fa74.tar.xz
forums-e0b2ceef833dee55a1701216d4f0823375e8fa74.zip
[ticket/11366] Extension's version's check
Add a feature to check automatically the version of the installed extensions. The informations are cached for 24 hours (like for the global update check on the main page of the acp). The informations about the versions are display both on the global list and on the detailled page. To do this the developper has to to let the composer.json of the latest version available and add some informations into it : "extra": { "version-check": { "host": "<the host>", "directory": "<the directory containing the file>", "filename": "<the composer.json of the latest version>" } } He can also add two extra informations which will be displayed if a new version is available : "extra": { "download": "<download link>", "annoucement": "<announcement link>", } Currently a notice is displayed when the "extra.version-check" informations are missing. Ticket: https://tracker.phpbb.com/browse/PHPBB3-11366 Signed-off-by: Nicofuma <github@nicofuma.fr> PHPBB3-11366
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_extensions.php137
1 files changed, 111 insertions, 26 deletions
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php
index 9033fbbe60..ac26621b89 100644
--- a/phpBB/includes/acp/acp_extensions.php
+++ b/phpBB/includes/acp/acp_extensions.php
@@ -27,17 +27,19 @@ class acp_extensions
private $config;
private $template;
private $user;
+ private $cache;
private $log;
function main()
{
// Start the page
- global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx, $phpbb_log;
+ global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx, $phpbb_log, $cache;
$this->db = $db;
$this->config = $config;
$this->template = $template;
$this->user = $user;
+ $this->cache = $cache;
$this->log = $phpbb_log;
$user->add_lang(array('install', 'acp/extensions', 'migrator'));
@@ -247,7 +249,24 @@ class acp_extensions
// Output it to the template
$md_manager->output_template_data();
- $template->assign_var('U_BACK', $this->u_action . '&amp;action=list');
+ try
+ {
+ $infos = array();
+ $this->version_check($md_manager, $infos, $request->variable('versioncheck_force', false));
+ $template->assign_vars($infos);
+ }
+ catch (\RuntimeException $e)
+ {
+ $template->assign_vars(array(
+ 'S_VERSIONCHECK_FAIL' => true,
+ 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '',
+ ));
+ }
+
+ $template->assign_vars(array(
+ 'U_BACK' => $this->u_action . '&amp;action=list',
+ 'U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name')),
+ ));
$this->tpl_name = 'acp_ext_details';
break;
@@ -270,25 +289,31 @@ class acp_extensions
try
{
- $enabled_extension_meta_data[$name] = $md_manager->get_metadata('display-name');
+ $meta = $md_manager->get_metadata('all');
+ $enabled_extension_meta_data[$name] = array(
+ 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
+ 'META_VERSION' => $meta['version'],
+ );
+
+ $this->version_check($md_manager, $enabled_extension_meta_data[$name]);
}
catch(\phpbb\extension\exception $e)
{
$this->template->assign_block_vars('disabled', array(
'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e),
+ 'S_VERSIONCHECK' => false,
));
}
}
- natcasesort($enabled_extension_meta_data);
+ uasort($enabled_extension_meta_data, array('self', 'sort_extension_meta_data_table'));
- foreach ($enabled_extension_meta_data as $name => $display_name)
+ foreach ($enabled_extension_meta_data as $name => $infos)
{
- $this->template->assign_block_vars('enabled', array(
- 'META_DISPLAY_NAME' => $display_name,
-
- 'U_DETAILS' => $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name),
- ));
+ $values = $infos;
+ $values['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
+
+ $this->template->assign_block_vars('enabled', $values);
$this->output_actions('enabled', array(
'DISABLE' => $this->u_action . '&amp;action=disable_pre&amp;ext_name=' . urlencode($name),
@@ -312,25 +337,31 @@ class acp_extensions
try
{
- $disabled_extension_meta_data[$name] = $md_manager->get_metadata('display-name');
+ $meta = $md_manager->get_metadata('all');
+ $disabled_extension_meta_data[$name] = array(
+ 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
+ 'META_VERSION' => $meta['version'],
+ );
+
+ $this->version_check($md_manager, $disabled_extension_meta_data[$name]);
}
catch(\phpbb\extension\exception $e)
{
$this->template->assign_block_vars('disabled', array(
'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e),
+ 'S_VERSIONCHECK' => false,
));
}
}
- natcasesort($disabled_extension_meta_data);
+ uasort($disabled_extension_meta_data, array('self', 'sort_extension_meta_data_table'));
- foreach ($disabled_extension_meta_data as $name => $display_name)
+ foreach ($disabled_extension_meta_data as $name => $infos)
{
- $this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $display_name,
-
- 'U_DETAILS' => $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name),
- ));
+ $values = $infos;
+ $values['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
+
+ $this->template->assign_block_vars('disabled', $values);
$this->output_actions('disabled', array(
'ENABLE' => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
@@ -357,25 +388,31 @@ class acp_extensions
try
{
- $available_extension_meta_data[$name] = $md_manager->get_metadata('display-name');
+ $meta = $md_manager->get_metadata('all');
+ $available_extension_meta_data[$name] = array(
+ 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
+ 'META_VERSION' => $meta['version'],
+ );
+
+ $this->version_check($md_manager, $available_extension_meta_data[$name]);
}
catch(\phpbb\extension\exception $e)
{
$this->template->assign_block_vars('disabled', array(
'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e),
+ 'S_VERSIONCHECK' => false,
));
}
}
- natcasesort($available_extension_meta_data);
+ uasort($available_extension_meta_data, array('self', 'sort_extension_meta_data_table'));
- foreach ($available_extension_meta_data as $name => $display_name)
+ foreach ($available_extension_meta_data as $name => $infos)
{
- $this->template->assign_block_vars('disabled', array(
- 'META_DISPLAY_NAME' => $display_name,
-
- 'U_DETAILS' => $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name),
- ));
+ $values = $infos;
+ $values['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
+
+ $this->template->assign_block_vars('disabled', $values);
$this->output_actions('disabled', array(
'ENABLE' => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
@@ -400,4 +437,52 @@ class acp_extensions
));
}
}
+
+ /**
+ * Check the version and dump to the template
+ *
+ * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check.
+ * @param array $array_dest The array to bind to the template.
+ * @param bool $force Ignores cached data. Default to false.
+ */
+ private function version_check(\phpbb\extension\metadata_manager $md_manager, &$array_dest, $force = false)
+ {
+ $meta = $md_manager->get_metadata('all');
+
+ if (! isset($meta['extra']['version-check']))
+ {
+ throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'));
+ }
+
+ $version_helper = new \phpbb\extension\version_helper($this->cache, $this->user);
+ $version_helper->set_metadata($meta);
+
+ try
+ {
+ $version_helper->get_version($force);
+ $version_compare = $version_helper->is_uptodate();
+
+ $array_dest = array_merge($array_dest, array(
+ 'S_VERSIONCHECK' => true,
+ 'S_UP_TO_DATE' => $version_compare,
+ 'LATEST_VERSION' => $version_helper->get_latest_version(),
+ 'LATEST_DOWNLOAD' => $version_helper->get_latest_download_link(),
+ 'LATEST_ANNOUNCEMENT' => $version_helper->get_latest_announcement_link(),
+ 'UP_TO_DATE_MSG' => $this->user->lang($version_compare ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')),
+ 'U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name')),
+ ));
+ }
+ catch(\RuntimeException $e)
+ {
+ $array_dest['S_VERSIONCHECK'] = false;
+ }
+ }
+
+ /**
+ * Sort helper for the table containing the metadata about the extensions.
+ */
+ static private function sort_extension_meta_data_table($val1, $val2)
+ {
+ return strnatcasecmp($val1['META_DISPLAY_NAME'], $val2['META_DISPLAY_NAME']);
+ }
}