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
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Convert bbcode pages to html pages post-3.4 upgrade
|
||||
* @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 Content
|
||||
* @since 22 Jul 2016
|
||||
*/
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
@@ -12,26 +12,35 @@
|
||||
namespace IPS\cms\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_NORMAL;
|
||||
|
||||
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 _FixCommentAttachments
|
||||
class FixCommentAttachments extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', \IPS\Db::i()->like( 'location_key', 'cms_Records' ) )->first();
|
||||
$data['count'] = Db::i()->select( 'COUNT(*)', 'core_attachments_map', Db::i()->like( 'location_key', 'cms_Records' ) )->first();
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
@@ -49,11 +58,11 @@ class _FixCommentAttachments
|
||||
* @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( array &$data, int $offset ): int
|
||||
{
|
||||
$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 )
|
||||
foreach( Db::i()->select( '*', 'core_attachments_map', Db::i()->like( 'location_key', 'cms_Records' ), 'attachment_id ASC', array( $offset, REBUILD_NORMAL ) ) as $map )
|
||||
{
|
||||
$completed++;
|
||||
|
||||
@@ -72,16 +81,16 @@ class _FixCommentAttachments
|
||||
/* 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();
|
||||
$comment = 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'] ) );
|
||||
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 )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -101,10 +110,10 @@ class _FixCommentAttachments
|
||||
* @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
|
||||
* @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
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'rebuilding_cms_comment_attachments' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack( 'rebuilding_cms_comment_attachments' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -12,29 +12,48 @@
|
||||
namespace IPS\cms\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Records;
|
||||
use IPS\cms\Records\Comment;
|
||||
use IPS\Content\Search\Index;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Log;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Task;
|
||||
use OutOfRangeException;
|
||||
use Throwable;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
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 _MoveComments
|
||||
class MoveComments extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = \IPS\REBUILD_SLOW;
|
||||
public int $rebuild = REBUILD_SLOW;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
$data['done'] = 0;
|
||||
$data['lastId'] = 0;
|
||||
@@ -46,27 +65,27 @@ class _MoveComments
|
||||
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'] ) ) ) ) );
|
||||
$where = array( Db::i()->in( 'comment_record_id', iterator_to_array( 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();
|
||||
$data['count'] = 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 );
|
||||
$where = array( "new_topic=? AND " . Db::i()->in( 'topic_id', iterator_to_array( 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 );
|
||||
$where = array( "new_topic=? AND " . Db::i()->in( 'topic_id', iterator_to_array( Db::i()->select( 'record_topicid', "cms_custom_database_{$data['databaseId']}" ) ) ), 0 );
|
||||
}
|
||||
|
||||
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', $where )->first();
|
||||
$data['count'] = Db::i()->select( 'COUNT(*)', 'forums_posts', $where )->first();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -76,16 +95,16 @@ class _MoveComments
|
||||
/* 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' ) );
|
||||
Task::queue( 'cms', 'ResyncTopicContent', array( 'databaseId' => $data['databaseId'] ), 3, array( 'databaseId' ) );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
catch( \Throwable $e )
|
||||
catch( Throwable $e )
|
||||
{
|
||||
/* Something went wrong - log it and return */
|
||||
\IPS\Log::log( $e, 'cms_move_comments' );
|
||||
Log::log( $e, 'cms_move_comments' );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -98,9 +117,9 @@ class _MoveComments
|
||||
* @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
|
||||
* @throws 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
|
||||
{
|
||||
/* 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'] )
|
||||
@@ -120,7 +139,7 @@ class _MoveComments
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
throw new Task\Queue\OutOfRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,12 +149,12 @@ class _MoveComments
|
||||
* @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
|
||||
* @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
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $data['databaseId'] );
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'moving_database_comments', FALSE, array( 'sprintf' => array( $database->_title ) ) ), 'complete' => $data['done'] ? ( round( 100 / $data['count'] * $data['done'], 2 ) ) : 0 );
|
||||
$database = Databases::load( $data['databaseId'] );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack( 'moving_database_comments', FALSE, array( 'sprintf' => array( $database->_title ) ) ), 'complete' => $data['done'] ? ( round( 100 / $data['count'] * $data['done'], 2 ) ) : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,33 +164,34 @@ class _MoveComments
|
||||
* @param int $offset Offset
|
||||
* @return int New offset
|
||||
*/
|
||||
protected function _toForums( &$data, int $offset ): int
|
||||
protected function _toForums( mixed &$data, int $offset ): int
|
||||
{
|
||||
$done = 0;
|
||||
/* This is easy... kind of */
|
||||
$database = \IPS\cms\Databases::load( $data['databaseId'] );
|
||||
$database = 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'] );
|
||||
$where = array( "comment_database_id=? AND comment_id>? AND " . Db::i()->in( 'comment_record_id', iterator_to_array( 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 )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'cms_database_comments', $where, "comment_id ASC", $this->rebuild ), $commentClass ) AS $row )
|
||||
{
|
||||
/* Check the record exists */
|
||||
try
|
||||
{
|
||||
/* @var Comment $row */
|
||||
$row->item();
|
||||
|
||||
/* Check the topic exists */
|
||||
try
|
||||
{
|
||||
\IPS\forums\Topic::load( $row->item()->record_topicid );
|
||||
Topic::load( $row->item()->record_topicid );
|
||||
}
|
||||
catch( \OutOfRangeException )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
/* If the topic does not exist, reset the value so it can be re-created */
|
||||
$row->item()->record_topicid = 0;
|
||||
@@ -181,11 +201,11 @@ class _MoveComments
|
||||
/* 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.
|
||||
$row->item()->syncTopic(); # Sync Topic will create it for us and link it, while also handling database and category level settings.
|
||||
}
|
||||
}
|
||||
// Exception may be that the item does not exist, or the category does not have syncing enabled
|
||||
catch( \UnderflowException | \OutOfRangeException $e )
|
||||
catch( UnderflowException | OutOfRangeException $e )
|
||||
{
|
||||
$data['lastId'] = $row->id;
|
||||
$data['done']++;
|
||||
@@ -208,7 +228,7 @@ class _MoveComments
|
||||
$queued = -1;
|
||||
}
|
||||
|
||||
$post = new \IPS\forums\Topic\Post;
|
||||
$post = new Post;
|
||||
$post->author_id = $row->user;
|
||||
$post->append_edit = $row->edit_show;
|
||||
$post->edit_time = $row->edit_date;
|
||||
@@ -223,9 +243,9 @@ class _MoveComments
|
||||
$post->save();
|
||||
|
||||
/* Update post before register */
|
||||
\IPS\Db::i()->update( 'core_post_before_registering', array( 'class' => "\IPS\forums\Topic\Post", 'id' => $post->id ), array( 'class=? and id=?', $commentClass, $row->id ) );
|
||||
Db::i()->update( 'core_post_before_registering', array( 'class' => "\IPS\forums\Topic\Post", 'id' => $post->id ), array( 'class=? and id=?', $commentClass, $row->id ) );
|
||||
|
||||
\IPS\Content\Search\Index::i()->index( $post );
|
||||
Index::i()->index( $post );
|
||||
|
||||
$data['lastId'] = $row->id;
|
||||
$data['done']++;
|
||||
@@ -234,9 +254,9 @@ class _MoveComments
|
||||
$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() )
|
||||
if ( !(bool) 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 = Topic::load( $row->item()->record_topicid );
|
||||
$topic->resyncCommentCounts();
|
||||
$topic->save();
|
||||
|
||||
@@ -265,24 +285,25 @@ class _MoveComments
|
||||
* @param int $offset Offset
|
||||
* @return int New offset
|
||||
*/
|
||||
protected function _toPages( &$data, int $offset ): int
|
||||
protected function _toPages( mixed &$data, int $offset ): int
|
||||
{
|
||||
$done = 0;
|
||||
|
||||
/* This ones a little more complicated */
|
||||
$database = \IPS\cms\Databases::load( $data['databaseId'] );
|
||||
$database = 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'] ) ) );
|
||||
$subquery = iterator_to_array( 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}" ) );
|
||||
$subquery = iterator_to_array( 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 )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'forums_posts', array( "pid>? AND new_topic=? AND " . Db::i()->in( 'topic_id', $subquery ), $data['lastId'], 0 ), "pid ASC", $this->rebuild ), 'IPS\forums\Topic\Post' ) AS $row )
|
||||
{
|
||||
/* @var Records $recordClass */
|
||||
$record = $recordClass::load( $row->topic_id, 'record_topicid' );
|
||||
|
||||
$approved = $row->queued;
|
||||
@@ -310,9 +331,9 @@ class _MoveComments
|
||||
$comment->save();
|
||||
|
||||
/* Update post before register */
|
||||
\IPS\Db::i()->update( 'core_post_before_registering', array( 'class' => $commentClass, 'id' => $comment->id ), array( 'class=? and id=?', "\IPS\forums\Topic\Post", $row->id ) );
|
||||
Db::i()->update( 'core_post_before_registering', array( 'class' => $commentClass, 'id' => $comment->id ), array( 'class=? and id=?', "\IPS\forums\Topic\Post", $row->id ) );
|
||||
|
||||
\IPS\Content\Search\Index::i()->index( $comment );
|
||||
Index::i()->index( $comment );
|
||||
|
||||
$row->delete();
|
||||
|
||||
@@ -321,9 +342,9 @@ class _MoveComments
|
||||
$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 )
|
||||
if ( $data['deleteTopics'] AND (int) Db::i()->select( 'COUNT(*)', 'forums_posts', array( "topic_id=?", $row->topic_id ) )->first() === 1 )
|
||||
{
|
||||
\IPS\forums\Topic::load( $row->topic_id )->delete();
|
||||
Topic::load( $row->topic_id )->delete();
|
||||
$record->record_topicid = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
<?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', FALSE, array( 'sprintf' => array( $record->url(), $record->mapped('title') ) ) ), 'complete' => 100 / $data['count'] * $data['done'] );
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild database categories
|
||||
* @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 Content
|
||||
* @since 13 Jun 2014
|
||||
*/
|
||||
|
||||
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 categories
|
||||
*/
|
||||
class _RebuildCategories
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = \IPS\REBUILD_NORMAL;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$databaseId = mb_substr( $classname, 18 );
|
||||
|
||||
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildCategories' );
|
||||
|
||||
try
|
||||
{
|
||||
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_database_categories' )->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 )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$databaseId = mb_substr( $classname, 18 );
|
||||
|
||||
$class = '\IPS\cms\Categories' . $databaseId;
|
||||
$parsed = 0;
|
||||
|
||||
foreach ( \IPS\Db::i()->select( '*', 'cms_database_categories', array( 'category_database_id=?', $databaseId ), 'category_id asc', array( $offset, $this->rebuild ) ) as $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
$cat = $class::constructFromData( $row );
|
||||
$cat->setLastComment();
|
||||
$cat->setLastReview();
|
||||
$cat->save();
|
||||
|
||||
$parsed++;
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$databaseId = mb_substr( $classname, 18 );
|
||||
|
||||
$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 );
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild comment likes
|
||||
* @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 Content
|
||||
* @since 16 Feb 2016
|
||||
*/
|
||||
|
||||
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 = \IPS\REBUILD_QUICK;
|
||||
|
||||
/**
|
||||
* 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 ) );
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild database editor fields
|
||||
* @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 Content
|
||||
* @since 27 March 2015
|
||||
*/
|
||||
|
||||
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 editor fields
|
||||
*/
|
||||
class _RebuildEditorFields
|
||||
{
|
||||
/**
|
||||
* @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 )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$databaseId = mb_substr( $classname, 15 );
|
||||
$fieldId = $data['fieldId'];
|
||||
|
||||
try
|
||||
{
|
||||
$data['count'] = (int) \IPS\Db::i()->select( 'MAX(primary_id_field)', 'cms_custom_database_' . $databaseId )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
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 )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$databaseId = mb_substr( $classname, 15 );
|
||||
$fieldId = $data['fieldId'];
|
||||
|
||||
$parsed = 0;
|
||||
$class = '\IPS\cms\Records' . $databaseId;
|
||||
$last = NULL;
|
||||
|
||||
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 )
|
||||
{
|
||||
$item = $class::constructFromData( $row );
|
||||
$contentColumn = 'field_' . $fieldId;
|
||||
|
||||
$member = \IPS\Member::load( $item->mapped('author') );
|
||||
$extensions = \IPS\Application::load( $classname::$application )->extensions( 'core', 'EditorLocations' );
|
||||
$idColumn = $classname::$databaseColumnId;
|
||||
|
||||
if( isset( $classname::$itemClass ) )
|
||||
{
|
||||
$itemClass = $classname::$itemClass;
|
||||
$module = 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;
|
||||
}
|
||||
}
|
||||
|
||||
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 ) );
|
||||
}
|
||||
catch( \InvalidArgumentException $e )
|
||||
{
|
||||
if( $e->getcode() == 103014 )
|
||||
{
|
||||
$item->$contentColumn = preg_replace( "#\[/?([^\]]+?)\]#", '', $item->$contentColumn );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$item->save();
|
||||
|
||||
$last = $item->$idColumn;
|
||||
$data['completed']++;
|
||||
}
|
||||
}
|
||||
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$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'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -12,40 +12,51 @@
|
||||
namespace IPS\cms\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Fields;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_QUICK;
|
||||
|
||||
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: Rebuild database reciprocal maps
|
||||
*/
|
||||
class _RebuildReciprocalMaps
|
||||
class RebuildReciprocalMaps extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = \IPS\REBUILD_QUICK;
|
||||
public int $rebuild = REBUILD_QUICK;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
$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();
|
||||
$data['count'] = (int) Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $databaseId, array( 'field_' . $fieldId . ' != \'\' or field_' . $fieldId . ' IS NOT NULL' ) )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
@@ -57,26 +68,27 @@ class _RebuildReciprocalMaps
|
||||
|
||||
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
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return int New offset or NULL if complete
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
public function run( mixed &$data, int $offset ): int
|
||||
{
|
||||
$databaseId = $data['database'];
|
||||
$fieldId = $data['field'];
|
||||
$last = NULL;
|
||||
|
||||
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) )
|
||||
if ( Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) )
|
||||
{
|
||||
/* @var Fields $fieldsClass */
|
||||
$fieldsClass = 'IPS\cms\Fields' . $databaseId;
|
||||
$field = $fieldsClass::load( $fieldId );
|
||||
|
||||
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 )
|
||||
foreach ( 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'] ) )
|
||||
@@ -85,7 +97,7 @@ class _RebuildReciprocalMaps
|
||||
{
|
||||
if ( $foreignId )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_database_fields_reciprocal_map', array(
|
||||
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'],
|
||||
@@ -115,11 +127,11 @@ class _RebuildReciprocalMaps
|
||||
* @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
|
||||
* @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
|
||||
{
|
||||
$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'] * $data['completed'], 2 ) ) : 100 );
|
||||
return array( 'text' => Member::loggedIn()->language()->addToStack('rebuilding_cms_database_reciprocal_map', FALSE, array( 'sprintf' => array( Databases::load( $databaseId )->_title, $data['field'] ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild database records
|
||||
* @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 Content
|
||||
* @since 13 Jun 2014
|
||||
*/
|
||||
|
||||
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 _RebuildRecords
|
||||
{
|
||||
/**
|
||||
* @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 )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$databaseId = mb_substr( $classname, 15 );
|
||||
|
||||
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildRecords' );
|
||||
|
||||
try
|
||||
{
|
||||
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $databaseId )->first();
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['completed'] = 0;
|
||||
|
||||
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 )
|
||||
{
|
||||
$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'] ) )
|
||||
{
|
||||
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;
|
||||
$class = '\IPS\cms\Records' . $databaseId;
|
||||
|
||||
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $databaseId ) )
|
||||
{
|
||||
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();
|
||||
$save = FALSE;
|
||||
|
||||
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( "'" , "'", $record->$column );
|
||||
$record->$column = str_replace( "!" , "!", $record->$column );
|
||||
$record->$column = str_replace( "$", "$", $record->$column );
|
||||
$record->$column = str_replace( "|", "|", $record->$column );
|
||||
$record->$column = str_replace( "&" , "&", $record->$column );
|
||||
$record->$column = str_replace( ">" , ">", $record->$column );
|
||||
$record->$column = str_replace( "<" , "<", $record->$column );
|
||||
$record->$column = str_replace( "<" , "<", $record->$column );
|
||||
$record->$column = str_replace( ">" , ">", $record->$column );
|
||||
$record->$column = str_replace( """, '"', $record->$column );
|
||||
$record->$column = str_replace( '"', '"', $record->$column );
|
||||
$record->$column = str_replace( '<', '<', $record->$column );
|
||||
$record->$column = str_replace( '>', '>', $record->$column );
|
||||
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['completed']++;
|
||||
$last = $record->primary_id_field;
|
||||
}
|
||||
}
|
||||
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$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'] * $data['completed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -12,45 +12,58 @@
|
||||
namespace IPS\cms\extensions\core\Queue;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Records;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_NORMAL;
|
||||
|
||||
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: Rebuild database records
|
||||
*/
|
||||
class _ResyncTopicContent
|
||||
class ResyncTopicContent extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = \IPS\REBUILD_NORMAL;
|
||||
public int $rebuild = REBUILD_NORMAL;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $data['databaseId'] );
|
||||
$database = Databases::load( $data['databaseId'] );
|
||||
|
||||
if ( $database->forum_record )
|
||||
{
|
||||
$data['count'] = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $data['databaseId'] )->first();
|
||||
$data['count'] = (int) 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'] ) ) );
|
||||
$cats = iterator_to_array( 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();
|
||||
$data['count'] = (int) Db::i()->select( 'COUNT(*)', 'cms_custom_database_' . $data['databaseId'], array( Db::i()->in( 'category_id', $cats ) ) )->first();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -58,9 +71,9 @@ class _ResyncTopicContent
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
@@ -81,37 +94,38 @@ 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( mixed &$data, int $offset ): int
|
||||
{
|
||||
/* @var Records $class */
|
||||
$class = '\IPS\cms\Records' . $data['databaseId'];
|
||||
$where = array( 'primary_id_field>?', $offset );
|
||||
$last = NULL;
|
||||
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $data['databaseId'] );
|
||||
$database = Databases::load( $data['databaseId'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
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 ) );
|
||||
$cats = iterator_to_array( Db::i()->select( 'category_id', 'cms_database_categories', array( 'category_forum_record=1 AND category_database_id=?', $data['databaseId'] ) ) );
|
||||
$where[] = array( Db::i()->in( 'category_id', $cats ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Db::i()->checkForTable( 'cms_custom_database_' . $data['databaseId'] ) )
|
||||
if ( Db::i()->checkForTable( 'cms_custom_database_' . $data['databaseId'] ) )
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( '*', 'cms_custom_database_' . $data['databaseId'], $where, 'primary_id_field asc', array( 0, $this->rebuild ) ) as $row )
|
||||
foreach ( Db::i()->select( '*', 'cms_custom_database_' . $data['databaseId'], $where, 'primary_id_field asc', array( 0, $this->rebuild ) ) as $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
$record = $class::constructFromData( $row );
|
||||
$record->syncTopic();
|
||||
}
|
||||
catch( \Exception $ex ) { }
|
||||
catch( Exception $ex ) { }
|
||||
|
||||
$data['completed']++;
|
||||
$last = $row['primary_id_field'];
|
||||
@@ -132,11 +146,11 @@ class _ResyncTopicContent
|
||||
* @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
|
||||
* @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
|
||||
{
|
||||
$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'] * $data['completed'], 2 ) ) : 100 );
|
||||
$title = ( Application::appIsEnabled('cms') ) ? Databases::load( $data['databaseId'] )->_title : 'Database #' . $data['databaseId'];
|
||||
return array( 'text' => 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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?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 18 Dec 2023
|
||||
*/
|
||||
|
||||
namespace IPS\cms\extensions\core\Queue;
|
||||
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\QueueAbstract;
|
||||
use IPS\Lang;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Task\Queue\OutOfRangeException as QueueOutOfRangeException;
|
||||
use IPS\Widget\Area;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use const IPS\REBUILD_SLOW;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Task
|
||||
*/
|
||||
class UpdateHtmlPages extends QueueAbstract
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array|null
|
||||
*/
|
||||
public function preQueueData( array $data ): ?array
|
||||
{
|
||||
$data['count'] = (int) Db::i()->select( 'count(page_id)', 'cms_pages' )->first();
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @param array $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return int New offset
|
||||
* @throws QueueOutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( array &$data, int $offset ): int
|
||||
{
|
||||
$limit = REBUILD_SLOW;
|
||||
$rows = iterator_to_array(
|
||||
new ActiveRecordIterator(
|
||||
Db::i()->select( '*', 'cms_pages', null, 'page_id', array( $offset, $limit ) ),
|
||||
Page::class
|
||||
)
|
||||
);
|
||||
|
||||
$lang = Lang::load( Lang::defaultLanguage() );
|
||||
foreach( $rows as $row )
|
||||
{
|
||||
/* Builder pages need minor adjustment */
|
||||
if( $row->type == 'builder' )
|
||||
{
|
||||
$row->ipb_wrapper = true;
|
||||
$row->show_sidebar = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Convert the page to a builder page with a single column */
|
||||
$area = Area::create( 'col1', [
|
||||
[
|
||||
'title' => $lang->addToStack( 'block_Codemirror' ),
|
||||
'config' => true,
|
||||
'blank' => false,
|
||||
'app' => 'cms',
|
||||
'key' => 'Codemirror',
|
||||
'unique' => mt_rand(),
|
||||
'configuration' => [
|
||||
'content' => $row->content
|
||||
]
|
||||
]
|
||||
], [ 'wrapBehavior' => 'stack' ] );
|
||||
$row->saveArea( $area );
|
||||
|
||||
$row->type = 'builder';
|
||||
$row->content = null;
|
||||
|
||||
if( $row->wrapper_template === null or $row->wrapper_template == '__none__')
|
||||
{
|
||||
$row->ipb_wrapper = true;
|
||||
$row->show_sidebar = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( $row->template == 'page_builder__single_column__page_page_builder_single_column' or $row->template == 'page_builder__single_column__page_builder_single_column' )
|
||||
{
|
||||
$row->template = null;
|
||||
}
|
||||
|
||||
$row->save();
|
||||
}
|
||||
|
||||
$offset += $limit;
|
||||
if( $offset >= $data['count'] )
|
||||
{
|
||||
throw new QueueOutOfRangeException;
|
||||
}
|
||||
|
||||
return $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Progress
|
||||
*
|
||||
* @param array $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( array $data, int $offset ): array
|
||||
{
|
||||
return array(
|
||||
'text' => 'Converting HTML Pages to Builder',
|
||||
'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user