Skip to content

Commit

Permalink
Fix Solr.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Jul 28, 2021
1 parent 5e0d8ef commit 8d12c44
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/valkyrie/persistence/solr/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Valkyrie::Persistence::Solr
# Most methods are delegated to {Valkyrie::Persistence::Solr::Repository}
class Persister
attr_reader :adapter
delegate :connection, :resource_factory, to: :adapter
delegate :connection, :query_service, :resource_factory, to: :adapter

# @param adapter [Valkyrie::Persistence::Solr::MetadataAdapter] The adapter with the
# configured solr connection.
Expand All @@ -16,9 +16,15 @@ def initialize(adapter:)

# (see Valkyrie::Persistence::Memory::Persister#save)
def save(resource:)
raise Valkyrie::Persistence::ObjectNotFoundError, "The object #{resource.id} is previously persisted but not found at save time." unless valid_for_save?(resource)
repository([resource]).persist.first
end

def valid_for_save?(resource)
return true unless resource.persisted? # a new resource
query_service.find_by(id: resource.id).present? # a persisted resource must be found
end

# (see Valkyrie::Persistence::Memory::Persister#save_all)
def save_all(resources:)
repository(resources).persist
Expand Down

0 comments on commit 8d12c44

Please sign in to comment.