Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,28 @@
|
||||
namespace IPS\forums\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Db;
|
||||
use IPS\Email;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Member;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* solvedNotifications Task
|
||||
*/
|
||||
class _solvedNotifications extends \IPS\Task
|
||||
class solvedNotifications extends Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
@@ -32,11 +44,11 @@ class _solvedNotifications extends \IPS\Task
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
* @throws Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : mixed
|
||||
{
|
||||
if ( ! \IPS\Settings::i()->forums_solved_topic_reengage )
|
||||
if ( ! Settings::i()->forums_solved_topic_reengage )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -45,23 +57,23 @@ class _solvedNotifications extends \IPS\Task
|
||||
super inefficient with sites with millions of members, we can consider an index on members_bitoptions2 or remove that sub-query and just check the author in the code before sending
|
||||
which would suck if all 50 were for members with re-enagement emails off, but we will see */
|
||||
$where = [
|
||||
[ \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
|
||||
[ 'posts > 1 and start_date > ? and start_date < ? and solved_reminder_sent=0 and topic_answered_pid=0', ( time() - ( 365 * 86400) ), ( time() - ( (int) \IPS\Settings::i()->forums_solved_topic_reengage * 86400 ) ) ],
|
||||
[ \IPS\Db::i()->in( 'forum_id', iterator_to_array( \IPS\Db::i()->select( 'id', 'forums_forums', '(' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers_member' ) . ') AND (' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers_moderator' ) . ')' ) ) ) ],
|
||||
[ 'starter_id NOT IN (?)', \IPS\Db::i()->select( 'member_id', 'core_members', \IPS\Db::i()->bitwiseWhere( \IPS\Member::$bitOptions['members_bitoptions'], 'no_solved_reenage' ) ) ]
|
||||
[ Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
|
||||
[ 'posts > 1 and start_date > ? and start_date < ? and solved_reminder_sent=0 and topic_answered_pid=0', ( time() - ( 365 * 86400) ), ( time() - ( (int) Settings::i()->forums_solved_topic_reengage * 86400 ) ) ],
|
||||
[ Db::i()->in( 'forum_id', iterator_to_array( Db::i()->select( 'id', 'forums_forums', '(' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_solved_set_by_member' ) . ') AND (' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_solved_set_by_moderator' ) . ')' ) ) ) ],
|
||||
[ 'starter_id NOT IN (?)', Db::i()->select( 'member_id', 'core_members', Db::i()->bitwiseWhere( Member::$bitOptions['members_bitoptions'], 'no_solved_reenage' ) ) ]
|
||||
];
|
||||
|
||||
$topics = [];
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_topics', $where, 'start_date ASC', [ 0, 50 ] ) as $row )
|
||||
foreach( Db::i()->select( '*', 'forums_topics', $where, 'start_date ASC', [ 0, 50 ] ) as $row )
|
||||
{
|
||||
$topics[ $row['tid'] ] = $row;
|
||||
}
|
||||
|
||||
$starters = [];
|
||||
if ( \count( $topics ) )
|
||||
if ( count( $topics ) )
|
||||
{
|
||||
/* Get a count of how many reminders have been sent already */
|
||||
foreach( \IPS\Db::i()->select( 'starter_id, COUNT(*) as count', 'forums_topics', [
|
||||
foreach( Db::i()->select( 'starter_id, COUNT(*) as count', 'forums_topics', [
|
||||
[ 'solved_reminder_sent > ?', time() - ( 86400 * 7 ) ]
|
||||
], NULL, NULL, 'starter_id' ) as $row ) {
|
||||
$starters[ $row['starter_id'] ] = $row['count'];
|
||||
@@ -80,19 +92,19 @@ class _solvedNotifications extends \IPS\Task
|
||||
We don't want to send this one as the starter has had too many sent, so reset time to 5 days ago so a task can check again on this one in a few days
|
||||
There is hardcoded to 5 max a week. We could consider a setting but I feel that 5 max per week isn't overwhelming but is enough to prompt re-engagement
|
||||
*/
|
||||
\IPS\Db::i()->update( 'forums_topics', [ 'solved_reminder_sent' => time() - ( 86400 * 5 ) ], ['tid=?', $row['tid']] );
|
||||
Db::i()->update( 'forums_topics', [ 'solved_reminder_sent' => time() - ( 86400 * 5 ) ], ['tid=?', $row['tid']] );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Avoid race conditions and make sure its updated even if constructFromData fails */
|
||||
\IPS\Db::i()->update( 'forums_topics', [ 'solved_reminder_sent' => time() ], ['tid=?', $row['tid']] );
|
||||
Db::i()->update( 'forums_topics', [ 'solved_reminder_sent' => time() ], ['tid=?', $row['tid']] );
|
||||
|
||||
/* Increment so the next foreach will count it correctly */
|
||||
$starters[ $row['starter_id'] ]++;
|
||||
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::constructFromData( $row );
|
||||
$topic = Topic::constructFromData( $row );
|
||||
|
||||
/* Don't send for converted live topics */
|
||||
if ( $topic->getLiveTopic() )
|
||||
@@ -110,10 +122,10 @@ class _solvedNotifications extends \IPS\Task
|
||||
continue;
|
||||
}
|
||||
|
||||
\IPS\Email::buildFromTemplate( 'core', 'solved_reengagement', array($topic, $firstPost, $replies), \IPS\Email::TYPE_TRANSACTIONAL )->send( $topic->author() );
|
||||
Email::buildFromTemplate( 'core', 'solved_reengagement', array($topic, $firstPost, $replies), Email::TYPE_TRANSACTIONAL )->send( $topic->author() );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user