Sha256: c7916f99f6488e6b2b0d0a5cdd6988eb49a453f012ab6ab5dd89660409ece883

Contents?: true

Size: 1.78 KB

Versions: 26

Compression:

Stored size: 1.78 KB

Contents

module Scrivito
  module Migrations
    class CmsBackend
      def read
        obj = find_migration_store_obj

        if obj
          obj[attribute_name]
        else
          initial_value
        end
      end

      def save(value)
        CmsRestApi.put(
          endpoint("objs/#{migration_store_obj.id}"),
          :obj => {
            attribute_name => value
          }
        )
      end

      private

      def create
        # Create obj class
        CmsRestApi.post(
          endpoint('obj_classes'),
          :obj_class => {
            :name => obj_class_name,
            :attributes => [
              {
                :name => attribute_name,
                :type => :text,
              },
            ],
            :type => :publication,
            :title => obj_class_name,
          }
        )

        # Create obj
        CmsRestApi.post(
          endpoint('objs'),
          :obj => {
            :_path => path,
            :_obj_class => obj_class_name,
            attribute_name => initial_value,
          }
        )

        # Deactivate obj class
        CmsRestApi.put(
          endpoint("obj_classes/#{obj_class_name}"),
          :obj_class => {
            :is_active => false,
          }
        )
      end

      def migration_store_obj
        unless find_migration_store_obj
          create
        end

        find_migration_store_obj
      end

      def find_migration_store_obj
        Obj.find_by_path(path)
      end

      def attribute_name
        'versions'
      end

      def obj_class_name
        'MigrationStore'
      end

      def path
        '/_internal/migration-store'
      end

      def initial_value
        ''
      end

      def endpoint(path)
        "workspaces/#{Workspace.current.id}/#{path}"
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
scrivito_sdk-0.50.1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.50.0 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.50.0.rc2 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.50.0.rc1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.42.1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.42.1.rc3 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.42.1.rc2 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.42.1.rc1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.42.0 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.41.1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.41.0 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.41.0.rc2 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.41.0.rc1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.40.0 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.40.0.rc2 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.40.0.rc1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.30.0 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.30.0.rc1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.18.1 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.18.0 lib/scrivito/migrations/cms_backend.rb