<commit_before><?php
namespace wcf\system\worker;
use wcf\data\article\content\ArticleContentList;
use wcf\data\article\ArticleEditor;
use wcf\data\article\ArticleList;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\search\SearchIndexManager;
use wcf\system\WCF;

/**
 * Worker implementation for updating articles.
 * 
 * @author	<NAME>
 * @copyright	2001-2016 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Worker
 * @since	3.0
 * 
 * @method	ArticleList	getObjectList()
 */
class ArticleRebuildDataWorker extends AbstractRebuildDataWorker {
	/**
	 * @inheritDoc
	 */
	protected $objectListClassName = ArticleList::class;
	
	/**
	 * @inheritDoc
	 */
	protected $limit = 100;
	
	/**
	 * @inheritDoc
	 */
	protected function initObjectList() {
		parent::initObjectList();
		
		$this->objectList->sqlOrderBy = 'article.articleID';
	}
	
	/**
	 * @inheritDoc
	 */
	public function execute() {
		parent::execute();
		
		if (!$this->loopCount) {
			// reset search index
			SearchIndexManager::getInstance()->reset('com.woltlab.wcf.article');
		}
		
		if (!count($this->objectList)) {
			return;
		}
		$articles = $this->objectList->getObjects();
		
		$commentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.articleComment');
		$sql = "SELECT	COUNT(*) AS comments, SUM(responses) AS responses
			FROM	wcf".WCF_N."_comment
			WHERE	objectTypeID = ?
				AND objectID = ?";
		$commentStatement = WCF::getDB()->prepareStatement($sql);
		$comments = [];
		
		// update article content
		$articleContentList = new ArticleContentList();
		$articleContentList->getConditionBuilder()->add('article_content.articleID IN (?)', [$this->objectList->getObjectIDs()]);
		$articleContentList->readObjects();
		foreach ($articleContentList as $articleContent) {
			// count comments
			$commentStatement->execute([$commentObjectType->objectTypeID, $articleContent->articleContentID]);
			$row = $commentStatement->fetchSingleRow();
			if (!isset($comments[$articleContent->articleID])) $comments[$articleContent->articleID] = 0;
			$comments[$articleContent->articleID] += $row['comments'] + $row['responses'];
			
			// update search index
			SearchIndexManager::getInstance()->set(
				'com.woltlab.wcf.article',
				$articleContent->articleContentID,
				$articleContent->content,
				$articleContent->title,
				$articles[$articleContent->articleID]->time,
				$articles[$articleContent->articleID]->userID,
				$articles[$articleContent->articleID]->username,
				$articleContent->languageID,
				$articleContent->teaser
			);
		}
		
		// fetch cumulative likes
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("objectTypeID = ?", [ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'com.woltlab.wcf.likeableArticle')]);
		$conditions->add("objectID IN (?)", [$this->objectList->getObjectIDs()]);
		
		$sql = "SELECT	objectID, cumulativeLikes
			FROM	wcf".WCF_N."_like_object
			".$conditions;
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute($conditions->getParameters());
		$cumulativeLikes = $statement->fetchMap('objectID', 'cumulativeLikes');
		
		foreach ($this->objectList as $article) {
			$editor = new ArticleEditor($article);
			$data = [];
			
			// update cumulative likes
			$data['cumulativeLikes'] = isset($cumulativeLikes[$article->articleID]) ? $cumulativeLikes[$article->articleID] : 0;
			
			// update comment counter
			$data['comments'] = isset($comments[$article->articleID]) ? $comments[$article->articleID] : 0;
			
			// update data
			$editor->update($data);
		}
	}
}<commit_msg>Added missing update of embedded objects<commit_after><?php
namespace wcf\system\worker;
use wcf\data\article\content\ArticleContentEditor;
use wcf\data\article\content\ArticleContentList;
use wcf\data\article\ArticleEditor;
use wcf\data\article\ArticleList;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\search\SearchIndexManager;
use wcf\system\WCF;

/**
 * Worker implementation for updating articles.
 * 
 * @author	<NAME>
 * @copyright	2001-2016 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Worker
 * @since	3.0
 * 
 * @method	ArticleList	getObjectList()
 */
class ArticleRebuildDataWorker extends AbstractRebuildDataWorker {
	/**
	 * @inheritDoc
	 */
	protected $objectListClassName = ArticleList::class;
	
