https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292010-10-02T19:52:34ZRedmineRedmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=209342010-10-02T19:52:34ZFelix Schäfer
<ul></ul><p>Ok, so a follow-up on this: as I said earlier, users who had selected "For any event on the selected projects only…" get updated to "Only for things I watch or I'm involved in", which isn't a desired state. The hotfix for people who have been bitten by this: open a console (run <code>RAILS_ENV=production script/console</code> in your redmine directory) and execute the following command:</p>
<pre><code class="ruby syntaxhl"><span class="no">User</span><span class="p">.</span><span class="nf">find_all_by_mail_notification</span><span class="p">(</span><span class="s1">'only_my_events'</span><span class="p">).</span><span class="nf">select</span> <span class="p">{</span><span class="o">|</span><span class="n">u</span><span class="o">|</span> <span class="o">!</span><span class="n">u</span><span class="p">.</span><span class="nf">notified_projects_ids</span><span class="p">.</span><span class="nf">empty?</span><span class="p">}.</span><span class="nf">each</span> <span class="p">{</span><span class="o">|</span><span class="n">u</span><span class="o">|</span> <span class="n">u</span><span class="p">.</span><span class="nf">mail_notification</span> <span class="o">=</span> <span class="s1">'selected'</span><span class="p">;</span> <span class="n">u</span><span class="p">.</span><span class="nf">save!</span><span class="p">}</span></code></pre>
<p>2 things: this will only work for people whose account hasn't been "written to" since the faulty migration, this won't work for users who have been to their account page and changed something, be it the mail notification options or their name or whatever. The hotfix only works because of a dangling "data inconsistency" left over by the faulty migration and corrects that, users who have changed their account in some way have overwritten this. The second thing is: I take <em>no responsibility</em> whatsoever in what happens with your data with the above line, it worked well on my test and production rig, if it blows your DB, well, you should replay this backup you made beforehand.</p>
<p>So much for the hotfix, I have a probable fix for the migration, which I have to test a little bit more before posting it here.</p>
<p>(oh, and if you want a list of affected users, this should give you the list of mail addresses of those users, same conditions as above apply:</p>
<pre><code class="ruby syntaxhl"><span class="no">User</span><span class="p">.</span><span class="nf">find_all_by_mail_notification</span><span class="p">(</span><span class="s1">'only_my_events'</span><span class="p">).</span><span class="nf">select</span> <span class="p">{</span><span class="o">|</span><span class="n">u</span><span class="o">|</span> <span class="o">!</span><span class="n">u</span><span class="p">.</span><span class="nf">notified_projects_ids</span><span class="p">.</span><span class="nf">empty?</span><span class="p">}.</span><span class="nf">collect</span><span class="p">(</span><span class="o">&</span><span class="ss">:mail</span><span class="p">)</span></code></pre>
<p>Replace the <code>mail</code> in the <code>collect(&:mail)</code> at the end with another attribute to get a list of this attribute of the affect users.)</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=209372010-10-02T20:51:43ZFelix Schäfer
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>7</i></li></ul><p>Ok, here's the commit to fix the migration: <a class="external" href="http://github.com/thegcat/redmine/commit/811bc0863015c2d2ed87f71edaec95560ada9318">http://github.com/thegcat/redmine/commit/811bc0863015c2d2ed87f71edaec95560ada9318</a></p>
<p>Here's the diff of the proposed change, comments after that:</p>
<pre><code class="ruby syntaxhl"><span class="n">diff</span> <span class="o">--</span><span class="n">git</span> <span class="n">a</span><span class="o">/</span><span class="n">db</span><span class="o">/</span><span class="n">migrate</span><span class="o">/</span><span class="mi">20100129193813</span><span class="n">_update_mail_notification_values</span><span class="p">.</span><span class="nf">rb</span> <span class="n">b</span><span class="o">/</span><span class="n">db</span><span class="o">/</span><span class="n">migrate</span><span class="o">/</span><span class="mi">20100129193813</span><span class="n">_update_mail_notification_values</span><span class="p">.</span><span class="nf">rb</span>
<span class="n">index</span> <span class="n">bfe0a59</span><span class="o">..</span><span class="mi">4</span><span class="n">b49d87</span> <span class="mi">100644</span>
<span class="o">---</span> <span class="n">a</span><span class="o">/</span><span class="n">db</span><span class="o">/</span><span class="n">migrate</span><span class="o">/</span><span class="mi">20100129193813</span><span class="n">_update_mail_notification_values</span><span class="p">.</span><span class="nf">rb</span>
<span class="o">+++</span> <span class="n">b</span><span class="o">/</span><span class="n">db</span><span class="o">/</span><span class="n">migrate</span><span class="o">/</span><span class="mi">20100129193813</span><span class="n">_update_mail_notification_values</span><span class="p">.</span><span class="nf">rb</span>
<span class="err">@@</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">8</span> <span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="mi">12</span> <span class="err">@@</span>
<span class="c1"># Patch the data from a boolean change.</span>
<span class="k">class</span> <span class="nc">UpdateMailNotificationValues</span> <span class="o"><</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span>
<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span>
<span class="o">-</span> <span class="no">User</span><span class="p">.</span><span class="nf">update_all</span><span class="p">(</span><span class="s2">"mail_notification = 'all'"</span><span class="p">,</span> <span class="s2">"mail_notification = '1'"</span><span class="p">)</span>
<span class="o">-</span> <span class="no">User</span><span class="p">.</span><span class="nf">update_all</span><span class="p">(</span><span class="s2">"mail_notification = 'only_my_events'"</span><span class="p">,</span> <span class="s2">"mail_notification = '0'"</span><span class="p">)</span>
<span class="o">+</span> <span class="no">User</span><span class="p">.</span><span class="nf">record_timestamps</span> <span class="o">=</span> <span class="kp">false</span>
<span class="o">+</span> <span class="no">User</span><span class="p">.</span><span class="nf">all</span><span class="p">.</span><span class="nf">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">u</span><span class="o">|</span>
<span class="o">+</span> <span class="n">u</span><span class="p">.</span><span class="nf">mail_notification</span> <span class="o">=</span> <span class="p">(</span><span class="n">u</span><span class="p">.</span><span class="nf">mail_notification</span> <span class="o">=~</span> <span class="sr">/\A(1|t)\z/</span> <span class="p">?</span> <span class="s1">'all'</span> <span class="p">:</span> <span class="p">(</span><span class="n">u</span><span class="p">.</span><span class="nf">notified_projects_ids</span><span class="p">.</span><span class="nf">empty?</span> <span class="p">?</span> <span class="s1">'only_my_events'</span> <span class="p">:</span> <span class="s1">'selected'</span><span class="p">))</span>
<span class="o">+</span> <span class="n">u</span><span class="p">.</span><span class="nf">save!</span>
<span class="o">+</span> <span class="k">end</span>
<span class="o">+</span> <span class="no">User</span><span class="p">.</span><span class="nf">record_timestamps</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">end</span>
<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span></code></pre>
<p>I didn't find any "nice" way to get this done all through <code>User.update_all</code>, so I went the programmatic way. The timestamps are disabled for the duration of the change so that all users don't their <code>updated_on</code> bumped up needlessly to the time the migration is applied. This migration also takes into account that some databases migrate a <code>true</code> boolean field to <code>t</code> and not to <code>1</code> when the field is changed to a <code>varchar</code>.</p>
<p>Eric: Want me to merge that with the other patch from <a class="issue tracker-1 status-5 priority-5 priority-high2 closed" title="Defect: Email notifications send to everybody (Closed)" href="https://www.redmine.org/issues/6541">#6541</a>, or will you take care of it?</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=209952010-10-04T13:38:35ZFelix Schäfer
<ul></ul><p><a href="http://github.com/thegcat/redmine/commit/811bc0863015c2d2ed87f71edaec95560ada9318#commitcomment-161195" class="external">ChrisMcKee wrote on github</a>:</p>
<blockquote>
<p>Oddly this didnt fix my Trunk SVN Redmine site</p>
</blockquote>
<p>Chris, this doesn't fix already migrated sites, i.e. if you already applied the migration when there were the <code>User.update_all</code> blurbs in there, it won't fix anything, the patch I submitted to github only prevents this error from happening for people who will run the migration later on.</p>
<p>I suspect you had already run the faulty migration, please see my <a href="/issues/6549#note-1">first comment</a> on this page for a way to correct this.</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=209992010-10-04T14:27:02ZChris McKee
<ul></ul><p>What modifications this making to the users table (wondering as the first script wont run in WinServer2k3)<br />Would I be better off restoring the user preferences table from pre-upgrade?</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=210002010-10-04T14:32:52ZChris McKee
<ul></ul><p>I should add I'm using MySQL and mail notification is being set to 1 for groups while users obviously still have their own settings only_my_events.<br />Not so much fun in a top500 company when your VP starts to get updates on web tasks :|</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=210012010-10-04T15:09:41ZFelix Schäfer
<ul></ul><p>Chris McKee wrote:</p>
<blockquote>
<p>Not so much fun in a top500 company when your VP starts to get updates on web tasks :|</p>
</blockquote>
<p>Well, maybe you shouldn't run trunk then ;-) Repeat after me: trunk is not stable, trunk is not stable, trunk…</p>
<p>Anyway, the line in comment 1 updates the settings correctly, but doesn't solve the problem which causes mails to be sent to every project member rather than just to those who requested it, see <a class="issue tracker-1 status-5 priority-5 priority-high2 closed" title="Defect: Email notifications send to everybody (Closed)" href="https://www.redmine.org/issues/6541">#6541</a> for more info and a patch for that.</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=210022010-10-04T15:29:13ZChris McKee
<ul></ul><p>Felix Schäfer wrote:</p>
<blockquote>
<p>Well, maybe you shouldn't run trunk then ;-) Repeat after me: trunk is not stable, trunk is not stable, trunk…</p>
</blockquote>
<p>To be fair id only updated to the 1.0.2 tag; the errors even in the Bitnami release + tag</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=210042010-10-04T15:38:13ZFelix Schäfer
<ul></ul><p>Chris McKee wrote:</p>
<blockquote>
<p>Felix Schäfer wrote:</p>
<blockquote>
<p>Well, maybe you shouldn't run trunk then ;-) Repeat after me: trunk is not stable, trunk is not stable, trunk…</p>
</blockquote>
<p>To be fair id only updated to the 1.0.2 tag; the errors even in the Bitnami release + tag</p>
</blockquote>
<p>Then you shouldn't have this migration in yet at all, this is staged for 1.1 at the earliest…</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=210052010-10-04T15:45:48ZChris McKee
<ul></ul><p>Curse of automation, I think our trunk server ended up updating the main servers email settings so the database migration took place for dev into live. What a difference an xcopy makes.<br />Ah well even with mass mailing its still more usable than Sharepoint.</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=210242010-10-05T08:10:57ZChris McKee
<ul></ul><p>Adding this to a clean 'trunk' and manually rolling back the user table and running <a class="issue tracker-1 status-5 priority-5 priority-high2 closed" title="Defect: Email notifications send to everybody (Closed)" href="https://www.redmine.org/issues/6541">#6541</a> in script/console seems to have fixed it :o)</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=212052010-10-10T21:14:04ZEric Davis
<ul><li><strong>Status</strong> changed from <i>7</i> to <i>Closed</i></li><li><strong>Target version</strong> set to <i>1.1.0</i></li><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul><p>Fixed in <a class="changeset" title="Correctly update all mail_notification options. #6549 * Need to check for 't' values to support ..." href="https://www.redmine.org/projects/redmine/repository/svn/revisions/4246">r4246</a> with a modified version of Felix's patch.</p> Redmine - Defect #6549: Notification settings not migrated properlyhttps://www.redmine.org/issues/6549?journal_id=226242010-11-22T14:37:00ZAndreas R
<ul></ul><p>I just updated to my svn instalation from svn trunk (Revision: 4425 and read the above comments about using trunk) and found a funny thing:</p>
<p>My database didn't migrate the mail_notification from bool to string but <code>db/migrate/20100129193402_change_users_mail_notification_to_string.rb</code> was there and looked good.</p>
<p>Made the migrations manually and the it worked.</p>
<p>Is there any reason while a migration didn't get executed? Can i look somehwere what went wrong? Nothing n log/production.log though.</p>