<commit_before><?php
/**
 * @package plugins.captionSearch
 * @subpackage lib
 */
class kCaptionSearchFlowManager implements kObjectDataChangedEventConsumer, kObjectDeletedEventConsumer, kObjectAddedEventConsumer
{
	/* (non-PHPdoc)
	 * @see kObjectAddedEventConsumer::shouldConsumeAddedEvent
	 */
	public function shouldConsumeAddedEvent(BaseObject $object)
	{
		if(class_exists('CaptionAsset') && $object instanceof CaptionAsset 
				&& CaptionSearchPlugin::isAllowedPartner($object->getPartnerId()
					&& $object->getStatus() == CaptionAsset::ASSET_STATUS_READY)){
						return true;
					}
					
		return false;
	}

	/* (non-PHPdoc)
	 * @see kObjectAddedEventConsumer::objectAdded
	 */
	public function objectAdded(BaseObject $object, BatchJob $raisedJob = null)
	{
		return self::addParseJobAndIndexEntry($object, $raisedJob);
	}

	/* (non-PHPdoc)
	 * @see kObjectDataChangedEventConsumer::shouldConsumeDataChangedEvent()
	 */
	public function shouldConsumeDataChangedEvent(BaseObject $object, $previousVersion = null)
	{
		if(class_exists('CaptionAsset') && $object instanceof CaptionAsset)
			return CaptionSearchPlugin::isAllowedPartner($object->getPartnerId());
			
		return false;
	}
	
	/* (non-PHPdoc)
	 * @see kObjectDataChangedEventConsumer::objectDataChanged()
	 */
	public function objectDataChanged(BaseObject $object, $previousVersion = null, BatchJob $raisedJob = null)
	{
		return self::addParseJobAndIndexEntry($object, $raisedJob);
	}
	
	private function addParseJobAndIndexEntry(BaseObject $object, BatchJob $raisedJob = null)
	{
		/* @var $object CaptionAsset */		
		try
		{
			self::addParseCaptionAssetJob($object, $raisedJob);
		}
		catch (kCoreException $kce)
		{
			KalturaLog::err("Cannot create parse caption job, error [" . $kce->getMessage() . "]");
		}
		
		// updated in the entry in the indexing server
		$entry = $object->getentry();
		if($entry)
		{
			$entry->indexToSearchIndex();
			$entry->setUpdatedAt(time());
			$entry->save();
		}
		
		return true;
	}
	
	/**
	 * @param CaptionAsset $captionAsset
	 * @param BatchJob $parentJob
	 * @throws kCoreException FILE_NOT_FOUND
	 * @return BatchJob
	 */
	public function addParseCaptionAssetJob(CaptionAsset $captionAsset, BatchJob $parentJob = null)<commit_msg>def: 7275 switched indexToSearchIndex and save to avoid double indexing<commit_after><?php
/**
 * @package plugins.captionSearch
 * @subpackage lib
 */
class kCaptionSearchFlowManager implements kObjectDataChangedEventConsumer, kObjectDeletedEventConsumer, kObjectAddedEventConsumer
{
	/* (non-PHPdoc)
	 * @see kObjectAddedEventConsumer::shouldConsumeAddedEvent
	 */
	public function shouldConsumeAddedEvent(BaseObject $object)
	{
		if(class_exists('CaptionAsset') && $object instanceof CaptionAsset 
				&& CaptionSearchPlugin::isAllowedPartner($object->getPartnerId()
					&& $object->getStatus() == CaptionAsset::ASSET_STATUS_READY)){
						return true;
					}
					
		return false;
	}

	/* (non-PHPdoc)
	 * @see kObjectAddedEventConsumer::objectAdded
	 */
	public function objectAdded(BaseObject $object, BatchJob $raisedJob = null)
	{
		return self::addParseJobAndIndexEntry($object, $raisedJob);
	}

	/* (non-PHPdoc)
	 * @see kObjectDataChangedEventConsumer::shouldConsumeDataChangedEvent()
	 */
	public function shouldConsumeDataChangedEvent(BaseObject $object, $previousVersion = null)
	{
		if(class_exists('CaptionAsset') && $object instanceof CaptionAsset)
			return CaptionSearchPlugin::isAllowedPartner($object->getPartnerId());
			
		return false;
	}
	
	/* (non-PHPdoc)
	 * @see kObjectDataChangedEventConsumer::objectDataChanged()
	 */
	public function objectDataChanged(BaseObject $object, $previousVersion = null, BatchJob $raisedJob = null)
	{
		return self::addParseJobAndIndexEntry($object, $raisedJob);
	}
	
	private function addParseJobAndIndexEntry(BaseObject $object, BatchJob $raisedJob = null)
	{
		/* @var $object CaptionAsset */		
		try
		{
			self::addParseCaptionAssetJob($object, $raisedJob);
		}
		catch (kCoreException $kce)
		{
			KalturaLog::err("Cannot create parse caption job, error [" . $kce->getMessage() . "]");
		}
		
		// updated in the entry in the indexing server
		$entry = $object->getentry();
		if($entry)
		{
			$entry->setUpdatedAt(time());
			$entry->save();
			$entry->indexToSearchIndex();
		}
		
		return true;
	}
	
	/**
	 * @param CaptionAsset $captionAsset
	 * @param BatchJob $parentJob
	 * @throws kCoreException FILE_NOT_FOUND
	 * @return BatchJob
	 */
	public function addParseCaptionAssetJob(CaptionAsset $captionAsset, BatchJob $parentJob = null)
{'fraction_non_alphanumeric': 0.12050043898156278, 'fraction_numerical': 0.000877963125548727, 'mean_word_length': 5.027777777777778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '5216865', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1371, 'n_words': 270}