	/**
	 * @inheritDoc
	 */
	protected $limit = 100;
	
	/**
	 * @var HtmlInputProcessor
	 */
	protected $htmlInputProcessor;
	
	/**
	 * @inheritDoc
	 */
	protected function initObjectList() {
		parent::initObjectList();
		
		$this->objectList->sqlOrderBy = 'article.articleID';
	}
	
	/**
	 * @inheritDoc
	 */
	public function execute() {
		parent::execute();
		
		if (!$this->loopCount) {
			// reset search index
			SearchIndexManager::getInstance()->reset('com.woltlab.wcf.article');
		}
		
		if (!count($this->objectList)) {
			return;
		}
		$articles = $this->objectList->getObjects();
		
		$commentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.articleComment');
		$sql = "SELECT	COUNT(*) AS comments, SUM(responses) AS responses
			FROM	wcf".WCF_N."_comment
			WHERE	objectTypeID = ?
				AND objectID = ?";
		$commentStatement = WCF::getDB()->prepareStatement($sql);
		$comments = [];
		
		// update article content
		$articleContentList = new ArticleContentList();
		$articleContentList->getConditionBuilder()->add('article_content.articleID IN (?)', [$this->objectList->getObjectIDs()]);
		$articleContentList->readObjects();
		foreach ($articleContentList as $articleContent) {
			// count comments
			$commentStatement->execute([$commentObjectType->objectTypeID, $articleContent->articleContentID]);
			$row = $commentStatement->fetchSingleRow();
			if (!isset($comments[$articleContent->articleID])) $comments[$articleContent->articleID] = 0;
			$comments[$articleContent->articleID] += $row['comments'] + $row['responses'];
			
			// update search index
			SearchIndexManager::getInstance()->set(
				'com.woltlab.wcf.article',
				$articleContent->articleContentID,
				$articleContent->content,
				$articleContent->title,
				$articles[$articleContent->articleID]->time,
				$articles[$articleContent->articleID]->userID,
				$articles[$articleContent->articleID]->username,
				$articleContent->languageID,
				$articleContent->teaser
			);
			
			// update embedded objects
			$this->getHtmlInputProcessor()->processEmbeddedContent($articleContent->content, 'com.woltlab.wcf.article.content', $articleContent->articleContentID);
			
			$hasEmbeddedObjects = 0;
			if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->getHtmlInputProcessor())) {
				$hasEmbeddedObjects = 1;
			}
			
			if ($hasEmbeddedObjects != $articleContent->hasEmbeddedObjects) {
				$articleContentEditor = new ArticleContentEditor($articleContent);
				$articleContentEditor->update(['hasEmbeddedObjects' => $hasEmbeddedObjects]);
			}
		}
		
		// fetch cumulative likes
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("objectTypeID = ?", [ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'com.woltlab.wcf.likeableArticle')]);
		$conditions->add("objectID IN (?)", [$this->objectList->getObjectIDs()]);
		
		$sql = "SELECT	objectID, cumulativeLikes
			FROM	wcf".WCF_N."_like_object
			".$conditions;
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute($conditions->getParameters());
		$cumulativeLikes = $statement->fetchMap('objectID', 'cumulativeLikes');
		
		foreach ($this->objectList as $article) {
			$editor = new ArticleEditor($article);
			$data = [];
			
			// update cumulative likes
			$data['cumulativeLikes'] = isset($cumulativeLikes[$article->articleID]) ? $cumulativeLikes[$article->articleID] : 0;
			
			// update comment counter
			$data['comments'] = isset($comments[$article->articleID]) ? $comments[$article->articleID] : 0;
			
			// update data
			$editor->update($data);
		}
	}
	
	/**
	 * @return HtmlInputProcessor
	 */
	protected function getHtmlInputProcessor() {
		if ($this->htmlInputProcessor === null) {
			$this->htmlInputProcessor = new HtmlInputProcessor();
		}
		
		return $this->htmlInputProcessor;
	}
}
{'fraction_non_alphanumeric': 0.1538900296600502, 'fraction_numerical': 0.0038786219484371436, 'mean_word_length': 4.879946344735077, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3230772', 'n_tokens_mistral': 3023, 'n_tokens_neox': 2582, 'n_words': 422}