<commit_before><?php
namespace wcf\system\worker;
use wcf\data\comment\Comment;
use wcf\data\comment\CommentEditor;
use wcf\data\comment\CommentList;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\WCF;

/**
 * Worker implementation for updating comments.
 * 
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Worker
 */
class CommentRebuildDataWorker extends AbstractRebuildDataWorker {
	/**
	 * @inheritDoc
	 */
	protected $limit = 500;
	
	/**
	 * @var HtmlInputProcessor
	 */
	protected $htmlInputProcessor;
	
	/** @noinspection PhpMissingParentCallCommonInspection */
	/**
	 * @inheritDoc
	 */
	public function countObjects() {
		if ($this->count === null) {
			$this->count = 0;
			$sql = "SELECT	MAX(commentID) AS commentID
				FROM	wcf".WCF_N."_comment";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute();
			$row = $statement->fetchArray();
			if ($row !== false) $this->count = $row['commentID'];
		}
	}
	
	/** @noinspection PhpMissingParentCallCommonInspection */
	/**
	 * @inheritDoc
	 */
	protected function initObjectList() {
		$this->objectList = new CommentList();
		$this->objectList->sqlOrderBy = 'comment.commentID';
	}
	
	/**
	 * @inheritDoc
	 */
	public function execute() {
		$this->objectList->getConditionBuilder()->add('comment.commentID BETWEEN ? AND ?', [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]);
		
		parent::execute();
		
		if (!count($this->objectList)) {
			return;
		}
		
		WCF::getDB()->beginTransaction();
		/** @var Comment $comment */
		foreach ($this->objectList as $comment) {
			// update message
			if (!$comment->enableHtml) {
				$this->getHtmlInputProcessor()->process($comment->message, 'com.woltlab.wcf.comment', $comment->commentID, true);
				
				(new CommentEditor($comment))->update([
					'message' => $this->getHtmlInputProcessor()->getHtml(),
					'enableHtml' => 1
				]);
			}
		}
		WCF::getDB()->commitTransaction();
	}
	
	/**
	 * @return HtmlInputProcessor
	 */
	protected function getHtmlInputProcessor() {
		if ($this->htmlInputProcessor === null) {
			$this->htmlInputProcessor = new HtmlInputProcessor();
		}
		
		return $this->htmlInputProcessor;
	}
}<commit_msg>Force rebuilding response ids for comments<commit_after><?php
namespace wcf\system\worker;
use wcf\data\comment\Comment;
use wcf\data\comment\CommentEditor;
use wcf\data\comment\CommentList;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\WCF;

/**
 * Worker implementation for updating comments.
 * 
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Worker
 */
class CommentRebuildDataWorker extends AbstractRebuildDataWorker {
	/**
	 * @inheritDoc
	 */
	protected $limit = 50;
	
	/**
	 * @var HtmlInputProcessor
	 */
	protected $htmlInputProcessor;
	
	/** @noinspection PhpMissingParentCallCommonInspection */
	/**
	 * @inheritDoc
	 */
	public function countObjects() {
		if ($this->count === null) {
			$this->count = 0;
			$sql = "SELECT	MAX(commentID) AS commentID
				FROM	wcf".WCF_N."_comment";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute();
			$row = $statement->fetchArray();
			if ($row !== false) $this->count = $row['commentID'];
		}
	}
	
	/** @noinspection PhpMissingParentCallCommonInspection */
	/**
	 * @inheritDoc
	 */
	protected function initObjectList() {
		$this->objectList = new CommentList();
		$this->objectList->sqlOrderBy = 'comment.commentID';
	}
	
	/**
	 * @inheritDoc
	 */
	public function execute() {
		$this->objectList->getConditionBuilder()->add('comment.commentID BETWEEN ? AND ?', [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]);
		
		parent::execute();
		
		if (!count($this->objectList)) {
			return;
		}
		
		WCF::getDB()->beginTransaction();
		/** @var Comment $comment */
		foreach ($this->objectList as $comment) {
			$commentEditor = new CommentEditor($comment);
			
			$commentEditor->updateResponseIDs();
			$commentEditor->updateUnfilteredResponseIDs();
			
			// update message
			if (!$comment->enableHtml) {
				$this->getHtmlInputProcessor()->process($comment->message, 'com.woltlab.wcf.comment', $comment->commentID, true);
				
				$commentEditor->update([
					'message' => $this->getHtmlInputProcessor()->getHtml(),
					'enableHtml' => 1
				]);
			}
		}
		WCF::getDB()->commitTransaction();
	}
	
	/**
	 * @return HtmlInputProcessor
	 */
	protected function getHtmlInputProcessor() {
		if ($this->htmlInputProcessor === null) {
			$this->htmlInputProcessor = new HtmlInputProcessor();
		}
		
		return $this->htmlInputProcessor;
	}
}
{'fraction_non_alphanumeric': 0.16591189790037053, 'fraction_numerical': 0.005557842733635241, 'mean_word_length': 4.019628099173554, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 77, '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': '5713599', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1504, 'n_words': 283}