Sha256: f8d597ac11da3be550357a5b73e118cfd52c1122f5b7cf48c4cc1fbd921355cb

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

module Fiona7
  module BinaryFilesCleaner

    def delete_unused(binary)
      perform_with_unused(binary, "delete!")
    end
    def unrelease_unused(binary)
      perform_with_unused(binary, "unrelease!")
    end

    private
    def perform_with_unused(binary, action)
      blob_objs = Fiona7::WriteObj.where(obj_class: binary.obj_class, parent_obj_id: binary.parent_obj_id)
      blob_objs.each do |blob_obj|
        Rails.logger.info("Checking binary obj #{blob_obj.obj_id}")
        if (!blob_obj.has_super_links? && blob_obj.obj_id != binary.obj_id)
          # perform delete! without to check released?
          if action == "delete!" ||  blob_obj.released?
            Rails.logger.info("#{action} binary obj #{blob_obj.obj_id}")
            Reactor::Sudo.su(Fiona7.root) do
              blob_obj.send(:crul_obj).send(action)
            end
          end
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/binary_files_cleaner.rb