Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\forums\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;
|
||||
@@ -46,16 +46,16 @@ class _DeleteLegacyPosts
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_posts', 'queued > 2', 'pid ASC', array( 0, 5 ) );
|
||||
if ( !count( $select ) )
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_posts', 'queued > 2', 'pid 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\Post' ) as $post )
|
||||
{
|
||||
$post->delete();
|
||||
$post->logDelete( FALSE );
|
||||
$done++;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\forums\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;
|
||||
@@ -46,16 +46,16 @@ class _DeleteLegacyTopics
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_topics', 'approved > 1', 'tid ASC', array( 0, 5 ) );
|
||||
if ( !count( $select ) )
|
||||
$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->delete();
|
||||
$topic->logDelete( FALSE );
|
||||
$done++;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\forums\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;
|
||||
@@ -46,8 +46,8 @@ class _HiddenFirstPost
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
$select = \IPS\Db::i()->select( '*', 'forums_posts', 'new_topic = 1 and queued = -1', 'topic_id ASC', array( 0, 50 ) );
|
||||
if ( !count( $select ) )
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\forums\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;
|
||||
@@ -34,6 +34,7 @@ class _RebuildNewTopicFlag
|
||||
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 )
|
||||
{
|
||||
@@ -44,6 +45,8 @@ class _RebuildNewTopicFlag
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -56,7 +59,7 @@ class _RebuildNewTopicFlag
|
||||
* @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' ) )
|
||||
{
|
||||
@@ -70,7 +73,7 @@ class _RebuildNewTopicFlag
|
||||
$firstPostIds = array();
|
||||
$firstPostArchivedIds = array();
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, 50 ) ), 'IPS\forums\Topic' ) AS $topic )
|
||||
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 )
|
||||
{
|
||||
@@ -103,26 +106,27 @@ class _RebuildNewTopicFlag
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$data['completed']++;
|
||||
$last = $topic->tid;
|
||||
}
|
||||
|
||||
/* 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 ) . ')' ) );
|
||||
}
|
||||
|
||||
if( count( $firstPostIds ) )
|
||||
if( \count( $firstPostIds ) )
|
||||
{
|
||||
\IPS\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 ) . ')' ) );
|
||||
}
|
||||
|
||||
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 ) . ')' ) );
|
||||
}
|
||||
@@ -145,6 +149,6 @@ class _RebuildNewTopicFlag
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_new_topic_flag'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_new_topic_flag'), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild Solved Index
|
||||
* @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
|
||||
* @since 20 February 2020
|
||||
*/
|
||||
|
||||
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: Rebuild Solved Index
|
||||
*/
|
||||
class _RebuildSolvedIndex
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
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();
|
||||
}
|
||||
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;
|
||||
|
||||
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 )
|
||||
{
|
||||
/* 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();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* No? Best slap it in then */
|
||||
try
|
||||
{
|
||||
$comment = \IPS\forums\Topic\Post::load( $topic->topic_answered_pid );
|
||||
|
||||
\IPS\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
|
||||
) );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
|
||||
$data['completed']++;
|
||||
$last = $topic->tid;
|
||||
}
|
||||
|
||||
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_solved_posts'), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\forums\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;
|
||||
@@ -23,11 +23,6 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _TopicStarterIds
|
||||
{
|
||||
/**
|
||||
* @brief Number of topics to build per cycle
|
||||
*/
|
||||
public $perCycle = 500;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
@@ -50,6 +45,8 @@ class _TopicStarterIds
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -63,17 +60,21 @@ class _TopicStarterIds
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
$count = 0;
|
||||
$last = NULL;
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_topics', array(), 'tid ASC', array( $offset, $this->perCycle ) ) as $topic )
|
||||
foreach( \IPS\Db::i()->select( 'tid, starter_id', 'forums_topics', array( 'tid>?', $offset ), 'tid ASC', array( 0, \IPS\REBUILD_QUICK ) ) as $topic )
|
||||
{
|
||||
$count++;
|
||||
$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();
|
||||
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'starter_id' => $firstPost ), array( 'tid=?', $topic['tid'] ) );
|
||||
if( $firstPost != $topic['starter_id'] )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'starter_id' => $firstPost ), array( 'tid=?', $topic['tid'] ) );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
@@ -81,12 +82,12 @@ class _TopicStarterIds
|
||||
}
|
||||
}
|
||||
|
||||
if( !$count )
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
return ( $offset + $count );
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +100,6 @@ class _TopicStarterIds
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_starter_ids'), 'complete' => round( 100 / $data['count'] * $offset, 2 ) );
|
||||
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