Sha256: d88d465a3ffb08aa466ef663ce0e1a1f4f298a5cf7380fdc50d6437d9d683dd9

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module Scrivito
  module Migrations
    class CmsBackend
      def read
        if obj = find_migration_store_obj
          obj.data_from_cms.value_of('versions')
        else
          ''
        end
      end

      def save(value)
        if Workspace.current.uses_obj_classes
          CmsRestApi.put(endpoint("objs/#{migration_store_obj.id}"), obj: {versions: value})
        else
          CmsRestApi.put(endpoint("objs/#{migration_store_obj.id}"),
            obj: {versions: ['string', value]})
        end
      end

      private

      def create
        if Workspace.current.uses_obj_classes
          CmsRestApi.post(endpoint('objs'),
            obj: {_path: path, _obj_class: 'MigrationStore', versions: ''})
        else
          CmsRestApi.post(endpoint('objs'),
            obj: {_path: path, _obj_class: 'MigrationStore', versions: ['string', '']})
        end
      end

      def migration_store_obj
        create unless find_migration_store_obj
        find_migration_store_obj
      end

      def find_migration_store_obj
        Obj.find_by_path(path)
      end

      def path
        '/_internal/migration-store'
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrivito_sdk-0.60.0 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.60.0.rc2 lib/scrivito/migrations/cms_backend.rb
scrivito_sdk-0.60.0.rc1 lib/scrivito/migrations/cms_backend.rb