MyBB Community Forums

Full Version: Force Subscription to Forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I've figured out how to update the database to change all users subscription to "Instant Email Notification".

Now I need to make sure all members are subscribed to a forum. This is a new, small private forum with only one forum and about 40 members and very few modifications/plugins. I want to make this change once, and then allow users to unsubscribe from the forum if they want.

Thanks for any help.
Anyone have an answer to this? Or is this not possible?

In phpMyAdmin, I see there is a table called forumsubscriptions, with 3 rows.
fid = forum id
uid = user id
fsid = ?

forum subscription id? Is this number important to the system in any way, or can I continue numbering consecutively as I add in the uid of my members?
I am also interested in this. Any ideas out there?
I saw this but it didn't look like you could subscribe users to certain (or all) forums. It set the default notification, and stopped users from changing it, but I didn't see an actual subscription part.

There is code for changing subscriptions of current users, but not new ones.

Did I miss something?
(2013-02-12, 03:52 PM)Lwestcott Wrote: [ -> ]Anyone have an answer to this? Or is this not possible?

In phpMyAdmin, I see there is a table called forumsubscriptions, with 3 rows.
fid = forum id
uid = user id
fsid = ?

forum subscription id? Is this number important to the system in any way, or can I continue numbering consecutively as I add in the uid of my members?

You can do a one-time insert of the rows in the database, but new members would not be subscribed automatically. Not sure if this is what you want.

fsid is just an auto-increment sequence.

Assuming your fid is 999, this script should work:
INSERT INTO forumsubscriptions (uid, fid)
SELECT uid, 999 FROM users;
I would like every new registered user to be subscribed to the forums I pick.

If I knew what code runs the registration process, I could probably do it. It would have to be at activation point. The program would do what you outlined, inserting a line into forumsubsciptions for each forum to be subscribed to, with the uid that just got registered and fid.

It wouldn't be too tough for someone who knew what they were doing. Unfortunately, that's not me!

Here is code which did the same thing in phpBB rather than MyBB, after a user was already registered. Can someone use this and make it work in MyBB?


// * You supply forum id and userid to the function
function createinsertq($a,$b)
{

// * This insert statement has one line for each forum being subscribed to
return ("INSERT INTO $b (forum_id, user_id, notify_status) VALUES
(8, $a, 0),
(10, $a, 0),
(11, $a, 0),
(12, $a, 0)");
}

//* these vars for $user and $password would be defined above.
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

//* don't remember what this TRUNCATE does
mysql_query("TRUNCATE TABLE $tablename") ;

//* Here we are calling the function 3 times for 3 userids. Tablename would be defined above
mysql_query(createinsertq(14,$tablename));
mysql_query(createinsertq(15,$tablename));
mysql_query(createinsertq(16,$tablename));

mysql_close();
(2013-06-10, 11:51 PM)kramsman Wrote: [ -> ]I would like every new registered user to be subscribed to the forums I pick.

If I knew what code runs the registration process, I could probably do it. It would have to be at activation point. The program would do what you outlined, inserting a line into forumsubsciptions for each forum to be subscribed to, with the uid that just got registered and fid.

It wouldn't be too tough for someone who knew what they were doing. Unfortunately, that's not me!

It would be fairly simple to make a plugin for this - the hook is "datahandler_user_insert".

Modifying the core file is not recommended at all, but if there is no plugin and you want something quick and dirty, this should do it. In inc/datahandlers/user.php, add this at the end of the "insert_user" function (just before the return):

//BEGIN CUSTOM MOD
$db->write_query("
	INSERT INTO ".TABLE_PREFIX."forumsubscriptions (fid, uid)
	SELECT fid, ".$this->uid."
	FROM ".TABLE_PREFIX."forums
	WHERE fid IN (997,998,999)
");
//END CUSTOM MOD

Substitute the "997,998,999" with a comma-separated list of the fids you want added. This would only work for new users, and you would need to run some one-time SQL (like I posted above) for your existing users.

Note: I haven't tested this at all, use at your own risk.
Would all the variables already be defined in the program? Like $db, table_prefix, and $this->uid? I don't really know php, and I know less of the programming environment, so your code is greek to me.

But I'll give it a try. I'm goint to set up a test BB in the next day or two, so I will try it there.

Thanks.
(2013-06-11, 12:48 AM)kramsman Wrote: [ -> ]Would all the variables already be defined in the program? Like $db, table_prefix, and $this->uid? I don't really know php, and I know less of the programming environment, so your code is greek to me.

But I'll give it a try. I'm goint to set up a test BB in the next day or two, so I will try it there.

Thanks.

Yes, those variables are already declared. Good luck Smile
Pages: 1 2