Version 4.5.0

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

No files matched your search

@@ -6,14 +6,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -27,14 +27,14 @@ class _DeleteEmptyTopics
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
{
try
{
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics' )->first();
$data['count'] = \IPS\Db::i()->select( 'count(tid)', 'forums_topics', array( 'forums_posts.pid IS NULL' ) )->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid' )->first();
}
catch( \Exception $e )
{
@@ -46,18 +46,20 @@ class _DeleteEmptyTopics
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|null New offset or NULL if complete
* @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 )
public function run( &$data, $offset )
{
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
{
@@ -76,7 +78,7 @@ class _DeleteEmptyTopics
$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 )
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>? AND forums_posts.pid IS NULL", $offset ), "tid ASC", array( 0, \IPS\REBUILD_SLOW ) )->join( 'forums_posts', 'forums_posts.topic_id=forums_topics.tid' ), 'IPS\forums\Topic' ) AS $topic )
{
$tid = $topic->tid;
@@ -89,26 +91,21 @@ class _DeleteEmptyTopics
catch( \OutOfRangeException $e )
{
$last = $tid;
$data['completed']++;
continue;
}
/* If the topic isn't archived, we can delete it */
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();
}
$topic->delete();
}
else
{
/* Archived topics will erroneously be picked up by our query, but that's ok...we'll just check them here and delete if empty */
try
{
/* Set first post */
/* Do we have any posts? This is more efficient than running a COUNT(*) query, funny enough */
\IPS\forums\Topic\ArchivedPost::db()->select( 'archive_id', 'forums_archive_posts', array( "archive_topic_id=?", $topic->tid ), NULL, 1 )->first();
}
/* This topic is empty */
@@ -119,6 +116,7 @@ class _DeleteEmptyTopics
}
$last = $tid;
$data['completed']++;
}
if( $last === NULL )
@@ -134,10 +132,10 @@ class _DeleteEmptyTopics
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
* @return array Text 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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_deleting_empty_topics' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 08 Aug 2017
*/
namespace IPS\convert\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,12 +26,12 @@ class _InvisionCommunityRebuildContent
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 50;
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -108,7 +108,7 @@ class _InvisionCommunityRebuildContent
\IPS\Log::debug( "Running " . $classname . ", with an offset of " . $offset, 'ICrebuildPosts' );
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
$where = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( \is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
$select = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?', $data['runPid'] ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
$last = NULL;
@@ -212,7 +212,7 @@ class _InvisionCommunityRebuildContent
*
* @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
* @return array Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
@@ -230,7 +230,7 @@ class _InvisionCommunityRebuildContent
/**
* Update mentions with new display name, ID and URL
*
* @param \DOMElement $element
* @param \DOMElement $element DOM element
* @return void
*/
public function updateMention( \DOMElement $element )
@@ -259,7 +259,7 @@ class _InvisionCommunityRebuildContent
/**
* Update local embeds for new names, IDs
*
* @param \DOMElement $element
* @param \DOMElement $element DOM element
* @return void
*/
public function updateEmbed( \DOMElement $element )
@@ -268,7 +268,7 @@ class _InvisionCommunityRebuildContent
{
$url = \IPS\Http\Url::createFromString( str_replace( '<___base_url___>', rtrim( \IPS\Settings::i()->base_url, '/' ), $element->getAttribute( 'src' ) ) );
if( !in_array( $url->hiddenQueryString['app'], array_keys( $this->embedLocations ) ) )
if( !\in_array( $url->hiddenQueryString['app'], array_keys( $this->embedLocations ) ) )
{
return;
}
@@ -307,7 +307,7 @@ class _InvisionCommunityRebuildContent
/**
* Update quotes for new names, IDs
*
* @param \DOMElement $element
* @param \DOMElement $element DOM element
* @return void
*/
public function updateQuote( \DOMElement $element )
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,12 +26,12 @@ class _RebuildContent
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 50;
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -102,7 +102,7 @@ class _RebuildContent
\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();
$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;
@@ -128,14 +128,14 @@ class _RebuildContent
{
/* If the last rebuild cycle timed out, currentRebuild might be set and we might have already rebuilt this post (the post that caused the rebuild to fail might come after this (but before in chronological order).
If that is the case, we should skip rebuilding this post again. */
if( is_array( \IPS\Data\Store::i()->currentRebuild ) AND \IPS\Data\Store::i()->currentRebuild[0] == $classname AND \IPS\Data\Store::i()->currentRebuild[1] < $item->$idColumn )
if( \is_array( \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 )
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;
@@ -220,7 +220,7 @@ class _RebuildContent
}
/* Then pass off to legacy parser to bring up to 4.x */
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, $classname::$application . '_' . mb_ucfirst( $module ), $id1, $id2, NULL, isset( $classname::$itemClass ) ? $classname::$itemClass : get_class( $item ) );
$item->$contentColumn = \IPS\Text\LegacyParser::parseStatic( $item->$contentColumn, $member, $canUseHtml, $classname::$application . '_' . mb_ucfirst( $module ), $id1, $id2, NULL, isset( $classname::$itemClass ) ? $classname::$itemClass : \get_class( $item ) );
}
catch( \InvalidArgumentException $e )
{
@@ -261,7 +261,7 @@ class _RebuildContent
*
* @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
* @return array Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,7 +26,7 @@ class _RebuildConversationFirstIds
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -45,6 +45,8 @@ class _RebuildConversationFirstIds
return NULL;
}
$data['completed'] = 0;
return $data;
}
@@ -56,14 +58,14 @@ class _RebuildConversationFirstIds
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
$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 )
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_message_topics', array( "mt_id>?", $offset ), "mt_id ASC", array( 0, \IPS\REBUILD_SLOW ) ), 'IPS\core\Messenger\Conversation' ) AS $conversation )
{
try
{
@@ -79,15 +81,16 @@ class _RebuildConversationFirstIds
catch( \UnderflowException $e ) {}
$last = $conversation->id;
$data['completed']++;
}
/* Reset flags as needed */
if( count( $topicIdsToReset ) )
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 ) )
if( \count( $firstPostIds ) )
{
\IPS\Db::i()->update( 'core_message_posts', array( 'msg_is_first_post' => 1 ), array( 'msg_id IN(' . implode( ',', $firstPostIds ) . ')' ) );
}
@@ -105,11 +108,10 @@ class _RebuildConversationFirstIds
*
* @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
* @return array Text explaining task and percentage 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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_conversation_first_id'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,7 +26,7 @@ class _RebuildFirstPostIds
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -45,6 +45,8 @@ class _RebuildFirstPostIds
return NULL;
}
$data['completed'] = 0;
return $data;
}
@@ -56,7 +58,7 @@ class _RebuildFirstPostIds
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
{
@@ -70,7 +72,7 @@ class _RebuildFirstPostIds
$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 )
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_topics', array( "tid>?", $offset ), "tid ASC", array( 0, \IPS\REBUILD_SLOW ) ), 'IPS\forums\Topic' ) AS $topic )
{
if ( $topic->isArchived() == FALSE )
{
@@ -104,25 +106,26 @@ class _RebuildFirstPostIds
}
$last = $topic->tid;
$data['completed']++;
}
/* Reset flags as needed */
if( count( $topicIdsToReset ) )
if( \count( $topicIdsToReset ) )
{
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 0 ), array( 'topic_id IN(' . implode( ',', $topicIdsToReset ) . ')' ) );
}
if( count( $firstPostIds ) )
if( \count( $firstPostIds ) )
{
\IPS\Db::i()->update( 'forums_posts', array( 'new_topic' => 1 ), array( 'pid IN(' . implode( ',', $firstPostIds ) . ')' ) );
}
if( count( $archivedTopicIdsToReset ) )
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 ) )
if( \count( $firstPostArchivedIds ) )
{
\IPS\forums\Topic\ArchivedPost::db()->update( 'forums_archive_posts', array( 'archive_is_first' => 1 ), array( 'archive_id IN(' . implode( ',', $firstPostArchivedIds ) . ')' ) );
}
@@ -140,11 +143,10 @@ class _RebuildFirstPostIds
*
* @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
* @return array Text explaining task and percentage 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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('queue_rebuilding_new_topic_flag'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,7 +26,7 @@ class _RebuildGalleryImages
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -44,6 +44,8 @@ class _RebuildGalleryImages
{
return NULL;
}
$data['completed'] = 0;
return $data;
}
@@ -56,7 +58,7 @@ class _RebuildGalleryImages
* @return int|null New offset or NULL if complete
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
if ( !class_exists( 'IPS\gallery\Image' ) OR !\IPS\Application::appIsEnabled( 'gallery' ) )
{
@@ -75,8 +77,10 @@ class _RebuildGalleryImages
$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 )
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_images', array( "image_id>?", $offset ), 'image_id ASC', array( 0, \IPS\REBUILD_SLOW ) ), 'IPS\gallery\Image' ) AS $image )
{
$data['completed']++;
/* Is this converted content? */
try
{
@@ -120,10 +124,10 @@ class _RebuildGalleryImages
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
* @return array Text 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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_rebuilding_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,12 +26,12 @@ class _RebuildNonContent
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 50;
public $rebuild = \IPS\REBUILD_SLOW;
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -107,7 +107,7 @@ class _RebuildNonContent
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaning task and percentage complete
* @return array Text explaning task and percentage complete
*/
public function getProgress( $data, $offset )
{
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,15 +23,10 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _RebuildTagCache
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 200;
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -42,11 +37,7 @@ class _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;
$data['count'] = \IPS\Db::i()->select( 'COUNT(DISTINCT tag_aai_lookup)', 'core_tags', array( 'tag_meta_app=? AND tag_meta_area=?', $classname::$application, $classname::$module ) )->first();
}
catch( \Exception $ex )
{
@@ -61,6 +52,7 @@ class _RebuildTagCache
}
$data['indexed'] = 0;
$data['currentId'] = 0;
return $data;
}
@@ -77,7 +69,7 @@ class _RebuildTagCache
{
$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 ) ) )
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;
}
@@ -94,43 +86,82 @@ class _RebuildTagCache
\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 );
$select = \IPS\Db::i()->select( '*', 'core_tags', array( 'tag_id>? AND tag_meta_app=? AND tag_meta_area=?', $data['currentId'], $classname::$application, $classname::$module ), 'tag_id ASC', array( 0, \IPS\REBUILD_QUICK ), NULL, NULL, \IPS\Db::SELECT_DISTINCT );
$last = NULL;
foreach( $iterator as $item )
foreach( $select as $outerTag )
{
$idColumn = $classname::$databaseColumnId;
/* Get all tags with this AAI Key */
$tags = array();
$last = $outerTag['tag_id'];
$prefix = NULL;
foreach( \IPS\Db::i()->select( '*', 'core_tags', array( 'tag_aai_lookup=?', $outerTag['tag_aai_lookup'] ) ) as $tag )
{
if( $tag['tag_prefix'] )
{
$prefix = $tag['tag_text'];
}
else
{
$tags[] = $tag['tag_text'];
}
if( $tag['tag_id'] > $last )
{
$last = $tag['tag_id'];
}
}
/* Is this converted content? */
try
{
/* Just checking, we don't actually need anything */
$app->checkLink( $item->$idColumn, $data['link'] );
$app->checkLink( $outerTag['tag_meta_id'], $data['link'] );
}
catch( \OutOfRangeException $e )
{
$last = $item->$idColumn;
continue;
}
$tags = array();
$tags['prefix'] = $item->prefix();
foreach( $item->tags() AS $val )
/* Make sure the content item exists */
try
{
$tags[] = $val;
$item = $classname::load( $outerTag['tag_meta_id'] );
}
catch( \OutOfRangeException $e )
{
continue;
}
$item->setTags( $tags, \IPS\Member::load( $item->mapped('author') ) );
\IPS\Db::i()->insert( 'core_tags_cache', array(
'tag_cache_key' => $outerTag['tag_aai_lookup'],
'tag_cache_text' => json_encode( array( 'tags' => $tags, 'prefix' => $prefix ) ),
'tag_cache_date' => time()
), TRUE );
$last = $item->$idColumn;
$containerClass = $classname::$containerNodeClass;
if ( isset( $containerClass::$permissionMap['read'] ) )
{
$permissions = $containerClass::load( $item->container()->_id )->permissions();
if ( isset( $permissions[ 'perm_' . $containerClass::$permissionMap['read'] ] ) )
{
\IPS\Db::i()->insert( 'core_tags_perms', array(
'tag_perm_aai_lookup' => $outerTag['tag_aai_lookup'],
'tag_perm_aap_lookup' => $outerTag['tag_aap_lookup'],
'tag_perm_text' => $permissions[ 'perm_' . $containerClass::$permissionMap['read'] ],
'tag_perm_visible' => ( $item->hidden() OR $item->isFutureDate() ) ? 0 : 1,
), TRUE );
}
}
$data['indexed']++;
}
/* Store the runPid for the next iteration of this Queue task. This allows the progress bar to show correctly. */
$data['runPid'] = $last;
$data['currentId'] = $last;
if( $last === NULL )
{
@@ -146,7 +177,7 @@ class _RebuildTagCache
*
* @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
* @return array Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
@@ -158,6 +189,6 @@ class _RebuildTagCache
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 );
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['count'] ? ( round( 100 / $data['count'] * $data['indexed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,7 +26,7 @@ class _RecountAnswerRatings
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -38,6 +38,8 @@ class _RecountAnswerRatings
return NULL;
}
$data['completed'] = 0;
return $data;
}
@@ -49,7 +51,7 @@ class _RecountAnswerRatings
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
if ( !class_exists( 'IPS\forums\Topic\Post' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
{
@@ -58,7 +60,7 @@ class _RecountAnswerRatings
$last = NULL;
/* Intentionally no try/catch as it means app doesn't exist */
/* If the app doesn't exist, stop now */
try
{
$app = \IPS\convert\App::load( $data['app'] );
@@ -68,25 +70,27 @@ class _RecountAnswerRatings
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 )
/* Loop over distinct post IDs in forums_answer_ratings - while using the DISTINCT flag can be slower, there generally aren't many of these */
foreach( \IPS\Db::i()->select( 'post', 'forums_answer_ratings', array( "post>?", $offset ), "post ASC", array( 0, \IPS\REBUILD_NORMAL ), NULL, NULL, \IPS\Db::SELECT_DISTINCT ) AS $pid )
{
$last = $pid;
$data['completed']++;
/* Is this converted content? */
try
{
/* Just checking, we don't actually need anything */
$app->checkLink( $answer->pid, 'forums_posts' );
$app->checkLink( $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;
\IPS\Db::i()->update( 'forums_posts', array(
'post_field_int' => (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $pid ) )->first()
), array( 'pid=?', $pid ) );
}
if( $last === NULL )
@@ -102,11 +106,10 @@ class _RecountAnswerRatings
*
* @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
* @return array Text explaining task and percentage 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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_answer_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 26 July 2017
*/
namespace IPS\convert\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,7 +26,7 @@ class _RecountClubMembers
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -38,6 +38,8 @@ class _RecountClubMembers
return NULL;
}
$data['completed'] = 0;
return $data;
}
@@ -49,14 +51,15 @@ class _RecountClubMembers
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
$last = NULL;
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_clubs', array( "id>?", $offset ), "id ASC", array( 0, 200 ) ), 'IPS\Member\Club' ) AS $club )
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_clubs', array( "id>?", $offset ), "id ASC", array( 0, \IPS\REBUILD_NORMAL ) ), 'IPS\Member\Club' ) AS $club )
{
$club->recountMembers();
$last = $club->id;
$data['completed']++;
}
if( $last === NULL )
@@ -72,11 +75,10 @@ class _RecountClubMembers
*
* @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
* @return array Text explaining task and percentage complete
*/
public function getProgress( $data, $offset )
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_club_members' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_club_members' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
@@ -5,14 +5,14 @@
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @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' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -26,7 +26,7 @@ class _RecountQuestionRatings
/**
* Parse data before queuing
*
* @param array $data
* @param array $data Data
* @return array
*/
public function preQueueData( $data )
@@ -38,6 +38,8 @@ class _RecountQuestionRatings
return NULL;
}
$data['completed'] = 0;
return $data;
}
@@ -49,7 +51,7 @@ class _RecountQuestionRatings
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( &$data, $offset )
{
if ( !class_exists( 'IPS\forums\Topic' ) OR !\IPS\Application::appisEnabled( 'forums' ) )
{
@@ -58,7 +60,7 @@ class _RecountQuestionRatings
$last = NULL;
/* Intentionally no try/catch as it means app doesn't exist */
/* If the app doesn't exist, stop now */
try
{
$app = \IPS\convert\App::load( $data['app'] );
@@ -68,25 +70,27 @@ class _RecountQuestionRatings
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 )
/* Loop over distinct topic IDs in forums_question_ratings - while using the DISTINCT flag can be slower, there generally aren't many of these */
foreach( \IPS\Db::i()->select( 'topic', 'forums_question_ratings', array( "topic>?", $offset ), "topic ASC", array( 0, \IPS\REBUILD_NORMAL ), NULL, NULL, \IPS\Db::SELECT_DISTINCT ) AS $topic )
{
$last = $topic;
$data['completed']++;
/* Is this converted content? */
try
{
/* Just checking, we don't actually need anything */
$app->checkLink( $question->tid, 'forums_topics' );
$app->checkLink( $topic, '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;
\IPS\Db::i()->update( 'forums_topics', array(
'question_rating' => (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $topic ) )->first()
), array( 'tid=?', $topic ) );
}
if( $last === NULL )
@@ -102,11 +106,10 @@ class _RecountQuestionRatings
*
* @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
* @return array Text explaining task and percentage 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 );
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'queue_recounting_question_ratings' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['completed'], 2 ) ) : 100 );
}
}
Whitespace-only changes.