lib/scrivito/migrations/workspace_lock.rb in scrivito_sdk-0.65.2 vs lib/scrivito/migrations/workspace_lock.rb in scrivito_sdk-0.66.0.rc1

- old
+ new

@@ -3,24 +3,22 @@ module Scrivito module Migrations class WorkspaceLock include Singleton - def validate(workspace) - unless exists? && workspace.revision_id == File.read(filename) - raise ScrivitoError.new("There is a migration in progress right now. \ - Please try again after the migration working copy '#{workspace.id}' has \ - been published or removed.") + def get + if exists? + begin + Workspace.find(workspace_id) + rescue Scrivito::ResourceNotFound + create_workspace + end + else + create_workspace end end - def write(workspace) - File.open(filename, 'w') do |file| - file.write(workspace.revision_id) - end - end - def remove if exists? File.delete(filename) end end @@ -28,9 +26,23 @@ def exists? File.exists?(filename) end private + + def create_workspace + Workspace.create(title: 'Migration Working Copy').tap do |workspace| + write(workspace) + end + end + + def write(workspace) + File.write(filename, workspace.id) + end + + def workspace_id + File.read(filename) + end def filename File.join(Rails.root, 'tmp/migration_store.lock') end end