#require 'fiona7/released_obj' #require 'fiona7/edited_obj' require 'digest/sha1' module Fiona7 class VersionHelper def initialize(workspace_id) @workspace_id = workspace_id.to_sym end def revision_id if @workspace_id == :published published_revision_id else rtc_revision_id end end def content_state_id if @workspace_id == :published published_content_state_id else rtc_content_state_id end end def base_revision_id published_revision_id end def base_content_state_id published_content_state_id end protected def published_revision_id klass = ReleasedObj last_changed = klass.maximum(:last_changed) obj_count = klass.count revision_id = Digest::SHA1.hexdigest("published:#{last_changed}:#{obj_count}").sub(/^./, 'f') revision_id[0] = 'f' revision_id end def rtc_revision_id klass = EditedObj changed = klass.connection.execute("SELECT * from #{klass.table_name} WHERE last_changed = '#{klass.maximum(:last_changed)}' ORDER BY obj_id").to_json obj_count = klass.count revision_id = Digest::SHA1.hexdigest("rtc:#{changed}:#{obj_count}") revision_id[0] = 'b' revision_id end def published_content_state_id obj_class_names = RailsConnector::ObjClass.select([:obj_class_name, :is_enabled]).map {|o| "#{o.name}:#{o.is_enabled}"}.join("|") attribute_names = RailsConnector::Attribute.select(:attribute_name).map(&:name).join("|") attribute_joins = self.obj_class_attrs Digest::SHA1.hexdigest("#{published_revision_id}:#{obj_class_names}:#{attribute_names}:#{attribute_joins}") end def rtc_content_state_id obj_class_names = RailsConnector::ObjClass.select([:obj_class_name, :is_enabled]).map {|o| "#{o.name}:#{o.is_enabled}"}.join("|") attribute_names = RailsConnector::Attribute.select(:attribute_name).map(&:name).join("|") attribute_joins = self.obj_class_attrs Digest::SHA1.hexdigest("#{rtc_revision_id}:#{obj_class_names}:#{attribute_names}:#{attribute_joins}") end def obj_class_attrs if Fiona7.mode == :standalone '' elsif Fiona7.mode == :legacy klass = ReleasedObj table_name = "#{klass.table_name_prefix}obj_class_attrs" klass.connection.execute("SELECT * from #{table_name}").to_a.map {|(id1,id2)| "#{id1}:#{id2}" }.join("|") else raise "Invalid Fiona7.mode = #{Fiona7.mode}" end end end end