Commit 41939057 by Scott

Merge branch 'pr/769' into dev

parents 3be51d3e 8f65dc18
...@@ -164,6 +164,13 @@ function qa_version_check(uri, version, elem, isCore) ...@@ -164,6 +164,13 @@ function qa_version_check(uri, version, elem, isCore)
); );
} }
function qa_version_check_array(versionChecks)
{
for (var i = 0; i < versionChecks.length; i++) {
qa_version_check(versionChecks[i].uri, versionChecks[i].version, versionChecks[i].elem, false)
}
}
function qa_get_enabled_plugins_hashes() function qa_get_enabled_plugins_hashes()
{ {
var hashes = []; var hashes = [];
......
...@@ -273,6 +273,7 @@ return array( ...@@ -273,6 +273,7 @@ return array(
'users_registered' => 'Registered users:', 'users_registered' => 'Registered users:',
'users_title' => 'Users', 'users_title' => 'Users',
'users_voted' => 'Users who voted:', 'users_voted' => 'Users who voted:',
'version_check' => 'Check for updates',
'version_get_x' => 'get ^', 'version_get_x' => 'get ^',
'version_latest' => 'latest', 'version_latest' => 'latest',
'version_latest_unknown' => 'latest unknown', 'version_latest_unknown' => 'latest unknown',
......
...@@ -68,7 +68,9 @@ class Plugins extends BaseController ...@@ -68,7 +68,9 @@ class Plugins extends BaseController
$enabledPluginHashesArray = explode(';', $enabledPluginHashes); $enabledPluginHashesArray = explode(';', $enabledPluginHashes);
$pluginDirectories = array_keys(array_intersect($pluginHashes, $enabledPluginHashesArray)); $pluginDirectories = array_keys(array_intersect($pluginHashes, $enabledPluginHashesArray));
$pluginManager->setEnabledPlugins($pluginDirectories); $pluginManager->setEnabledPlugins($pluginDirectories);
qa_redirect('admin/plugins');
} elseif (qa_clicked('doversioncheck')) {
$pluginManager->performUpdateCheck(0);
qa_redirect('admin/plugins'); qa_redirect('admin/plugins');
} }
} }
...@@ -143,6 +145,9 @@ class Plugins extends BaseController ...@@ -143,6 +145,9 @@ class Plugins extends BaseController
qa_sort_by($sortedPluginFiles, 'name'); qa_sort_by($sortedPluginFiles, 'name');
$versionChecks = array();
$shouldCheckForUpdate = $pluginManager->shouldCheckForUpdate();
$pluginIndex = -1; $pluginIndex = -1;
foreach ($sortedPluginFiles as $pluginDirectory => $metadata) { foreach ($sortedPluginFiles as $pluginDirectory => $metadata) {
$pluginIndex++; $pluginIndex++;
...@@ -169,17 +174,20 @@ class Plugins extends BaseController ...@@ -169,17 +174,20 @@ class Plugins extends BaseController
$authorhtml = '<a href="' . qa_html($metadata['author_uri']) . '">' . $authorhtml . '</a>'; $authorhtml = '<a href="' . qa_html($metadata['author_uri']) . '">' . $authorhtml . '</a>';
$authorhtml = qa_lang_html_sub('main/by_x', $authorhtml); $authorhtml = qa_lang_html_sub('main/by_x', $authorhtml);
} else } else {
$authorhtml = ''; $authorhtml = '';
}
if ($metaver && isset($metadata['update_uri']) && strlen($metadata['update_uri'])) { if ($shouldCheckForUpdate && $metaver && isset($metadata['update_uri']) && strlen($metadata['update_uri'])) {
$elementid = 'version_check_' . md5($pluginDirectory); $elementid = 'version_check_' . md5($pluginDirectory);
$updatehtml = '(<span id="' . $elementid . '">...</span>)'; $versionChecks[] = array(
'uri' => $metadata['update_uri'],
$qa_content['script_onloads'][] = array( 'version' => $metadata['version'],
"qa_version_check(" . qa_js($metadata['update_uri']) . ", " . qa_js($metadata['version'], true) . ", " . qa_js($elementid) . ", false);" 'elem' => $elementid,
); );
$updatehtml = '(<span id="' . $elementid . '">...</span>)';
} else { } else {
$updatehtml = ''; $updatehtml = '';
} }
...@@ -250,6 +258,14 @@ class Plugins extends BaseController ...@@ -250,6 +258,14 @@ class Plugins extends BaseController
} }
} }
} }
if ($shouldCheckForUpdate) {
$pluginManager->performUpdateCheck();
$qa_content['script_onloads'][] = array(
sprintf('qa_version_check_array(%s);', json_encode($versionChecks)),
);
}
} }
$qa_content['navigation']['sub'] = qa_admin_sub_navigation(); $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
...@@ -264,6 +280,10 @@ class Plugins extends BaseController ...@@ -264,6 +280,10 @@ class Plugins extends BaseController
'tags' => 'name="dosave"', 'tags' => 'name="dosave"',
'label' => qa_lang_html('admin/save_options_button'), 'label' => qa_lang_html('admin/save_options_button'),
), ),
'doversioncheck' => array(
'tags' => 'name="doversioncheck"',
'label' => qa_lang_html('admin/version_check'),
),
), ),
'hidden' => array( 'hidden' => array(
......
...@@ -25,6 +25,8 @@ class PluginManager ...@@ -25,6 +25,8 @@ class PluginManager
{ {
const PLUGIN_DELIMITER = ';'; const PLUGIN_DELIMITER = ';';
const OPT_ENABLED_PLUGINS = 'enabled_plugins'; const OPT_ENABLED_PLUGINS = 'enabled_plugins';
const OPT_LAST_UPDATE_CHECK = 'last_plugin_update_check';
const NUMBER_OF_DAYS_TO_CHECK_FOR_UPDATE = 14;
private $loadBeforeDbInit = array(); private $loadBeforeDbInit = array();
private $loadAfterDbInit = array(); private $loadAfterDbInit = array();
...@@ -180,4 +182,27 @@ class PluginManager ...@@ -180,4 +182,27 @@ class PluginManager
$this->setEnabledPluginsOption($finalEnabledPlugins); $this->setEnabledPluginsOption($finalEnabledPlugins);
} }
/**
* @return bool
*/
public function shouldCheckForUpdate()
{
$lastUpdateCheck = (int)qa_opt(self::OPT_LAST_UPDATE_CHECK);
$currentTime = (int)qa_opt('db_time');
return $currentTime - $lastUpdateCheck > self::NUMBER_OF_DAYS_TO_CHECK_FOR_UPDATE * 24 * 60 * 60;
}
/**
* @param int|null $time
*/
public function performUpdateCheck($time = null)
{
if ($time === null) {
$time = time();
}
qa_opt(self::OPT_LAST_UPDATE_CHECK, $time);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment