diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 592bdb705..77b57b4d8 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1049,7 +1049,7 @@ class Pref_Prefs extends Handler_Protected { } $rv = array_values(array_filter($rv, function ($item) { - return !empty($item["rv"]["o"]); + return $item["rv"]["need_update"]; })); return $rv; @@ -1071,10 +1071,10 @@ class Pref_Prefs extends Handler_Protected { $proc = proc_open("git fetch -q origin -a && git log HEAD..origin/master --oneline", $descriptorspec, $pipes, $plugin_dir); if (is_resource($proc)) { - $rv["o"] = stream_get_contents($pipes[1]); - $rv["e"] = stream_get_contents($pipes[2]); - $status = proc_close($proc); - $rv["s"] = $status; + $rv["stdout"] = stream_get_contents($pipes[1]); + $rv["stderr"] = stream_get_contents($pipes[2]); + $rv["git_status"] = proc_close($proc); + $rv["need_update"] = !empty($rv["stdout"]); } } @@ -1098,10 +1098,9 @@ class Pref_Prefs extends Handler_Protected { $proc = proc_open("git fetch origin -a && git log HEAD..origin/master --oneline && git pull --ff-only origin master", $descriptorspec, $pipes, $plugin_dir); if (is_resource($proc)) { - $rv["o"] = stream_get_contents($pipes[1]); - $rv["e"] = stream_get_contents($pipes[2]); - $status = proc_close($proc); - $rv["s"] = $status; + $rv["stdout"] = stream_get_contents($pipes[1]); + $rv["stderr"] = stream_get_contents($pipes[2]); + $rv["git_status"] = proc_close($proc); } } diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 04ee10a41..eaa571a89 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -358,7 +358,7 @@ const Helpers = { // only user-enabled actually counts in the checkbox when saving because system plugin checkboxes are disabled (see below) container.innerHTML += ` -
  • +
  • ${p.plugin}

    - ${p.rv.e ? `
    ${p.rv.e}
    ` : ''} - ${p.rv.o ? `
    ${p.rv.o}
    ` : ''} + ${p.rv.stderr ? `
    ${p.rv.stderr}
    ` : ''} + ${p.rv.stdout ? `
    ${p.rv.stdout}
    ` : ''}
    - ${p.rv.s ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.s) : + ${p.rv.git_status ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.git_status) : App.FormFields.icon("check") + " " + __("Update done.")}
  • @@ -648,9 +649,74 @@ const Helpers = { dijit.getEnclosingWidget(dialog.domNode.querySelector(".update-btn")).attr('disabled', !enable_update_btn); }); }, + checkNextPlugin: function() { + const name = dialog.plugins_to_check.shift(); + + if (name) { + this.checkUpdates(name); + } else { + const num_updated = dialog.plugins_to_update.length; + + if (num_updated > 0) + dialog.attr('title', + App.l10n.ngettext('Updates pending for %d plugin', 'Updates pending for %d plugins', num_updated) + .replace("%d", num_updated)); + else + dialog.attr('title', __("No updates available")); + + dijit.getEnclosingWidget(dialog.domNode.querySelector(".update-btn")) + .attr('disabled', num_updated == 0); + + } + }, + checkUpdates: function(name) { + console.log('checkUpdates', name); + + const container = dialog.domNode.querySelector(".update-results"); + + dialog.attr('title', __("Checking: %s").replace("%s", name)); + + //container.innerHTML = `
  • ${__("Checking: %s...").replace("%s", name)}
  • `; + + xhr.json("backend.php", {op: "pref-prefs", method: "checkForPluginUpdates", name: name}, (reply) => { + + if (!reply) { + container.innerHTML += `
  • ${__("%s: Operation failed: check event log.").replace("%s", name)}
  • `; + } else { + + reply.forEach((p) => { + if (p.rv.need_update) { + dialog.plugins_to_update.push(p.plugin); + + const update_button = dijit.getEnclosingWidget( + App.find(`*[data-update-btn-for-plugin="${p.plugin}"]`)); + + if (update_button) + update_button.domNode.show(); + } + + if (p.rv.need_update || p.rv.git_status != 0) { + container.innerHTML += + ` +
  • ${p.plugin}

    + ${p.rv.stderr ? `
    ${p.rv.stderr}
    ` : ''} + ${p.rv.stdout ? `
    ${p.rv.stdout}
    ` : ''} +
    + ${p.rv.git_status ? App.FormFields.icon("error_outline") + " " + __("Exited with RC: %d").replace("%d", p.rv.git_status) : + App.FormFields.icon("check") + " " + __("Ready to update")} +
    +
  • + ` + } + dialog.checkNextPlugin(); + }); + } + + }); + + }, content: `