lib/scrivito/workspace_data.rb in scrivito_sdk-0.65.2 vs lib/scrivito/workspace_data.rb in scrivito_sdk-0.66.0.rc1
- old
+ new
@@ -10,32 +10,68 @@
data_attr_reader :id
data_attr_reader :title
data_attr_reader :memberships
data_attr_reader :revision_id
- data_attr_reader :content_state_id
- data_attr_reader :uses_obj_classes
data_attr_reader :base_revision_id
- data_attr_reader :base_content_state_id
+ def content_state_id
+ @data["content_state_id"] or raise InternalError
+ end
+
+ def content_state_id?
+ @data["content_state_id"].present?
+ end
+
+ def base_content_state_id
+ @data["base_content_state_id"] or raise InternalError
+ end
+
+ def base_content_state_id?
+ @data["base_content_state_id"].present?
+ end
+
def initialize(data)
+ raise InternalError unless Hash === data && data["id"].present?
@data = data
+ assert_no_obj_classes
end
def store_in_cache
CmsDataCache.write_workspace_data(id, to_hash)
end
+ def content_state
+ @content_state ||= ContentState.find_or_create(content_state_id) if content_state_id
+ end
+
+ def base_content_state
+ if base_content_state_id
+ @base_content_state ||= ContentState.find_or_create(base_content_state_id)
+ end
+ end
+
private
+ def assert_no_obj_classes
+ if @data['uses_obj_classes']
+ raise ScrivitoError, "The working copy titled #{title} has ObjClasses, which is no longer "\
+ "supported. Please use version 0.60.0 to have CMS-based ObjClasses removed from your "\
+ "working copies. See https://scrivito.com/scrivito/obj-class-migration for a "\
+ "detailed guide on upgrading."
+ end
+ end
+
def to_hash
+ base_csid = base_content_state_id? ? base_content_state_id : nil
+
{
'id' => id,
'revision_id' => revision_id,
'title' => title,
'content_state_id' => content_state_id,
'base_revision_id' => base_revision_id,
- 'base_content_state_id' => base_content_state_id,
+ 'base_content_state_id' => base_csid,
'memberships' => memberships,
}
end
end
end