Skip to content
Snippets Groups Projects
Commit 36694b09 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

Merge branch 'fix-rake-topics' into 'master'

Fix rake topics



See merge request !164
parents cf0a7910 65efc03b
No related branches found
No related tags found
No related merge requests found
...@@ -9,26 +9,33 @@ class TopicsImporter ...@@ -9,26 +9,33 @@ class TopicsImporter
def import def import
relations = [] learning_objects = []
@items.each do |learning_object| @items.each do |learning_object|
lo_topics = parse_topics ( learning_object.get_metadata_values_of "dc.subject.category" ) lo_topics = parse_topics ( learning_object.get_metadata_values_of "dc.subject.category" )
lo_topics.each_with_index do |topic_name, i| lo_topics.each do |topic_name|
topic = @@topics[topic_name]
if !topic_exists? topic_name
topic = Topic.where(name: topic_name).new
elsif @@topics[topic_name].nil?
topic = Topic.find_by_name topic_name
end
next if topic_exists? topic_name
topic = Topic.where(name: topic_name).new create_relations(topic_name)
topic.learning_objects << learning_object learning_object.topics << topic
create_relations(lo_topics[i - 1], topic_name) unless i == 0
@@topics[topic_name] = topic @@topics[topic_name] = topic
end end
learning_objects << learning_object
separate_relations() separate_relations()
end end
Topic.import @@topics.values Topic.import @@topics.values
LearningObject.import learning_objects
import_topics_relations() import_topics_relations()
end end
...@@ -36,9 +43,8 @@ class TopicsImporter ...@@ -36,9 +43,8 @@ class TopicsImporter
private private
def create_relations parent_name, child_name def create_relations topic_name
@@topics_relations.push(parent_name) @@topics_relations << topic_name
@@topics_relations.push(child_name)
end end
def separate_relations def separate_relations
...@@ -53,7 +59,7 @@ class TopicsImporter ...@@ -53,7 +59,7 @@ class TopicsImporter
unless relation.nil? || @@topics_relations[i - 1].nil? unless relation.nil? || @@topics_relations[i - 1].nil?
parent_id = Topic.find_by_name(@@topics_relations[i - 1]).id parent_id = Topic.find_by_name(@@topics_relations[i - 1]).id
child_id = Topic.find_by_name(relation).id child_id = Topic.find_by_name(relation).id
unless TopicRelationship.exists?(parent_id: parent_id, child_id: child_id) || i == 0 unless TopicRelationship.exists?(parent_id: parent_id, child_id: child_id)
relations.push TopicRelationship.where(parent_id: parent_id, child_id: child_id ).new relations.push TopicRelationship.where(parent_id: parent_id, child_id: child_id ).new
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment