require 'scrivito/basic_obj' module Scrivito class BasicObj # Type computer computes with global Obj by default # which in legacy mode belongs to fiona_connector # Therefore we limit the scope of the search to Scrivito::Obj def self.type_computer @_type_computer ||= TypeComputer.new(Scrivito::BasicObj, Obj) end # optimized away def outdated? false end # optimized away def transfer_modifications_to(target_workspace) return unless modification raise TransferModificationsModifiedError, "Already modified in workspace #{target_workspace.id}" end # Originally this method checks for conflicts # which are impossible here, hence the method is stubbed out def publishable? # TODO: implement CM validations here # FIXME: this can be solved much faster in PublishChecker self.id && Fiona7::EditedObj.find(self.id).permission.release? end # Original implentation reads file extension from name # but since dots are not allowed in the names # it has to be worked around. def file_extension if (blob = find_blob) File.extname(blob.filename)[1..-1] else "" end end # Original implementation mishandles attribute => [type, value] def copy_binaries(attributes) attribute_defintions = self.class.find_attribute_definitions(obj_class) destination_obj_id = attributes.fetch(:_id) Hash[attributes.map do |name, value| # Here is the change if value && attribute_defintions[name].try(:type) == 'binary' && (binary = self[name]) [name, ['binary', copy_binary(destination_obj_id, binary)]] else [name, value] end end] end # Original implmentation uses the blob copy API # This is completely unneccessary, as the required # logic is already possible implemented similar to FutureBinary def copy_binary(destination_obj_id, binary) { obj_id: destination_obj_id, id_to_copy: binary.id, filename: binary.filename, content_type: binary.content_type }.stringify_keys end def fiona_obj @fiona_obj ||= ::RailsConnector::BasicObj.find(self.id) end # Patch to allow reverting in rtc workspace def assert_revertable if workspace.id != 'rtc' raise ScrivitoError, "cannot revert changes, since obj is not from valid revertable workspace." end if modification == Modification::NEW || modification == Modification::DELETED raise ScrivitoError, "cannot revert changes, since obj is #{modification}." end end # Originally this method refers to the global Obj via ::Obj # and does not support shadow classes def self.where(field, operator, value, boost = nil) assert_not_basic_obj('.where') if self == ::Obj || self == Obj Workspace.current.objs.where(field, operator, value, boost) else Workspace.current.objs.where(:_obj_class, :equals, to_s) .and(field, operator, value, boost) end end # Originally this method refers to the global Obj via ::Obj # and does not support shadow classes def self.all assert_not_basic_obj('.all') if self == ::Obj || self == Obj Workspace.current.objs.all else find_all_by_obj_class(to_s) end end class << self def inherited(subclass,*args) super # Under certain condition a circular dependency may arise in rails when # loading classes, especially when eager_load = true # Thusfar it has only been observed in standalone-mode thus far: # Loading Obj < Scrivito::BasicObj triggers this hook # which tries to set RailsConnector::Obj to a reasonable value, # RailsConnector::AbstractObj provided by reactor. # RailsConnector::AbstractObj tries set itself to couple of # values, one of which is ::Obj # If this occurs with eager_load = true Rails may get confused # and trigger circular dependency error. # We work around this problem by hijacking intelligent initialization # of RailsConnector::AbstractObj in reactor and set it to a # desired value ourselves. if subclass.name == 'Obj' && !::RailsConnector.const_defined?('AbstractObj', false) ::RailsConnector.const_set('AbstractObj', ::RailsConnector::BasicObj) end if subclass.name == 'Obj' && !::RailsConnector.const_defined?('Obj', false) ::RailsConnector.const_set('Obj', ::RailsConnector::AbstractObj) end ensure if subclass.name.present? subclass.register_attribute_definitions(subclass.to_s) end end end end end