it would be excellent if i could force all users to be subscribed to a newsletter. i'm sure this could be accomplished through a sql query on my part, but i dont know mysql too well. if theres a query i can run periodically to subscribe all users to a newsletter, let me know

-adam

Comments

ngstigator’s picture

I had the same requirement. This will insert a record into sn_subscriptions for every user (except for user 0) that hasn't already subscribed.

INSERT INTO sn_subscriptions( a_status, s_status, mail, uid )
SELECT 1 AS a_status, 1 AS s_status, mail, uid
FROM users
WHERE users.uid NOT
IN (

SELECT uid
FROM sn_subscriptions
)
AND users.uid !=0
ngstigator’s picture

It seems that more interaction with tables is needed than my paltry SQL snippet.

An easier way to do this is to go to http://www.yourdrupalsite.com/admin/newsletter/users/add and add the email addresses listed in:

SELECT mail FROM users;
cutesimaus’s picture

Thanks. I like this approach better than the patch i saw in another thread.

sutharsan’s picture

Status: Active » Closed (fixed)

A one time subscription of all users will not make it as a feature into Simplenews. Subscription of new users is now available as a HEAD patch: http://drupal.org/node/76648. It will not get rolled back to 4.7.x.

binarylime’s picture

Version: 4.7.x-1.x-dev » 6.x-1.0-rc6
Component: Miscellaneous » Usability
Assigned: Unassigned » binarylime
Status: Closed (fixed) » Fixed
Issue tags: +autosubscribe, +SimpleNews, +force

I've written a MySQL / PHP snipet that will add anyone who isn't already to the simplenews newsletter. I've created this as a page in Drupal and it will run each time the page is visited.

You should be able to just copy and paste and just change the '69' to your newsletter id.

<?php

$count = 0;

$a = db_query("select users.uid, users.mail from users order by users.uid asc");

while ($result_a = db_fetch_object($a))
{
	$mail = addslashes($result_a->mail);
	
	$b = db_query("select simplenews_subscriptions.uid from simplenews_subscriptions where simplenews_subscriptions.uid = $result_a->uid");
	
	if (mysql_num_rows($b)==0)
	{
		db_query("insert into simplenews_subscriptions (activated, mail, uid) values (1, '$mail', $result_a->uid)");
		
		$c = db_query("select simplenews_subscriptions.snid from simplenews_subscriptions order by snid asc");
		
		while ($result_c = db_fetch_object($c))
		{
			$d = db_query("select simplenews_snid_tid.snid from simplenews_snid_tid where simplenews_snid_tid.snid = $result_c->snid");
			
			if (mysql_num_rows($d)==0)	
			{
				$count++;
				db_query("insert into simplenews_snid_tid (snid, tid) values ($result_c->snid, 69)");
			}
		}
		
	}
}

echo "Process complete. " . $count . " users added to the newsletter.";

?>


Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rfranquet’s picture

Thanks Andrew, this is a new release.

<?php
$newsletter = 69; // <<---- PLEASE PUT YOUR NEWSLETTER ID
$count_newusr = 0;
$count_newreg = 0;

$a = db_query("select users.uid, users.mail from users order by users.uid asc");

while ($result_a = db_fetch_object($a))
{
    $mail = addslashes($result_a->mail);
   
    $b = db_query("select simplenews_subscriptions.uid from simplenews_subscriptions where simplenews_subscriptions.uid = $result_a->uid");
   
    if (db_result($b)===FALSE && $result_a->uid !=0)
    {
		$count_newusr++;
        db_query("insert into simplenews_subscriptions (activated, mail, uid) values (1, '$mail', $result_a->uid)");
	}
}

$a = db_query("select simplenews_subscriptions.snid from simplenews_subscriptions order by simplenews_subscriptions.snid asc");

while ($result_a = db_fetch_object($a))
{
	$b = db_query("select simplenews_snid_tid.snid from simplenews_snid_tid where simplenews_snid_tid.snid = $result_a->snid AND simplenews_snid_tid.tid = $newsletter");
   
    if (db_result($b)===FALSE)
    {
			$count_newreg++;
			db_query("insert into simplenews_snid_tid (snid, tid) values ($result_a->snid, $newsletter)");
	}
}


    
echo "<h2>";
echo "Process complete. <br /> ";
echo " $count_newusr users added to the simplenews. <br /> ";
echo " $count_newreg users added to the newsletter. <br /> ";
echo "</h2>";

?>
binarylime’s picture

I'm now having issues with this as I have around 8000 users.

I'm getting the error
:
Fatal error: Out of memory (allocated XXXX) (tried to allocate X bytes) in drupalsite.com/html/includes/bootstrap.inc on line 584.

Any ideas to refine this code?