Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief archive Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage forums
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Forums
|
||||
* @since 24 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -44,18 +44,10 @@ class _archive extends \IPS\Task
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/* If we're disabled, disable the task, but only if we don't have things that need restoring */
|
||||
$count = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_RESTORE ) )->first();
|
||||
|
||||
$restoreOnly = FALSE;
|
||||
if ( !\IPS\Settings::i()->archive_on AND $count > 0 )
|
||||
/* If archiving is disabled, disable the task */
|
||||
if ( !\IPS\Settings::i()->archive_on )
|
||||
{
|
||||
$restoreOnly = TRUE;
|
||||
}
|
||||
|
||||
if ( !\IPS\Settings::i()->archive_on AND $restoreOnly !== TRUE )
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'archive' ) );
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'archive' ) );
|
||||
}
|
||||
|
||||
/* Otherwise, let's do this! */
|
||||
@@ -75,50 +67,49 @@ class _archive extends \IPS\Task
|
||||
'sql_tbl_prefix'=> \IPS\Settings::i()->archive_sql_tbl_prefix,
|
||||
'sql_utf8mb4' => isset( \IPS\Settings::i()->sql_utf8mb4 ) ? \IPS\Settings::i()->sql_utf8mb4 : FALSE
|
||||
) );
|
||||
|
||||
/* Do we have a topic we're working on? */
|
||||
if ( $restoreOnly !== TRUE )
|
||||
|
||||
/* Do we have a topic we are working on? */
|
||||
try
|
||||
{
|
||||
try
|
||||
/* Get the topic */
|
||||
$topic = \IPS\forums\Topic::constructFromData( \IPS\Db::i()->select( '*', 'forums_topics', array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_WORKING ) )->first() );
|
||||
|
||||
/* Do as many posts as we can */
|
||||
$offset = $this->storage->select( 'MAX(archive_id)', 'forums_archive_posts', array( 'archive_topic_id=?', $topic->tid ) )->first();
|
||||
$posts = \IPS\Db::i()->select( 'forums_posts.*,forums_topics.forum_id', 'forums_posts', array( 'pid>? AND topic_id=?', intval( $offset ), $topic->tid ), 'pid ASC', static::PROCESS_PER_BATCH, NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )->join( 'forums_topics', 'tid=topic_id' );
|
||||
foreach ( $posts as $post )
|
||||
{
|
||||
$this->archive( $post, $post['forum_id'] );
|
||||
$postsProcessed++;
|
||||
}
|
||||
|
||||
/* If we did them all, mark that this topic is done and remove from search index */
|
||||
if ( $postsProcessed == $posts->count( TRUE ) )
|
||||
{
|
||||
/* Get the topic */
|
||||
$topic = \IPS\forums\Topic::constructFromData( \IPS\Db::i()->select( '*', 'forums_topics', array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_WORKING ) )->first() );
|
||||
|
||||
/* Do as many posts as we can */
|
||||
$offset = $this->storage->select( 'MAX(archive_id)', 'forums_archive_posts', array( 'archive_topic_id=?', $topic->tid ) )->first();
|
||||
$posts = \IPS\Db::i()->select( 'forums_posts.*,forums_topics.forum_id', 'forums_posts', array( 'pid>? AND topic_id=?', intval( $offset ), $topic->tid ), 'pid ASC', static::PROCESS_PER_BATCH, NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )->join( 'forums_topics', 'tid=topic_id' );
|
||||
foreach ( $posts as $post )
|
||||
{
|
||||
$this->archive( $post, $post['forum_id'] );
|
||||
$postsProcessed++;
|
||||
}
|
||||
$topic->topic_archive_status = \IPS\forums\Topic::ARCHIVE_DONE;
|
||||
$topic->save();
|
||||
|
||||
/* If we did them all, mark that this topic is done and remove from search index */
|
||||
if ( $postsProcessed == $posts->count( TRUE ) )
|
||||
{
|
||||
$topic->topic_archive_status = \IPS\forums\Topic::ARCHIVE_DONE;
|
||||
$topic->save();
|
||||
|
||||
\IPS\Db::i()->delete( 'forums_posts', array( 'topic_id=?', $inProgress ) );
|
||||
|
||||
\IPS\Content\Search\Index::i()->removeFromSearchIndex( $topic );
|
||||
}
|
||||
\IPS\Db::i()->delete( 'forums_posts', array( 'topic_id=?', $topic->tid ) );
|
||||
|
||||
\IPS\Content\Search\Index::i()->removeFromSearchIndex( $topic );
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
/* Any that need to be restored? */
|
||||
catch ( \UnderflowException $e ) { }
|
||||
|
||||
/* Can we do even more? */
|
||||
$query = array_merge( array( array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_NOT ) ), \IPS\Application::load('forums')->archiveWhere( \IPS\Db::i()->select( '*', 'forums_archive_rules' ) ) );
|
||||
if ( $postsProcessed < static::PROCESS_PER_BATCH )
|
||||
{
|
||||
/* Loop topics */
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_RESTORE ), 'tid ASC', 250 ), 'IPS\forums\Topic' ) as $topic )
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', $query, 'tid ASC', 250 ), 'IPS\forums\Topic' ) as $topic )
|
||||
{
|
||||
/* First set it as working */
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_WORKING ), array( 'tid=?', $topic->tid ) );
|
||||
|
||||
/* Do as many posts as we can */
|
||||
$offset = \IPS\Db::i()->select( 'MAX(pid)', 'forums_posts', array( 'topic_id=?', $topic->tid ) )->first();
|
||||
foreach ( $this->storage->select( '*', 'forums_archive_posts', array( 'archive_id>? AND archive_topic_id=?', intval( $offset ), $topic->tid ), 'archive_id ASC', static::PROCESS_PER_BATCH - $postsProcessed ) as $post )
|
||||
foreach ( \IPS\Db::i()->select( '*', 'forums_posts', array( 'topic_id=?', $topic->tid ), 'pid ASC', static::PROCESS_PER_BATCH - $postsProcessed ) as $post )
|
||||
{
|
||||
$this->unarchive( $post );
|
||||
\IPS\Content\Search\Index::i()->index( \IPS\forums\Topic\Post::load( $post['archive_id'] ) );
|
||||
$this->archive( $post, $topic->forum_id );
|
||||
$postsProcessed++;
|
||||
if ( $postsProcessed >= static::PROCESS_PER_BATCH )
|
||||
{
|
||||
@@ -127,41 +118,11 @@ class _archive extends \IPS\Task
|
||||
}
|
||||
|
||||
/* Set that it's done */
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_EXCLUDE ), array( 'tid=?', $topic->tid ) );
|
||||
$this->storage->delete( 'forums_archive_posts', array( 'archive_topic_id=?', $topic->tid ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Can we do even more? */
|
||||
if ( $restoreOnly !== TRUE )
|
||||
{
|
||||
$query = array_merge( array( array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_NOT ) ), \IPS\Application::load('forums')->archiveWhere( \IPS\Db::i()->select( '*', 'forums_archive_rules' ) ) );
|
||||
if ( $postsProcessed < static::PROCESS_PER_BATCH )
|
||||
{
|
||||
/* Loop topics */
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', $query, 'tid ASC', 250 ), 'IPS\forums\Topic' ) as $topic )
|
||||
{
|
||||
/* First set it as working */
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_WORKING ), array( 'tid=?', $topic->tid ) );
|
||||
|
||||
/* Do as many posts as we can */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'forums_posts', array( 'topic_id=?', $topic->tid ), 'pid ASC', static::PROCESS_PER_BATCH - $postsProcessed ) as $post )
|
||||
{
|
||||
$this->archive( $post, $topic->forum_id );
|
||||
$postsProcessed++;
|
||||
if ( $postsProcessed >= static::PROCESS_PER_BATCH )
|
||||
{
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set that it's done */
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_DONE ), array( 'tid=?', $topic->tid ) );
|
||||
\IPS\Db::i()->delete( 'forums_posts', array( 'topic_id=?', $topic->tid ) );
|
||||
\IPS\Db::i()->update( 'forums_topics', array( 'topic_archive_status' => \IPS\forums\Topic::ARCHIVE_DONE ), array( 'tid=?', $topic->tid ) );
|
||||
\IPS\Db::i()->delete( 'forums_posts', array( 'topic_id=?', $topic->tid ) );
|
||||
|
||||
/* Remove from search index */
|
||||
\IPS\Content\Search\Index::i()->removeFromSearchIndex( $topic );
|
||||
}
|
||||
/* Remove from search index */
|
||||
\IPS\Content\Search\Index::i()->removeFromSearchIndex( $topic );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,39 +164,9 @@ class _archive extends \IPS\Task
|
||||
|
||||
/* Insert */
|
||||
$this->storage->replace( 'forums_archive_posts', $archive );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unarchive
|
||||
*
|
||||
* @param array $post The post to be unarchived
|
||||
* @return void
|
||||
*/
|
||||
protected function unarchive( $post )
|
||||
{
|
||||
/* Translate the fields */
|
||||
$row = array(
|
||||
'pid' => intval( $post['archive_id'] ),
|
||||
'author_id' => intval( $post['archive_author_id'] ),
|
||||
'author_name' => $post['archive_author_name'],
|
||||
'ip_address' => $post['archive_ip_address'],
|
||||
'post_date' => intval( $post['archive_content_date'] ),
|
||||
'post' => $post['archive_content'],
|
||||
'queued' => $post['archive_queued'],
|
||||
'topic_id' => intval( $post['archive_topic_id'] ),
|
||||
'new_topic' => intval( $post['archive_is_first'] ),
|
||||
'post_bwoptions' => $post['archive_bwoptions'],
|
||||
'post_key' => $post['archive_attach_key'],
|
||||
'post_htmlstate' => $post['archive_html_mode'],
|
||||
'append_edit' => $post['archive_show_edited_by'],
|
||||
'edit_time' => $post['archive_edit_time'],
|
||||
'edit_name' => $post['archive_edit_name'],
|
||||
'post_edit_reason' => $post['archive_edit_reason'],
|
||||
'post_field_int' => $post['archive_field_int'],
|
||||
);
|
||||
|
||||
/* Insert */
|
||||
\IPS\Db::i()->replace( 'forums_posts', $row );
|
||||
/* Update reports table */
|
||||
\IPS\Db::i()->update( 'core_rc_index', array( 'class' => 'IPS\forums\Topic\ArchivedPost' ), array( 'class=? AND content_id=?', 'IPS\forums\Topic\Post', $post['pid'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user