<commit_before><?php
namespace wcf\system\importer;
use wcf\data\like\Like;
use wcf\data\reaction\type\ReactionType;
use wcf\system\reaction\ReactionHandler;
use wcf\system\WCF;

/**
 * Imports likes.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Importer
 */
class AbstractLikeImporter extends AbstractImporter {
	/**
	 * @inheritDoc
	 */
	protected $className = Like::class;
	
	/**
	 * object type id for likes
	 * @var	integer
	 */
	protected $objectTypeID = 0;
	
	/**
	 * @inheritDoc
	 */
	public function import($oldID, array $data, array $additionalData = []) {
		if ($data['objectUserID']) $data['objectUserID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['objectUserID']);
		$data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
		if (!$data['userID']) return 0;
		if (empty($data['time'])) $data['time'] = 1;
		
		if (!isset($data['reactionTypeID'])) {
			if ($data['likeValue'] == 1) {
				$data['reactionTypeID'] = ReactionHandler::getInstance()->getLegacyReactionTypeID(ReactionType::REACTION_TYPE_POSITIVE);
			}
			else {
				$data['reactionTypeID'] = ReactionHandler::getInstance()->getLegacyReactionTypeID(ReactionType::REACTION_TYPE_NEGATIVE);
			}
		}
		else {
			$data['reactionTypeID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.reactionType', $data['reactionTypeID']);
		}
		
		$sql = "INSERT IGNORE INTO	wcf".WCF_N."_like
						(objectID, objectTypeID, objectUserID, userID, time, likeValue, reactionTypeID)
			VALUES			(?, ?, ?, ?, ?, ?, ?)";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute([
			$data['objectID'],
			$this->objectTypeID,
			$data['objectUserID'],
			$data['userID'],
			$data['time'],
			$data['likeValue']
		]);
		
		return 0;
	}
}
<commit_msg>Do not import reactionTypes with unknown reactionTypeID See #2508<commit_after><?php
namespace wcf\system\importer;
use wcf\data\like\Like;
use wcf\data\reaction\type\ReactionType;
use wcf\system\reaction\ReactionHandler;
use wcf\system\WCF;

/**
 * Imports likes.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Importer
 */
class AbstractLikeImporter extends AbstractImporter {
	/**
	 * @inheritDoc
	 */
	protected $className = Like::class;
	
	/**
	 * object type id for likes
	 * @var	integer
	 */
	protected $objectTypeID = 0;
	
	/**
	 * @inheritDoc
	 */
	public function import($oldID, array $data, array $additionalData = []) {
		if ($data['objectUserID']) $data['objectUserID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['objectUserID']);
		$data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
		if (!$data['userID']) return 0;
		if (empty($data['time'])) $data['time'] = 1;
		
		if (!isset($data['reactionTypeID'])) {
			if ($data['likeValue'] == 1) {
				$data['reactionTypeID'] = ReactionHandler::getInstance()->getLegacyReactionTypeID(ReactionType::REACTION_TYPE_POSITIVE);
			}
			else {
				$data['reactionTypeID'] = ReactionHandler::getInstance()->getLegacyReactionTypeID(ReactionType::REACTION_TYPE_NEGATIVE);
			}
		}
		else {
			$data['reactionTypeID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.reactionType', $data['reactionTypeID']);
		}
		
		if ($data['reactionTypeID'] === null) {
			return 0;
		}
		
		$sql = "INSERT IGNORE INTO	wcf".WCF_N."_like
						(objectID, objectTypeID, objectUserID, userID, time, likeValue, reactionTypeID)
			VALUES			(?, ?, ?, ?, ?, ?, ?)";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute([
			$data['objectID'],
			$this->objectTypeID,
			$data['objectUserID'],
			$data['userID'],
			$data['time'],
			$data['likeValue']
		]);
		
		return 0;
	}
}

{'fraction_non_alphanumeric': 0.18172740888667, 'fraction_numerical': 0.007738392411382925, 'mean_word_length': 4.782106782106782, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '6722486', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1347, 'n_words': 229}