|
From: shane <sh...@lo...> - 2006-03-22 01:47:36
|
On Mar 20, 2006, at 2:15 PM, Alexandre Leroux wrote:
>
> Hi list,
>
> Here's what I want to do: change the setting of all my users and
> the default setting for "Journal Entry by Friend" and "Journal
> Reply" to 'email' by default. This is found in Messages user
> preferences.
>
>
> The related tables are users_messages and message_codes.
>
>
> mysql> describe users_messages;
> +-------+-----------------------+------+-----+---------
> +----------------+
> | Field | Type | Null | Key | Default |
> Extra |
> +-------+-----------------------+------+-----+---------
> +----------------+
> | id | int(11) | | PRI | NULL |
> auto_increment |
> | uid | mediumint(8) unsigned | | MUL | 0
> | |
> | code | int(11) | | | 0
> | |
> | mode | tinyint(4) | | | 0
> | |
> +-------+-----------------------+------+-----+---------
> +----------------+
> 4 rows in set (0.00 sec)
>
> mysql> select * from users_messages where uid='3';
> +-----+-----+------+------+
> | id | uid | code | mode |
> +-----+-----+------+------+
> | 929 | 3 | 0 | 0 |
> | 928 | 3 | 1 | 0 |
> | 927 | 3 | 4 | 0 |
> | 930 | 3 | 5 | 0 |
> | 926 | 3 | 7 | 0 |
> | 925 | 3 | 11 | 0 |
> +-----+-----+------+------+
> 6 rows in set (0.00 sec)
>
> mysql> select * from message_codes;
> +------+----------------------------+---------+-------+------------
> +-----------+-------+
> | code | type | seclev | modes | send
> | subscribe | acl |
> +------+----------------------------+---------+-------+------------
> +-----------+-------+
> | -2 | Registration Mail | 1 | 0 | now
> | 0 | |
> | -1 | Unknown Message | 1 | 0 | now
> | 0 | |
> | 0 | Daily Newsletter | 1 | 0 | now
> | 0 | |
> | 1 | Daily Headlines | 1 | 0 | now
> | 0 | |
> | 2 | Metamoderation Results | 1 | | collective
> | 0 | |
> | 3 | Comment Moderation | 1 | | collective
> | 0 | |
> | 4 | Comment Reply | 1 | | now
> | 0 | |
> | 5 | Journal Entry by Friend | 1 | | now
> | 0 | |
> | 6 | New Submission | 100 | 0 | now
> | 0 | |
> | 7 | Journal Reply | 1 | | now
> | 0 | |
> | 8 | New Comment | 1000000 | | now
> | 0 | |
> | 10 | Daily Site Stats | 100 | 0 | now
> | 0 | stats |
> | 11 | Email Story | 1 | 0 | now
> | 0 | |
> | 12 | Relationship Change | 1 | | collective
> | 1 | |
> | 13 | Bad login attempt warnings | 1 | 1 | now
> | 0 | |
> | 14 | Daily Moderation Stats | 100 | 0 | now
> | 0 | stats |
> | 18 | Invalid HTML Input | 100 | | now
> | 0 | |
> +------+----------------------------+---------+-------+------------
> +-----------+-------+
> 17 rows in set (0.00 sec)
>
>
> I am not really a sql pro, but I guess to set the default values to
> 'email' I should do:
> >update messages_codes set modes='0' where code='5';
> >update messages_codes set modes='0' where code='7';
>
I think once you do the above updates, then when a user edits his
prefs the only method they can choose from to receive an update for
either of those two message types will be 'email'.
> Now, in order to change existing accounts (about 450) settings, I
> must update the users_messages table and add mode='0' to code='5'
> and '7' to all uid with an incremental 'id'. Is this needed or does
> the messages_codes table update enough? How do you suggest I proceed?
>
I would do
update users_messages set mode=0 where code in (5,7);
that will change anyone who already has it set.
as for creating entries for any users that do not have an try for
either code 5, or 7, you would do best to write some perl code to do
that.
you could probably do it with a few lines of Slash::Test somethin
like this (don't run this, not complete, not tested, I don't have
time at the moment for this, but it should get you looking in the
right direction)
#!/usr/bin/perl -w
use strict;
use Slash::Test shift;
my $messages = getObject('Slash::Messages');
my @users = $slashdb->sqlSelectAll('uid','users');
foreach my $uid (@users) {
my %params;
$params{MSG_CODE_JOURNAL_REPLY()} = MSG_MODE_EMAIL();
$params{MSG_CODE_JOURNAL_FRIEND()} = MSG_MODE_EMAIL();
$messages->setPrefs($uid, \%params);
}
Shane
|