Sha256: c21e8223e79669a9c53a3e871d846c5a846616e15a2ae5bc12cdf85573c8d7dc

Contents?: true

Size: 849 Bytes

Versions: 20

Compression:

Stored size: 849 Bytes

Contents

require 'uri'

module Ddr::Datastreams
  class DeleteExternalFiles

    def self.call(*args)
      event = ActiveSupport::Notifications::Event.new(*args)
      case event.name
      when Ddr::Datastreams::DELETE
        delete_files(event.payload[:version_history])
      when Ddr::Models::Base::DELETE, Ddr::Models::Base::DEACCESSION
        delete_files(event.payload[:datastream_history].values.flatten)
      end
    end

    def self.get_files_to_delete(profiles)
      return [] if profiles.empty?
      profiles
        .select { |prof| (prof["dsControlGroup"] == "E") && prof["dsLocation"].start_with?("file:") }
        .map    { |prof| Ddr::Utils.path_from_uri(prof["dsLocation"]) }
    end

    def self.delete_files(profiles)
      paths = get_files_to_delete(profiles)
      FileUtils.rm_f(paths) unless paths.empty?
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.10.2 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.10.1 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.10.0 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.10.0.rc2 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.10.0.rc1 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.9.2 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.9.1 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.9.0 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.9.0.rc1 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.8.0 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.8.0.rc1 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.6 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.5 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.4 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.3 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.2 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.1 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.0 lib/ddr/datastreams/delete_external_files.rb
ddr-models-2.7.0.rc1 lib/ddr/datastreams/delete_external_files.rb