Skip to content

Commit

Permalink
QA: Update the last updated properly
Browse files Browse the repository at this point in the history
* When you upgrade or downgrade, or load an installed plugin, update the last_updated column.
  • Loading branch information
TheWitness committed Nov 22, 2024
1 parent 7993a02 commit 99b9b13
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
29 changes: 29 additions & 0 deletions lib/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -1430,12 +1430,24 @@ function api_plugin_archive_restore($plugin, $id, $type = 'archive') {
WHERE plugin = ?
AND id = ?',
array($plugin, $id));

$new_updated = db_fetch_cell_prepared('SELECT last_updated
FROM plugin_archive
WHERE plugin = ?
AND id = ?',
array($plugin, $id));
} else {
$archive = db_fetch_cell_prepared('SELECT archive
FROM plugin_available
WHERE plugin = ?
AND tag_name = ?',
array($plugin, $id));

$new_updated = db_fetch_cell_prepared('SELECT published_at
FROM plugin_available
WHERE plugin = ?
AND tag_name = ?',
array($plugin, $id));
}

if ($archive != '') {
Expand Down Expand Up @@ -1582,8 +1594,25 @@ function api_plugin_archive_restore($plugin, $id, $type = 'archive') {

if ($type == 'archive') {
raise_message('archive_restored', __('Restore succeeded! The archived Plugin \'%s\' Restore succeeded.', $plugin), MESSAGE_LEVEL_INFO);

db_execute_prepared('UPDATE plugin_config
SET last_updated = ?,
WHERE directory = ?',
array($new_updated, $plugin));
} else {
raise_message('archive_restored', __('Load succeeded! The available Plugin \'%s\' Load succeeded.', $plugin), MESSAGE_LEVEL_INFO);

if ($id == 'develop') {
db_execute_prepared('UPDATE plugin_config
SET last_updated = NOW()
WHERE directory = ?',
array($plugin));
} else {
db_execute_prepared('UPDATE plugin_config
SET last_updated = ?,
WHERE directory = ?',
array($new_updated, $plugin));
}
}

return true;
Expand Down
27 changes: 18 additions & 9 deletions plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@

raise_message('fetch_background', __('The fetch latest plugins process has been launched into background.'), MESSAGE_LEVEL_INFO);
} elseif ($running === true) {
raise_message('fetch_background', __('The fetch latest plugins process has already been started.'), MESSAGE_LEVEL_INFO);
raise_message('fetch_background', __('The fetch latest plugins process has already been started.'), MESSAGE_LEVEL_WARN);
}

header('Location: plugins.php');
Expand Down Expand Up @@ -1001,7 +1001,7 @@ function displayFileDialog(url, dialogTitle, height, width) {
$sql = "SELECT pa.id, pa.plugin, pa.description, pi.status, pi.remote_status,
pa.author, pa.webpage, pi.version, pi.capabilities, pi.requires, pi.last_updated,
pa.requires AS archive_requires, pa.compat AS archive_compat, pa.version AS archive_version,
pa.user_id, pa.last_updated AS archive_date, pa.dir_md5sum
pa.user_id, pa.last_updated AS archive_date, pa.dir_md5sum, length(archive) AS archive_length
FROM plugin_archive AS pa
LEFT JOIN $table AS pi
ON pa.plugin = pi.plugin
Expand All @@ -1017,7 +1017,7 @@ function displayFileDialog(url, dialogTitle, height, width) {
pa.plugin, pa.description AS avail_description,
pa.author AS avail_author, pa.webpage AS avail_webpage,
pa.compat AS avail_compat, pa.published_at AS avail_published, pa.tag_name AS avail_tag_name,
pa.requires AS avail_requires, length(pa.changelog) AS changelog
pa.requires AS avail_requires, length(pa.changelog) AS changelog, length(archive) AS archive_length
FROM plugin_available AS pa
LEFT JOIN $table AS pi
ON pa.plugin = pi.plugin
Expand Down Expand Up @@ -1080,7 +1080,7 @@ function displayFileDialog(url, dialogTitle, height, width) {
'tip' => __('The author of this Plugin.')
),
'pa.compat' => array(
'display' => __('Min Cacti Release'),
'display' => __('Cacti Requires'),
'align' => 'right',
'sort' => 'ASC',
'tip' => __('The version of this Plugin.')
Expand Down Expand Up @@ -1337,11 +1337,20 @@ function format_plugin_row($plugin, $last_plugin, $include_ordering, $table) {
$row .= "<td class='nowrap'>" . $status_names[$plugin['status']];
}

$newer = db_fetch_cell_prepared('SELECT COUNT(*)
FROM plugin_available
WHERE plugin = ?
AND last_updated > ?',
array($plugin['plugin'], $plugin['last_updated']));
if (read_config_option('github_allow_unsafe') == 'on') {
$newer = db_fetch_cell_prepared('SELECT COUNT(*)
FROM plugin_available
WHERE plugin = ?
AND last_updated > ?',
array($plugin['plugin'], $plugin['last_updated']));
} else {
$newer = db_fetch_cell_prepared('SELECT COUNT(*)
FROM plugin_available
WHERE plugin = ?
AND last_updated > ?
AND tag_name != "develop"',
array($plugin['plugin'], $plugin['last_updated']));
}

if ($newer > 0) {
$row .= ", <a class='pic deviceUp' href='" . html_escape('plugins.php?action=list&state=6&filter=' . $plugin['plugin']) . "'>" . __('Newer Version Available') . '</a>';
Expand Down

0 comments on commit 99b9b13

Please sign in to comment.