Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move AdminSet, workflow initialization inside migration safety check #562

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions lib/extensions/allinson_flex_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@
# profile texts
AllinsonFlex::ProfileText.include Extensions::AllinsonFlex::IncludeProfileText

# Recreate only the AdminSet, not the associated permission template that is still in the database.
# (Instead of AdminSet.find_or_create_default_admin_set_id)
if AdminSet.count.zero?
AdminSet.create id: AdminSet::DEFAULT_ID, title: Array.wrap(AdminSet::DEFAULT_TITLE)
end
# recreate permission template if it's not in the database, after all
if ActiveRecord::Base.connection.table_exists?('permission_templates') && Hyrax::PermissionTemplate.count.zero?
hascs = Hyrax::AdminSetCreateService.new(admin_set: AdminSet.first, creating_user: nil)
pt = hascs.send :create_permission_template
workflow = hascs.send :create_workflows_for, permission_template: pt
access = hascs.send :create_default_access_for, permission_template: pt, workflow: workflow
end

# Create transient new objects for all registered work types. Attempts to work around failures to
# define methods for some properties when loading works (e.g. missing ocr_state)
unless ActiveRecord::Base.connection.migration_context.needs_migration?
# Create transient new objects for all registered work types. Attempts to work around failures to
# define methods for some properties when loading works (e.g. missing ocr_state)
Hyrax.config.registered_curation_concern_types.each do |klass|
klass.constantize.new
end

# Recreate only the AdminSet, not the associated permission template that is still (?) in the database.
# (Instead of AdminSet.find_or_create_default_admin_set_id)
if AdminSet.count.zero?
AdminSet.create id: AdminSet::DEFAULT_ID, title: Array.wrap(AdminSet::DEFAULT_TITLE)
end
# recreate permission template if it's not in the database, after all
if ActiveRecord::Base.connection.table_exists?('permission_templates') && Hyrax::PermissionTemplate.count.zero?
hascs = Hyrax::AdminSetCreateService.new(admin_set: AdminSet.first, creating_user: nil)
pt = hascs.send :create_permission_template
workflow = hascs.send :create_workflows_for, permission_template: pt
access = hascs.send :create_default_access_for, permission_template: pt, workflow: workflow
end

end
Loading