Version 4.1.19.4
This commit is contained in:
1 parent
2bd5025018
commit
0dc2aee5ed
312 files changed
+53730
-32118
No files matched your search
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 26 July 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _DeleteEmptyTopics
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return int|null New offset or NULL if complete
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* If app was removed, then cancel this */
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$last = NULL;
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, 50 ) ), 'IPS\forums\Topic' ) AS $topic )
|
||||
{
|
||||
$tid = $topic->tid;
|
||||
|
||||
/* Is this converted content? */
|
||||
try
|
||||
{
|
||||
/* Just checking, we don't actually need anything */
|
||||
$app->checkLink( $tid, 'forums_topics' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $tid;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $topic->isArchived() == FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->select( 'pid', 'forums_posts', array( 'topic_id=?', $topic->tid ), NULL, 1 )->first();
|
||||
}
|
||||
/* This topic is empty */
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$topic->delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Set first post */
|
||||
\IPS\forums\Topic\ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), NULL, 1 )->first();
|
||||
}
|
||||
/* This topic is empty */
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$topic->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$last = $tid;
|
||||
}
|
||||
|
||||
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 explaning task and percentage complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_deleting_empty_topics' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild Content
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 10 Sep 2015
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RebuildContent
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = 50;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
|
||||
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildPosts' );
|
||||
|
||||
try
|
||||
{
|
||||
$data['count'] = $classname::db()->select( 'MAX(' . $classname::$databasePrefix . $classname::$databaseColumnId . ')', $classname::$databaseTable, ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? $classname::commentWhere() : array() )->first();
|
||||
$data['realCount'] = $classname::db()->select( 'COUNT(*)', $classname::$databaseTable, ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? $classname::commentWhere() : array() )->first();
|
||||
|
||||
/* We're going to use the < operator, so we need to ensure the most recent item is rebuilt */
|
||||
$data['runPid'] = $data['count'] + 1;
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
\IPS\Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildPosts' );
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['indexed'] = 0;
|
||||
|
||||
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 \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$exploded = explode( '\\', $classname );
|
||||
if ( !class_exists( $classname ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Make sure there's even content to parse */
|
||||
if( !isset( $classname::$databaseColumnMap['content'] ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Intentionally no try/catch as it means app doesn't exist */
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$softwareClass = $app->getSource( FALSE, FALSE );
|
||||
|
||||
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildPosts' );
|
||||
|
||||
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
|
||||
$select = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?', $data['runPid'] ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
|
||||
$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
|
||||
$last = NULL;
|
||||
|
||||
foreach( $iterator as $item )
|
||||
{
|
||||
$idColumn = $classname::$databaseColumnId;
|
||||
|
||||
/* Is this converted content? */
|
||||
try
|
||||
{
|
||||
/* Just checking, we don't actually need anything */
|
||||
$app->checkLink( $item->$idColumn, $data['link'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $item->$idColumn;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Did the rebuild previously time out on this? If so we need to skip it and move along */
|
||||
if( isset( \IPS\Data\Store::i()->currentRebuild ) )
|
||||
{
|
||||
/* If the last rebuild cycle timed out, currentRebuild might be set and we might have already rebuilt this post (the post that caused the rebuild to fail might come after this (but before in chronological order).
|
||||
If that is the case, we should skip rebuilding this post again. */
|
||||
if( is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] < $item->$idColumn )
|
||||
{
|
||||
$last = $item->$idColumn;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If the last rebuild cycle failed and we have just retrieved the post we last attempted to rebuild, skip it and move along */
|
||||
if( is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] == $item->$idColumn )
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->currentRebuild );
|
||||
$last = $item->$idColumn;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( $item->mapped('author') );
|
||||
$extensions = \IPS\Application::load( $classname::$application )->extensions( 'core', 'EditorLocations' );
|
||||
|
||||
if( isset( $classname::$itemClass ) )
|
||||
{
|
||||
$itemClass = $classname::$itemClass;
|
||||
$module = ucfirst( $itemClass::$module );
|
||||
}
|
||||
else
|
||||
{
|
||||
$module = ucfirst( $classname::$module );
|
||||
}
|
||||
|
||||
$extension = NULL;
|
||||
|
||||
if ( isset( $extensions[ $module ] ) )
|
||||
{
|
||||
$extension = $extensions[ $module ];
|
||||
}
|
||||
|
||||
$canUseHtml = (bool) $member->group['g_dohtml'];
|
||||
|
||||
if ( $extension )
|
||||
{
|
||||
$extensionCanUseHtml = $extension->canUseHtml( $member );
|
||||
if ( $extensionCanUseHtml !== NULL )
|
||||
{
|
||||
$canUseHtml = $extensionCanUseHtml;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $canUseHtml )
|
||||
{
|
||||
$canUseHtml = $item->htmlParsingEnforced();
|
||||
}
|
||||
|
||||
$contentColumn = $classname::$databaseColumnMap['content'];
|
||||
|
||||
/* Figure out ids for attachments */
|
||||
if( isset( $classname::$itemClass ) )
|
||||
{
|
||||
$itemIdColumn = $itemClass::$databaseColumnId;
|
||||
$module = $itemClass::$module;
|
||||
|
||||
try
|
||||
{
|
||||
$id1 = $item->item()->$itemIdColumn;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
/* Post is orphaned and can be skipped */
|
||||
$last = $item->$idColumn;
|
||||
continue;
|
||||
}
|
||||
|
||||
$id2 = $item->$idColumn;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id1 = $item->$idColumn;
|
||||
$id2 = 0;
|
||||
$module = $classname::$module;
|
||||
}
|
||||
|
||||
/* Before we start trying to rebuild, set a flag to note what we are trying to rebuild. If it times out, we can check
|
||||
this on the next load and skip the problematic content */
|
||||
\IPS\Data\Store::i()->currentRebuild = array( $classname, $item->$idColumn );
|
||||
|
||||
try
|
||||
{
|
||||
/* Pass off to software class */
|
||||
if ( $softwareClass::$contentFixed === FALSE )
|
||||
{
|
||||
$item->$contentColumn = $softwareClass::fixPostData( $item->$contentColumn );
|
||||
}
|
||||
|
||||
/* Then pass off to legacy parser to bring up to IPS4 */
|
||||
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, $classname::$application . '_' . ucfirst( $module ), $id1, $id2, NULL, 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['indexed']++;
|
||||
|
||||
/* Now we will reset the rebuild flag we previously set since it rebuilt and saved successfully */
|
||||
unset( \IPS\Data\Store::i()->currentRebuild );
|
||||
}
|
||||
|
||||
/* Store the runPid for the next iteration of this Queue task. This allows the progress bar to show correctly. */
|
||||
$data['runPid'] = $last;
|
||||
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Return the number rebuilt so far, so that the rebuild progress bar text makes sense */
|
||||
return $data['indexed'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$class = $data['class'];
|
||||
$exploded = explode( '\\', $class );
|
||||
if ( !class_exists( $class ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 28 July 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RebuildConversationFirstIds
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(mt_id)', 'core_message_topics' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
$last = NULL;
|
||||
|
||||
$topicIdsToReset = array();
|
||||
$firstPostIds = array();
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_message_topics', array( "mt_id>?", $offset ), "mt_id ASC", array( 0, 50 ) ), 'IPS\core\Messenger\Conversation' ) AS $conversation )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Set first post */
|
||||
$conversation->first_msg_id = \IPS\Db::i()->select( 'msg_id', 'core_message_posts', array( 'msg_topic_id=?', $conversation->id ), 'msg_date ASC', 1 )->first();
|
||||
$conversation->save();
|
||||
|
||||
/* Reset new_topic value for topic */
|
||||
$topicIdsToReset[] = $conversation->id;
|
||||
$firstPostIds[] = $conversation->first_msg_id;
|
||||
}
|
||||
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
|
||||
catch( \UnderflowException $e ) {}
|
||||
|
||||
$last = $conversation->id;
|
||||
}
|
||||
|
||||
/* Reset flags as needed */
|
||||
if( count( $topicIdsToReset ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 0 ), array( 'msg_topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
|
||||
}
|
||||
|
||||
if( count( $firstPostIds ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 1 ), array( 'msg_id IN(' . implode( ',', $firstPostIds ) . ')' ) );
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_conversation_first_id'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 26 Feb 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RebuildFirstPostIds
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$last = NULL;
|
||||
|
||||
$topicIdsToReset = array();
|
||||
$archivedTopicIdsToReset = array();
|
||||
$firstPostIds = array();
|
||||
$firstPostArchivedIds = array();
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, 50 ) ), 'IPS\forums\Topic' ) AS $topic )
|
||||
{
|
||||
if ( $topic->isArchived() == FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Set first post */
|
||||
$topic->topic_firstpost = \IPS\Db::i()->select( 'pid', 'forums_posts', array( 'topic_id=?', $topic->tid ), 'post_date ASC', 1 )->first();
|
||||
$topic->save();
|
||||
|
||||
/* Reset new_topic value for topic */
|
||||
$topicIdsToReset[] = $topic->tid;
|
||||
$firstPostIds[] = $topic->topic_firstpost;
|
||||
}
|
||||
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Set first post */
|
||||
$topic->topic_firstpost = \IPS\forums\Topic\ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), "archive_content_date ASC", 1 )->first();
|
||||
$topic->save();
|
||||
|
||||
/* Reset new_topic value for topic */
|
||||
$archivedTopicIdsToReset[] = $topic->tid;
|
||||
$firstPostArchivedIds[] = $topic->topic_firstpost;
|
||||
}
|
||||
/* Underflow exception may occur if the topic doesn't have any posts for an unknown reason */
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$last = $topic->tid;
|
||||
}
|
||||
|
||||
/* Reset flags as needed */
|
||||
if( count( $topicIdsToReset ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 0 ), array( 'topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
|
||||
}
|
||||
|
||||
if( count( $firstPostIds ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 1 ), array( 'pid IN(' . implode( ',', $firstPostIds ) . ')' ) );
|
||||
}
|
||||
|
||||
if( count( $archivedTopicIdsToReset ) )
|
||||
{
|
||||
\IPS\forums\Topic\ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 0 ), array( 'archive_topic_id IN(' . implode( ',', $archivedTopicIdsToReset ) . ')' ) );
|
||||
}
|
||||
|
||||
if( count( $firstPostArchivedIds ) )
|
||||
{
|
||||
\IPS\forums\Topic\ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 1 ), array( 'archive_id IN(' . implode( ',', $firstPostArchivedIds ) . ')' ) );
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_new_topic_flag'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 16 Oct 2015
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RebuildGalleryImages
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(image_id)', 'gallery_images' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Background Task
|
||||
*
|
||||
* @param mixed $data Data as it was passed to \IPS\Task::queue()
|
||||
* @param int $offset Offset
|
||||
* @return int|null New offset or NULL if complete
|
||||
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
if ( !class_exists( 'IPS\gallery\Image' ) OR !\IPS\Application::appIsEnabled( 'gallery' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$last = NULL;
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_images', array( "image_id>?", $offset ), 'image_id ASC', array( 0, 10 ) ), 'IPS\gallery\Image' ) AS $image )
|
||||
{
|
||||
try
|
||||
{
|
||||
$image->buildThumbnails();
|
||||
$image->save();
|
||||
}
|
||||
catch( \DomainException $e )
|
||||
{
|
||||
$image->delete();
|
||||
}
|
||||
/* File fails the image type test */
|
||||
catch( \InvalidArgumentException $e )
|
||||
{
|
||||
$image->delete();
|
||||
}
|
||||
|
||||
$last = $image->id;
|
||||
}
|
||||
|
||||
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 explaning task and percentage complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_rebuilding_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 07 Oct 2015
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RebuildNonContent
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = 50;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$data['count'] = 0;
|
||||
$_extensionData = explode( '_', $data['extension'] );
|
||||
|
||||
foreach( \IPS\Application::load( $_extensionData[0] )->extensions( 'core', 'EditorLocations' ) as $_key => $extension )
|
||||
{
|
||||
if( $_key != $_extensionData[1] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( method_exists( $extension, 'contentCount' ) )
|
||||
{
|
||||
$data['count'] = (int) $extension->contentCount();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
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 \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( $data, $offset )
|
||||
{
|
||||
foreach( \IPS\Application::allExtensions( 'core', 'EditorLocations', FALSE, NULL, NULL, TRUE ) as $_key => $extension )
|
||||
{
|
||||
if( $_key != $data['extension'] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
$softwareClass = $app->getSource( TRUE, FALSE );
|
||||
|
||||
if( method_exists( $extension, 'rebuildContent' ) )
|
||||
{
|
||||
$did = $extension->rebuildContent( $offset, $softwareClass::fixPostData( $this->rebuild ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$did = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if( $did == $this->rebuild )
|
||||
{
|
||||
return $offset + $this->rebuild;
|
||||
}
|
||||
|
||||
/* Rebuild is complete */
|
||||
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 explaning task and percentage complete
|
||||
*/
|
||||
public function getProgress( $data, $offset )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'rebuilding_noncontent_posts', FALSE, array( 'sprintf' => \IPS\Member::loggedIn()->language()->addToStack( 'editor__' . $data['extension'] ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task: Rebuild Tag Cache
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 12 October 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RebuildTagCache
|
||||
{
|
||||
/**
|
||||
* @brief Number of content items to rebuild per cycle
|
||||
*/
|
||||
public $rebuild = 200;
|
||||
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
|
||||
\IPS\Log::debug( "Getting preQueueData for " . $classname, 'rebuildTagCache' );
|
||||
|
||||
try
|
||||
{
|
||||
$data['count'] = $classname::db()->select( 'MAX(' . $classname::$databasePrefix . $classname::$databaseColumnId . ')', $classname::$databaseTable )->first();
|
||||
$data['realCount'] = $classname::db()->select( 'COUNT(*)', $classname::$databaseTable )->first();
|
||||
|
||||
/* We're going to use the < operator, so we need to ensure the most recent item is rebuilt */
|
||||
$data['runPid'] = $data['count'] + 1;
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
\IPS\Log::debug( "PreQueue count for " . $classname . " is " . $data['count'], 'rebuildTagCache' );
|
||||
|
||||
if( $data['count'] == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['indexed'] = 0;
|
||||
|
||||
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 \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
|
||||
*/
|
||||
public function run( &$data, $offset )
|
||||
{
|
||||
$classname = $data['class'];
|
||||
$exploded = explode( '\\', $classname );
|
||||
if ( !class_exists( $classname ) or !\IPS\Application::appIsEnabled( $exploded[1] ) OR !in_array( 'IPS\Content\Tags', class_implements( $classname ) ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Intentionally no try/catch as it means app doesn't exist */
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'rebuildTagCache' );
|
||||
|
||||
$select = $classname::db()->select( '*', $classname::$databaseTable, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?', $data['runPid'] ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
|
||||
$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
|
||||
$last = NULL;
|
||||
|
||||
foreach( $iterator as $item )
|
||||
{
|
||||
$idColumn = $classname::$databaseColumnId;
|
||||
|
||||
/* Is this converted content? */
|
||||
try
|
||||
{
|
||||
/* Just checking, we don't actually need anything */
|
||||
$app->checkLink( $item->$idColumn, $data['link'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $item->$idColumn;
|
||||
continue;
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
$tags['prefix'] = $item->prefix();
|
||||
|
||||
foreach( $item->tags() AS $val )
|
||||
{
|
||||
$tags[] = $val;
|
||||
}
|
||||
|
||||
$item->setTags( $tags, \IPS\Member::load( $item->mapped('author') ) );
|
||||
|
||||
$last = $item->$idColumn;
|
||||
|
||||
$data['indexed']++;
|
||||
}
|
||||
|
||||
/* Store the runPid for the next iteration of this Queue task. This allows the progress bar to show correctly. */
|
||||
$data['runPid'] = $last;
|
||||
|
||||
if( $last === NULL )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Return the number rebuilt so far, so that the rebuild progress bar text makes sense */
|
||||
return $data['indexed'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$class = $data['class'];
|
||||
$exploded = explode( '\\', $class );
|
||||
if ( !class_exists( $class ) or !\IPS\Application::appIsEnabled( $exploded[1] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_rebuilding_tag_cache', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['realCount'] ? ( round( 100 / $data['realCount'] * $data['indexed'], 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 19 Nov 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RecountAnswerRatings
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(pid)', 'forums_posts' )->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 )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic\Post' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Intentionally no try/catch as it means app doesn't exist */
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_posts', array( "pid>?", $offset ), "pid ASC", array( 0, 200 ) ), 'IPS\forums\Topic\Post' ) AS $answer )
|
||||
{
|
||||
/* Is this converted content? */
|
||||
try
|
||||
{
|
||||
/* Just checking, we don't actually need anything */
|
||||
$app->checkLink( $answer->pid, 'forums_posts' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $answer->pid;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Rebuild count */
|
||||
$answer->post_field_int = (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $answer->pid ) )->first();
|
||||
$answer->save();
|
||||
|
||||
$last = $answer->pid;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_answer_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Background Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Converter
|
||||
* @since 19 Nov 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\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 _RecountQuestionRatings
|
||||
{
|
||||
/**
|
||||
* Parse data before queuing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function preQueueData( $data )
|
||||
{
|
||||
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics' )->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 )
|
||||
{
|
||||
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Intentionally no try/catch as it means app doesn't exist */
|
||||
try
|
||||
{
|
||||
$app = \IPS\convert\App::load( $data['app'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Task\Queue\OutOfRangeException;
|
||||
}
|
||||
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, 200 ) ), 'IPS\forums\Topic' ) AS $question )
|
||||
{
|
||||
/* Is this converted content? */
|
||||
try
|
||||
{
|
||||
/* Just checking, we don't actually need anything */
|
||||
$app->checkLink( $question->tid, 'forums_topics' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$last = $question->tid;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Rebuild count */
|
||||
$question->question_rating = \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $question->tid ) )->first();
|
||||
$question->save();
|
||||
|
||||
$last = $question->tid;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_question_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user