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\tasks;
|
||||
|
||||
/* 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,6 +23,9 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _archive extends \IPS\Task
|
||||
{
|
||||
/**
|
||||
* @brief Number of items to process per cycle
|
||||
*/
|
||||
const PROCESS_PER_BATCH = 250;
|
||||
|
||||
/**
|
||||
@@ -56,16 +59,23 @@ class _archive extends \IPS\Task
|
||||
$postsProcessed = 0;
|
||||
|
||||
/* Connect to the remote DB if needed */
|
||||
$this->storage = !\IPS\Settings::i()->archive_remote_sql_host ? \IPS\Db::i() : \IPS\Db::i( 'archive', array(
|
||||
'sql_host' => \IPS\Settings::i()->archive_remote_sql_host,
|
||||
'sql_user' => \IPS\Settings::i()->archive_remote_sql_user,
|
||||
'sql_pass' => \IPS\Settings::i()->archive_remote_sql_pass,
|
||||
'sql_database' => \IPS\Settings::i()->archive_remote_sql_database,
|
||||
'sql_port' => \IPS\Settings::i()->archive_sql_port,
|
||||
'sql_socket' => \IPS\Settings::i()->archive_sql_socket,
|
||||
'sql_tbl_prefix'=> \IPS\Settings::i()->archive_sql_tbl_prefix,
|
||||
'sql_utf8mb4' => isset( \IPS\Settings::i()->sql_utf8mb4 ) ? \IPS\Settings::i()->sql_utf8mb4 : FALSE
|
||||
) );
|
||||
if ( \IPS\CIC2 )
|
||||
{
|
||||
$this->storage = \IPS\Cicloud\getForumArchiveDb();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->storage = !\IPS\Settings::i()->archive_remote_sql_host ? \IPS\Db::i() : \IPS\Db::i( 'archive', array(
|
||||
'sql_host' => \IPS\Settings::i()->archive_remote_sql_host,
|
||||
'sql_user' => \IPS\Settings::i()->archive_remote_sql_user,
|
||||
'sql_pass' => \IPS\Settings::i()->archive_remote_sql_pass,
|
||||
'sql_database' => \IPS\Settings::i()->archive_remote_sql_database,
|
||||
'sql_port' => \IPS\Settings::i()->archive_sql_port,
|
||||
'sql_socket' => \IPS\Settings::i()->archive_sql_socket,
|
||||
'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 are working on? */
|
||||
try
|
||||
@@ -74,8 +84,9 @@ class _archive extends \IPS\Task
|
||||
$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' );
|
||||
$offset = $this->storage->select( 'MAX(archive_id)', 'forums_archive_posts', array( 'archive_topic_id=?', $topic->tid ) )->first();
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', array( 'pid>? AND topic_id=?', \intval( $offset ), $topic->tid ) )->join( 'forums_topics', 'tid=topic_id' )->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 )->join( 'forums_topics', 'tid=topic_id' );
|
||||
foreach ( $posts as $post )
|
||||
{
|
||||
$this->archive( $post, $post['forum_id'] );
|
||||
@@ -83,7 +94,7 @@ class _archive extends \IPS\Task
|
||||
}
|
||||
|
||||
/* If we did them all, mark that this topic is done and remove from search index */
|
||||
if ( $postsProcessed == $posts->count( TRUE ) )
|
||||
if ( $postsProcessed == $total )
|
||||
{
|
||||
$topic->topic_archive_status = \IPS\forums\Topic::ARCHIVE_DONE;
|
||||
$topic->save();
|
||||
@@ -140,25 +151,25 @@ class _archive extends \IPS\Task
|
||||
{
|
||||
/* Translate the fields */
|
||||
$archive = array(
|
||||
'archive_id' => intval( $post['pid'] ),
|
||||
'archive_author_id' => intval( $post['author_id'] ),
|
||||
'archive_id' => \intval( $post['pid'] ),
|
||||
'archive_author_id' => \intval( $post['author_id'] ),
|
||||
'archive_author_name' => $post['author_name'],
|
||||
'archive_ip_address' => $post['ip_address'],
|
||||
'archive_content_date' => intval( $post['post_date'] ),
|
||||
'archive_content_date' => \intval( $post['post_date'] ),
|
||||
'archive_content' => $post['post'],
|
||||
'archive_queued' => $post['queued'],
|
||||
'archive_topic_id' => intval( $post['topic_id'] ),
|
||||
'archive_is_first' => intval( $post['new_topic'] ),
|
||||
'archive_topic_id' => \intval( $post['topic_id'] ),
|
||||
'archive_is_first' => \intval( $post['new_topic'] ),
|
||||
'archive_bwoptions' => $post['post_bwoptions'],
|
||||
'archive_added' => time(),
|
||||
'archive_attach_key' => $post['post_key'],
|
||||
'archive_html_mode' => $post['post_htmlstate'],
|
||||
'archive_show_edited_by' => $post['append_edit'],
|
||||
'archive_edit_time' => intval( $post['edit_time'] ),
|
||||
'archive_show_edited_by' => \intval( $post['append_edit'] ),
|
||||
'archive_edit_time' => \intval( $post['edit_time'] ),
|
||||
'archive_edit_name' => (string) $post['edit_name'],
|
||||
'archive_edit_reason' => $post['post_edit_reason'],
|
||||
'archive_field_int' => intval( $post['post_field_int'] ),
|
||||
'archive_forum_id' => $forumId ?: \IPS\Db::i()->select( 'forum_id', 'forums_topics', array( 'tid=?', intval( $post['topic_id'] ) ) )->first()
|
||||
'archive_field_int' => \intval( $post['post_field_int'] ),
|
||||
'archive_forum_id' => $forumId ?: \IPS\Db::i()->select( 'forum_id', 'forums_topics', array( 'tid=?', \intval( $post['topic_id'] ) ) )->first()
|
||||
);
|
||||
|
||||
/* Insert */
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief rssimport 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 05 Feb 2014
|
||||
*/
|
||||
|
||||
namespace IPS\forums\tasks;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* rssimport Task
|
||||
*/
|
||||
class _rssimport extends \IPS\Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* If ran successfully, should return anything worth logging. Only log something
|
||||
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
|
||||
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$timeCheck = new \IPS\DateTime;
|
||||
$timeCheck->sub( new \DateInterval( 'PT10M' ) );
|
||||
|
||||
$this->runUntilTimeout(function() use ( $timeCheck ) {
|
||||
try
|
||||
{
|
||||
$feed = \IPS\forums\Feed::constructFromData( \IPS\Db::i()->select( '*', 'forums_rss_import', array( 'rss_import_enabled=1 AND rss_import_last_import<?', $timeCheck->getTimestamp() ), 'rss_import_last_import ASC', 1 )->first() );
|
||||
$feed->run();
|
||||
}
|
||||
/* There's nothing more left to process */
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
/* Check to see if there are any feeds.. If no feed, we can disable the task */
|
||||
if( !\IPS\Db::i()->select( 'count(rss_import_id)', 'forums_rss_import', array( 'rss_import_enabled=1' ), NULL, 1 )->first() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'rssimport' ) );
|
||||
}
|
||||
|
||||
/* No further processing needed */
|
||||
return FALSE;
|
||||
}
|
||||
/* Any other exception means an error which should be logged */
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
/* If there is an error, we need to log it but the error should not prevent other feeds from importing */
|
||||
if ( isset( $feed ) AND ( $feed instanceof \IPS\forums\Feed ) )
|
||||
{
|
||||
$feed->last_import = time();
|
||||
$feed->save();
|
||||
}
|
||||
throw new \IPS\Task\Exception( $this, $e->getMessage() );
|
||||
}
|
||||
|
||||
/* Run again to see if there's anything left */
|
||||
return TRUE;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*
|
||||
* If your task takes longer than 15 minutes to run, this method
|
||||
* will be called before execute(). Use it to clean up anything which
|
||||
* may not have been done
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\forums\tasks;
|
||||
|
||||
/* 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,6 +23,9 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _unarchive extends \IPS\Task
|
||||
{
|
||||
/**
|
||||
* @brief Number of items to process per cycle
|
||||
*/
|
||||
const PROCESS_PER_BATCH = 250;
|
||||
|
||||
/**
|
||||
@@ -57,26 +60,32 @@ class _unarchive extends \IPS\Task
|
||||
$postsProcessed = 0;
|
||||
|
||||
/* Connect to the remote DB if needed */
|
||||
$this->storage = !\IPS\Settings::i()->archive_remote_sql_host ? \IPS\Db::i() : \IPS\Db::i( 'archive', array(
|
||||
'sql_host' => \IPS\Settings::i()->archive_remote_sql_host,
|
||||
'sql_user' => \IPS\Settings::i()->archive_remote_sql_user,
|
||||
'sql_pass' => \IPS\Settings::i()->archive_remote_sql_pass,
|
||||
'sql_database' => \IPS\Settings::i()->archive_remote_sql_database,
|
||||
'sql_port' => \IPS\Settings::i()->archive_sql_port,
|
||||
'sql_socket' => \IPS\Settings::i()->archive_sql_socket,
|
||||
'sql_tbl_prefix'=> \IPS\Settings::i()->archive_sql_tbl_prefix,
|
||||
'sql_utf8mb4' => isset( \IPS\Settings::i()->sql_utf8mb4 ) ? \IPS\Settings::i()->sql_utf8mb4 : FALSE
|
||||
) );
|
||||
|
||||
if ( \IPS\CIC2 )
|
||||
{
|
||||
$this->storage = \IPS\Cicloud\getForumArchiveDb();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->storage = !\IPS\Settings::i()->archive_remote_sql_host ? \IPS\Db::i() : \IPS\Db::i( 'archive', array(
|
||||
'sql_host' => \IPS\Settings::i()->archive_remote_sql_host,
|
||||
'sql_user' => \IPS\Settings::i()->archive_remote_sql_user,
|
||||
'sql_pass' => \IPS\Settings::i()->archive_remote_sql_pass,
|
||||
'sql_database' => \IPS\Settings::i()->archive_remote_sql_database,
|
||||
'sql_port' => \IPS\Settings::i()->archive_sql_port,
|
||||
'sql_socket' => \IPS\Settings::i()->archive_sql_socket,
|
||||
'sql_tbl_prefix'=> \IPS\Settings::i()->archive_sql_tbl_prefix,
|
||||
'sql_utf8mb4' => isset( \IPS\Settings::i()->sql_utf8mb4 ) ? \IPS\Settings::i()->sql_utf8mb4 : FALSE
|
||||
) );
|
||||
}
|
||||
|
||||
/* 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 )
|
||||
{
|
||||
/* 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 ( $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 )
|
||||
{
|
||||
$unarchivedPost = $this->unarchive( $post );
|
||||
\IPS\Content\Search\Index::i()->index( $unarchivedPost );
|
||||
$postsProcessed++;
|
||||
if ( $postsProcessed >= static::PROCESS_PER_BATCH )
|
||||
{
|
||||
@@ -85,6 +94,7 @@ class _unarchive extends \IPS\Task
|
||||
}
|
||||
|
||||
/* Set that it's done */
|
||||
\IPS\Content\Search\Index::i()->indexSingleItem( $topic );
|
||||
\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 ) );
|
||||
}
|
||||
@@ -102,15 +112,15 @@ class _unarchive extends \IPS\Task
|
||||
{
|
||||
/* Translate the fields */
|
||||
$row = array(
|
||||
'pid' => intval( $post['archive_id'] ),
|
||||
'author_id' => intval( $post['archive_author_id'] ),
|
||||
'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_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'] ),
|
||||
'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'],
|
||||
|
||||
Reference in new issue
Block a user