Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -0,0 +1,110 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Pages
* @since 05 Dec 2019
*/
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
*/
class _FixCommentAttachments
{
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', \IPS\Db::i()->like( 'location_key', 'cms_Records' ) )->first();
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 )
{
$completed = 0;
foreach( \IPS\Db::i()->select( '*', 'core_attachments_map', \IPS\Db::i()->like( 'location_key', 'cms_Records' ), 'attachment_id ASC', array( $offset, \IPS\REBUILD_NORMAL ) ) as $map )
{
$completed++;
/* If id3 has "-review" in it, this is a review attachment and we can skip already */
if( mb_strpos( $map['id3'], '-review' ) !== FALSE )
{
continue;
}
/* If id3 already has "-comment" in it, this is a known comment attachment (likely submitted after the upgrade) and we can skip already */
if( mb_strpos( $map['id3'], '-comment' ) !== FALSE )
{
continue;
}
/* Otherwise, we need to see if the attachment was used in a comment. If so, update the map, otherwise just continue - record maps didn't change. */
try
{
$comment = \IPS\Db::i()->select( 'comment_post', 'cms_database_comments', array( 'comment_database_id=? AND comment_id=?', $map['id3'], $map['id2'] ) )->first();
/* We are looking for data-fileid="{attach_id}" */
if( preg_match( "/data\-fileid=['\"]{$map['attachment_id']}[\"']/ims", $comment ) )
{
/* We found it - attachment is for the comment so update the map record */
\IPS\Db::i()->update( 'core_attachments_map', array( 'id3' => $map['id3'] . '-comment' ), array( 'attachment_id=? AND location_key=? AND id1=? AND id2=?', $map['attachment_id'], $map['location_key'], $map['id1'], $map['id2'] ) );
}
}
catch( \UnderflowException $e )
{
continue;
}
}
if( !$completed )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $offset + $completed;
}
/**
* 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_cms_comment_attachments' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
}
}
@@ -0,0 +1,304 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Pages
* @since 20 Aug 2019
*/
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
*/
class _MoveComments
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['done'] = 0;
$data['lastId'] = 0;
try
{
switch( $data['to'] )
{
case 'forums':
if ( isset( $data['categoryId'] ) )
{
$where = array( \IPS\Db::i()->in( 'comment_record_id', iterator_to_array( \IPS\Db::i()->select( 'record_id', "cms_custom_database_{$data['databaseId']}", array( "category_id=?", $data['categoryId'] ) ) ) ) );
}
else
{
$where = array( "comment_database_id=?", $data['databaseId'] );
}
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_comments', $where )->first();
break;
case 'pages':
if ( isset( $data['categoryId'] ) )
{
$where = array( "new_topic=? AND " . \IPS\Db::i()->in( 'topic_id', iterator_to_array( \IPS\Db::i()->select( 'record_topicid', "cms_custom_database_{$data['databaseId']}", array( "category_id=?", $data['categoryId'] ) ) ) ), 0 );
}
else
{
$where = array( "new_topic=? AND " . \IPS\Db::i()->in( 'topic_id', iterator_to_array( \IPS\Db::i()->select( 'record_topicid', "cms_custom_database_{$data['databaseId']}" ) ) ), 0 );
}
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', $where )->first();
break;
}
/* If there are no comments, then don't bother. */
if ( !$data['count'] )
{
/* But wait... if we're going from Pages to Forums, we still need to create the topics, so kick off that task instead. */
if ( $data['to'] === 'forums' )
{
\IPS\Task::queue( 'cms', 'ResyncTopicContent', array( 'databaseId' => $data['databaseId'] ), 3, array( 'databaseId' ) );
}
return NULL;
}
}
catch( \Throwable $e )
{
/* Something went wrong - log it and return */
\IPS\Log::log( $e, 'cms_move_comments' );
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 )
{
/* Okay let's figure out what we're doing. Separate these out to different methods since they can be a little complex. */
switch( $data['to'] )
{
case 'forums':
$done = $this->_toForums( $data, $offset );
break;
case 'pages':
$done = $this->_toPages( $data, $offset );
break;
}
if ( $done )
{
return $done;
}
else
{
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 )
{
$database = \IPS\cms\Databases::load( $data['databaseId'] );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'moving_database_comments', NULL, array( 'sprintf' => array( $database->_title ) ) ), 'complete' => $data['done'] ? ( round( 100 / $data['count'] * $data['done'], 2 ) ) : 0 );
}
/**
* Move Comments to the Forums
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
*/
protected function _toForums( &$data, int $offset ): int
{
$done = 0;
/* This is easy... kind of */
$database = \IPS\cms\Databases::load( $data['databaseId'] );
$commentClass = '\IPS\cms\Records\Comment' . $database->_id;
if ( isset( $data['categoryId'] ) )
{
$where = array( "comment_database_id=? AND comment_id>? AND " . \IPS\Db::i()->in( 'comment_record_id', iterator_to_array( \IPS\Db::i()->select( 'primary_id_field', "cms_custom_database_{$database->_id}", array( "category_id=?", $data['categoryId'] ) ) ) ), $database->_id, $data['lastId'] );
}
else
{
$where = array( "comment_database_id=? AND comment_id>?", $database->_id, $data['lastId'] );
}
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'cms_database_comments', $where, "comment_id ASC", $this->rebuild ), $commentClass ) AS $row )
{
/* First, create the topic if it doesn't already exist */
if ( !$row->item()->record_topicid )
{
$row->item()->syncTopic( FALSE ); # Sync Topic will create it for us and link it, while also handling database and category level settings.
}
/* I'm not sure how to do this properly yet */
$queued = 0;
if ( $row->approved == 0 )
{
$queued = 1;
}
else if ( $row->approved == -1 )
{
$queued = -1;
}
$post = new \IPS\forums\Topic\Post;
$post->author_id = $row->user;
$post->append_edit = $row->edit_show;
$post->edit_time = $row->edit_date;
$post->author_name = $row->author;
$post->ip_address = $row->ip_address;
$post->post_date = $row->date;
$post->post = $row->post;
$post->queued = $queued;
$post->topic_id = $row->item()->record_topicid;
$post->edit_name = $row->edit_member_name;
$post->post_edit_reason = $row->edit_reason ?: '';
$post->save();
\IPS\Content\Search\Index::i()->index( $post );
$data['lastId'] = $row->id;
$data['done']++;
$done++;
$row->delete();
/* Are we done? If so, sync the topic */
if ( !(bool) \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_comments', array( "comment_database_id=? AND comment_record_id=?", $database->_id, $row->item()->primary_id_field ) )->first() )
{
$topic = \IPS\forums\Topic::load( $row->item()->record_topicid );
$topic->resyncCommentCounts();
$topic->save();
$forum = $topic->container();
$forum->resetCommentCounts();
$forum->save();
$record = $row->item();
$category = $record->container();
$record->resyncCommentCounts();
$record->save();
$category->resetCommentCounts();
$category->save();
}
}
return $done;
}
/**
* Move Comments to Pages
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
*/
protected function _toPages( &$data, int $offset ): int
{
$done = 0;
/* This ones a little more complicated */
$database = \IPS\cms\Databases::load( $data['databaseId'] );
$commentClass = '\IPS\cms\Records\Comment' . $database->_id;
$recordClass = '\IPS\cms\Records' . $database->_id;
if ( isset( $data['categoryId'] ) )
{
$subquery = iterator_to_array( \IPS\Db::i()->select( 'record_topicid', "cms_custom_database_{$database->_id}", array( "category_id=?", $data['categoryId'] ) ) );
}
else
{
$subquery = iterator_to_array( \IPS\Db::i()->select( 'record_topicid', "cms_custom_database_{$database->_id}" ) );
}
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_posts', array( "pid>? AND new_topic=? AND " . \IPS\Db::i()->in( 'topic_id', $subquery ), $data['lastId'], 0 ), "pid ASC", $this->rebuild ), 'IPS\forums\Topic\Post' ) AS $row )
{
$record = $recordClass::load( $row->topic_id, 'record_topicid' );
$approved = 1;
if ( $row->queued == 1 )
{
$approved = 0;
}
else if ( $row->queued == -1 )
{
$approved = -1;
}
$comment = new $commentClass;
$comment->user = $row->author_id;
$comment->database_id = $database->_id;
$comment->record_id = $record->primary_id_field;
$comment->date = $row->post_date;
$comment->ip_address = $row->ip_address;
$comment->post = $row->post;
$comment->approved = $approved;
$comment->author = $row->author_name;
$comment->edit_date = $row->edit_time ?: 0;
$comment->edit_reason = $row->edit_reason;
$comment->edit_member_name = $row->edit_name;
$comment->save();
\IPS\Content\Search\Index::i()->index( $comment );
$row->delete();
$data['lastId'] = $row->pid;
$data['done']++;
$done++;
/* If we're no longer keeping the topic, then delete it, but only if we're really done with it (ex, only the first post still exists). Otherwise, we still want the topic linked, we're just not using it for comments anymore. */
if ( $data['deleteTopics'] AND (int) \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', array( "topic_id=?", $row->topic_id ) )->first() === 1 )
{
\IPS\forums\Topic::load( $row->topic_id )->delete();
$record->record_topicid = 0;
}
$record->resyncCommentCounts();
$record->save();
$category = $record->container();
$category->resetCommentCounts();
$category->save();
}
return $done;
}
}
@@ -0,0 +1,185 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Pages
* @since 28 Aug 2019
*/
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
*/
class _MoveSingleRecord
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
$data['done'] = 0;
$data['lastId'] = 0;
$recordClass = '\IPS\cms\Records' . $data['databaseId'];
$record = $recordClass::load( $data['recordId'] );
if ( $data['to'] === 'forums' )
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_comments', array( "comment_database_id=? AND comment_record_id=?", $data['databaseId'], $record->primary_id_field ) )->first();
}
else
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', array( "topic_id=? AND new_topic=0", $record->record_topicid ) )->first();
}
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 )
{
$done = 0;
$recordClass = '\IPS\cms\Records' . $data['databaseId'];
$commentClass = '\IPS\cms\Records\Comment' . $data['databaseId'];
$record = $recordClass::load( $data['recordId'] );
$map = array(
'user' => 'author_id',
'date' => 'post_date',
'ip_address' => 'ip_address',
'post' => 'post',
'approved' => 'queued',
'author' => 'author_name',
'edit_date' => 'edit_time',
'edit_reason' => 'post_edit_reason',
'edit_member_name' => 'edit_name',
);
if ( $data['to'] === 'forums' )
{
$it = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'cms_database_comments', array( "comment_id>? AND comment_database_id=? AND comment_record_id=?", $data['lastId'], $data['databaseId'], $data['recordId'] ), 'comment_id ASC', $this->rebuild ), $commentClass );
}
else
{
$it = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_posts', array( "pid>? AND new_topic=0 AND topic_id=?", $data['lastId'], $record->record_topicid ), 'pid ASC', $this->rebuild ), 'IPS\forums\Topic\Post' );
$map = \array_flip( $map );
}
foreach( $it AS $old )
{
if ( $data['to'] === 'forums' )
{
$new = new \IPS\forums\Topic\Post;
$new->topic_id = $record->record_topicid;
$newIdColumn = 'pid';
$oldIdColumn = 'id';
}
else
{
$new = new $commentClass;
$new->record_id = $data['recordId'];
$newIdColumn = 'id';
$oldIdColumn = 'pid';
}
foreach( $map AS $k => $v )
{
switch( $k )
{
case 'approved':
if ( $old->$k == 1 )
{
$new->$v = 0;
}
else if ( $old->$k == 0 )
{
$new->$v = 1;
}
else
{
$new->$v = -1;
}
break;
case 'queued':
if ( $old->$k == 0 )
{
$new->$v = 1;
}
elseif ( $old->$k == 1 )
{
$new->$v = 0;
}
else
{
$new->$v = -1;
}
break;
default:
$new->$v = $old->$k ?? '';
break;
}
}
$new->save();
\IPS\Content\Search\Index::i()->index( $new );
$old->delete();
$data['lastId'] = $old->$oldIdColumn;
$data['done']++;
$done++;
}
$record->syncRecordFromTopic( $record->topic( FALSE ) );
if ( !$done )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $done;
}
/**
* 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 )
{
$recordClass = '\IPS\cms\Records' . $data['databaseId'];
$record = $recordClass::load( $data['recordId'] );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'moving_database_comments_single', NULL, array( 'sprintf' => array( $record->url(), $record->mapped('title') ) ) ), 'complete' => 100 / $data['count'] * $data['done'] );
}
}
@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -26,7 +26,7 @@ class _RebuildCategories
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 50;
public $rebuild = \IPS\REBUILD_NORMAL;
/**
* Parse data before queuing
@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -26,7 +26,7 @@ class _RebuildCommentLikes
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 500;
public $rebuild = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
@@ -71,7 +71,7 @@ class _RebuildCommentLikes
try
{
$databaseId = \IPS\Db::i()->select( 'comment_database_id', 'cms_database_comments', array( 'comment_id=?', intval( $item['id'] ) ) )->first();
$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'] ) );
}
@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -26,7 +26,7 @@ class _RebuildEditorFields
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 50;
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
@@ -53,6 +53,8 @@ class _RebuildEditorFields
{
return null;
}
$data['completed'] = 0;
return $data;
}
@@ -65,7 +67,7 @@ class _RebuildEditorFields
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
$classname = $data['class'];
$databaseId = mb_substr( $classname, 15 );
@@ -116,7 +118,7 @@ class _RebuildEditorFields
try
{
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, 'cms_Records', $item->$idColumn, $data['fieldId'], $databaseId, isset( $classname::$itemClass ) ? $classname::$itemClass : get_class( $item ) );
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, 'cms_Records', $item->$idColumn, $data['fieldId'], $databaseId, isset( $classname::$itemClass ) ? $classname::$itemClass : \get_class( $item ) );
}
catch( \InvalidArgumentException $e )
{
@@ -133,6 +135,7 @@ class _RebuildEditorFields
$item->save();
$last = $item->$idColumn;
$data['completed']++;
}
}
@@ -157,6 +160,6 @@ class _RebuildEditorFields
$classname = $data['class'];
$databaseId = mb_substr( $classname, 15 );
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 );
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'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -26,7 +26,7 @@ class _RebuildReciprocalMaps
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 500;
public $rebuild = \IPS\REBUILD_QUICK;
/**
* Parse data before queuing
@@ -53,6 +53,8 @@ class _RebuildReciprocalMaps
return null;
}
$data['completed'] = 0;
return $data;
}
/**
@@ -63,18 +65,18 @@ class _RebuildReciprocalMaps
* @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 )
public function run( &$data, $offset )
{
$databaseId = $data['database'];
$databaseId = $data['database'];
$fieldId = $data['field'];
$parsed = 0;
$last = NULL;
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 )
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $databaseId, array( 'primary_id_field > ? AND (field_' . $fieldId . ' != \'\' or field_' . $fieldId . ' IS NOT NULL)', $offset ), 'primary_id_field asc', array( 0, $this->rebuild ) ) as $row )
{
$extra = $field->extra;
if ( $row[ 'field_' . $fieldId ] and ! empty( $extra['database'] ) )
@@ -94,16 +96,17 @@ class _RebuildReciprocalMaps
}
}
$parsed++;
$data['completed']++;
$last = $row['primary_id_field'];
}
}
if ( ! $parsed )
if ( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $offset + $this->rebuild;
return $last;
}
/**
@@ -117,6 +120,6 @@ class _RebuildReciprocalMaps
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 );
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'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -26,7 +26,7 @@ class _RebuildRecords
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 50;
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
@@ -54,6 +54,8 @@ class _RebuildRecords
{
return null;
}
$data['completed'] = 0;
return $data;
}
@@ -66,10 +68,11 @@ class _RebuildRecords
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
$classname = $data['class'];
$databaseId = mb_substr( $classname, 15 );
$classname = $data['class'];
$databaseId = mb_substr( $classname, 15 );
$last = NULL;
/* Make sure there's even content to parse */
if( !class_exists( $classname ) or !isset( $classname::$databaseColumnMap['content'] ) )
@@ -80,12 +83,11 @@ class _RebuildRecords
$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;
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) )
{
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $databaseId, NULL, 'primary_id_field asc', array( $offset, $this->rebuild ) ) as $row )
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $databaseId, array( 'primary_id_field > ?', $offset ), 'primary_id_field asc', array( 0, $this->rebuild ) ) as $row )
{
$record = $class::constructFromData( $row );
$record->resetLastComment();
@@ -128,7 +130,7 @@ class _RebuildRecords
{
$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 ) )
if ( \count( $fields ) )
{
foreach( $fields as $field )
{
@@ -167,16 +169,17 @@ class _RebuildRecords
}
}
$parsed++;
$data['completed']++;
$last = $record->primary_id_field;
}
}
if( $parsed != $this->rebuild )
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return ( $offset + $this->rebuild );
return $last;
}
/**
@@ -193,6 +196,6 @@ class _RebuildRecords
$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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_cms_database_records', FALSE, array( 'sprintf' => array( $title ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -12,7 +12,7 @@
namespace IPS\cms\extensions\core\Queue;
/* 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' );
exit;
@@ -26,7 +26,7 @@ class _ResyncTopicContent
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 100;
public $rebuild = \IPS\REBUILD_NORMAL;
/**
* Parse data before queuing
@@ -48,7 +48,7 @@ class _ResyncTopicContent
{
$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 ) )
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();
}
@@ -67,6 +67,8 @@ class _ResyncTopicContent
{
return null;
}
$data['completed'] = 0;
return $data;
}
@@ -79,11 +81,12 @@ class _ResyncTopicContent
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
$class = '\IPS\cms\Records' . $data['databaseId'];
$where = NULL;
$parsed = 0;
$class = '\IPS\cms\Records' . $data['databaseId'];
$where = array( 'primary_id_field>?', $offset );
$last = NULL;
try
{
$database = \IPS\cms\Databases::load( $data['databaseId'] );
@@ -101,7 +104,7 @@ class _ResyncTopicContent
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 )
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $data['databaseId'], $where, 'primary_id_field asc', array( 0, $this->rebuild ) ) as $row )
{
try
{
@@ -110,16 +113,17 @@ class _ResyncTopicContent
}
catch( \Exception $ex ) { }
$parsed++;
$data['completed']++;
$last = $row['primary_id_field'];
}
}
if( $parsed != $this->rebuild )
if( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return ( $offset + $this->rebuild );
return $last;
}
/**
@@ -133,6 +137,6 @@ class _ResyncTopicContent
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 );
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'] * $data['completed'], 2 ) ) : 100 );
}
}