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,30 +12,41 @@
|
||||
namespace IPS\convert\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Task\Queue\OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_SLOW;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _RebuildConversationFirstIds
|
||||
class RebuildConversationFirstIds
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data Data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(mt_id)', 'core_message_topics' )->first();
|
||||
$data['count'] = Db::i()->select( 'count(mt_id)', 'core_message_topics' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
@@ -56,21 +67,21 @@ class _RebuildConversationFirstIds
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return int New offset
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
public function run( mixed &$data, int $offset ): int
|
||||
{
|
||||
$last = NULL;
|
||||
|
||||
$topicIdsToReset = array();
|
||||
$firstPostIds = array();
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_message_topics', array( "mt_id>?", $offset ), "mt_id ASC", array( 0, \IPS\REBUILD_SLOW ) ), 'IPS\core\Messenger\Conversation' ) AS $conversation )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_message_topics', array( "mt_id>?", $offset ), "mt_id ASC", array( 0, REBUILD_SLOW ) ), 'IPS\core\Messenger\Conversation' ) AS $conversation )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Set first post */
|
||||
$conversation->first_msg_id = \IPS\Db::i()->select( 'msg_id', 'core_message_posts', array( 'msg_topic_id=?', $conversation->id ), 'msg_date ASC', 1 )->first();
|
||||
$conversation->first_msg_id = Db::i()->select( 'msg_id', 'core_message_posts', array( 'msg_topic_id=?', $conversation->id ), 'msg_date ASC', 1 )->first();
|
||||
$conversation->save();
|
||||
|
||||
/* Reset new_topic value for topic */
|
||||
@@ -78,26 +89,26 @@ class _RebuildConversationFirstIds
|
||||
$firstPostIds[] = $conversation->first_msg_id;
|
||||
}
|
||||
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
|
||||
$last = $conversation->id;
|
||||
$data['completed']++;
|
||||
}
|
||||
|
||||
/* Reset flags as needed */
|
||||
if( \count( $topicIdsToReset ) )
|
||||
if( count( $topicIdsToReset ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 0 ), array( 'msg_topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
|
||||
Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 0 ), array( 'msg_topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
|
||||
}
|
||||
|
||||
if( \count( $firstPostIds ) )
|
||||
if( count( $firstPostIds ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 1 ), array( 'msg_id IN(' . implode( ',', $firstPostIds ) . ')' ) );
|
||||
Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 1 ), array( 'msg_id IN(' . implode( ',', $firstPostIds ) . ')' ) );
|
||||
}
|
||||
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return $last;
|
||||
@@ -110,8 +121,8 @@ class _RebuildConversationFirstIds
|
||||
* @param int $offset Offset
|
||||
* @return array Text explaining task and percentage complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
public function getProgress( mixed $data, int $offset ): array
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_conversation_first_id'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('queue_rebuilding_conversation_first_id'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user