Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -0,0 +1,62 @@
<?php
/**
* @brief Background Task: Convert bbcode pages to html pages post-3.4 upgrade
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Content
* @since 22 Jul 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task: Convert bbcode pages to html pages post-3.4 upgrade
*/
class _ConvertPages
{
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
foreach( \IPS\Db::i()->select( '*', 'cms_pages', array( 'page_type=?', 'bbcode' ) ) as $page )
{
$update = array(
'page_content' => \IPS\Text\LegacyParser::parseStatic( $page['page_content'] ),
'page_type' => 'html'
);
\IPS\Db::i()->update( 'cms_pages', $update, array( 'page_id=?', $page['page_id'] ) );
}
throw new \IPS\Task\Queue\OutOfRangeException;
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'converting_pages_34x' ), 'complete' => 100 );
}
}
@@ -2,9 +2,10 @@
/**
* @brief Background Task: Rebuild database categories
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Content
* @since 13 Jun 2014
* @version SVN_VERSION_NUMBER
*/
@@ -39,7 +40,7 @@ class _RebuildCategories
$classname = $data['class'];
$databaseId = mb_substr( $classname, 18 );
\IPS\Log::i( LOG_DEBUG )->write( "Getting preQueueData for " . $classname, 'rebuildCategories' );
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildCategories' );
try
{
@@ -61,10 +62,10 @@ class _RebuildCategories
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
@@ -84,12 +85,15 @@ class _RebuildCategories
$parsed++;
}
catch( \Exception $e )
{
}
catch( \Exception $e ){}
}
if( $parsed !== $this->rebuild )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return ( $parsed == $this->rebuild ) ? ( $offset + $this->rebuild ) : null;
return ( $offset + $this->rebuild );
}
/**
@@ -97,14 +101,15 @@ class _RebuildCategories
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
$classname = $data['class'];
$databaseId = mb_substr( $classname, 18 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'rebuilding_cms_database_categories', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( $databaseId )->_title ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
$title = ( \IPS\Application::appIsEnabled('cms') ) ? \IPS\cms\Databases::load( $databaseId )->_title : 'Database #' . $databaseId;
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'rebuilding_cms_database_categories', FALSE, array( 'sprintf' => array( $title ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
}
}
@@ -0,0 +1,106 @@
<?php
/**
* @brief Background Task: Rebuild comment likes
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Content
* @since 16 Feb 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task: Rebuild comment likes
*/
class _RebuildCommentLikes
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 500;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
try
{
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'core_reputation_index', array( 'app=? AND type=?', 'cms', 'id' ) )->first();
}
catch( \Exception $ex )
{
throw new \OutOfRangeException;
}
if( $data['count'] == 0 )
{
return null;
}
return $data;
}
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( &$data, $offset )
{
$count = 0;
foreach( \IPS\Db::i()->select( '*', 'core_reputation_index', array( '`app`=? AND `type`=?', 'cms', 'id' ), 'type_id ASC', array( 0, $this->rebuild ) ) as $item )
{
$count++;
try
{
$databaseId = \IPS\Db::i()->select( 'comment_database_id', 'cms_database_comments', array( 'comment_id=?', intval( $item['id'] ) ) )->first();
\IPS\Db::i()->update( 'core_reputation_index', array( 'type' => 'comment_id_' . $databaseId ), array( 'id=?', $item['id'] ) );
}
catch( \UnderflowException $e )
{
/* Comment no longer exists */
\IPS\Db::i()->delete( 'core_reputation_index', array( '`app`=? and `type`=? and `id`=?', 'cms', 'id', $item['id'] ) );
}
}
if( !$count )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return ( $offset + $count );
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_comment_likes'), 'complete' => round( 100 / $data['count'] * $offset, 2 ) );
}
}
@@ -2,9 +2,10 @@
/**
* @brief Background Task: Rebuild database editor fields
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Content
* @since 27 March 2015
* @version SVN_VERSION_NUMBER
*/
@@ -60,10 +61,10 @@ class _RebuildEditorFields
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
@@ -75,7 +76,7 @@ class _RebuildEditorFields
$class = '\IPS\cms\Records' . $databaseId;
$last = NULL;
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) )
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) AND \IPS\Db::i()->checkForColumn( 'cms_custom_database_' . $databaseId, 'field_' . $fieldId ) )
{
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $databaseId, array( 'primary_id_field > ?', $offset ), 'primary_id_field asc', array( 0, $this->rebuild ) ) as $row )
{
@@ -135,6 +136,11 @@ class _RebuildEditorFields
$last = $item->$idColumn;
}
}
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $last;
}
@@ -144,7 +150,7 @@ class _RebuildEditorFields
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
@@ -0,0 +1,123 @@
<?php
/**
* @brief Background Task: Rebuild database reciprocal maps
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Content
* @since 31 May 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task: Rebuild database reciprocal maps
*/
class _RebuildReciprocalMaps
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 500;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$databaseId = $data['database'];
$fieldId = $data['field'];
try
{
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $databaseId, array( 'field_' . $fieldId . ' != \'\' or field_' . $fieldId . ' IS NOT NULL' ) )->first();
}
catch( \Exception $ex )
{
throw new \OutOfRangeException;
}
if( $data['count'] == 0 )
{
return null;
}
return $data;
}
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
$databaseId = $data['database'];
$fieldId = $data['field'];
$parsed = 0;
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) )
{
$fieldsClass = 'IPS\cms\Fields' . $databaseId;
$field = $fieldsClass::load( $fieldId );
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $databaseId, array( 'field_' . $fieldId . ' != \'\' or field_' . $fieldId . ' IS NOT NULL' ), 'primary_id_field asc', array( $offset, $this->rebuild ) ) as $row )
{
$extra = $field->extra;
if ( $row[ 'field_' . $fieldId ] and ! empty( $extra['database'] ) )
{
foreach( explode( ',', $row[ 'field_' . $fieldId ] ) as $foreignId )
{
if ( $foreignId )
{
\IPS\Db::i()->insert( 'cms_database_fields_reciprocal_map', array(
'map_origin_database_id' => $databaseId,
'map_foreign_database_id' => $extra['database'],
'map_origin_item_id' => $row['primary_id_field'],
'map_foreign_item_id' => $foreignId,
'map_field_id' => $fieldId
) );
}
}
}
$parsed++;
}
}
if ( ! $parsed )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $offset + $this->rebuild;
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
$databaseId = $data['database'];
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_cms_database_reciprocal_map', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( $databaseId )->_title, $data['field'] ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
}
}
@@ -2,9 +2,10 @@
/**
* @brief Background Task: Rebuild database records
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Content
* @since 13 Jun 2014
* @version SVN_VERSION_NUMBER
*/
@@ -39,7 +40,7 @@ class _RebuildRecords
$classname = $data['class'];
$databaseId = mb_substr( $classname, 15 );
\IPS\Log::i( LOG_DEBUG )->write( "Getting preQueueData for " . $classname, 'rebuildRecords' );
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildRecords' );
try
{
@@ -61,22 +62,25 @@ class _RebuildRecords
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int|null New offset or NULL if complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
$classname = $data['class'];
$databaseId = mb_substr( $classname, 15 );
/* Make sure there's even content to parse */
if( !isset( $classname::$databaseColumnMap['content'] ) )
{
throw new \OutOfRangeException;
}
/* Make sure there's even content to parse */
if( !class_exists( $classname ) or !isset( $classname::$databaseColumnMap['content'] ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$fixImage = isset( $data['fixImage'] ) ? (boolean) $data['fixImage'] : TRUE;
$fixHtml = isset( $data['fixHtml'] ) ? (boolean) $data['fixHtml'] : FALSE;
$fixFurls = isset( $data['fixFurls']) ? (boolean) $data['fixFurls'] : FALSE;
$parsed = 0;
$class = '\IPS\cms\Records' . $databaseId;
@@ -86,24 +90,94 @@ class _RebuildRecords
{
$record = $class::constructFromData( $row );
$record->resetLastComment();
$save = FALSE;
if ( $record->record_image and file_exists( \IPS\ROOT_PATH . '/uploads/' . $record->record_image ) )
{
$record->record_image = (string) \IPS\File::create( 'content_Records', $record->record_image, file_get_contents( \IPS\ROOT_PATH . '/uploads/' . $record->record_image ) );
$record->save();
if ( $fixImage )
{
if ( $record->record_image and file_exists( \IPS\ROOT_PATH . '/uploads/' . $record->record_image ) )
{
try
{
$record->record_image = (string) \IPS\File::create( 'cms_Records', $record->record_image, file_get_contents( \IPS\ROOT_PATH . '/uploads/' . $record->record_image ) );
}
catch ( \Exception $e )
{
$record->record_image = NULL;
}
$save = TRUE;
}
}
if ( ! $record->record_publish_date )
{
$record->record_publish_date = $record->record_saved;
$save = TRUE;
}
if ( $fixFurls and preg_match( '#%([\d\w]{2})#', $record->record_static_furl ) )
{
$record->record_static_furl = urldecode( $record->record_static_furl );
$save = TRUE;
}
if ( $save )
{
$record->save();
}
if ( $fixHtml )
{
$fields = iterator_to_array( \IPS\Db::i()->select( '*', 'cms_database_fields', array( 'field_database_id=? AND field_type=? AND field_html=1', $databaseId, 'Editor' ) ) );
if ( count( $fields ) )
{
foreach( $fields as $field )
{
$column = 'field_' . $field['field_id'];
if ( $record->member_id and $record->$column )
{
try
{
$author = \IPS\Member::load( $record->member_id );
/* In 3.x this would have been shown as HTML */
if ( $author->group['g_dohtml'] )
{
/* This code is copied from IPB3 to ensure it is compatible with data saved */
$record->$column = str_replace( "&#39;" , "'", $record->$column );
$record->$column = str_replace( "&#33;" , "!", $record->$column );
$record->$column = str_replace( "&#036;", "$", $record->$column );
$record->$column = str_replace( "&#124;", "|", $record->$column );
$record->$column = str_replace( "&amp;" , "&", $record->$column );
$record->$column = str_replace( "&gt;" , ">", $record->$column );
$record->$column = str_replace( "&lt;" , "<", $record->$column );
$record->$column = str_replace( "&#60;" , "<", $record->$column );
$record->$column = str_replace( "&#62;" , ">", $record->$column );
$record->$column = str_replace( "&quot;", '"', $record->$column );
$record->$column = str_replace( '&quot;', '"', $record->$column );
$record->$column = str_replace( '&lt;', '<', $record->$column );
$record->$column = str_replace( '&gt;', '>', $record->$column );
$record->save();
}
}
catch( \OutOfRangeException $e ) { }
}
}
}
}
$parsed++;
}
}
return ( $parsed == $this->rebuild ) ? ( $offset + $this->rebuild ) : null;
if( $parsed != $this->rebuild )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return ( $offset + $this->rebuild );
}
/**
@@ -111,14 +185,15 @@ class _RebuildRecords
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
$classname = $data['class'];
$databaseId = mb_substr( $classname, 18 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_cms_database_records', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( $databaseId )->_title ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
$databaseId = mb_substr( $classname, 15 );
$title = ( \IPS\Application::appIsEnabled('cms') ) ? \IPS\cms\Databases::load( $databaseId )->_title : 'Database #' . $databaseId;
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_cms_database_records', FALSE, array( 'sprintf' => array( $title ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
}
}
@@ -0,0 +1,131 @@
<?php
/**
* @brief Background Task: Resychronise the first post of a topic generated by Pages
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Content
* @since 7 Oct 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task: Rebuild database records
*/
class _ResyncTopicContent
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 100;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
try
{
$database = \IPS\cms\Databases::load( $data['databaseId'] );
if ( $database->forum_record )
{
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $data['databaseId'] )->first();
}
else
{
$cats = iterator_to_array( \IPS\Db::i()->select( 'category_id', 'cms_database_categories', array( 'category_forum_record=1 AND category_database_id=?', $data['databaseId'] ) ) );
if ( count( $cats ) )
{
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $data['databaseId'], array( \IPS\Db::i()->in( 'category_id', $cats ) ) )->first();
}
else
{
return null;
}
}
}
catch( \Exception $ex )
{
throw new \OutOfRangeException;
}
if( $data['count'] == 0 )
{
return null;
}
return $data;
}
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
$class = '\IPS\cms\Records' . $data['databaseId'];
$where = NULL;
$parsed = 0;
$database = \IPS\cms\Databases::load( $data['databaseId'] );
if ( ! $database->forum_record )
{
$cats = iterator_to_array( \IPS\Db::i()->select( 'category_id', 'cms_database_categories', array( 'category_forum_record=1 AND category_database_id=?', $data['databaseId'] ) ) );
$where = array( \IPS\Db::i()->in( 'category_id', $cats ) );
}
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $data['databaseId'] ) )
{
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $data['databaseId'], $where, 'primary_id_field asc', array( $offset, $this->rebuild ) ) as $row )
{
try
{
$record = $class::constructFromData( $row );
$record->syncTopic();
}
catch( \Exception $ex ) { }
$parsed++;
}
}
if( $parsed != $this->rebuild )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return ( $offset + $this->rebuild );
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
$title = ( \IPS\Application::appIsEnabled('cms') ) ? \IPS\cms\Databases::load( $data['databaseId'] )->_title : 'Database #' . $data['databaseId'];
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_cms_database_sync_topics', FALSE, array( 'sprintf' => array( $title ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
}
}