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

@@ -13,30 +13,43 @@
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\Application;
use IPS\convert\App;
use IPS\Db;
use IPS\forums\Topic\ArchivedPost;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Task\Queue\OutOfRangeException;
use UnderflowException;
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 _DeleteEmptyTopics
class DeleteEmptyTopics
{
/**
* 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(tid)', 'forums_topics', array( 'forums_posts.pid IS NULL' ) )->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid' )->first();
$data['count'] = Db::i()->select( 'count(tid)', 'forums_topics', array( 'forums_posts.pid IS NULL' ) )->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid' )->first();
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \OutOfRangeException;
}
@@ -57,28 +70,28 @@ class _DeleteEmptyTopics
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @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;
}
/* If app was removed, then cancel this */
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;
}
$last = NULL;
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>? AND forums_posts.pid IS NULL", $offset ), "tid ASC", array( 0, \IPS\REBUILD_SLOW ) )->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid' ), 'IPS\forums\Topic' ) AS $topic )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'forums_topics', array( "tid>? AND forums_posts.pid IS NULL", $offset ), "tid ASC", array( 0, REBUILD_SLOW ) )->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid' ), 'IPS\forums\Topic' ) AS $topic )
{
$tid = $topic->tid;
@@ -106,10 +119,10 @@ class _DeleteEmptyTopics
try
{
/* Do we have any posts? This is more efficient than running a COUNT(*) query, funny enough */
\IPS\forums\Topic\ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), NULL, 1 )->first();
ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), NULL, 1 )->first();
}
/* This topic is empty */
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$topic->delete();
}
@@ -121,7 +134,7 @@ class _DeleteEmptyTopics
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -134,8 +147,8 @@ class _DeleteEmptyTopics
* @param int $offset Offset
* @return array Text explaning 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_deleting_empty_topics' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_deleting_empty_topics' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,33 +12,51 @@
namespace IPS\convert\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DOMElement;
use Exception;
use IPS\Application;
use IPS\convert\App;
use IPS\Http\Url;
use IPS\Log;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Settings;
use IPS\Text\DOMParser;
use IPS\Xml\DOMDocument;
use OutOfRangeException;
use function defined;
use function in_array;
use function is_array;
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 _InvisionCommunityRebuildContent
class InvisionCommunityRebuildContent
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = \IPS\REBUILD_SLOW;
public $rebuild = REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data Data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$classname = $data['class'];
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'ICrebuildPosts' );
Log::debug( "Getting preQueueData for " . $classname, 'ICrebuildPosts' );
try
{
@@ -48,12 +66,12 @@ class _InvisionCommunityRebuildContent
/* We're going to use the < operator, so we need to ensure the most recent item is rebuilt */
$data['runPid'] = $data['count'] + 1;
}
catch( \Exception $ex )
catch( Exception $ex )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
\IPS\Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'ICrebuildPosts' );
Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'ICrebuildPosts' );
if( $data['count'] == 0 )
{
@@ -73,11 +91,11 @@ class _InvisionCommunityRebuildContent
* @return int|null New offset or NULL if complete
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( &$data, $offset )
public function run( mixed &$data, int $offset ): int
{
$classname = $data['class'];
$exploded = explode( '\\', $classname );
if ( !class_exists( $classname ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
if ( !class_exists( $classname ) or !Application::appIsEnabled( $exploded[1] ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
@@ -91,7 +109,7 @@ class _InvisionCommunityRebuildContent
/* Intentionally no try/catch as it means app doesn't exist */
try
{
$this->app = \IPS\convert\App::load( $data['app'] );
$this->app = App::load( $data['app'] );
/* This extension is ONLY for InvisionCommunity conversions */
if( $this->app->app_key != 'invisioncommunity' )
@@ -99,18 +117,18 @@ class _InvisionCommunityRebuildContent
throw new \IPS\Task\Queue\OutOfRangeException;
}
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$softwareClass = $this->app->getSource( FALSE, FALSE );
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'ICrebuildPosts' );
Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'ICrebuildPosts' );
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( \is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
$select = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?', $data['runPid'] ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
$iterator = new ActiveRecordIterator( $select, $classname );
$last = NULL;
foreach( $iterator as $item )
@@ -123,7 +141,7 @@ class _InvisionCommunityRebuildContent
/* Just checking, we don't actually need anything */
$this->app->checkLink( $item->$idColumn, $data['link'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$last = $item->$idColumn;
$data['indexed']++;
@@ -132,8 +150,8 @@ class _InvisionCommunityRebuildContent
$contentColumn = $classname::$databaseColumnMap['content'];
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $item->$contentColumn ) );
$source = new DOMDocument( '1.0', 'UTF-8' );
$source->loadHTML( DOMDocument::wrapHtml( $item->$contentColumn ) );
if( mb_stristr( $item->$contentColumn, 'data-mentionid' ) )
{
@@ -180,7 +198,7 @@ class _InvisionCommunityRebuildContent
}
/* Get DOMDocument output */
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
$content = DOMParser::getDocumentBodyContents( $source );
/* Replace file storage tags */
$content = preg_replace( '/&lt;fileStore\.([\d\w\_]+?)&gt;/i', '<fileStore.$1>', $content );
@@ -213,27 +231,27 @@ class _InvisionCommunityRebuildContent
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array Text explaining task and percentage complete
* @throws \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 getProgress( $data, $offset )
public function getProgress( mixed $data, int $offset ): array
{
$class = $data['class'];
$exploded = explode( '\\', $class );
if ( !class_exists( $class ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
if ( !class_exists( $class ) or !Application::appIsEnabled( $exploded[1] ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
}
/**
* Update mentions with new display name, ID and URL
*
* @param \DOMElement $element DOM element
* @param DOMElement $element DOM element
* @return void
*/
public function updateMention( \DOMElement $element )
public function updateMention( DOMElement $element )
{
try
{
@@ -241,14 +259,14 @@ class _InvisionCommunityRebuildContent
$newMemberId = $this->app->getLink( $element->getAttribute( 'data-mentionid' ), 'core_members' );
/* Get new member */
$member = \IPS\Member::load( $newMemberId );
$member = Member::load( $newMemberId );
$element->setAttribute( 'data-mentionid', $newMemberId );
$element->setAttribute( 'href', str_replace( \IPS\Settings::i()->base_url, '<___base_url___>/', $member->url() ) );
$element->setAttribute( 'data-ipshover-target', str_replace( \IPS\Settings::i()->base_url, '<___base_url___>/', $member->url()->setQueryString( 'do', 'hovercard' ) ) );
$element->setAttribute( 'href', str_replace( Settings::i()->base_url, '<___base_url___>/', $member->url() ) );
$element->setAttribute( 'data-ipshover-target', str_replace( Settings::i()->base_url, '<___base_url___>/', $member->url()->setQueryString( 'do', 'hovercard' ) ) );
$element->nodeValue = '@' . $member->name;
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
/**
@@ -259,16 +277,16 @@ class _InvisionCommunityRebuildContent
/**
* Update local embeds for new names, IDs
*
* @param \DOMElement $element DOM element
* @param DOMElement $element DOM element
* @return void
*/
public function updateEmbed( \DOMElement $element )
public function updateEmbed( DOMElement $element )
{
try
{
$url = \IPS\Http\Url::createFromString( str_replace( '<___base_url___>', rtrim( \IPS\Settings::i()->base_url, '/' ), $element->getAttribute( 'src' ) ) );
$url = Url::createFromString( str_replace( '<___base_url___>', rtrim( Settings::i()->base_url, '/' ), $element->getAttribute( 'src' ) ) );
if( !\in_array( $url->hiddenQueryString['app'], array_keys( $this->embedLocations ) ) )
if( !in_array( $url->hiddenQueryString['app'], array_keys( $this->embedLocations ) ) )
{
return;
}
@@ -282,7 +300,7 @@ class _InvisionCommunityRebuildContent
$url = $url->setQueryString( 'comment', $this->app->getLink( $url->queryString['comment'], $this->embedLocations[ $url->hiddenQueryString['app'] ]['comment'] ) );
}
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$url = $url->stripQueryString( 'comment' );
}
@@ -294,23 +312,23 @@ class _InvisionCommunityRebuildContent
$url = $url->setQueryString( 'embedComment', $this->app->getLink( $url->queryString['embedComment'], $this->embedLocations[ $url->hiddenQueryString['app'] ]['comment'] ) );
}
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$url = $url->stripQueryString( 'embedComment' );
}
$element->setAttribute( 'src', str_replace( \IPS\Settings::i()->base_url, '<___base_url___>/', (string) $url->correctFriendlyUrl() ) );
$element->setAttribute( 'src', str_replace( Settings::i()->base_url, '<___base_url___>/', (string) $url->correctFriendlyUrl() ) );
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
/**
* Update quotes for new names, IDs
*
* @param \DOMElement $element DOM element
* @param DOMElement $element DOM element
* @return void
*/
public function updateQuote( \DOMElement $element )
public function updateQuote( DOMElement $element )
{
try
{
@@ -318,7 +336,7 @@ class _InvisionCommunityRebuildContent
$newMemberId = $this->app->getLink( $element->getAttribute( 'data-ipsquote-userid' ), 'core_members' );
/* Get new member */
$member = \IPS\Member::load( $newMemberId );
$member = Member::load( $newMemberId );
/* Get old username */
$oldUsername = $element->getAttribute( 'data-ipsquote-username' );
@@ -335,12 +353,12 @@ class _InvisionCommunityRebuildContent
/* find the citation to update the username */
foreach ( $element->childNodes as $child )
{
if ( $child instanceof \DOMElement and $child->getAttribute('class') == 'ipsQuote_citation' )
if ( $child instanceof DOMElement and $child->getAttribute('class') == 'ipsQuote_citation' )
{
$child->nodeValue = str_replace( $oldUsername, $member->name, $child->nodeValue );
}
}
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
}
@@ -12,33 +12,50 @@
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 InvalidArgumentException;
use IPS\Application;
use IPS\convert\App;
use IPS\Data\Store;
use IPS\IPS;
use IPS\Log;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Text\LegacyParser;
use OutOfRangeException;
use function defined;
use function get_class;
use function is_array;
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 _RebuildContent
class RebuildContent
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = \IPS\REBUILD_SLOW;
public $rebuild = REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data Data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$classname = $data['class'];
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildPosts' );
Log::debug( "Getting preQueueData for " . $classname, 'rebuildPosts' );
try
{
@@ -48,12 +65,12 @@ class _RebuildContent
/* We're going to use the < operator, so we need to ensure the most recent item is rebuilt */
$data['runPid'] = $data['count'] + 1;
}
catch( \Exception $ex )
catch( Exception $ex )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
\IPS\Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildPosts' );
Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildPosts' );
if( $data['count'] == 0 )
{
@@ -73,11 +90,11 @@ class _RebuildContent
* @return int|null New offset or NULL if complete
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( &$data, $offset )
public function run( mixed &$data, int $offset ): int
{
$classname = $data['class'];
$exploded = explode( '\\', $classname );
if ( !class_exists( $classname ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
if ( !class_exists( $classname ) or !Application::appIsEnabled( $exploded[1] ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
@@ -91,20 +108,20 @@ class _RebuildContent
/* Intentionally no try/catch as it means app doesn't exist */
try
{
$app = \IPS\convert\App::load( $data['app'] );
$app = App::load( $data['app'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$softwareClass = $app->getSource( FALSE, FALSE );
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildPosts' );
Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildPosts' );
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( \is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
$select = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?', $data['runPid'] ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
$iterator = new ActiveRecordIterator( $select, $classname );
$last = NULL;
foreach( $iterator as $item )
@@ -117,66 +134,42 @@ class _RebuildContent
/* Just checking, we don't actually need anything */
$app->checkLink( $item->$idColumn, $data['link'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$last = $item->$idColumn;
continue;
}
/* Did the rebuild previously time out on this? If so we need to skip it and move along */
if( isset( \IPS\Data\Store::i()->currentRebuild ) )
if( isset( Store::i()->currentRebuild ) )
{
/* If the last rebuild cycle timed out, currentRebuild might be set and we might have already rebuilt this post (the post that caused the rebuild to fail might come after this (but before in chronological order).
If that is the case, we should skip rebuilding this post again. */
if( \is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] < $item->$idColumn )
if( is_array( Store::i()->currentRebuild ) AND Store::i()->currentRebuild[0] == $classname AND Store::i()->currentRebuild[1] < $item->$idColumn )
{
$last = $item->$idColumn;
continue;
}
/* If the last rebuild cycle failed and we have just retrieved the post we last attempted to rebuild, skip it and move along */
if( \is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] == $item->$idColumn )
if( is_array( Store::i()->currentRebuild ) AND Store::i()->currentRebuild[0] == $classname AND Store::i()->currentRebuild[1] == $item->$idColumn )
{
unset( \IPS\Data\Store::i()->currentRebuild );
unset( Store::i()->currentRebuild );
$last = $item->$idColumn;
continue;
}
}
$member = \IPS\Member::load( $item->mapped('author') );
$extensions = \IPS\Application::load( $classname::$application )->extensions( 'core', 'EditorLocations' );
$member = Member::load( $item->mapped('author') );
if( isset( $classname::$itemClass ) )
{
$itemClass = $classname::$itemClass;
$module = mb_ucfirst( $itemClass::$module );
$module = IPS::mb_ucfirst( $itemClass::$module );
}
else
{
$module = mb_ucfirst( $classname::$module );
}
$extension = NULL;
if ( isset( $extensions[ $module ] ) )
{
$extension = $extensions[ $module ];
}
$canUseHtml = (bool) $member->group['g_dohtml'];
if ( $extension )
{
$extensionCanUseHtml = $extension->canUseHtml( $member );
if ( $extensionCanUseHtml !== NULL )
{
$canUseHtml = $extensionCanUseHtml;
}
}
if ( ! $canUseHtml )
{
$canUseHtml = $item->htmlParsingEnforced();
$module = IPS::mb_ucfirst( $classname::$module );
}
$contentColumn = $classname::$databaseColumnMap['content'];
@@ -191,7 +184,7 @@ class _RebuildContent
{
$id1 = $item->item()->$itemIdColumn;
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
/* Post is orphaned and can be skipped */
$last = $item->$idColumn;
@@ -209,20 +202,20 @@ class _RebuildContent
/* Before we start trying to rebuild, set a flag to note what we are trying to rebuild. If it times out, we can check
this on the next load and skip the problematic content */
\IPS\Data\Store::i()->currentRebuild = array( $classname, $item->$idColumn );
Store::i()->currentRebuild = array( $classname, $item->$idColumn );
try
{
/* Pass off to software class */
if ( $softwareClass::$contentFixed === FALSE )
{
$item->$contentColumn = $softwareClass::fixPostData( $item->$contentColumn );
$item->$contentColumn = $softwareClass::fixPostData( $item->$contentColumn, $data['class'], $item->$idColumn );
}
/* Then pass off to legacy parser to bring up to 4.x */
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, $classname::$application . '_' . mb_ucfirst( $module ), $id1, $id2, NULL, isset( $classname::$itemClass ) ? $classname::$itemClass : \get_class( $item ) );
$item->$contentColumn = LegacyParser::parseStatic( $item->$contentColumn, $member, false, $classname::$application . '_' . IPS::mb_ucfirst( $module ), $id1, $id2, NULL, isset( $classname::$itemClass ) ? $classname::$itemClass : get_class( $item ) );
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
if( $e->getcode() == 103014 )
{
@@ -241,7 +234,7 @@ class _RebuildContent
$data['indexed']++;
/* Now we will reset the rebuild flag we previously set since it rebuilt and saved successfully */
unset( \IPS\Data\Store::i()->currentRebuild );
unset( Store::i()->currentRebuild );
}
/* Store the runPid for the next iteration of this Queue task. This allows the progress bar to show correctly. */
@@ -262,17 +255,17 @@ class _RebuildContent
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array Text explaining task and percentage complete
* @throws \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 getProgress( $data, $offset )
public function getProgress( mixed $data, int $offset ): array
{
$class = $data['class'];
$exploded = explode( '\\', $class );
if ( !class_exists( $class ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
if ( !class_exists( $class ) or !Application::appIsEnabled( $exploded[1] ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
}
}
@@ -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 );
}
}
@@ -12,30 +12,43 @@
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\Application;
use IPS\Db;
use IPS\forums\Topic\ArchivedPost;
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 _RebuildFirstPostIds
class RebuildFirstPostIds
{
/**
* 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(tid)', 'forums_topics' )->first();
$data['count'] = Db::i()->select( 'count(tid)', 'forums_topics' )->first();
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \OutOfRangeException;
}
@@ -56,13 +69,13 @@ class _RebuildFirstPostIds
* @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;
@@ -72,14 +85,14 @@ class _RebuildFirstPostIds
$firstPostIds = array();
$firstPostArchivedIds = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, \IPS\REBUILD_SLOW ) ), 'IPS\forums\Topic' ) AS $topic )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, REBUILD_SLOW ) ), 'IPS\forums\Topic' ) AS $topic )
{
if ( $topic->isArchived() == FALSE )
{
try
{
/* Set first post */
$topic->topic_firstpost = \IPS\Db::i()->select( 'pid', 'forums_posts', array( 'topic_id=?', $topic->tid ), 'post_date ASC', 1 )->first();
$topic->topic_firstpost = Db::i()->select( 'pid', 'forums_posts', array( 'topic_id=?', $topic->tid ), 'post_date ASC', 1 )->first();
$topic->save();
/* Reset new_topic value for topic */
@@ -87,14 +100,14 @@ class _RebuildFirstPostIds
$firstPostIds[] = $topic->topic_firstpost;
}
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
else
{
try
{
/* Set first post */
$topic->topic_firstpost = \IPS\forums\Topic\ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), "archive_content_date ASC", 1 )->first();
$topic->topic_firstpost = ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), "archive_content_date ASC", 1 )->first();
$topic->save();
/* Reset new_topic value for topic */
@@ -102,7 +115,7 @@ class _RebuildFirstPostIds
$firstPostArchivedIds[] = $topic->topic_firstpost;
}
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
$last = $topic->tid;
@@ -110,29 +123,29 @@ class _RebuildFirstPostIds
}
/* Reset flags as needed */
if( \count( $topicIdsToReset ) )
if( count( $topicIdsToReset ) )
{
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 0 ), array( 'topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
Db::i()->update( 'forums_posts', array( 'new_topic' => 0 ), array( 'topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
}
if( \count( $firstPostIds ) )
if( count( $firstPostIds ) )
{
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 1 ), array( 'pid IN(' . implode( ',', $firstPostIds ) . ')' ) );
Db::i()->update( 'forums_posts', array( 'new_topic' => 1 ), array( 'pid IN(' . implode( ',', $firstPostIds ) . ')' ) );
}
if( \count( $archivedTopicIdsToReset ) )
if( count( $archivedTopicIdsToReset ) )
{
\IPS\forums\Topic\ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 0 ), array( 'archive_topic_id IN(' . implode( ',', $archivedTopicIdsToReset ) . ')' ) );
ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 0 ), array( 'archive_topic_id IN(' . implode( ',', $archivedTopicIdsToReset ) . ')' ) );
}
if( \count( $firstPostArchivedIds ) )
if( count( $firstPostArchivedIds ) )
{
\IPS\forums\Topic\ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 1 ), array( 'archive_id IN(' . implode( ',', $firstPostArchivedIds ) . ')' ) );
ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 1 ), array( 'archive_id IN(' . implode( ',', $firstPostArchivedIds ) . ')' ) );
}
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -145,8 +158,8 @@ class _RebuildFirstPostIds
* @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_new_topic_flag'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack('queue_rebuilding_new_topic_flag'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,30 +12,43 @@
namespace IPS\convert\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use InvalidArgumentException;
use IPS\Application;
use IPS\convert\App;
use IPS\Db;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Task\Queue\OutOfRangeException;
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 _RebuildGalleryImages
class RebuildGalleryImages
{
/**
* 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(image_id)', 'gallery_images' )->first();
$data['count'] = Db::i()->select( 'count(image_id)', 'gallery_images' )->first();
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \OutOfRangeException;
}
@@ -56,28 +69,28 @@ class _RebuildGalleryImages
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @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\gallery\Image' ) OR !\IPS\Application::appIsEnabled( 'gallery' ) )
if ( !class_exists( 'IPS\gallery\Image' ) OR !Application::appIsEnabled( 'gallery' ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
/* Intentionally no try/catch as it means app doesn't exist */
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;
}
$last = NULL;
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_images', array( "image_id>?", $offset ), 'image_id ASC', array( 0, \IPS\REBUILD_INTENSE ) ), 'IPS\gallery\Image' ) AS $image )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'gallery_images', array( "image_id>?", $offset ), 'image_id ASC', array( 0, REBUILD_SLOW ) ), 'IPS\gallery\Image' ) AS $image )
{
$data['completed']++;
@@ -98,12 +111,12 @@ class _RebuildGalleryImages
$image->buildThumbnails();
$image->save();
}
catch( \DomainException $e )
catch( DomainException $e )
{
$image->delete();
}
/* File fails the image type test */
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
$image->delete();
}
@@ -113,7 +126,7 @@ class _RebuildGalleryImages
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -126,8 +139,8 @@ class _RebuildGalleryImages
* @param int $offset Offset
* @return array Text explaning 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_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_rebuilding_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,34 +12,42 @@
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\Member;
use IPS\Task\Queue\OutOfRangeException;
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 _RebuildNonContent
class RebuildNonContent
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = \IPS\REBUILD_SLOW;
public $rebuild = REBUILD_SLOW;
/**
* 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'] = 0;
$_extensionData = explode( '_', $data['extension'] );
foreach( \IPS\Application::load( $_extensionData[0] )->extensions( 'core', 'EditorLocations' ) as $_key => $extension )
foreach( Application::load( $_extensionData[0] )->extensions( 'core', 'EditorLocations' ) as $_key => $extension )
{
if( $_key != $_extensionData[1] )
{
@@ -63,11 +71,11 @@ class _RebuildNonContent
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @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( array &$data, int $offset ): int
{
foreach( \IPS\Application::allExtensions( 'core', 'EditorLocations', FALSE, NULL, NULL, TRUE ) as $_key => $extension )
foreach( Application::allExtensions( 'core', 'EditorLocations', FALSE, NULL, NULL, TRUE ) as $_key => $extension )
{
if( $_key != $data['extension'] )
{
@@ -76,11 +84,11 @@ class _RebuildNonContent
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;
}
if( method_exists( $extension, 'rebuildContent' ) )
@@ -99,7 +107,7 @@ class _RebuildNonContent
}
/* Rebuild is complete */
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
/**
@@ -109,8 +117,8 @@ class _RebuildNonContent
* @param int $offset Offset
* @return array Text explaning 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( 'rebuilding_noncontent_posts', FALSE, array( 'sprintf' => \IPS\Member::loggedIn()->language()->addToStack( 'editor__' . $data['extension'] ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'rebuilding_noncontent_posts', FALSE, array( 'sprintf' => Member::loggedIn()->language()->addToStack( 'editor__' . $data['extension'] ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
}
}
@@ -12,30 +12,42 @@
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\convert\App;
use IPS\Db;
use IPS\File;
use IPS\Member;
use IPS\Task\Queue\OutOfRangeException;
use UnderflowException;
use function defined;
use const IPS\PHOTO_THUMBNAIL_SIZE;
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 _RebuildProfilePhotos
class RebuildProfilePhotos
{
/**
* 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(member_id)', 'core_members', [ 'pp_photo_type=?', 'custom' ] )->first();
$data['count'] = Db::i()->select( 'count(member_id)', 'core_members', [ 'pp_photo_type=?', 'custom' ] )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
throw new \OutOfRangeException;
}
@@ -56,23 +68,23 @@ class _RebuildProfilePhotos
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @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
{
/* Intentionally no try/catch as it means app doesn't exist */
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;
}
$last = NULL;
foreach( \IPS\Db::i()->select( '*', 'core_members', [ "member_id>? AND pp_photo_type=?", $offset, 'custom' ], 'member_id ASC', [ 0, \IPS\REBUILD_SLOW ] ) AS $member )
foreach( Db::i()->select( '*', 'core_members', [ "member_id>? AND pp_photo_type=?", $offset, 'custom' ], 'member_id ASC', [ 0, REBUILD_SLOW ] ) AS $member )
{
$data['completed']++;
@@ -90,18 +102,18 @@ class _RebuildProfilePhotos
try
{
$photo = \IPS\File::get( 'core_Profile', $member['pp_main_photo'] );
$thumbnail = $photo->thumbnail( 'core_Profile', \IPS\PHOTO_THUMBNAIL_SIZE, \IPS\PHOTO_THUMBNAIL_SIZE, TRUE );
\IPS\Db::i()->update( 'core_members', [ 'pp_thumb_photo' => (string) $thumbnail ], [ 'member_id=?', $member['member_id'] ] );
$photo = File::get( 'core_Profile', $member['pp_main_photo'] );
$thumbnail = $photo->thumbnail( 'core_Profile', PHOTO_THUMBNAIL_SIZE, PHOTO_THUMBNAIL_SIZE, TRUE );
Db::i()->update( 'core_members', [ 'pp_thumb_photo' => (string) $thumbnail ], [ 'member_id=?', $member['member_id'] ] );
}
catch( \Exception $e ) { }
catch( Exception $e ) { }
$last = $member['member_id'];
}
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -114,8 +126,8 @@ class _RebuildProfilePhotos
* @param int $offset Offset
* @return array Text explaning 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_profile_photos' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_rebuilding_profile_photos' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,39 +12,52 @@
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\Application;
use IPS\convert\App;
use IPS\Db;
use IPS\IPS;
use IPS\Log;
use IPS\Member;
use OutOfRangeException;
use function defined;
use function in_array;
use const IPS\REBUILD_QUICK;
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 _RebuildTagCache
class RebuildTagCache
{
/**
* Parse data before queuing
*
* @param array $data Data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
$classname = $data['class'];
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildTagCache' );
Log::debug( "Getting preQueueData for " . $classname, 'rebuildTagCache' );
try
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(DISTINCT tag_aai_lookup)', 'core_tags', array( 'tag_meta_app=? AND tag_meta_area=?', $classname::$application, $classname::$module ) )->first();
$data['count'] = Db::i()->select( 'COUNT(DISTINCT tag_aai_lookup)', 'core_tags', array( 'tag_meta_app=? AND tag_meta_area=?', $classname::$application, $classname::$module ) )->first();
}
catch( \Exception $ex )
catch( Exception $ex )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
\IPS\Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildTagCache' );
Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildTagCache' );
if( $data['count'] == 0 )
{
@@ -65,11 +78,11 @@ class _RebuildTagCache
* @return int|null New offset or NULL if complete
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( &$data, $offset )
public function run( mixed &$data, int $offset ): int
{
$classname = $data['class'];
$exploded = explode( '\\', $classname );
if ( !class_exists( $classname ) or !\IPS\Application::appIsEnabled( $exploded[1] ) OR !\in_array( 'IPS\Content\Tags', class_implements( $classname ) ) )
if ( !class_exists( $classname ) or !Application::appIsEnabled( $exploded[1] ) OR !in_array( 'IPS\Content\Taggable', class_implements( $classname ) ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
@@ -77,16 +90,16 @@ class _RebuildTagCache
/* Intentionally no try/catch as it means app doesn't exist */
try
{
$app = \IPS\convert\App::load( $data['app'] );
$app = App::load( $data['app'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildTagCache' );
Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildTagCache' );
$select = \IPS\Db::i()->select( '*', 'core_tags', array( 'tag_id>? AND tag_meta_app=? AND tag_meta_area=?', $data['currentId'], $classname::$application, $classname::$module ), 'tag_id ASC', array( 0, \IPS\REBUILD_QUICK ), NULL, NULL, \IPS\Db::SELECT_DISTINCT );
$select = Db::i()->select( '*', 'core_tags', array( 'tag_id>? AND tag_meta_app=? AND tag_meta_area=?', $data['currentId'], $classname::$application, $classname::$module ), 'tag_id ASC', array( 0, REBUILD_QUICK ), NULL, NULL, Db::SELECT_DISTINCT );
$last = NULL;
foreach( $select as $outerTag )
@@ -96,7 +109,7 @@ class _RebuildTagCache
$last = $outerTag['tag_id'];
$prefix = NULL;
foreach( \IPS\Db::i()->select( '*', 'core_tags', array( 'tag_aai_lookup=?', $outerTag['tag_aai_lookup'] ) ) as $tag )
foreach( Db::i()->select( '*', 'core_tags', array( 'tag_aai_lookup=?', $outerTag['tag_aai_lookup'] ) ) as $tag )
{
if( $tag['tag_prefix'] )
{
@@ -119,7 +132,7 @@ class _RebuildTagCache
/* Just checking, we don't actually need anything */
$app->checkLink( $outerTag['tag_meta_id'], $data['link'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
continue;
}
@@ -129,12 +142,12 @@ class _RebuildTagCache
{
$item = $classname::load( $outerTag['tag_meta_id'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
continue;
}
\IPS\Db::i()->insert( 'core_tags_cache', array(
Db::i()->insert( 'core_tags_cache', array(
'tag_cache_key' => $outerTag['tag_aai_lookup'],
'tag_cache_text' => json_encode( array( 'tags' => $tags, 'prefix' => $prefix ) ),
'tag_cache_date' => time()
@@ -148,11 +161,11 @@ class _RebuildTagCache
if ( isset( $containerClass::$permissionMap['read'] ) )
{
\IPS\Db::i()->insert( 'core_tags_perms', array(
Db::i()->insert( 'core_tags_perms', array(
'tag_perm_aai_lookup' => $outerTag['tag_aai_lookup'],
'tag_perm_aap_lookup' => $outerTag['tag_aap_lookup'],
'tag_perm_text' => $permissions[ 'perm_' . $containerClass::$permissionMap['read'] ] ?? '',
'tag_perm_visible' => ( $item->hidden() OR $item->isFutureDate() ) ? 0 : 1,
'tag_perm_visible' => ( $item->hidden() OR ( IPS::classUsesTrait( $item, 'IPS\Content\FuturePublishing' ) AND $item->isFutureDate() ) ) ? 0 : 1,
), TRUE );
}
}
@@ -178,17 +191,17 @@ class _RebuildTagCache
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array Text explaining task and percentage complete
* @throws \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 getProgress( $data, $offset )
public function getProgress( mixed $data, int $offset ): array
{
$class = $data['class'];
$exploded = explode( '\\', $class );
if ( !class_exists( $class ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
if ( !class_exists( $class ) or !Application::appIsEnabled( $exploded[1] ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_rebuilding_tag_cache', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['indexed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_rebuilding_tag_cache', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['indexed'], 2 ) ) : 100 );
}
}
@@ -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 _RecountAnswerRatings
class RecountAnswerRatings
{
/**
* 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(pid)', 'forums_posts' )->first();
$data['count'] = Db::i()->select( 'count(pid)', 'forums_posts' )->first();
if( $data['count'] == 0 )
{
@@ -49,13 +58,13 @@ class _RecountAnswerRatings
* @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\Post' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
if ( !class_exists( 'IPS\forums\Topic\Post' ) OR !Application::appisEnabled( 'forums' ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
$last = NULL;
@@ -63,15 +72,15 @@ class _RecountAnswerRatings
/* 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 post IDs in forums_answer_ratings - while using the DISTINCT flag can be slower, there generally aren't many of these */
foreach( \IPS\Db::i()->select( 'post', 'forums_answer_ratings', array( "post>?", $offset ), "post ASC", array( 0, \IPS\REBUILD_NORMAL ), NULL, NULL, \IPS\Db::SELECT_DISTINCT ) AS $pid )
foreach( Db::i()->select( 'post', 'forums_answer_ratings', array( "post>?", $offset ), "post ASC", array( 0, REBUILD_NORMAL ), NULL, NULL, Db::SELECT_DISTINCT ) AS $pid )
{
$last = $pid;
$data['completed']++;
@@ -88,14 +97,14 @@ class _RecountAnswerRatings
}
/* Rebuild count */
\IPS\Db::i()->update( 'forums_posts', array(
'post_field_int' => (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $pid ) )->first()
Db::i()->update( 'forums_posts', array(
'post_field_int' => (int) Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $pid ) )->first()
), array( 'pid=?', $pid ) );
}
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -108,8 +117,8 @@ class _RecountAnswerRatings
* @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_answer_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_recounting_answer_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,26 +12,34 @@
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\Db;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
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 _RecountClubMembers
class RecountClubMembers
{
/**
* 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(id)', 'core_clubs' )->first();
$data['count'] = Db::i()->select( 'count(id)', 'core_clubs' )->first();
if( $data['count'] == 0 )
{
@@ -49,13 +57,13 @@ class _RecountClubMembers
* @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;
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_clubs', array( "id>?", $offset ), "id ASC", array( 0, \IPS\REBUILD_NORMAL ) ), 'IPS\Member\Club' ) AS $club )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_clubs', array( "id>?", $offset ), "id ASC", array( 0, REBUILD_NORMAL ) ), 'IPS\Member\Club' ) AS $club )
{
$club->recountMembers();
$last = $club->id;
@@ -64,7 +72,7 @@ class _RecountClubMembers
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
return $last;
@@ -77,8 +85,8 @@ class _RecountClubMembers
* @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_club_members' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
return array( 'text' => Member::loggedIn()->language()->addToStack( 'queue_recounting_club_members' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -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 );
}
}