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)
);
}
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()
{
var hashes = [];
......
......@@ -273,6 +273,7 @@ return array(
'users_registered' => 'Registered users:',
'users_title' => 'Users',
'users_voted' => 'Users who voted:',
'version_check' => 'Check for updates',
'version_get_x' => 'get ^',
'version_latest' => 'latest',
'version_latest_unknown' => 'latest unknown',
......
......@@ -68,7 +68,9 @@ class Plugins extends BaseController
$enabledPluginHashesArray = explode(';', $enabledPluginHashes);
$pluginDirectories = array_keys(array_intersect($pluginHashes, $enabledPluginHashesArray));
$pluginManager->setEnabledPlugins($pluginDirectories);
qa_redirect('admin/plugins');
} elseif (qa_clicked('doversioncheck')) {
$pluginManager->performUpdateCheck(0);
qa_redirect('admin/plugins');
}
}
......@@ -143,6 +145,9 @@ class Plugins extends BaseController
qa_sort_by($sortedPluginFiles, 'name');
$versionChecks = array();
$shouldCheckForUpdate = $pluginManager->shouldCheckForUpdate();
$pluginIndex = -1;
foreach ($sortedPluginFiles as $pluginDirectory => $metadata) {
$pluginIndex++;
......@@ -169,17 +174,20 @@ class Plugins extends BaseController
$authorhtml = '<a href="' . qa_html($metadata['author_uri']) . '">' . $authorhtml . '</a>';
$authorhtml = qa_lang_html_sub('main/by_x', $authorhtml);
} else
} else {
$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);
$updatehtml = '(<span id="' . $elementid . '">...</span>)';
$qa_content['script_onloads'][] = array(
"qa_version_check(" . qa_js($metadata['update_uri']) . ", " . qa_js($metadata['version'], true) . ", " . qa_js($elementid) . ", false);"
$versionChecks[] = array(
'uri' => $metadata['update_uri'],
'version' => $metadata['version'],
'elem' => $elementid,
);
$updatehtml = '(<span id="' . $elementid . '">...</span>)';
} else {
$updatehtml = '';
}
......@@ -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();
......@@ -264,6 +280,10 @@ class Plugins extends BaseController
'tags' => 'name="dosave"',
'label' => qa_lang_html('admin/save_options_button'),
),
'doversioncheck' => array(
'tags' => 'name="doversioncheck"',
'label' => qa_lang_html('admin/version_check'),
),
),
'hidden' => array(
......
......@@ -25,6 +25,8 @@ class PluginManager
{
const PLUGIN_DELIMITER = ';';
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 $loadAfterDbInit = array();
......@@ -180,4 +182,27 @@ class PluginManager
$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