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 # to_param should only return strings and our ids are numbers def to_param id.to_s 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) blob.file_extension else "" end 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 # This method may be called like this: image_tag(obj) in a view # which is fundamentally broken. image_tag(scrivito_path(obj)) # should be called instead. def body_data_url if binary? && read_attribute('blob') raise "This method is not supported by Fiona7 and should not be called, try using Scrivito::Binary#content or scrivito_url(obj) when appropriate" end end # Originally this method refers to the global Obj via ::Obj 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 assert_has_obj_class('.where') Workspace.current.objs.where(:_obj_class, :equals, obj_class_name) .and(field, operator, value, boost) end end # Originally this method refers to the global Obj via ::Obj def self.all assert_not_basic_obj('.all') if self == Obj || self == ::Obj Workspace.current.objs.all else assert_has_obj_class('.all') find_all_by_obj_class(obj_class_name) end end class << self def assert_has_obj_class(method_name) unless Workspace.current.obj_classes[obj_class_name].present? raise ScrivitoError, "#{name} has no corresponding ObjClass." + " Please use Obj.#{method_name} instead." end end end end end