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
@@ -1,85 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background 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 Forums
|
||||
* @since 18 Mar 2015
|
||||
*/
|
||||
|
||||
namespace IPS\forums\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _DeleteLegacyPosts
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', 'queued > 2' )->first();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_posts', 'queued > 2', NULL, array( 0, \IPS\REBUILD_NORMAL ) );
|
||||
if ( !\count( $select ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$done = 0;
|
||||
foreach( $select as $post )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\forums\Topic\Post::constructFromData( $post )->logDelete( FALSE );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', [ 'queued' => '-1' ], [ 'pid=?', $post['pid'] ] );
|
||||
}
|
||||
|
||||
$done++;
|
||||
}
|
||||
|
||||
return $offset + $done;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_deleting_legacy_posts'), 'complete' => round( 100 / ( $data['count'] ?: 1 + $offset ) * $offset, 2 ) );
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background 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 Forums
|
||||
* @since 18 Mar 2015
|
||||
*/
|
||||
|
||||
namespace IPS\forums\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _DeleteLegacyTopics
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', 'approved > 1' )->first();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_topics', 'approved > 1', 'tid ASC', array( 0, \IPS\REBUILD_NORMAL ) );
|
||||
if ( !\count( $select ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$done = 0;
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\forums\Topic' ) as $topic )
|
||||
{
|
||||
$topic->logDelete( FALSE );
|
||||
$done++;
|
||||
}
|
||||
|
||||
return $offset + $done;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_deleting_legacy_topics'), 'complete' => round( 100 / ( $data['count'] ?: 1 + $offset ) * $offset, 2 ) );
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background 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 Forums
|
||||
* @since 18 Mar 2015
|
||||
*/
|
||||
|
||||
namespace IPS\forums\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task to fix an issue where topics are not hidden, but the first post is hidden with -1.
|
||||
*/
|
||||
class _HiddenFirstPost
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', 'new_topic = 1 and queued = -1' )->first();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_posts', 'new_topic = 1 and queued = -1', 'topic_id ASC', array( 0, \IPS\REBUILD_SLOW ) );
|
||||
if ( !\count( $select ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$done = 0;
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\forums\Topic\Post' ) as $post )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'queued' => 2 ), array( 'topic_id=?', $post->topic_id ) );
|
||||
$item = $post->item();
|
||||
$item->hide( NULL );
|
||||
$done++;
|
||||
}
|
||||
|
||||
return $offset + $done;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_fixing_hidden_first_post'), 'complete' => round( 100 / ( $data['count'] ?: 1 + $offset ) * $offset, 2 ) );
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background 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 Converter
|
||||
* @since 26 Feb 2016
|
||||
*/
|
||||
|
||||
namespace IPS\forums\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _RebuildNewTopicFlag
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'MAX(tid)', 'forums_topics' )->first();
|
||||
$data['realCount'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$last = NULL;
|
||||
|
||||
$topicIdsToReset = array();
|
||||
$archivedTopicIdsToReset = array();
|
||||
$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 )
|
||||
{
|
||||
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->save();
|
||||
|
||||
/* Reset new_topic value for topic */
|
||||
$topicIdsToReset[] = $topic->tid;
|
||||
$firstPostIds[] = $topic->topic_firstpost;
|
||||
}
|
||||
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
|
||||
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->save();
|
||||
|
||||
/* Reset new_topic value for topic */
|
||||
$archivedTopicIdsToReset[] = $topic->tid;
|
||||
$firstPostArchivedIds[] = $topic->topic_firstpost;
|
||||
}
|
||||
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$data['completed']++;
|
||||
$last = $topic->tid;
|
||||
}
|
||||
|
||||
/* Reset flags as needed */
|
||||
if( \count( $topicIdsToReset ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 0 ), array( 'topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
|
||||
}
|
||||
|
||||
if( \count( $firstPostIds ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 1 ), array( 'pid IN(' . implode( ',', $firstPostIds ) . ')' ) );
|
||||
}
|
||||
|
||||
if( \count( $archivedTopicIdsToReset ) )
|
||||
{
|
||||
\IPS\forums\Topic\ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 0 ), array( 'archive_topic_id IN(' . implode( ',', $archivedTopicIdsToReset ) . ')' ) );
|
||||
}
|
||||
|
||||
if( \count( $firstPostArchivedIds ) )
|
||||
{
|
||||
\IPS\forums\Topic\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;
|
||||
}
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_new_topic_flag'), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -11,33 +11,46 @@
|
||||
namespace IPS\forums\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\Extensions\QueueAbstract;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
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: Rebuild Solved Index
|
||||
*/
|
||||
class _RebuildSolvedIndex
|
||||
class RebuildSolvedIndex extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'MAX(tid)', 'forums_topics', array( 'topic_answered_pid > 0' ) )->first();
|
||||
$data['realCount'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array( 'topic_answered_pid > 0' ) )->first();
|
||||
$data['count'] = Db::i()->select( 'MAX(tid)', 'forums_topics', array( 'topic_answered_pid > 0' ) )->first();
|
||||
$data['realCount'] = Db::i()->select( 'COUNT(*)', 'forums_topics', array( 'topic_answered_pid > 0' ) )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
@@ -58,39 +71,40 @@ class _RebuildSolvedIndex
|
||||
* @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( 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;
|
||||
}
|
||||
|
||||
$last = NULL;
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>? and topic_answered_pid > 0", $offset ), "tid ASC", array( 0, \IPS\REBUILD_QUICK ) ), 'IPS\forums\Topic' ) AS $topic )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'forums_topics', array( "tid>? and topic_answered_pid > 0", $offset ), "tid ASC", array( 0, REBUILD_QUICK ) ), 'IPS\forums\Topic' ) AS $topic )
|
||||
{
|
||||
/* I told him we already got one! */
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->select( '*', 'core_solved_index', array( 'comment_class=? and item_id=? and comment_id=?', 'IPS\\forums\\Topic\\Post', $topic->tid, $topic->topic_answered_pid ) )->first();
|
||||
Db::i()->select( '*', 'core_solved_index', array( 'comment_class=? and item_id=? and comment_id=? AND type=?', 'IPS\\forums\\Topic\\Post', $topic->tid, $topic->topic_answered_pid, 'solved' ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* No? Best slap it in then */
|
||||
try
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::load( $topic->topic_answered_pid );
|
||||
$comment = Post::load( $topic->topic_answered_pid );
|
||||
|
||||
\IPS\Db::i()->insert( 'core_solved_index', array(
|
||||
Db::i()->insert( 'core_solved_index', array(
|
||||
'member_id' => $comment->author()->member_id,
|
||||
'app' => 'forums',
|
||||
'comment_class' => 'IPS\\forums\\Topic\\Post',
|
||||
'comment_id' => $comment->pid,
|
||||
'item_id' => $topic->tid,
|
||||
'solved_date' => $comment->post_date // We don't have the real solve date so this will have to do
|
||||
'solved_date' => $comment->post_date, // We don't have the real solve date so this will have to do
|
||||
'type' => 'solved'
|
||||
) );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
$data['completed']++;
|
||||
@@ -111,11 +125,11 @@ class _RebuildSolvedIndex
|
||||
* @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
|
||||
* @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
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_solved_posts'), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['completed'], 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('queue_rebuilding_solved_posts'), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,42 +12,56 @@
|
||||
namespace IPS\forums\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Member;
|
||||
use IPS\Settings;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
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 _RebuildSolvedStats
|
||||
class RebuildSolvedStats extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of days to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = 30;
|
||||
public int $rebuild = 30;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( $data['forum_id'] );
|
||||
$timezone = new \DateTimeZone( \IPS\Settings::i()->reputation_timezone );
|
||||
$forum = Forum::load( $data['forum_id'] );
|
||||
$timezone = new DateTimeZone( Settings::i()->reputation_timezone );
|
||||
|
||||
/* Reset solved time */
|
||||
$forum->solved_stats_from = 0;
|
||||
$forum->save();
|
||||
|
||||
/* We work a day in arrears */
|
||||
$oldest = \IPS\DateTime::ts( $forum->getFirstSolvedTime() )->setTimezone( $timezone )->setTime( 12, 0 );
|
||||
$newest = \IPS\DateTime::create()->setTimezone( $timezone )->setTime( 12, 0 );
|
||||
$oldest = DateTime::ts( $forum->getFirstSolvedTime() )->setTimezone( $timezone )->setTime( 12, 0 );
|
||||
$newest = DateTime::create()->setTimezone( $timezone )->setTime( 12, 0 );
|
||||
|
||||
$diff = $newest->diff( $oldest );
|
||||
|
||||
@@ -55,11 +69,11 @@ class _RebuildSolvedStats
|
||||
$data['date'] = $oldest->getTimeStamp();
|
||||
$data['max'] = $newest->getTimeStamp();
|
||||
|
||||
\IPS\Db::i()->delete( 'core_statistics', [ 'type=? and value_1=?', 'solved', $forum->_id ] );
|
||||
Db::i()->delete( 'core_statistics', [ 'type=? and value_1=?', 'solved', $forum->_id ] );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
@@ -78,18 +92,18 @@ class _RebuildSolvedStats
|
||||
* @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( 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;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( $data['forum_id'] );
|
||||
$forum = Forum::load( $data['forum_id'] );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
@@ -97,8 +111,8 @@ class _RebuildSolvedStats
|
||||
$done = 0;
|
||||
for( $i = 0; $i < $this->rebuild; $i++ )
|
||||
{
|
||||
$timezone = new \DateTimeZone( \IPS\Settings::i()->reputation_timezone );
|
||||
$end = \IPS\DateTime::ts( $data['date'], true )->setTimezone( $timezone )->sub( new \DateInterval('P1D') )->setTime( 23, 59 );
|
||||
$timezone = new DateTimeZone( Settings::i()->reputation_timezone );
|
||||
$end = DateTime::ts( $data['date'], true )->setTimezone( $timezone )->sub( new DateInterval('P1D') )->setTime( 23, 59 );
|
||||
|
||||
if ( $end->getTimeStamp() >= $data['max'] )
|
||||
{
|
||||
@@ -106,21 +120,22 @@ class _RebuildSolvedStats
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$start = \IPS\DateTime::ts( $forum->getFirstSolvedTime() )->setTimezone( $timezone );
|
||||
$start = DateTime::ts( $forum->getFirstSolvedTime() )->setTimezone( $timezone );
|
||||
|
||||
$where = [
|
||||
[ \IPS\Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ],
|
||||
[ \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
|
||||
[ Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ],
|
||||
[ Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ],
|
||||
[ 'forum_id=?', $forum->_id ],
|
||||
[ 'start_date > ? AND start_date < ?', $start->getTimestamp(), $end->getTimestamp() ]
|
||||
[ 'start_date > ? AND start_date < ?', $start->getTimestamp(), $end->getTimestamp() ],
|
||||
[ 'type=?', 'solved' ]
|
||||
];
|
||||
|
||||
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', $where )->first();
|
||||
$solved = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$avg = \IPS\Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$total = Db::i()->select( 'COUNT(*)', 'forums_topics', $where )->first();
|
||||
$solved = Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$avg = Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $where, [ [ 'core_solved_index.id IS NOT NULL' ] ] ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
|
||||
\IPS\Db::i()->insert( 'core_statistics', [
|
||||
Db::i()->insert( 'core_statistics', [
|
||||
'type' => 'solved',
|
||||
'value_1' => $forum->_id,
|
||||
'value_2' => $total,
|
||||
@@ -129,7 +144,7 @@ class _RebuildSolvedStats
|
||||
'time' => $end->getTimestamp()
|
||||
] );
|
||||
|
||||
$data['date'] = \IPS\DateTime::ts( $data['date'] )->add( new \DateInterval('P1D') )->getTimeStamp();
|
||||
$data['date'] = DateTime::ts( $data['date'] )->add( new DateInterval('P1D') )->getTimeStamp();
|
||||
$done++;
|
||||
}
|
||||
|
||||
@@ -147,20 +162,20 @@ class _RebuildSolvedStats
|
||||
* @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
|
||||
* @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
|
||||
{
|
||||
try
|
||||
{
|
||||
$forum = \IPS\forums\Forum::load( $data['forum_id'] );
|
||||
$forum = Forum::load( $data['forum_id'] );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('solved_rebuilding_stats', NULL, [ 'sprintf' => [ $forum->_title ] ] ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('solved_rebuilding_stats', NULL, [ 'sprintf' => [ $forum->_title ] ] ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +185,7 @@ class _RebuildSolvedStats
|
||||
* @param bool $processed Was anything processed or not? If preQueueData returns NULL, this will be FALSE.
|
||||
* @return void
|
||||
*/
|
||||
public function postComplete( $data, $processed = TRUE )
|
||||
public function postComplete( array $data, bool $processed = TRUE ) : void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background 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 Forums
|
||||
* @since 04 Jan 2016
|
||||
*/
|
||||
|
||||
namespace IPS\forums\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _TopicStarterIds
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics' )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
$last = NULL;
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'tid, starter_id', 'forums_topics', array( 'tid>?', $offset ), 'tid ASC', array( 0, \IPS\REBUILD_QUICK ) ) as $topic )
|
||||
{
|
||||
$last = $topic['tid'];
|
||||
$data['completed']++;
|
||||
|
||||
try
|
||||
{
|
||||
$firstPost = \IPS\Db::i()->select( 'author_id', 'forums_posts', array( 'new_topic=? AND topic_id=?', 1, $topic['tid'] ), 'pid ASC', array( 0, 1 ) )->first();
|
||||
|
||||
if( $firstPost != $topic['starter_id'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'starter_id' => $firstPost ), array( 'tid=?', $topic['tid'] ) );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_starter_ids'), 'complete' => round( 100 / $data['count'] * $data['completed'], 2 ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user