<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://cafuego.net"  xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Cafuego - simplenews</title>
 <link>http://cafuego.net/taxonomy/term/293/0</link>
 <description></description>
 <language>en</language>
<item>
 <title>Simplenews Mass Subscribe</title>
 <link>http://cafuego.net/2009/12/06/simplenews-mass-subscribe</link>
 <description>&lt;!-- google_ad_section_start --&gt;&lt;p&gt;&lt;a href=&quot;http://drupal.org/project/simplenews&quot;&gt;Simplenews&lt;/a&gt; is a quick and easy way to set up and manage newsletters on&amp;nbsp;Drupal, but if you add it to a site which already has users, you might want a way to quickly subscribe all your users to your newsletter.&lt;/p&gt;&lt;p&gt;Rather than click through all users and manually subscribe them - which can be a little bit boring if you have thousands of users - you can run a few SQL queries to mass-subscribe everyone in one go.&lt;/p&gt;&lt;p&gt;Each user that is subscribed to ANY newsletter has an entry in the &lt;em&gt;simplenews_subscriptions&lt;/em&gt; table, which contains their user id, their email address and an assigned subscription id. In addition to that, a user has a discrete entry in the &lt;em&gt;simplenews_snid_tid&lt;/em&gt; table for each separate newsletter they&#039;re subscribed to.&lt;/p&gt;&lt;p&gt;The latter basically links the unique ID from the subscriptions table to the term ID from the Newsletter taxonomy.&lt;/p&gt;&lt;p&gt;So what I do first is select the uid and email address for all authenticated users (the anonymous user has uid 0, so I select only users with a higher uid) and insert those into the &lt;em&gt;simplenews_subscriptions&lt;/em&gt; table.&lt;/p&gt;&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;strong&gt;INSERT INTO simplenews_subscriptions(activated,mail,uid) SELECT 1,mail,uid from USERS WHERE uid &amp;gt; 0 ORDER BY uid ASC;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;This automatically assigns a &lt;em&gt;snid&lt;/em&gt; (subscription id) to each entry. You&#039;ll notice that rather than selecting a column value into the &lt;em&gt;activated&lt;/em&gt; field, I just set it to 1.&lt;/p&gt;&lt;p&gt;Next, I need to find the taxonomy term ID (&lt;em&gt;tid&lt;/em&gt;) for the particular newsletter to which I want to subscribe all users. You can find this either by listing the terms in the Newsletter vocabulary or by listing all newsletters. In both cases the term id will be shown in your web browser&#039;s status bar if you hover the mouse over the edit link:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;http://example.com/admin/content/taxonomy/edit/term/&lt;strong&gt;42&lt;/strong&gt;?destination=admin/content/taxonomy/12&lt;/li&gt;&lt;li&gt;http://example.com/admin/content/simplenews/types/edit/&lt;strong&gt;42&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;On my Drupal site the &lt;em&gt;tid&lt;/em&gt; is 42, so that is the newsletter number I want to subscribe my users to. I need to refer to them via the automatically assigned &lt;em&gt;snid&lt;/em&gt; from the &lt;em&gt;simplenews_subscriptions&lt;/em&gt; table, so I select that and insert it directory into the &lt;em&gt;simplenews_snid_tid&lt;/em&gt; table, together with the correct &lt;em&gt;tid&lt;/em&gt;.&lt;/p&gt;&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;strong&gt;INSERT&amp;nbsp;INTO simplenews_snid_tid(snid,tid) SELECT snid,42 FROM simplenews_subscriptions;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;... and now all users on my site are subscribed to the newsletter with &lt;em&gt;tid&lt;/em&gt; 42.&lt;/p&gt;&lt;!-- google_ad_section_end --&gt;
&lt;!--
&lt;rdf:RDF xmlns:rdf=&quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot; xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:trackback=&quot;http://madskills.com/public/xml/rss/module/trackback/&quot;&gt;
&lt;rdf:Description rdf:about=&quot;http://cafuego.net/2009/12/06/simplenews-mass-subscribe&quot; dc:identifier=&quot;http://cafuego.net/2009/12/06/simplenews-mass-subscribe&quot; dc:title=&quot;Simplenews Mass Subscribe&quot; trackback:ping=&quot;http://cafuego.net/trackback/365&quot; /&gt;
&lt;/rdf:RDF&gt;
--&gt;
&lt;div class=&quot;trackback-url&quot;&gt;&lt;div class=&quot;box&quot;&gt;

  &lt;h2&gt;Trackback URL for this post:&lt;/h2&gt;

  &lt;div class=&quot;content&quot;&gt;http://cafuego.net/trackback/365&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</description>
 <comments>http://cafuego.net/2009/12/06/simplenews-mass-subscribe#comments</comments>
 <category domain="http://cafuego.net/category/tags/drupal">drupal</category>
 <category domain="http://cafuego.net/taxonomy/term/90">mysql</category>
 <category domain="http://cafuego.net/category/tags/simplenews">simplenews</category>
 <pubDate>Sun, 06 Dec 2009 06:58:07 +0000</pubDate>
 <dc:creator>cafuego</dc:creator>
 <guid isPermaLink="false">365 at http://cafuego.net</guid>
</item>
</channel>
</rss>

