Commit 9480ac712e653ed16b65db10ff3dbd5b4f794eec

Authored by Rodrigo Souto
1 parent 1aaa6fa7

[pluginize-solr] Moving solr_save calls on add_category methods

app/models/article.rb
@@ -142,7 +142,6 @@ class Article < ActiveRecord::Base @@ -142,7 +142,6 @@ class Article < ActiveRecord::Base
142 else 142 else
143 ArticleCategorization.add_category_to_article(c, self) 143 ArticleCategorization.add_category_to_article(c, self)
144 self.categories(reload) 144 self.categories(reload)
145 - self.solr_save  
146 end 145 end
147 end 146 end
148 147
@@ -160,7 +159,6 @@ class Article < ActiveRecord::Base @@ -160,7 +159,6 @@ class Article < ActiveRecord::Base
160 ArticleCategorization.add_category_to_article(item, self) 159 ArticleCategorization.add_category_to_article(item, self)
161 end 160 end
162 self.categories(true) 161 self.categories(true)
163 - self.solr_save  
164 pending_categorizations.clear 162 pending_categorizations.clear
165 end 163 end
166 164
@@ -630,23 +628,6 @@ class Article < ActiveRecord::Base @@ -630,23 +628,6 @@ class Article < ActiveRecord::Base
630 img.nil? ? '' : img.attributes['src'] 628 img.nil? ? '' : img.attributes['src']
631 end 629 end
632 630
633 - private  
634 -  
635 - # FIXME: workaround for development env.  
636 - # Subclasses aren't (re)loaded, and acts_as_solr  
637 - # depends on subclasses method to search  
638 - # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245  
639 - UploadedFile  
640 - TextArticle  
641 - TinyMceArticle  
642 - TextileArticle  
643 - Folder  
644 - EnterpriseHomepage  
645 - Gallery  
646 - Blog  
647 - Forum  
648 - Event  
649 -  
650 delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true 631 delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true
651 632
652 private 633 private
app/models/profile.rb
@@ -246,7 +246,6 @@ class Profile < ActiveRecord::Base @@ -246,7 +246,6 @@ class Profile < ActiveRecord::Base
246 else 246 else
247 ProfileCategorization.add_category_to_profile(c, self) 247 ProfileCategorization.add_category_to_profile(c, self)
248 self.categories(true) 248 self.categories(true)
249 - self.solr_save  
250 end 249 end
251 self.categories(reload) 250 self.categories(reload)
252 end 251 end
plugins/solr/lib/ext/article.rb
@@ -38,6 +38,20 @@ class Article @@ -38,6 +38,20 @@ class Article
38 solr_save 38 solr_save
39 end 39 end
40 40
  41 + def add_category_with_solr_save(c, reload=false)
  42 + add_category_without_solr_save(c, reload)
  43 + if !new_record?
  44 + self.solr_save
  45 + end
  46 + end
  47 + alias_method_chain :add_category, :solr_save
  48 +
  49 + def create_pending_categorizations_with_solr_save
  50 + create_pending_categorizations_without_solr_save
  51 + self.solr_save
  52 + end
  53 + alias_method_chain :create_pending_categorizations, :solr_save
  54 +
41 private 55 private
42 56
43 def self.solr_plugin_f_type_proc(klass) 57 def self.solr_plugin_f_type_proc(klass)
@@ -81,4 +95,19 @@ class Article @@ -81,4 +95,19 @@ class Article
81 def solr_plugin_name_sortable 95 def solr_plugin_name_sortable
82 name 96 name
83 end 97 end
  98 +
  99 + # FIXME: workaround for development env.
  100 + # Subclasses aren't (re)loaded, and acts_as_solr
  101 + # depends on subclasses method to search
  102 + # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245
  103 + UploadedFile
  104 + TextArticle
  105 + TinyMceArticle
  106 + TextileArticle
  107 + Folder
  108 + EnterpriseHomepage
  109 + Gallery
  110 + Blog
  111 + Forum
  112 + Event
84 end 113 end
plugins/solr/lib/ext/profile.rb
@@ -44,6 +44,14 @@ class Profile @@ -44,6 +44,14 @@ class Profile
44 self.solr_plugin_extra_index_methods.push(block) if block_given? 44 self.solr_plugin_extra_index_methods.push(block) if block_given?
45 end 45 end
46 46
  47 + def add_category_with_solr_save(c, reload=false)
  48 + add_category_without_solr_save(c, reload)
  49 + if !new_record?
  50 + self.solr_save
  51 + end
  52 + end
  53 + alias_method_chain :add_category, :solr_save
  54 +
47 private 55 private
48 56
49 def self.solr_plugin_f_categories_label_proc(environment) 57 def self.solr_plugin_f_categories_label_proc(environment)