Guest User

Untitled

a guest
Mar 17th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. def process_articles(mephisto_articles, permalink_format)
  2. # Create an array to store the processed articles
  3. processed = []
  4.  
  5. # Loop through them
  6. mephisto_articles.each do |a|
  7. # Find the article, or create a new one
  8. article = Article.new
  9. # Grab the information from the article feed item
  10. article.title = a.title
  11. article.content = a.body
  12. article.formatter = formatter(a.filter)
  13. article.published = "1"
  14. article.published_at = DateTime.now
  15. article.permalink = format_permalink(permalink_format,DateTime.now,a.title)
  16. article.user_id = self.current_user.id
  17.  
  18.  
  19. # Add the tags, if present in the feed, and if the tagging plugin is active
  20. if is_plugin_active("feather-tagging") && defined?(Tag) && defined?(Tagging) && article.respond_to?("tag_list=")
  21. tags = []
  22. sections = []
  23.  
  24. DataMapper.repository(:mephisto_database) do
  25. taggings = MephistoTagging.all(:taggable_id => a.id)
  26. tags = MephistoTag.all(:id => taggings.collect{|tg| tg.tag_id}.join(',')) unless taggings.empty?
  27.  
  28. assigned_sections = MephistoAssignedSection.all(:article_id => a.id)
  29. sections = MephistoSection.all(:sections => assigned_sections.collect{|as| as.section_id}.join(',')) unless assigned_sections.empty?
  30. end
  31.  
  32. article.tag_list = (tags.collect{|tag| tag.name} + sections.collect{|section| section.name}).compact.join(",")
  33. end
  34.  
  35. # Save the article
  36. Merb.logger.debug!(article.inspect)
  37. #
  38. article.save
  39.  
  40. @article_map[a.id] = article.id
  41.  
  42. # Add it to the list of processed articles
  43. processed << article
  44. end
  45.  
  46. # Return the list of processed articles
  47. processed
  48. end
Add Comment
Please, Sign In to add comment