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 def outdated? false end def copy_binaries(attributes) # TODO: what to do? attributes 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 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 if subclass.name == 'Obj' && !::RailsConnector.const_defined?('Obj', false) ::RailsConnector.const_set('Obj', ::RailsConnector::AbstractObj) end ensure if subclass.name.present? type_register = Fiona7::TypeRegister.instance subclass.attribute_definitions.each do |attribute_definition| type_register.add_usr_attr(subclass.name, attribute_definition.name, attribute_definition.type, attribute_definition.values.presence) end end end end end end