File tree Expand file tree Collapse file tree 4 files changed +29
-35
lines changed
Expand file tree Collapse file tree 4 files changed +29
-35
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,7 @@ class ContentItem < Cortex::ApplicationRecord
3232 end
3333
3434 def publish_state
35- # TODO: move logic to Transaction
36- PublishStateService . new . content_item_state ( self )
35+ GetPublishStateTransaction . new . call ( self ) . value!
3736 end
3837
3938 # FieldItem and State Convenience Methods. TODO: move to concern? transactions?
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # TODO: The entire Publish system needs to be reworked to avoid hardcoded references and data integrity issues
2+
3+ module Cortex
4+ class GetPublishStateTransaction < Cortex ::ApplicationTransaction
5+ step :sort_field_items
6+ step :process
7+
8+ def sort_field_items ( content_item )
9+ sorted_field_items = content_item . field_items . select do |field_item |
10+ field_item . field . field_type_instance . is_a? ( DateTimeFieldType ) && !field_item . field . metadata [ "state" ] . nil?
11+ end . sort_by { |field_item | field_item . data [ "timestamp" ] } . reverse
12+
13+ Success ( {
14+ sorted_field_items : sorted_field_items ,
15+ content_item : content_item
16+ } )
17+ end
18+
19+ def process ( input )
20+ timestamp_field_item = input [ :sorted_field_items ] . find do |field_item |
21+ field_item . data [ 'timestamp' ] . present? && DateTime . now > DateTime . parse ( field_item . data [ "timestamp" ] )
22+ end
23+
24+ active_state = timestamp_field_item ? timestamp_field_item . field . metadata [ "state" ] : input [ :content_item ] . state . titleize
25+ Success ( active_state )
26+ end
27+ end
28+ end
You can’t perform that action at this time.
0 commit comments