Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -6,14 +6,14 @@
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Converter
|
||||
* @subpackage convert
|
||||
* @since 26 July 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;
|
||||
@@ -27,14 +27,14 @@ class _DeleteEmptyTopics
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $data Data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics' )->first();
|
||||
$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();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
@@ -46,18 +46,20 @@ class _DeleteEmptyTopics
|
||||
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|null New offset or NULL if complete
|
||||
* @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
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
@@ -76,7 +78,7 @@ class _DeleteEmptyTopics
|
||||
|
||||
$last = NULL;
|
||||
|
||||
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>? 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 )
|
||||
{
|
||||
$tid = $topic->tid;
|
||||
|
||||
@@ -89,26 +91,21 @@ class _DeleteEmptyTopics
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $tid;
|
||||
$data['completed']++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If the topic isn't archived, we can delete it */
|
||||
if ( $topic->isArchived() == FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->select( 'pid', 'forums_posts', array( 'topic_id=?', $topic->tid ), NULL, 1 )->first();
|
||||
}
|
||||
/* This topic is empty */
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$topic->delete();
|
||||
}
|
||||
$topic->delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Archived topics will erroneously be picked up by our query, but that's ok...we'll just check them here and delete if empty */
|
||||
try
|
||||
{
|
||||
/* Set first post */
|
||||
/* 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();
|
||||
}
|
||||
/* This topic is empty */
|
||||
@@ -119,6 +116,7 @@ class _DeleteEmptyTopics
|
||||
}
|
||||
|
||||
$last = $tid;
|
||||
$data['completed']++;
|
||||
}
|
||||
|
||||
if( $last === NULL )
|
||||
@@ -134,10 +132,10 @@ class _DeleteEmptyTopics
|
||||
*
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
|
||||
* @return array Text explaning task and percentage complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_deleting_empty_topics' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_deleting_empty_topics' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user