Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TemplatesController < ApplicationController
def admin_index
authorize Template

funder_templates, org_templates, customizations = [], [], []
funder_templates, org_templates = [], []

# Get all of the unique template family ids (dmptemplate_id) for each funder and the current org
funder_ids = Org.funders.includes(:templates).collect{|f| f.templates.where(published: true).valid.collect{|ft| ft.dmptemplate_id } }.flatten.uniq
Expand Down Expand Up @@ -131,7 +131,7 @@ def admin_transfer_customization
# find corresponding question in new template
customization_question = customization_section.questions.where(number: question.number).first
# apply annotations
question.annotations.each do |annotation|
question.annotations.where(org_id: current_user.org_id).each do |annotation|
annotation_copy = Annotation.deep_copy(annotation)
annotation_copy.question_id = customization_question.id
annotation_copy.save!
Expand Down Expand Up @@ -213,7 +213,7 @@ def admin_template
new_version.save
@template = new_version
# @current = Template.current(@template.dmptemplate_id)
end
end
else
flash[:notice] = _('You are viewing a historical version of this template. You will not be able to make changes.')
end
Expand Down
21 changes: 16 additions & 5 deletions lib/tasks/migrate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ namespace :migrate do
if IdentifierScheme.find_by(name: 'orcid').nil?
IdentifierScheme.create!(name: 'orcid', description: 'ORCID', active: true)
end

scheme = IdentifierScheme.find_by(name: 'orcid')

unless scheme.nil?
User.all.each do |u|
if u.respond_to?(:orcid_id)
if u.orcid_id.present?
if u.orcid_id.present?
if u.orcid_id.gsub('orcid.org/', '').match(/^[\d-]+/)
u.user_identifiers << UserIdentifier.new(identifier_scheme: scheme,
u.user_identifiers << UserIdentifier.new(identifier_scheme: scheme,
identifier: u.orcid_id.gsub('orcid.org/', ''))
u.save!
end
Expand All @@ -253,5 +253,16 @@ namespace :migrate do
end
end
end


desc "remove duplicate annotations caused by bug"
task remove_duplicate_annotations: :environment do
questions = Question.joins(:annotations).group("questions.id").having("count(annotations.id) > count(DISTINCT annotations.text)")
questions.each do |q|
q.annotations.each do |a|
conflicts = Annotation.where(question_id: a.question_id, text: a.text).where.not(id: a.id)
conflicts.each {|c| matches += 1 }
end
end
end

end