Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
2641dbd9
Unverified
Commit
2641dbd9
authored
Nov 30, 2018
by
Scott
Committed by
GitHub
Nov 30, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #657 from pupi1985/patch-109
Avoid sending emails to blocked and unapproved users
parents
1c7e3713
306a9bec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
30 deletions
+42
-30
mailing.php
qa-include/app/mailing.php
+41
-29
users.php
qa-include/db/users.php
+1
-1
No files found.
qa-include/app/mailing.php
View file @
2641dbd9
...
...
@@ -59,48 +59,60 @@ function qa_mailing_stop()
function
qa_mailing_perform_step
()
{
require_once
QA_INCLUDE_DIR
.
'db/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
$lastuserid
=
qa_opt
(
'mailing_last_userid'
);
if
(
strlen
(
$lastuserid
))
{
$thistime
=
time
();
$lasttime
=
qa_opt
(
'mailing_last_timestamp'
);
$perminute
=
qa_opt
(
'mailing_per_minute'
);
if
(
strlen
(
$lastuserid
)
==
0
)
{
return
;
}
$thistime
=
time
();
$lasttime
=
qa_opt
(
'mailing_last_timestamp'
);
$perminute
=
qa_opt
(
'mailing_per_minute'
);
if
((
$lasttime
-
$thistime
)
>
60
)
// if it's been a while, we assume there hasn't been continuous mailing...
$lasttime
=
$thistime
-
1
;
// ... so only do 1 second's worth
else
// otherwise...
$lasttime
=
max
(
$lasttime
,
$thistime
-
6
);
// ... don't do more than 6 seconds' worth
if
((
$lasttime
-
$thistime
)
>
60
)
// if it's been a while, we assume there hasn't been continuous mailing...
$lasttime
=
$thistime
-
1
;
// ... so only do 1 second's worth
else
// otherwise...
$lasttime
=
max
(
$lasttime
,
$thistime
-
6
);
// ... don't do more than 6 seconds' worth
$count
=
min
(
floor
((
$thistime
-
$lasttime
)
*
$perminute
/
60
),
100
);
// don't do more than 100 messages at a time
$count
=
min
(
floor
((
$thistime
-
$lasttime
)
*
$perminute
/
60
),
100
);
// don't do more than 100 messages at a time
if
(
$count
>
0
)
{
qa_opt
(
'mailing_last_timestamp'
,
$thistime
+
30
)
;
// prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex)
if
(
$count
==
0
)
{
return
;
}
$sentusers
=
0
;
$users
=
qa_db_users_get_mailing_next
(
$lastuserid
,
$count
);
qa_opt
(
'mailing_last_timestamp'
,
$thistime
+
30
)
;
// prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex)
if
(
count
(
$users
))
{
foreach
(
$users
as
$user
)
{
$lastuserid
=
max
(
$lastuserid
,
$user
[
'userid'
]);
}
$sentusers
=
0
;
$users
=
qa_db_users_get_mailing_next
(
$lastuserid
,
$count
);
qa_opt
(
'mailing_last_userid'
,
$lastuserid
);
qa_opt
(
'mailing_done_users'
,
qa_opt
(
'mailing_done_users'
)
+
count
(
$users
));
if
(
count
(
$users
))
{
foreach
(
$users
as
$user
)
{
$lastuserid
=
max
(
$lastuserid
,
$user
[
'userid'
]);
}
foreach
(
$users
as
$user
)
{
if
(
!
(
$user
[
'flags'
]
&
QA_USER_FLAGS_NO_MAILINGS
))
{
qa_mailing_send_one
(
$user
[
'userid'
],
$user
[
'handle'
],
$user
[
'email'
],
$user
[
'emailcode'
]);
$sentusers
++
;
}
}
qa_opt
(
'mailing_last_userid'
,
$lastuserid
);
qa_opt
(
'mailing_done_users'
,
qa_opt
(
'mailing_done_users'
)
+
count
(
$users
));
qa_opt
(
'mailing_last_timestamp'
,
$lasttime
+
$sentusers
*
60
/
$perminute
);
// can be floating point result, based on number of mails actually sent
$isModeratingUsers
=
qa_opt
(
'moderate_users'
);
}
else
qa_mailing_stop
();
foreach
(
$users
as
$user
)
{
if
((
$user
[
'flags'
]
&
QA_USER_FLAGS_NO_MAILINGS
)
||
// exclude users who don't want to get the mailings
(
$user
[
'flags'
]
&
QA_USER_FLAGS_USER_BLOCKED
)
||
// exclude blocked users
(
$isModeratingUsers
&&
(
$user
[
'level'
]
<
QA_USER_LEVEL_APPROVED
)))
{
// if moderating users exclude unapproved users
continue
;
}
qa_mailing_send_one
(
$user
[
'userid'
],
$user
[
'handle'
],
$user
[
'email'
],
$user
[
'emailcode'
]);
$sentusers
++
;
}
qa_opt
(
'mailing_last_timestamp'
,
$lasttime
+
$sentusers
*
60
/
$perminute
);
// can be floating point result, based on number of mails actually sent
}
else
{
qa_mailing_stop
();
}
}
...
...
qa-include/db/users.php
View file @
2641dbd9
...
...
@@ -376,7 +376,7 @@ function qa_db_user_levels_set($userid, $userlevels)
function
qa_db_users_get_mailing_next
(
$lastuserid
,
$count
)
{
return
qa_db_read_all_assoc
(
qa_db_query_sub
(
'SELECT userid, email, handle, emailcode, flags FROM ^users WHERE userid># ORDER BY userid LIMIT #'
,
'SELECT userid, email, handle, emailcode, flags
, level
FROM ^users WHERE userid># ORDER BY userid LIMIT #'
,
$lastuserid
,
$count
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment