require 'fiona7/widget_gc/garbage_collector' require 'fiona7/recursive_object_finder' module Fiona7 class ReleaseController < ActionController::Base helper_method :current_locale 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]) if Fiona7.release_collector && Fiona7.release_collector.respond_to?(:call) @groups = Fiona7.release_collector.call(@obj.obj_id) else @groups = Fiona7::ReleaseCollector.call(@obj.obj_id) end render "preview", layout: false end end protected def current_locale Scrivito::Configuration.ui_locale || I18n.locale end def in_rtc_workspace(&block) Scrivito::Workspace.find('rtc').as_current(&block) end def carefully_release(errors, obj, comment=nil) # NOTE: widget garbage collection may be required on release # but only for objects which actually contain widgets. # # TODO: refactor this code! if obj.attr_values["X_widget_pool"].present? WidgetGc::GarbageCollector.new(obj.id, :release).gc! end 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 if Fiona7.mode == :standalone complex_object.check_binaries 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