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 142 else
143 143 ArticleCategorization.add_category_to_article(c, self)
144 144 self.categories(reload)
145   - self.solr_save
146 145 end
147 146 end
148 147  
... ... @@ -160,7 +159,6 @@ class Article < ActiveRecord::Base
160 159 ArticleCategorization.add_category_to_article(item, self)
161 160 end
162 161 self.categories(true)
163   - self.solr_save
164 162 pending_categorizations.clear
165 163 end
166 164  
... ... @@ -630,23 +628,6 @@ class Article < ActiveRecord::Base
630 628 img.nil? ? '' : img.attributes['src']
631 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 631 delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true
651 632  
652 633 private
... ...
app/models/profile.rb
... ... @@ -246,7 +246,6 @@ class Profile < ActiveRecord::Base
246 246 else
247 247 ProfileCategorization.add_category_to_profile(c, self)
248 248 self.categories(true)
249   - self.solr_save
250 249 end
251 250 self.categories(reload)
252 251 end
... ...
plugins/solr/lib/ext/article.rb
... ... @@ -38,6 +38,20 @@ class Article
38 38 solr_save
39 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 55 private
42 56  
43 57 def self.solr_plugin_f_type_proc(klass)
... ... @@ -81,4 +95,19 @@ class Article
81 95 def solr_plugin_name_sortable
82 96 name
83 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 113 end
... ...
plugins/solr/lib/ext/profile.rb
... ... @@ -44,6 +44,14 @@ class Profile
44 44 self.solr_plugin_extra_index_methods.push(block) if block_given?
45 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 55 private
48 56  
49 57 def self.solr_plugin_f_categories_label_proc(environment)
... ...