<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>db/migrate/062_add_notify_to_comments.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -9,6 +9,7 @@
 * use Desert plugin for code mixing and plugin migrations instead of Engines
 * allow moderators/activity owners to delete activities
 * only track login activity once per day
+* allow anonymous commenters to choose whether they want to receive follow-up comment notices by e-mail
 
 = 1.0.1
 * fixed error when cropping photos using file system storage</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -26,3 +26,4 @@ Upgrading an Engines-based CE app to use the new Desert-based CE is easy:
 
 Notes
 =====
+If you have old migrations from the Engines-based CE, you may experience some problems if you try to migrate your db from 0. That's because the old plugin migrations used the `Engines.plugins[&quot;community_engine&quot;].migrate(version_number)` format. You'll need to replace all those with `migrate_plugin(:community_engine, version_number)`, and also run `rake community_engine:db:migrate:upgrade_desert_plugin_migrations` to ensure your plugin migrations are listed in the correct table.
\ No newline at end of file</diff>
      <filename>UPGRADING.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -42,7 +42,8 @@ class Comment &lt; ActiveRecord::Base
     User.find(:all, 
       :conditions =&gt; [&quot;users.id NOT IN (?) AND users.notify_comments = ? 
                       AND commentable_id = ? AND commentable_type = ? 
-                      AND comments.created_at &gt; ?&quot;, [user_id, recipient_id.to_i], true, commentable_id, commentable_type, 2.weeks.ago], 
+                      AND comments.notify_by_email = ? 
+                      AND comments.created_at &gt; ?&quot;, [user_id, recipient_id.to_i], true, commentable_id, commentable_type, true, 2.weeks.ago], 
 #      :include =&gt; :comments_as_author, :group =&gt; &quot;users.id&quot;, :limit =&gt; 20)    
       :include =&gt; :comments_as_author, :limit =&gt; 20)
   end    
@@ -93,7 +94,7 @@ class Comment &lt; ActiveRecord::Base
   end
   
   def notify_previous_anonymous_commenters
-    anonymous_commenters_emails = commentable.comments.map{|c|  c.author_email if ( !c.user &amp;&amp; !c.author_email.eql?(self.author_email) &amp;&amp; c.author_email) }.uniq.compact
+    anonymous_commenters_emails = commentable.comments.map{|c|  c.author_email if (c.notify_by_email? &amp;&amp; !c.user &amp;&amp; !c.author_email.eql?(self.author_email) &amp;&amp; c.author_email) }.uniq.compact
     anonymous_commenters_emails.each do |email|
       UserNotifier.deliver_follow_up_comment_notice_anonymous(email, self)
     end    
@@ -101,7 +102,7 @@ class Comment &lt; ActiveRecord::Base
   
   def send_notifications
     UserNotifier.deliver_comment_notice(self) if should_notify_recipient?
