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

@@ -12,33 +12,50 @@
namespace IPS\convert\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use InvalidArgumentException;
use IPS\Application;
use IPS\convert\App;
use IPS\Data\Store;
use IPS\IPS;
use IPS\Log;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Text\LegacyParser;
use OutOfRangeException;
use function defined;
use function get_class;
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 _RebuildContent
class RebuildContent
{
/**
* @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, 'rebuildPosts' );
Log::debug( "Getting preQueueData for " . $classname, 'rebuildPosts' );
try
{
@@ -48,12 +65,12 @@ class _RebuildContent
/* 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'], 'rebuildPosts' );
Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildPosts' );
if( $data['count'] == 0 )
{
@@ -73,11 +90,11 @@ class _RebuildContent
* @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,20 +108,20 @@ class _RebuildContent
/* Intentionally no try/catch as it means app doesn't exist */
try
{
$app = \IPS\convert\App::load( $data['app'] );
$app = App::load( $data['app'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$softwareClass = $app->getSource( FALSE, FALSE );
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildPosts' );
Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildPosts' );
$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 )
@@ -117,66 +134,42 @@ class _RebuildContent
/* Just checking, we don't actually need anything */
$app->checkLink( $item->$idColumn, $data['link'] );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$last = $item->$idColumn;
continue;
}
/* Did the rebuild previously time out on this? If so we need to skip it and move along */
if( isset( \IPS\Data\Store::i()->currentRebuild ) )
if( isset( Store::i()->currentRebuild ) )
{
/* If the last rebuild cycle timed out, currentRebuild might be set and we might have already rebuilt this post (the post that caused the rebuild to fail might come after this (but before in chronological order).
If that is the case, we should skip rebuilding this post again. */
if( \is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] < $item->$idColumn )
if( is_array( Store::i()->currentRebuild ) AND Store::i()->currentRebuild[0] == $classname AND Store::i()->currentRebuild[1] < $item->$idColumn )
{
$last = $item->$idColumn;
continue;
}
/* If the last rebuild cycle failed and we have just retrieved the post we last attempted to rebuild, skip it and move along */
if( \is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] == $item->$idColumn )
if( is_array( Store::i()->currentRebuild ) AND Store::i()->currentRebuild[0] == $classname AND Store::i()->currentRebuild[1] == $item->$idColumn )
{
unset( \IPS\Data\Store::i()->currentRebuild );
unset( Store::i()->currentRebuild );
$last = $item->$idColumn;
continue;
}
}
$member = \IPS\Member::load( $item->mapped('author') );
$extensions = \IPS\Application::load( $classname::$application )->extensions( 'core', 'EditorLocations' );
$member = Member::load( $item->mapped('author') );
if( isset( $classname::$itemClass ) )
{
$itemClass = $classname::$itemClass;
$module = mb_ucfirst( $itemClass::$module );
$module = IPS::mb_ucfirst( $itemClass::$module );
}
else
{
$module = mb_ucfirst( $classname::$module );
}
$extension = NULL;
if ( isset( $extensions[ $module ] ) )
{
$extension = $extensions[ $module ];
}
$canUseHtml = (bool) $member->group['g_dohtml'];
if ( $extension )
{
$extensionCanUseHtml = $extension->canUseHtml( $member );
if ( $extensionCanUseHtml !== NULL )
{
$canUseHtml = $extensionCanUseHtml;
}
}
if ( ! $canUseHtml )
{
$canUseHtml = $item->htmlParsingEnforced();
$module = IPS::mb_ucfirst( $classname::$module );
}
$contentColumn = $classname::$databaseColumnMap['content'];
@@ -191,7 +184,7 @@ class _RebuildContent
{
$id1 = $item->item()->$itemIdColumn;
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
/* Post is orphaned and can be skipped */
$last = $item->$idColumn;
@@ -209,20 +202,20 @@ class _RebuildContent
/* Before we start trying to rebuild, set a flag to note what we are trying to rebuild. If it times out, we can check
this on the next load and skip the problematic content */
\IPS\Data\Store::i()->currentRebuild = array( $classname, $item->$idColumn );
Store::i()->currentRebuild = array( $classname, $item->$idColumn );
try
{
/* Pass off to software class */
if ( $softwareClass::$contentFixed === FALSE )
{
$item->$contentColumn = $softwareClass::fixPostData( $item->$contentColumn );
$item->$contentColumn = $softwareClass::fixPostData( $item->$contentColumn, $data['class'], $item->$idColumn );
}
/* Then pass off to legacy parser to bring up to 4.x */
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, $classname::$application . '_' . mb_ucfirst( $module ), $id1, $id2, NULL, isset( $classname::$itemClass ) ? $classname::$itemClass : \get_class( $item ) );
$item->$contentColumn = LegacyParser::parseStatic( $item->$contentColumn, $member, false, $classname::$application . '_' . IPS::mb_ucfirst( $module ), $id1, $id2, NULL, isset( $classname::$itemClass ) ? $classname::$itemClass : get_class( $item ) );
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
if( $e->getcode() == 103014 )
{
@@ -241,7 +234,7 @@ class _RebuildContent
$data['indexed']++;
/* Now we will reset the rebuild flag we previously set since it rebuilt and saved successfully */
unset( \IPS\Data\Store::i()->currentRebuild );
unset( Store::i()->currentRebuild );
}
/* Store the runPid for the next iteration of this Queue task. This allows the progress bar to show correctly. */
@@ -262,17 +255,17 @@ class _RebuildContent
* @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 );
}
}