Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -5,14 +5,14 @@
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Converter
|
||||
* @subpackage convert
|
||||
* @since 19 Nov 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -26,7 +26,7 @@ class _RecountQuestionRatings
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data Data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
@@ -38,6 +38,8 @@ class _RecountQuestionRatings
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -49,7 +51,7 @@ class _RecountQuestionRatings
|
||||
* @return int New offset
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
@@ -58,7 +60,7 @@ class _RecountQuestionRatings
|
||||
|
||||
$last = NULL;
|
||||
|
||||
/* Intentionally no try/catch as it means app doesn't exist */
|
||||
/* If the app doesn't exist, stop now */
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
@@ -68,25 +70,27 @@ class _RecountQuestionRatings
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, 200 ) ), 'IPS\forums\Topic' ) AS $question )
|
||||
/* 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 )
|
||||
{
|
||||
$last = $topic;
|
||||
$data['completed']++;
|
||||
|
||||
/* Is this converted content? */
|
||||
try
|
||||
{
|
||||
/* Just checking, we don't actually need anything */
|
||||
$app->checkLink( $question->tid, 'forums_topics' );
|
||||
$app->checkLink( $topic, 'forums_topics' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $question->tid;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Rebuild count */
|
||||
$question->question_rating = \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $question->tid ) )->first();
|
||||
$question->save();
|
||||
|
||||
$last = $question->tid;
|
||||
\IPS\Db::i()->update( 'forums_topics', array(
|
||||
'question_rating' => (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic ) )->first()
|
||||
), array( 'tid=?', $topic ) );
|
||||
}
|
||||
|
||||
if( $last === NULL )
|
||||
@@ -102,11 +106,10 @@ class _RecountQuestionRatings
|
||||
*
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
|
||||
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
* @return array Text explaining task and percentage complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_question_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_question_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user