module Fiona7 class ReleaseController < ActionController::Base def release obj_ids = params[:objs] objs = WriteObj.find(obj_ids) comment = params[:comment] errors = [] if !obj_ids.empty? main_obj = objs.shift carefully_release(errors, main_obj, comment) objs.each do |other_obj| carefully_release(errors, other_obj, comment) end end if errors.empty? render json: {} else render json: {message: errors.join("\n"), message_for_editor: errors.join("\n")}, status: 412 end rescue => e render json: {message: e.message}, status: 500 end def preview self.in_rtc_workspace do @obj = WriteObj.find(params[:id]) @recursive = Fiona7::RecursiveObjectFinder.new(@obj) @images = @recursive.images.select {|o| o.really_edited? } @downloads = @recursive.downloads.select {|o| o.really_edited? } @referenced = @recursive.referenced.select {|o| o.really_edited? } @linked = @recursive.linked.select {|o| o.really_edited? } render "preview", layout: false end end protected def in_rtc_workspace(&block) Scrivito::Workspace.find('rtc').as_current(&block) end def carefully_release(errors, obj, comment=nil) if obj.really_edited? # we don't care much if this fails obj.take obj.release!(comment) ::Fiona7.run_callbacks(:release_obj, obj.id) end complex_object = Fiona7::ComplexObject.new(obj) complex_object.widgets.each do |widget_obj| begin widget_obj.take widget_obj.release!(comment) if widget_obj.really_edited? rescue => e Rails.logger.error("Error occured when releasing #{obj.id}: unable to release Object with ID #{widget_obj.id} (#{widget_obj.path} because: #{e.inspect}") # TODO: translate error = "Unable to release Object with ID #{widget_obj.id} because: #{e.message}" errors << error end end #complex_object.binaries.each do |widget_obj| # widget_obj.take # widget_obj.release!(comment) #end rescue => e Rails.logger.error("Error occured when releasing #{obj.id}: unable to release Object with ID #{obj.id} (#{obj.path} because: #{e.inspect}") # TODO: translate error = "Unable to release Object with ID #{obj.id} because: #{e.message}" errors << error end end end