diff --git a/app/controllers/plugins_controller.rb b/app/controllers/plugins_controller.rb index a766832..c7210ea 100644 --- a/app/controllers/plugins_controller.rb +++ b/app/controllers/plugins_controller.rb @@ -30,9 +30,15 @@ class PluginsController < ApplicationController end def upgrade - pl = Plugin.new(gem_name: params[:plugins][:name]) - pl.uninstall! if pl.installed? GemInstaller.new.async.perform(params[:plugins][:name], params[:plugins][:version]) redirect_to plugins_path end + + def bulk_upgrade + params[:plugins].each do |gem_name| + pl = Plugin.new(gem_name: gem_name) + GemInstaller.new.async.perform(gem_name, pl.latest_version) + end + redirect_to plugins_path + end end diff --git a/app/models/plugin.rb b/app/models/plugin.rb index a87a499..5a1de99 100644 --- a/app/models/plugin.rb +++ b/app/models/plugin.rb @@ -78,7 +78,7 @@ class Plugin def inspect self.version ||= latest_version - %Q|<"#{gem_name}", "#{version}">| + %Q|<#{gem_name}, "#{version}">| end def rubygems_org_page @@ -88,9 +88,12 @@ class Plugin def self.installed Rails.cache.fetch("installed_gems", expires_in: 3.seconds) do Bundler.with_clean_env do - `#{fluent_gem_path} list`.lines.grep(/fluent-plugin/).map do |gem| - name, version = gem.strip.split(" (") - new(gem_name: name, version: version.gsub(/\)$/, "")) + gems = `#{fluent_gem_path} list`.try(:lines) + return [] unless gems + gems.grep(/fluent-plugin/).map do |gem| + name, versions_str = gem.strip.split(" ") + version = versions_str[/[^(), ]+/] + new(gem_name: name, version: version) end end end diff --git a/app/views/plugins/updated.html.haml b/app/views/plugins/updated.html.haml index 66288e7..0eba8a1 100644 --- a/app/views/plugins/updated.html.haml +++ b/app/views/plugins/updated.html.haml @@ -3,7 +3,7 @@ - unless @plugins.present? = t('.no_updates') - else - = form_tag(install_plugins_path, method: :patch) do + = form_tag(bulk_upgrade_plugins_path, method: :patch) do %table{class: "table table-striped table-hover"} %tr %th.col-lg-2= t('.name') diff --git a/config/routes.rb b/config/routes.rb index c94d097..a572596 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,7 @@ Rails.application.routes.draw do patch :install patch :uninstall patch :upgrade + patch :bulk_upgrade end end