Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,26 +12,35 @@
namespace IPS\convert\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\convert\App;
use IPS\Db;
use IPS\Member;
use IPS\Task\Queue\OutOfRangeException;
use function defined;
use const IPS\REBUILD_NORMAL;
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 _RecountQuestionRatings
class RecountQuestionRatings
{
/**
* Parse data before queuing
*
* @param array $data Data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics' )->first();
$data['count'] = Db::i()->select( 'count(tid)', 'forums_topics' )->first();
if( $data['count'] == 0 )
{
@@ -49,13 +58,13 @@ class _RecountQuestionRatings
* @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
{
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
if ( !class_exists( 'IPS\forums\Topic' ) OR !Application::appisEnabled( 'forums' ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
$last = NULL;
@@ -63,15 +72,15 @@ class _RecountQuestionRatings
/* If the app doesn't exist, stop now */
try
{
$app = \IPS\convert\App::load( $data['app'] );
$app = App::load( $data['app'] );
}
catch( \OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
/* Loop over distinct topic IDs in forums_question_ratings - while using the DISTINCT flag can be slower, there generally aren't many of these */
foreach( \IPS\Db::i()->select( 'topic', 'forums_question_ratings', array( "topic>?", $offset ), "topic ASC", array( 0, \IPS\REBUILD_NORMAL ), NULL, NULL, \IPS\Db::SELECT_DISTINCT ) AS $topic )
foreach( Db::i()->select( 'topic', 'forums_question_ratings', array( "topic>?", $offset ), "topic ASC", array( 0, REBUILD_NORMAL ), NULL, NULL, Db::SELECT_DISTINCT ) AS $topic )
{
$last = $topic;
$data['completed']++;
@@ -88,14 +97,14 @@ class _RecountQuestionRatings
}
/* Rebuild count */
\IPS\Db::i()->update( 'forums_topics', array(
'question_rating' => (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic ) )->first()
Db::i()->update( 'forums_topics', array(
'question_rating' => (int) Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic ) )->first()
), array( 'tid=?', $topic ) );
}
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -108,8 +117,8 @@ class _RecountQuestionRatings
* @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_recounting_question_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_recounting_question_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}