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

@@ -9,19 +9,36 @@
*/
namespace IPS\convert\Software\Forums;
use \IPS\convert\Software\Core\Vanilla as VanillaCore;
use DomainException;
use Exception;
use InvalidArgumentException;
use IPS\Content;
use IPS\convert\App;
use IPS\convert\Software;
use IPS\convert\Software\Core\Vanilla as VanillaCore;
use IPS\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Task;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function unserialize;
/* 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' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Vanilla Forums Converter
*/
class _Vanilla extends \IPS\convert\Software
class Vanilla extends Software
{
/**
* @brief Store the result of the check for reaction support
@@ -31,12 +48,12 @@ class _Vanilla extends \IPS\convert\Software
/**
* Constructor
*
* @param \IPS\convert\App $app The application to reference for database and other information.
* @param App $app The application to reference for database and other information.
* @param bool $needDB Establish a DB connection
* @return void
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct( \IPS\convert\App $app, $needDB=TRUE )
public function __construct( App $app, $needDB=TRUE )
{
$return = parent::__construct( $app, $needDB );
@@ -133,7 +150,7 @@ class _Vanilla extends \IPS\convert\Software
$rows['convertForumsPosts2'] = array(
'step_title' => 'convert_forums_posts',
'step_method' => 'convertForumsPosts2',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts' ),
'ips_rows' => Db::i()->select( 'COUNT(*)', 'forums_posts' ),
'source_rows' => array( 'table' => static::canConvert()['convertForumsPosts2']['table'], 'where' => static::canConvert()['convertForumsPosts2']['where'] ),
'per_cycle' => 200,
'dependencies' => array( 'convertForumsPosts' ),
@@ -165,9 +182,9 @@ class _Vanilla extends \IPS\convert\Software
$count += $this->db->select( 'COUNT(*)', 'Comment' )->first();
return $count;
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \IPS\convert\Exception( sprintf( \IPS\Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
throw new \IPS\convert\Exception( sprintf( Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
}
break;
@@ -217,13 +234,13 @@ class _Vanilla extends \IPS\convert\Software
$return['convertForumsForums'] = array();
/* Find out where the photos live */
\IPS\Member::loggedIn()->language()->words['attach_location_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'attach_location' );
Member::loggedIn()->language()->words['attach_location_desc'] = Member::loggedIn()->language()->addToStack( 'attach_location' );
$return['convertForumsForums']['attach_location'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_vanilla_photopath'),
'field_hint' => Member::loggedIn()->language()->addToStack('convert_vanilla_photopath'),
);
break;
case 'convertForumsPosts':
@@ -232,18 +249,18 @@ class _Vanilla extends \IPS\convert\Software
{
$options = array();
$descriptions = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
{
$options[ $reaction->id ] = $reaction->_icon->url;
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
$descriptions[ $reaction->id ] = Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
}
$return['convertForumsPosts'] = array();
foreach( $this->db->select( '*', 'Action' ) as $reaction )
{
\IPS\Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] ] = $reaction['Name'];
\IPS\Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] . '_desc' ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_convert_help');
Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] ] = $reaction['Name'];
Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] . '_desc' ] = Member::loggedIn()->language()->addToStack('reaction_convert_help');
$return['convertForumsPosts']['reaction_' . $reaction['ActionID'] ] = array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
@@ -263,8 +280,8 @@ class _Vanilla extends \IPS\convert\Software
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_vanilla_photopath'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_hint' => Member::loggedIn()->language()->addToStack('convert_vanilla_photopath'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
),
);
break;
@@ -281,31 +298,33 @@ class _Vanilla extends \IPS\convert\Software
public function finish()
{
/* Content Rebuilds */
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 4, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
\IPS\Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 4, array( 'class' ) );
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
/* Rebuild Leaderboard */
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
\IPS\Db::i()->delete('core_reputation_leaderboard_history');
Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
Db::i()->delete('core_reputation_leaderboard_history');
/* Caches */
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics", "f_topic_tags_recount" );
}
/**
* Fix post data
* Pre-process content for the Invision Community text parser
*
* @param string $post Raw post data
* @return string Parsed post data
* @param string The post
* @param string|null Content Classname passed by post-conversion rebuild
* @param int|null Content ID passed by post-conversion rebuild
* @return string The converted post
*/
public static function fixPostData( $post )
public static function fixPostData( string $post, ?string $className=null, ?int $contentId=null ): string
{
return \IPS\convert\Software\Core\Vanilla::fixPostData( $post );
return VanillaCore::fixPostData( $post, $className, $contentId );
}
/**
@@ -334,7 +353,7 @@ class _Vanilla extends \IPS\convert\Software
{
$discussionId = $this->db->select( 'DiscussionID', 'Comment', array( 'CommentID=?', $row['ForeignID'] ) )->first();
}
catch( \UnderflowException $ex )
catch( UnderflowException $ex )
{
$libraryClass->setLastKeyValue( $row['MediaID'] );
continue;
@@ -360,7 +379,7 @@ class _Vanilla extends \IPS\convert\Software
'attach_filesize' => $row['Size'],
);
$uploadPath = \IPS\convert\Software\Core\Vanilla::parseMediaLocation( $row['Path'], $this->app->_session['more_info']['convertAttachments']['attach_location'] );
$uploadPath = VanillaCore::parseMediaLocation( $row['Path'], $this->app->_session['more_info']['convertAttachments']['attach_location'] );
$libraryClass->convertAttachment( $info, $map, $uploadPath );
$libraryClass->setLastKeyValue( $row['MediaID'] );
@@ -436,7 +455,7 @@ class _Vanilla extends \IPS\convert\Software
{
if( substr( $row['Attributes'], 0, 2 ) == 'a:' ) // Probably serialize
{
$attributes = \unserialize( $row['Attributes'] );
$attributes = unserialize( $row['Attributes'] );
}
else
{
@@ -467,7 +486,7 @@ class _Vanilla extends \IPS\convert\Software
$row['LastCommentUserID'] = $data['InsertUserId'];
$row['LastCommentUserName'] = $data['Name'];
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
$info = array(
@@ -492,7 +511,7 @@ class _Vanilla extends \IPS\convert\Software
{
$tags = explode( ',', $row['Tags'] );
if ( \count( $tags ) )
if ( count( $tags ) )
{
foreach( $tags AS $tag )
{
@@ -539,7 +558,7 @@ class _Vanilla extends \IPS\convert\Software
{
if( substr( $row['Attributes'], 0, 2 ) == 'a:' ) // Probably serialize
{
$attributes = \unserialize( $row['Attributes'] );
$attributes = unserialize( $row['Attributes'] );
}
else
{
@@ -561,7 +580,7 @@ class _Vanilla extends \IPS\convert\Software
{
$editName = $this->db->select( 'Name', 'User', array( 'UserID=?', $row['UpdateUserID'] ) )->first();
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
// Add Format Type (for later processing) if Markdown
@@ -630,7 +649,7 @@ class _Vanilla extends \IPS\convert\Software
{
if( substr( $row['Attributes'], 0, 2 ) == 'a:' ) // Probably serialize
{
$attributes = \unserialize( $row['Attributes'] );
$attributes = unserialize( $row['Attributes'] );
}
else
{
@@ -652,7 +671,7 @@ class _Vanilla extends \IPS\convert\Software
{
$editName = $this->db->select( 'Name', 'User', array( 'UserID=?', $row['UpdateUserID'] ) )->first();
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
// Add Format Type (for later processing) if Markdown
@@ -680,20 +699,20 @@ class _Vanilla extends \IPS\convert\Software
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
* @return NULL|Url
* @note Forums and profiles don't use an ID in the URL. While we may be able to somehow cross reference this with our SEO slug, it wouldn't be reliable.
*/
public function checkRedirects()
{
$url = \IPS\Request::i()->url();
$url = Request::i()->url();
if( preg_match( '#/discussion/([0-9]+)/#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
if( preg_match( '#/discussion/([0-9]+)/#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
{
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = (int) $matches[1];
}
elseif( preg_match( '#/discussion/comment/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
elseif( preg_match( '#/discussion/comment/([0-9]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
@@ -708,13 +727,13 @@ class _Vanilla extends \IPS\convert\Software
{
$data = (string) $this->app->getLink( $oldId, $types );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$data = (string) $this->app->getLink( $oldId, $types, FALSE, TRUE );
}
$item = $class::load( $data );
if( $item instanceof \IPS\Content )
if( $item instanceof Content )
{
if( $item->canView() )
{
@@ -722,7 +741,7 @@ class _Vanilla extends \IPS\convert\Software
}
}
}
catch( \Exception $e )
catch( Exception $e )
{
return NULL;
}