Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,34 @@
|
||||
namespace IPS\convert\Software\Forums;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use IPS\Content;
|
||||
use IPS\convert\Software;
|
||||
use IPS\convert\Software\Core\Woltlab;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Task;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function preg_match;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Woltlab Forums Converter
|
||||
*/
|
||||
class _Woltlab extends \IPS\convert\Software
|
||||
class Woltlab extends Software
|
||||
{
|
||||
/**
|
||||
* @brief The WBB table prefix can change depending on the number of installs
|
||||
@@ -71,7 +89,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
'where' => NULL
|
||||
),
|
||||
'convertAttachments' => array(
|
||||
'table' => 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_attachment',
|
||||
'table' => 'wcf' . Woltlab::$installId . '_attachment',
|
||||
'where' => NULL
|
||||
)
|
||||
);
|
||||
@@ -105,18 +123,18 @@ class _Woltlab 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" );
|
||||
}
|
||||
@@ -134,19 +152,19 @@ class _Woltlab extends \IPS\convert\Software
|
||||
{
|
||||
switch( $table )
|
||||
{
|
||||
case 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_attachment':
|
||||
case 'wcf' . Woltlab::$installId . '_attachment':
|
||||
try
|
||||
{
|
||||
$postObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.post'" ) );
|
||||
return $this->db->select( 'count(attachmentID)', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_attachment', array( $this->db->in( 'objectTypeID', $postObjects ) ) )->first();
|
||||
$postObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.post'" ) );
|
||||
return $this->db->select( 'count(attachmentID)', 'wcf' . Woltlab::$installId . '_attachment', array( $this->db->in( 'objectTypeID', $postObjects ) ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -157,14 +175,16 @@ class _Woltlab extends \IPS\convert\Software
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix Post Data
|
||||
* Pre-process content for the Invision Community text parser
|
||||
*
|
||||
* @param string $post Post
|
||||
* @return string Fixed Post
|
||||
* @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\Woltlab::fixPostData( $post );
|
||||
return Woltlab::fixPostData( $post, $className, $contentId );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,10 +215,10 @@ class _Woltlab extends \IPS\convert\Software
|
||||
/* Get our reactions to let the admin map them */
|
||||
$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(
|
||||
@@ -228,8 +248,8 @@ class _Woltlab extends \IPS\convert\Software
|
||||
'field_default' => NULL,
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_woltlab_attach_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
'field_hint' => Member::loggedIn()->language()->addToStack('convert_woltlab_attach_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
|
||||
)
|
||||
);
|
||||
break;
|
||||
@@ -248,7 +268,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'boardID' );
|
||||
|
||||
$boardObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.board'" ) );
|
||||
$boardObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.board'" ) );
|
||||
|
||||
foreach( $this->fetch( 'wbb' . static::$installId . '_board', 'boardID' ) AS $row )
|
||||
{
|
||||
@@ -269,7 +289,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass->convertForumsForum( $info );
|
||||
|
||||
/* Followers */
|
||||
foreach( $this->db->select( 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_user_object_watch.*', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_user_object_watch', array( "objectID=? AND " . $this->db->in('objectTypeID', $boardObjects ), $row['boardID'] ) ) AS $follow )
|
||||
foreach( $this->db->select( 'wcf' . Woltlab::$installId . '_user_object_watch.*', 'wcf' . Woltlab::$installId . '_user_object_watch', array( "objectID=? AND " . $this->db->in('objectTypeID', $boardObjects ), $row['boardID'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'forums',
|
||||
@@ -301,7 +321,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'threadID' );
|
||||
|
||||
$threadObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.thread'" ) );
|
||||
$threadObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.thread'" ) );
|
||||
|
||||
foreach( $this->fetch( 'wbb' . static::$installId . '_thread', 'threadID', array( 'movedThreadID IS NULL' ) ) AS $row )
|
||||
{
|
||||
@@ -324,8 +344,8 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass->convertForumsTopic( $info );
|
||||
|
||||
/* Tags */
|
||||
$tags = $this->db->select( 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_tag_to_object.tagID', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_tag_to_object', array( "objectID=? AND " . $this->db->in('objectTypeID', $threadObjects ), $row['threadID'] ) );
|
||||
$tagText = $this->db->select( 'name', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_tag', array( $this->db->in( 'tagID', iterator_to_array( $tags ) ) ) );
|
||||
$tags = $this->db->select( 'wcf' . Woltlab::$installId . '_tag_to_object.tagID', 'wcf' . Woltlab::$installId . '_tag_to_object', array( "objectID=? AND " . $this->db->in('objectTypeID', $threadObjects ), $row['threadID'] ) );
|
||||
$tagText = $this->db->select( 'name', 'wcf' . Woltlab::$installId . '_tag', array( $this->db->in( 'tagID', iterator_to_array( $tags ) ) ) );
|
||||
|
||||
foreach( $tagText as $text )
|
||||
{
|
||||
@@ -341,7 +361,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
}
|
||||
|
||||
/* Follows */
|
||||
foreach( $this->db->select( 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_user_object_watch.*', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_user_object_watch', array( "objectID=? AND " . $this->db->in('objectTypeID', $threadObjects ), $row['threadID'] ) ) AS $follow )
|
||||
foreach( $this->db->select( 'wcf' . Woltlab::$installId . '_user_object_watch.*', 'wcf' . Woltlab::$installId . '_user_object_watch', array( "objectID=? AND " . $this->db->in('objectTypeID', $threadObjects ), $row['threadID'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'forums',
|
||||
@@ -373,7 +393,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'postID' );
|
||||
|
||||
$postLikeObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.likeablePost'" ) );
|
||||
$postLikeObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.likeablePost'" ) );
|
||||
|
||||
foreach( $this->fetch( 'wbb' . static::$installId . '_post', 'postID' ) AS $row )
|
||||
{
|
||||
@@ -393,7 +413,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass->convertForumsPost( $info );
|
||||
|
||||
/* Reputation */
|
||||
foreach( $this->db->select( '*', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_like', array( "objectID=? AND " . $this->db->in('objectTypeID', $postLikeObjects ), $row['postID'] ) ) AS $rep )
|
||||
foreach( $this->db->select( '*', 'wcf' . Woltlab::$installId . '_like', array( "objectID=? AND " . $this->db->in('objectTypeID', $postLikeObjects ), $row['postID'] ) ) AS $rep )
|
||||
{
|
||||
$reaction = ( $rep['likeValue'] > 0 ) ? $this->app->_session['more_info']['convertForumsPosts']['rep_positive'] : $this->app->_session['more_info']['convertForumsPosts']['rep_negative'];
|
||||
|
||||
@@ -423,15 +443,15 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'attachmentID' );
|
||||
|
||||
$postObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.post'" ) );
|
||||
$postObjects = iterator_to_array( $this->db->select( 'objectTypeID', 'wcf' . Woltlab::$installId . '_object_type', "objectType='com.woltlab.wbb.post'" ) );
|
||||
|
||||
foreach( $this->fetch( 'wcf' . \IPS\convert\Software\Core\Woltlab::$installId . '_attachment', 'attachmentID', array( $this->db->in( 'objectTypeID', $postObjects ) ) ) AS $row )
|
||||
foreach( $this->fetch( 'wcf' . Woltlab::$installId . '_attachment', 'attachmentID', array( $this->db->in( 'objectTypeID', $postObjects ) ) ) AS $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
$topicId = $this->db->select( 'threadID', 'wbb' . static::$installId . '_post', array( "postID=?", $row['objectID'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* Post is orphaned */
|
||||
$libraryClass->setLastKeyValue( $row['attachmentID'] );
|
||||
@@ -461,16 +481,16 @@ class _Woltlab extends \IPS\convert\Software
|
||||
{
|
||||
$pid = $this->app->getLink( $row['objectID'], 'forums_posts' );
|
||||
|
||||
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
|
||||
$post = Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
|
||||
|
||||
if( \preg_match( '#\[attach]#i', $post ) )
|
||||
if( preg_match( '#\[attach]#i', $post ) )
|
||||
{
|
||||
$post = str_ireplace( '[attach]' . $row['attachmentID'] . '[/attach]', '[attachment=' . $attachId . ':name]', $post );
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
|
||||
Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException | \OutOfRangeException $e ) {}
|
||||
catch( UnderflowException | OutOfRangeException $e ) {}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['attachmentID'] );
|
||||
}
|
||||
@@ -479,19 +499,19 @@ class _Woltlab 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
|
||||
*/
|
||||
public function checkRedirects()
|
||||
{
|
||||
$url = \IPS\Request::i()->url();
|
||||
$url = Request::i()->url();
|
||||
|
||||
if( preg_match( '#/thread/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
|
||||
if( preg_match( '#/thread/([0-9]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
|
||||
{
|
||||
if( !empty( \IPS\Request::i()->postID ) )
|
||||
if( !empty( Request::i()->postID ) )
|
||||
{
|
||||
$class = '\IPS\forums\Topic\Post';
|
||||
$types = array( 'posts', 'forums_posts' );
|
||||
$oldId = (int) \IPS\Request::i()->postID;
|
||||
$oldId = (int) Request::i()->postID;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -500,7 +520,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
$oldId = (int) $matches[1];
|
||||
}
|
||||
}
|
||||
elseif( preg_match( '#/board/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
|
||||
elseif( preg_match( '#/board/([0-9]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
|
||||
{
|
||||
$class = '\IPS\forums\Forum';
|
||||
$types = array( 'forums', 'forums_forums' );
|
||||
@@ -515,20 +535,20 @@ class _Woltlab 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() )
|
||||
{
|
||||
return $item->url();
|
||||
}
|
||||
}
|
||||
elseif( $item instanceof \IPS\Node\Model )
|
||||
elseif( $item instanceof Model )
|
||||
{
|
||||
if( $item->can( 'view' ) )
|
||||
{
|
||||
@@ -536,7 +556,7 @@ class _Woltlab extends \IPS\convert\Software
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user