<commit_before><?php
namespace wcf\system\log\modification;
use wcf\data\modification\log\ModificationLogEditor;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
use wcf\system\SingletonFactory;
use wcf\system\WCF;

/**
 * Handles modification logs.
 * 
 * @author	<NAME>
 * @copyright	2001-2014 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.log.modification
 * @category	Community Framework
 */
class ModificationLogHandler extends SingletonFactory {
	/**
	 * list of object types
	 * @var	array<\wcf\data\object\type\ObjectType>
	 */
	protected $cache = array();
	
	/**
	 * @see	\wcf\system\SingletonFactory::init()
	 */
	protected function init() {
		$this->cache = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.modifiableContent');
	}
	
	/**
	 * Returns object type by object type name.
	 * 
	 * @param	string		$objectType
	 * @return	\wcf\data\object\type\ObjectType
	 */
	public function getObjectType($objectType) {
		foreach ($this->cache as $objectTypeObj) {
			if ($objectTypeObj->objectType == $objectType) {
				return $objectTypeObj;
			}
		}
		
		return null;
	}
	
	/**
	 * Adds a new entry to modification log.
	 * 
	 * @param	string		$objectType
	 * @param	integer		$objectID
	 * @param	string		$action
	 * @param	array		$additionalData
	 * @param	integer		$time
	 * @param	integer		$userID
	 * @param	string		$username
	 * @return	\wcf\data\modification\log\ModificationLog
	 */
	protected function _add($objectType, $objectID, $action, array $additionalData = array(), $time = TIME_NOW, $userID = null, $username = null) {
		$objectTypeObj = $this->getObjectType($objectType);
		if ($objectTypeObj === null) {
			throw new SystemException("Object type '".$objectType."' not found within definition 'com.woltlab.wcf.modifiableContent'");
		}
		
		return ModificationLogEditor::create(array(
			'objectTypeID' => $objectTypeObj->objectTypeID,
			'objectID' => $objectID,
			'action' => $action,
			'userID' => ($userID === null ? WCF::getUser()->userID : $userID),
			'username' => ($username === null ? WCF::getUser()->username : $username),
			'time' => $time,
			'additionalData' => serialize($additionalData)
		));
	}
	<commit_msg>Fixed SQL error in modification log handler<commit_after><?php
namespace wcf\system\log\modification;
use wcf\data\modification\log\ModificationLogEditor;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
use wcf\system\SingletonFactory;
use wcf\system\WCF;

/**
 * Handles modification logs.
 * 
 * @author	<NAME>
 * @copyright	2001-2014 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	system.log.modification
 * @category	Community Framework
 */
class ModificationLogHandler extends SingletonFactory {
	/**
	 * list of object types
	 * @var	array<\wcf\data\object\type\ObjectType>
	 */
	protected $cache = array();
	
	/**
	 * @see	\wcf\system\SingletonFactory::init()
	 */
	protected function init() {
		$this->cache = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.modifiableContent');
	}
	
	/**
	 * Returns object type by object type name.
	 * 
	 * @param	string		$objectType
	 * @return	\wcf\data\object\type\ObjectType
	 */
	public function getObjectType($objectType) {
		foreach ($this->cache as $objectTypeObj) {
			if ($objectTypeObj->objectType == $objectType) {
				return $objectTypeObj;
			}
		}
		
		return null;
	}
	
	/**
	 * Adds a new entry to modification log.
	 * 
	 * @param	string		$objectType
	 * @param	integer		$objectID
	 * @param	string		$action
	 * @param	array		$additionalData
	 * @param	integer		$time
	 * @param	integer		$userID
	 * @param	string		$username
	 * @return	\wcf\data\modification\log\ModificationLog
	 */
	protected function _add($objectType, $objectID, $action, array $additionalData = array(), $time = TIME_NOW, $userID = null, $username = null) {
		$objectTypeObj = $this->getObjectType($objectType);
		if ($objectTypeObj === null) {
			throw new SystemException("Object type '".$objectType."' not found within definition 'com.woltlab.wcf.modifiableContent'");
		}
		
		if ($userID === null) $userID = WCF::getUser()->userID;
		if ($username === null) {
			if (WCF::getUser()->username) $username = WCF::getUser()->username;
			else $username = '';
		}
		
		return ModificationLogEditor::create(array(
			'objectTypeID' => $objectTypeObj->objectTypeID,
			'objectID' => $objectID,
			'action' => $action,
			'userID' => $userID,
			'username' => $username,
			'time' => $time,
			'additionalData' => serialize($additionalData)
		));
	}
	
{'fraction_non_alphanumeric': 0.14475839475839475, 'fraction_numerical': 0.003276003276003276, 'mean_word_length': 4.169312169312169, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 40, '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': '3232319', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1569, 'n_words': 344}