Sha256: 186fe13359030df3dbc37018339c81949558f9032d39bae5bdda70135944f8ab

Contents?: true

Size: 1.11 KB

Versions: 27

Compression:

Stored size: 1.11 KB

Contents

module Ddr
  module Managers
    class WorkflowManager < Manager

      PUBLISHED = "published"
      UNPUBLISHED = "unpublished"

      def published?
        object.workflow_state == PUBLISHED
      end

      def unpublished?
        object.workflow_state == UNPUBLISHED
      end

      def publish!(include_descendants: true)
        unless published?
          publish
          object.save!
        end
        if include_descendants && object.respond_to?(:children)
          solr_results = object.children(response_format: :solr)
          ActiveFedora::SolrService.lazy_reify_solr_results(solr_results).each do |child|
            child.publish!(include_descendants: include_descendants)
          end
        end
      end

      def unpublish!
        if published?
          unpublish
          object.save!
        end
        if object.respond_to?(:children)
          object.children.each { |child| child.unpublish! }
        end
      end

      private

      def publish
        object.workflow_state = PUBLISHED
      end

      def unpublish
        object.workflow_state = UNPUBLISHED
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/managers/workflow_manager.rb
ddr-models-2.10.2 lib/ddr/managers/workflow_manager.rb
ddr-models-2.10.1 lib/ddr/managers/workflow_manager.rb
ddr-models-2.10.0 lib/ddr/managers/workflow_manager.rb
ddr-models-2.10.0.rc2 lib/ddr/managers/workflow_manager.rb
ddr-models-2.10.0.rc1 lib/ddr/managers/workflow_manager.rb
ddr-models-2.9.2 lib/ddr/managers/workflow_manager.rb
ddr-models-2.9.1 lib/ddr/managers/workflow_manager.rb
ddr-models-2.9.0 lib/ddr/managers/workflow_manager.rb
ddr-models-2.9.0.rc1 lib/ddr/managers/workflow_manager.rb
ddr-models-2.8.0 lib/ddr/managers/workflow_manager.rb
ddr-models-2.8.0.rc1 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.6 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.5 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.4 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.3 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.2 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.1 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.0 lib/ddr/managers/workflow_manager.rb
ddr-models-2.7.0.rc1 lib/ddr/managers/workflow_manager.rb