Commit 8f0767ca788fab088b6138d0ba48863e1c12c6d3
1 parent
67ee0bbb
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: fix harvest job
Showing
2 changed files
with
7 additions
and
11 deletions
Show diff stats
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
| 1 | class VirtuosoPluginAdminController < AdminController | 1 | class VirtuosoPluginAdminController < AdminController |
| 2 | 2 | ||
| 3 | - #validates :dspace_servers, presence: true | ||
| 4 | - | ||
| 5 | def index | 3 | def index |
| 6 | - settings = params[:settings] | 4 | + settings = params[:settings] |
| 7 | settings ||= {} | 5 | settings ||= {} |
| 8 | @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | 6 | @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) |
| 9 | @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present? | 7 | @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present? |
| 10 | if request.post? | 8 | if request.post? |
| 11 | - settings[:dspace_servers].delete_if do | server | | 9 | + settings[:dspace_servers].delete_if do | server | |
| 12 | server[:dspace_uri].empty? | 10 | server[:dspace_uri].empty? |
| 13 | end | 11 | end |
| 14 | @settings.save! | 12 | @settings.save! |
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
| 1 | #inspired by https://github.com/code4lib/ruby-oai/blob/master/lib/oai/harvester/harvest.rb | 1 | #inspired by https://github.com/code4lib/ruby-oai/blob/master/lib/oai/harvester/harvest.rb |
| 2 | class VirtuosoPlugin::DspaceHarvest | 2 | class VirtuosoPlugin::DspaceHarvest |
| 3 | 3 | ||
| 4 | - DC_CONVERSION = [:title, :creator, :subject, :description, :date, :type, :identifier, :language, :rights, :format] | ||
| 5 | - | ||
| 6 | - def initialize(environment, dspace_uri = "") | 4 | + def initialize(environment, dspace_uri = nil) |
| 7 | @environment = environment | 5 | @environment = environment |
| 8 | @dspace_uri = dspace_uri | 6 | @dspace_uri = dspace_uri |
| 9 | end | 7 | end |
| @@ -69,19 +67,19 @@ class VirtuosoPlugin::DspaceHarvest | @@ -69,19 +67,19 @@ class VirtuosoPlugin::DspaceHarvest | ||
| 69 | settings.last_harvest = nil | 67 | settings.last_harvest = nil |
| 70 | settings.save! | 68 | settings.save! |
| 71 | end | 69 | end |
| 72 | - job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id) | 70 | + job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id, @dspace_uri) |
| 73 | Delayed::Job.enqueue(job) | 71 | Delayed::Job.enqueue(job) |
| 74 | end | 72 | end |
| 75 | end | 73 | end |
| 76 | 74 | ||
| 77 | def find_job | 75 | def find_job |
| 78 | - Delayed::Job.where(:handler => "--- !ruby/struct:VirtuosoPlugin::DspaceHarvest::Job\nenvironment_id: #{@environment.id}\n") | 76 | + Delayed::Job.where(:handler => "--- !ruby/struct:VirtuosoPlugin::DspaceHarvest::Job\nenvironment_id: #{@environment.id}\ndspace_uri: #{@dspace_uri}\n") |
| 79 | end | 77 | end |
| 80 | 78 | ||
| 81 | - class Job < Struct.new(:environment_id) | 79 | + class Job < Struct.new(:environment_id, :dspace_uri) |
| 82 | def perform | 80 | def perform |
| 83 | environment = Environment.find(environment_id) | 81 | environment = Environment.find(environment_id) |
| 84 | - harvest = VirtuosoPlugin::DspaceHarvest.new(environment) | 82 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, dspace_uri) |
| 85 | harvest.run | 83 | harvest.run |
| 86 | end | 84 | end |
| 87 | end | 85 | end |