Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+54 -38
View File
@@ -12,16 +12,30 @@
namespace IPS\forums\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Search\Index;
use IPS\Db;
use IPS\forums\Topic;
use IPS\forums\Topic\Post;
use IPS\Settings;
use IPS\Task;
use IPS\Task\Exception;
use UnderflowException;
use function defined;
use function intval;
use function IPS\Cicloud\getForumArchiveDb;
use const IPS\CIC2;
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;
}
/**
* unarchive Task
*/
class _unarchive extends \IPS\Task
class unarchive extends Task
{
/**
* @brief Number of items to process per cycle
@@ -31,7 +45,7 @@ class _unarchive extends \IPS\Task
/**
* @brief Storage database
*/
protected $storage;
protected mixed $storage = NULL;
/**
* Execute
@@ -42,36 +56,36 @@ class _unarchive extends \IPS\Task
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
* @throws Exception
*/
public function execute()
public function execute() : mixed
{
/* 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();
$count = Db::i()->select( 'COUNT(*)', 'forums_topics', array( 'topic_archive_status=?', Topic::ARCHIVE_RESTORE ) )->first();
if ( !\IPS\Settings::i()->archive_on AND !$count )
if ( !Settings::i()->archive_on AND !$count )
{
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'unarchive' ) );
Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'unarchive' ) );
return NULL;
}
/* Connect to the remote DB if needed */
if ( \IPS\CIC2 )
if ( CIC2 )
{
$this->storage = \IPS\Cicloud\getForumArchiveDb();
$this->storage = 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
$this->storage = !Settings::i()->archive_remote_sql_host ? Db::i() : Db::i( 'archive', array(
'sql_host' => Settings::i()->archive_remote_sql_host,
'sql_user' => Settings::i()->archive_remote_sql_user,
'sql_pass' => Settings::i()->archive_remote_sql_pass,
'sql_database' => Settings::i()->archive_remote_sql_database,
'sql_port' => Settings::i()->archive_sql_port,
'sql_socket' => Settings::i()->archive_sql_socket,
'sql_tbl_prefix'=> Settings::i()->archive_sql_tbl_prefix,
'sql_utf8mb4' => isset( Settings::i()->sql_utf8mb4 ) ? Settings::i()->sql_utf8mb4 : FALSE
) );
}
@@ -82,16 +96,16 @@ class _unarchive extends \IPS\Task
/* Loop topics */
try
{
$topic = \IPS\forums\Topic::constructFromData( \IPS\Db::i()->select( '*', 'forums_topics', array( 'topic_archive_status=?', \IPS\forums\Topic::ARCHIVE_RESTORE ), 'tid ASC', 1 )->first() );
$topic = Topic::constructFromData( Db::i()->select( '*', 'forums_topics', array( 'topic_archive_status=?', Topic::ARCHIVE_RESTORE ), 'tid ASC', 1 )->first() );
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
return FALSE;
}
/* 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 )
$offset = 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 )
{
$unarchivedPost = $this->unarchive( $post );
$postsProcessed++;
@@ -102,33 +116,35 @@ 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 ) );
Index::i()->indexSingleItem( $topic );
Db::i()->update( 'forums_topics', array( 'topic_archive_status' => Topic::ARCHIVE_EXCLUDE ), array( 'tid=?', $topic->tid ) );
$this->storage->delete( 'forums_archive_posts', array( 'archive_topic_id=?', $topic->tid ) );
return TRUE;
});
return true;
}
/**
* Unarchive
*
* @param array $post The post to be unarchived
* @return \IPS\forums\Topic\Post
* @param array $post The post to be unarchived
* @return Post
*/
protected function unarchive( $post )
protected function unarchive( array $post ): Post
{
/* 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'],
@@ -140,13 +156,13 @@ class _unarchive extends \IPS\Task
);
/* Insert */
\IPS\Db::i()->replace( 'forums_posts', $row );
Db::i()->replace( 'forums_posts', $row );
/* Update reports and promotes tables */
\IPS\Db::i()->update( 'core_rc_index', array( 'class' => 'IPS\forums\Topic\Post' ), array( 'class=? AND content_id=?', 'IPS\forums\Topic\ArchivedPost', $post['archive_id'] ) );
\IPS\Db::i()->update( 'core_social_promote', array( 'promote_class' => 'IPS\forums\Topic\Post' ), array( "promote_class=? AND promote_class_id=?", 'IPS\forums\Topic\ArchivedPost', $post['archive_id'] ) );
Db::i()->update( 'core_rc_index', array( 'class' => 'IPS\forums\Topic\Post' ), array( 'class=? AND content_id=?', 'IPS\forums\Topic\ArchivedPost', $post['archive_id'] ) );
Db::i()->update( 'core_content_promote', array( 'promote_class' => 'IPS\forums\Topic\Post' ), array( "promote_class=? AND promote_class_id=?", 'IPS\forums\Topic\ArchivedPost', $post['archive_id'] ) );
return \IPS\forums\Topic\Post::constructFromData( $row );
return Post::constructFromData( $row );
}
/**