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,33 +12,51 @@
|
||||
namespace IPS\convert\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DOMElement;
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\convert\App;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Log;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Settings;
|
||||
use IPS\Text\DOMParser;
|
||||
use IPS\Xml\DOMDocument;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use const IPS\REBUILD_SLOW;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class _InvisionCommunityRebuildContent
|
||||
class InvisionCommunityRebuildContent
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = \IPS\REBUILD_SLOW;
|
||||
public $rebuild = REBUILD_SLOW;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data Data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
$classname = $data['class'];
|
||||
|
||||
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'ICrebuildPosts' );
|
||||
Log::debug( "Getting preQueueData for " . $classname, 'ICrebuildPosts' );
|
||||
|
||||
try
|
||||
{
|
||||
@@ -48,12 +66,12 @@ class _InvisionCommunityRebuildContent
|
||||
/* We're going to use the < operator, so we need to ensure the most recent item is rebuilt */
|
||||
$data['runPid'] = $data['count'] + 1;
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
\IPS\Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'ICrebuildPosts' );
|
||||
Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'ICrebuildPosts' );
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
@@ -73,11 +91,11 @@ class _InvisionCommunityRebuildContent
|
||||
* @return int|null New offset or NULL if complete
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
public function run( mixed &$data, int $offset ): int
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$exploded = explode( '\\', $classname );
|
||||
if ( !class_exists( $classname ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
|
||||
if ( !class_exists( $classname ) or !Application::appIsEnabled( $exploded[1] ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
@@ -91,7 +109,7 @@ class _InvisionCommunityRebuildContent
|
||||
/* Intentionally no try/catch as it means app doesn't exist */
|
||||
try
|
||||
{
|
||||
$this->app = \IPS\convert\App::load( $data['app'] );
|
||||
$this->app = App::load( $data['app'] );
|
||||
|
||||
/* This extension is ONLY for InvisionCommunity conversions */
|
||||
if( $this->app->app_key != 'invisioncommunity' )
|
||||
@@ -99,18 +117,18 @@ class _InvisionCommunityRebuildContent
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$softwareClass = $this->app->getSource( FALSE, FALSE );
|
||||
|
||||
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'ICrebuildPosts' );
|
||||
Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'ICrebuildPosts' );
|
||||
|
||||
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( \is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
|
||||
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
|
||||
$select = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?', $data['runPid'] ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
|
||||
$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
|
||||
$iterator = new ActiveRecordIterator( $select, $classname );
|
||||
$last = NULL;
|
||||
|
||||
foreach( $iterator as $item )
|
||||
@@ -123,7 +141,7 @@ class _InvisionCommunityRebuildContent
|
||||
/* Just checking, we don't actually need anything */
|
||||
$this->app->checkLink( $item->$idColumn, $data['link'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
$last = $item->$idColumn;
|
||||
$data['indexed']++;
|
||||
@@ -132,8 +150,8 @@ class _InvisionCommunityRebuildContent
|
||||
|
||||
$contentColumn = $classname::$databaseColumnMap['content'];
|
||||
|
||||
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $item->$contentColumn ) );
|
||||
$source = new DOMDocument( '1.0', 'UTF-8' );
|
||||
$source->loadHTML( DOMDocument::wrapHtml( $item->$contentColumn ) );
|
||||
|
||||
if( mb_stristr( $item->$contentColumn, 'data-mentionid' ) )
|
||||
{
|
||||
@@ -180,7 +198,7 @@ class _InvisionCommunityRebuildContent
|
||||
}
|
||||
|
||||
/* Get DOMDocument output */
|
||||
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
|
||||
$content = DOMParser::getDocumentBodyContents( $source );
|
||||
|
||||
/* Replace file storage tags */
|
||||
$content = preg_replace( '/<fileStore\.([\d\w\_]+?)>/i', '<fileStore.$1>', $content );
|
||||
@@ -213,27 +231,27 @@ class _InvisionCommunityRebuildContent
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return array Text explaining task and percentage complete
|
||||
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
public function getProgress( mixed $data, int $offset ): array
|
||||
{
|
||||
$class = $data['class'];
|
||||
$exploded = explode( '\\', $class );
|
||||
if ( !class_exists( $class ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
|
||||
if ( !class_exists( $class ) or !Application::appIsEnabled( $exploded[1] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update mentions with new display name, ID and URL
|
||||
*
|
||||
* @param \DOMElement $element DOM element
|
||||
* @param DOMElement $element DOM element
|
||||
* @return void
|
||||
*/
|
||||
public function updateMention( \DOMElement $element )
|
||||
public function updateMention( DOMElement $element )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -241,14 +259,14 @@ class _InvisionCommunityRebuildContent
|
||||
$newMemberId = $this->app->getLink( $element->getAttribute( 'data-mentionid' ), 'core_members' );
|
||||
|
||||
/* Get new member */
|
||||
$member = \IPS\Member::load( $newMemberId );
|
||||
$member = Member::load( $newMemberId );
|
||||
|
||||
$element->setAttribute( 'data-mentionid', $newMemberId );
|
||||
$element->setAttribute( 'href', str_replace( \IPS\Settings::i()->base_url, '<___base_url___>/', $member->url() ) );
|
||||
$element->setAttribute( 'data-ipshover-target', str_replace( \IPS\Settings::i()->base_url, '<___base_url___>/', $member->url()->setQueryString( 'do', 'hovercard' ) ) );
|
||||
$element->setAttribute( 'href', str_replace( Settings::i()->base_url, '<___base_url___>/', $member->url() ) );
|
||||
$element->setAttribute( 'data-ipshover-target', str_replace( Settings::i()->base_url, '<___base_url___>/', $member->url()->setQueryString( 'do', 'hovercard' ) ) );
|
||||
$element->nodeValue = '@' . $member->name;
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
catch( Exception $e ) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,16 +277,16 @@ class _InvisionCommunityRebuildContent
|
||||
/**
|
||||
* Update local embeds for new names, IDs
|
||||
*
|
||||
* @param \DOMElement $element DOM element
|
||||
* @param DOMElement $element DOM element
|
||||
* @return void
|
||||
*/
|
||||
public function updateEmbed( \DOMElement $element )
|
||||
public function updateEmbed( DOMElement $element )
|
||||
{
|
||||
try
|
||||
{
|
||||
$url = \IPS\Http\Url::createFromString( str_replace( '<___base_url___>', rtrim( \IPS\Settings::i()->base_url, '/' ), $element->getAttribute( 'src' ) ) );
|
||||
$url = Url::createFromString( str_replace( '<___base_url___>', rtrim( Settings::i()->base_url, '/' ), $element->getAttribute( 'src' ) ) );
|
||||
|
||||
if( !\in_array( $url->hiddenQueryString['app'], array_keys( $this->embedLocations ) ) )
|
||||
if( !in_array( $url->hiddenQueryString['app'], array_keys( $this->embedLocations ) ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -282,7 +300,7 @@ class _InvisionCommunityRebuildContent
|
||||
$url = $url->setQueryString( 'comment', $this->app->getLink( $url->queryString['comment'], $this->embedLocations[ $url->hiddenQueryString['app'] ]['comment'] ) );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
$url = $url->stripQueryString( 'comment' );
|
||||
}
|
||||
@@ -294,23 +312,23 @@ class _InvisionCommunityRebuildContent
|
||||
$url = $url->setQueryString( 'embedComment', $this->app->getLink( $url->queryString['embedComment'], $this->embedLocations[ $url->hiddenQueryString['app'] ]['comment'] ) );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
$url = $url->stripQueryString( 'embedComment' );
|
||||
}
|
||||
|
||||
$element->setAttribute( 'src', str_replace( \IPS\Settings::i()->base_url, '<___base_url___>/', (string) $url->correctFriendlyUrl() ) );
|
||||
$element->setAttribute( 'src', str_replace( Settings::i()->base_url, '<___base_url___>/', (string) $url->correctFriendlyUrl() ) );
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
catch( Exception $e ) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update quotes for new names, IDs
|
||||
*
|
||||
* @param \DOMElement $element DOM element
|
||||
* @param DOMElement $element DOM element
|
||||
* @return void
|
||||
*/
|
||||
public function updateQuote( \DOMElement $element )
|
||||
public function updateQuote( DOMElement $element )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -318,7 +336,7 @@ class _InvisionCommunityRebuildContent
|
||||
$newMemberId = $this->app->getLink( $element->getAttribute( 'data-ipsquote-userid' ), 'core_members' );
|
||||
|
||||
/* Get new member */
|
||||
$member = \IPS\Member::load( $newMemberId );
|
||||
$member = Member::load( $newMemberId );
|
||||
|
||||
/* Get old username */
|
||||
$oldUsername = $element->getAttribute( 'data-ipsquote-username' );
|
||||
@@ -335,12 +353,12 @@ class _InvisionCommunityRebuildContent
|
||||
/* find the citation to update the username */
|
||||
foreach ( $element->childNodes as $child )
|
||||
{
|
||||
if ( $child instanceof \DOMElement and $child->getAttribute('class') == 'ipsQuote_citation' )
|
||||
if ( $child instanceof DOMElement and $child->getAttribute('class') == 'ipsQuote_citation' )
|
||||
{
|
||||
$child->nodeValue = str_replace( $oldUsername, $member->name, $child->nodeValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
catch( Exception $e ) {}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user