Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

+125
View File
@@ -0,0 +1,125 @@
<?php
/**
* @brief autolock Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
{subpackage}
* @since 23 Jul 2025
*/
namespace IPS\forums\tasks;
use IPS\Db;
use IPS\forums\Topic;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Settings as SettingsClass;
use IPS\Task;
use IPS\Task\Exception as TaskException;
use function defined;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* autolock Task
*/
class autolock extends Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws TaskException
*/
public function execute() : mixed
{
$settings = SettingsClass::i()->autolock_topic_settings ? json_decode( SettingsClass::i()->autolock_topic_settings, true ) : [];
/* Disable this task if it's mistakenly enabled */
if( empty( $settings['enabled'] ) )
{
Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'autolock' ) );
return null;
}
$where = [
[ 'state=?', 'open' ],
[ 'last_post < ?', ( time() - ( $settings['days'] * 86400 ) ) ],
[ Db::i()->in( 'topic_archive_status', [ Topic::ARCHIVE_DONE, Topic::ARCHIVE_WORKING, Topic::ARCHIVE_RESTORE ], true ) ]
];
if( !$settings['pinned'] )
{
$where[] = [ 'pinned=?', 0 ];
}
if( !$settings['featured'] )
{
$where[] = [ 'featured=?', 0 ];
}
if( !empty( $settings['forums'] ) )
{
$where[] = [ Db::i()->in( 'forum_id', $settings['forums'], true ) ];
}
if( !empty( $settings['members'] ) )
{
$where[] = [ Db::i()->in( 'starter_id', $settings['members'], true ) ];
}
if( !empty( $settings['tags'] ) )
{
$where[] = [ 'tid not in (?)', Db::i()->select( 'tag_meta_id', 'core_tags', [
[ 'tag_meta_app=?', 'forums' ],
[ 'tag_meta_area=?', 'forums' ],
[ Db::i()->in( 'tag_text', $settings['tags'] ) ]
] ) ];
}
$topicIds = [];
foreach( new ActiveRecordIterator(
Db::i()->select( '*', 'forums_topics', $where, 'tid DESC', [ 0, 200 ] ),
Topic::class
) as $topic )
{
try
{
/* @var Topic $topic */
$topic->modAction( 'lock' );
$topicIds[] = $topic->tid;
}
catch( \Exception )
{
/* Do nothing */
}
}
return count( $topicIds ) ? implode( ",", $topicIds ) : null;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup() : void
{
}
}
@@ -53,7 +53,7 @@ class expertUserNudge extends Task
*/
public function execute() : mixed
{
if ( ! Settings::i()->forums_solved_nudge_experts or !Bridge::i()->featureIsEnabled( 'experts' ) )
if ( ! Settings::i()->cloud_experts_email or ! Settings::i()->cloud_experts_email_day_start or ! Settings::i()->cloud_experts_email_day_end or !Bridge::i()->featureIsEnabled( 'experts' ) )
{
return NULL;
}
@@ -68,7 +68,7 @@ class expertUserNudge extends Task
$where = [
[ Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
[ 'start_date > ? and start_date < ? and topic_answered_pid=0', ( time() - ( 365 * 86400) ), ( time() - ( (int) Settings::i()->forums_solved_nudge_experts * 86400 ) ) ], //@todo limit by nudges sent/date?
[ 'start_date > ? and start_date < ? and topic_answered_pid=0', ( time() - ( (int) Settings::i()->cloud_experts_email_day_end * 86400) ), ( time() - ( (int) Settings::i()->cloud_experts_email_day_start * 86400 ) ) ], //@todo limit by nudges sent/date?
[ 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' ) . ')' ) ) ) ],
[ Db::i()->in( 'forum_id', array_keys( $nodeExperts ) ) ]
];
@@ -95,8 +95,12 @@ class expertUserNudge extends Task
try
{
$expert = Member::load( $expertId );
if( !$expert->members_bitoptions['expert_user_disabled'] and !$expert->members_bitoptions['expert_user_blocked'] and ( $expert->expert_nudge < time() - ( 86400 * 7 ) ) )
if( !$expert->members_bitoptions['expert_user_disabled'] and !$expert->members_bitoptions['expert_user_blocked'] and ( $expert->expert_nudge < time() - ( 86400 * Settings::i()->cloud_experts_topics_notify_gap ) ) )
{
/* Avoid race conditions */
$expert->expert_nudge = time();
$expert->save();
$topicIds = [];
foreach( $topics as $topic )
{
@@ -129,9 +133,6 @@ class expertUserNudge extends Task
$notification->recipients->attach( $expert );
$notification->send();
}
$expert->expert_nudge = time();
$expert->save();
}
}
catch ( OutOfRangeException $e ) {}
+156
View File
@@ -0,0 +1,156 @@
<?php
/**
* @brief largeTopics Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
{subpackage}
* @since 09 Oct 2025
*/
namespace IPS\forums\tasks;
use IPS\DateTime;
use IPS\Db;
use IPS\Events\Event;
use IPS\forums\Topic;
use IPS\forums\Topic\Post;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Task;
use IPS\Task\Exception as TaskException;
use function defined;
use const IPS\LARGE_TOPIC_LOCK;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* largeTopics Task
*/
class largeTopics extends Task
{
/**
* @brief timestamp of the earliest topic we want to fetch
* @var int
*/
const EARLIEST_TOPICS_TO_FETCH = 1762174055;
/**
* @brief Batch Size
* @var int
*/
const NO_OF_TOPICS_TO_FETCH = 10;
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws TaskException
*/
public function execute() : mixed
{
$largeTopics = iterator_to_array(
new ActiveRecordIterator(
Db::i()->select( '*', 'forums_topics', [ 'posts + topic_queuedposts >= ? and state=? and last_post > ?', LARGE_TOPIC_LOCK, 'open', static::EARLIEST_TOPICS_TO_FETCH ] , limit: static::NO_OF_TOPICS_TO_FETCH ),
Topic::class
)
);
$log = '';
foreach( $largeTopics as $topic )
{
$this->autoClose( $topic );
$log .= "Splitting topic {$topic->tid} with {$topic->posts} posts;";
}
return $log ?: null;
}
protected function autoClose( Topic $topic ) : void
{
/* Lock the original topic so that it doesn't get any bigger,
but we're going to skip the modAction method because it uses permissions */
$topic->state = 'closed';
$topic->topic_open_time = 0;
$topic->save();
/* Fire an event here */
Event::fire( 'onStatusChange', $topic, array( 'lock' ) );
/* Is this already a child topic? */
if( $parentTopic = $topic->parent() )
{
$sequence = $topic->sequence();
}
else
{
$sequence = 1;
/* Add a record to the topic relationships table */
Db::i()->insert( 'forums_topics_children', [ 'topic_id' => $topic->tid, 'parent_topic' => $topic->tid, 'sequence' => $sequence ] );
$parentTopic = $topic;
}
$sequence++;
/* Get the last post, that will be the first post in the new topic */
/* @var Post $lastPost */
$lastPost = $topic->comments( 1, 0, 'date', 'desc', includeHiddenComments: true );
/* Create a new topic, using the last post author and timestamp */
$newTopic = Topic::createItem( $lastPost->author(), $lastPost->ip_address, DateTime::ts( $lastPost->post_date ), $topic->container(), $topic->hidden() );
$title = $lastPost->author()->language()->addToStack( 'large_topic_new_title', false, [ 'sprintf' => [ $parentTopic->title, $sequence ] ] );
$lastPost->author()->language()->parseOutputForDisplay( $title );
$newTopic->title = $title;
$newTopic->save();
/* Immediately add a row to the topic relationships table */
Db::i()->insert( 'forums_topics_children', [ 'topic_id' => $newTopic->tid, 'parent_topic' => $parentTopic->tid, 'sequence' => $sequence ] );
/* Handle tags */
$newTopic->setTags( $parentTopic->tags() );
/* Copy the last post to the new topic */
$newFirstPost = Post::create( $newTopic, $lastPost->content(), true, null, null, $lastPost->author(), DateTime::ts( $lastPost->post_date ), $lastPost->ip_address );
/* Was the last post anonymous? */
if( $lastPost->author()->member_id and $lastPost->isAnonymous() )
{
$newTopic->setAnonymous( true, $lastPost->author() );
$newFirstPost->setAnonymous( true, $lastPost->author() );
}
$newTopic->topic_firstpost = $newFirstPost->pid;
$newTopic->save();
/* Recount on the forums */
$newTopic->container()->resetCommentCounts();
/* Fire an event so that we know the topic was split */
Event::fire( 'onItemSplit', $newTopic, array( $topic ) );
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup() : void
{
}
}