-    self.notify_previous_commenters  
+    self.notify_previous_commenters
     self.notify_previous_anonymous_commenters if AppConfig.allow_anonymous_commenting
   end
   </diff>
      <filename>app/models/comment.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,10 +28,15 @@
         =&quot;#{'E-mail'.l}:&quot;
         %em=&quot;(#{&quot;Required; won't be shown on site&quot;.l})&quot;
       = f.text_field :author_email, :size =&gt; 35        
-      %label{&quot;for&quot;=&gt;&quot;comment[author_email&quot;}
+      %br
+      %label 
+        =f.check_box :notify_by_email
+        =:notify_me_of_follow_ups_via_email.l
+      
+      %label{&quot;for&quot;=&gt;&quot;comment[author_url&quot;}
         =&quot;Web site (include http://):&quot;.l
         %em=&quot;(#{'Optional'.l})&quot;
-      = f.text_field :author_url, :size =&gt; 35        
+      = f.text_field :author_url, :size =&gt; 35
 
     
     %p</diff>
      <filename>app/views/comments/_comment_form.html.haml</filename>
    </modified>
    <modified>
      <diff>@@ -368,6 +368,7 @@
 #en: no_profile_photo: &quot;No profile photo?&quot;
 #en: no_recent_activity: No recent activity
 #en: no_tags: No tags
+#en: notify_me_of_follow_ups_via_email: Notify me of follow ups via e-mail  
 #en: notify_email_updates: Notify of community news
 #en: notify_of_comments: Notify of comments
 #en: notify_of_friend_requests: Notify of friend requests</diff>
      <filename>lang/base.yml</filename>
    </modified>
    <modified>
      <diff>@@ -751,6 +751,8 @@ en:
   no_tags: No tags
   #en: notify_email_updates: Notify of community news
   notify_email_updates: Notify of community news
+  #en: notify_me_of_follow_ups_via_email: Notify me of follow ups via e-mail  
+  notify_me_of_follow_ups_via_email: Notify me of follow ups via e-mail  
   #en: notify_of_comments: Notify of comments
   notify_of_comments: Notify of comments
   #en: notify_of_friend_requests: Notify of friend requests</diff>
      <filename>lang/ui/en-US.yml</filename>
    </modified>
    <modified>
      <diff>@@ -93,5 +93,49 @@ namespace :community_engine do
       end
     end
   end
+  
+  namespace :db do
+    namespace :migrate do 
+      desc 'For CE coming from version &lt; 1.0.1 that stored plugin migration info in the normal Rails schema_migrations table. Move that info back into the plugin_schema_migrations table.'
+      task :upgrade_desert_plugin_migrations =&gt; :environment do
+        plugin_migration_table = Desert::PluginMigrations::Migrator.schema_migrations_table_name
+        schema_migration_table = ActiveRecord::Migrator.schema_migrations_table_name
+          
+        unless ActiveRecord::Base.connection.table_exists?(plugin_migration_table)
+          abort &quot;Cannot find plugin migration table #{plugin_migration_table}.&quot;
+        end
+
+        def insert_new_version(plugin_name, version, table)
+          # Check if the row already exists for some reason - maybe run this task more than once.
+          return if ActiveRecord::Base.connection.select_rows(&quot;SELECT * FROM #{table} WHERE version = #{version} AND plugin_name = '#{plugin_name}'&quot;).size &gt; 0
+
+          puts &quot;Inserting new version #{version} for plugin #{plugin_name} in #{table}.&quot;
+          ActiveRecord::Base.connection.insert(&quot;INSERT INTO #{table} (plugin_name, version) VALUES ('#{plugin_name}', #{version.to_i})&quot;)
+        end
+        
+        def remove_old_version(plugin_name, version, table)
+          puts &quot;Removing old version #{version} for plugin #{plugin_name} in #{table}.&quot;          
+          ActiveRecord::Base.connection.execute(&quot;DELETE FROM #{table} WHERE version = '#{version}-#{plugin_name}'&quot;)
+        end
+
+        existing_migrations = ActiveRecord::Base.connection.select_rows(&quot;SELECT * FROM #{schema_migration_table}&quot;).uniq
+        migrations = {}
+        existing_migrations.flatten.each do |m|
+          plugin_version, plugin_name = m.split('-')
+          next if plugin_name.blank?
+          migrations[plugin_name] ||= []
+          migrations[plugin_name] &lt;&lt; plugin_version
+        end
+        
+        migrations.each do |plugin_name, versions|
+          versions.each do |version|
+            insert_new_version(plugin_name, version, plugin_migration_table)
+            remove_old_version(plugin_name, version, schema_migration_table)
+          end
+        end
+
+      end
+    end
+  end
 
 end
\ No newline at end of file</diff>
      <filename>tasks/community_engine_tasks.rake</filename>
    </modified>
    <modified>
      <diff>@@ -49,6 +49,17 @@ class CommentTest &lt; ActiveSupport::TestCase
     AppConfig.allow_anonymous_commenting = nil
   end  
   
+  def test_should_not_notify_previous_anonymous_commenter_if_notify_by_email_is_false
+    AppConfig.allow_anonymous_commenting = true
+    Comment.create!(:comment =&gt; 'foo', :author_email =&gt; 'bruno@foo.com', :author_ip =&gt; '123.123.123', :recipient =&gt; users(:quentin), :commentable =&gt; users(:quentin), :notify_by_email =&gt; false)
+
+    comment = Comment.create!(:comment =&gt; 'bar', :author_email =&gt; 'alicia@foo.com', :author_ip =&gt; '123.123.123', :recipient =&gt; users(:quentin), :commentable =&gt; users(:quentin))        
+
+    assert_difference ActionMailer::Base.deliveries, :length, 0 do
+      comment.notify_previous_anonymous_commenters
+    end
+    AppConfig.allow_anonymous_commenting = false
+  end
   
   def test_should_not_be_created_anonymously
     assert_no_difference Comment, :count do</diff>
      <filename>test/unit/comment_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fe78abd6d66b4b1ab55811bb2f8635cbbf2b72f7</id>
    </parent>
  </parents>
  <author>
    <name>bborn</name>
    <email>bruno.bornsztein@gmail.com</email>
  </author>
  <url>http://github.com/bborn/communityengine/commit/cf9e58e0aa0dfbd8df32292ee23b2947e3da2590</url>
  <id>cf9e58e0aa0dfbd8df32292ee23b2947e3da2590</id>
  <committed-date>2009-04-28T15:12:07-07:00</committed-date>
  <authored-date>2009-04-28T15:12:07-07:00</authored-date>
  <message>add rake task to move plugin migrations into the correct table
allow anonymous commenters to not receive email notifications of follow ups</message>
  <tree>17a7f57f20febf0ada98784986539f67855e79e1</tree>
  <committer>
    <name>bborn</name>
    <email>bruno.bornsztein@gmail.com</email>
  </committer>
</commit>
