<commit_before><?php

class kBusinessConvertDL
{
	public static function parseFlavorDescription(flavorParamsOutputWrap $flavor)
	{
		$description = '';
		if(is_array($flavor->_errors) && count($flavor->_errors))
		{
			$errDesc = '';
			foreach($flavor->_errors as $section => $errors)
				$errDesc .= "$section errors: " . join("; ", $errors) . "\n";
				
			KalturaLog::log("Flavor errors: $errDesc");
			$description .= $errDesc;
		}
			<commit_msg>Support entry media replacement<commit_after><?php

class kBusinessConvertDL
{
	/**
	 * @param entry $entry
	 * @param entry $tempEntry
	 */
	public static function replaceEntry(entry $entry, entry $tempEntry = null)
	{
		if(!$tempEntry)
			$tempEntry = entryPeer::retrieveByPK($entry->getReplacedEntryId());
			
		if(!$tempEntry)
		{
			KalturaLog::err("Temp entry id [" . $entry->getReplacedEntryId() . "] not found");
			return;
		}
		
		assetPeer::resetInstanceCriteriaFilter();
		$tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId());
		$oldAssets = assetPeer::retrieveByEntryId($entry->getId());
		$newAssets = array();
		foreach($tempAssets as $newAsset)
		{
			if($newAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_READY)
				$newAssets[$newAsset->getFlavorParamsId()] = $newAsset;
		}
		
		$saveEntry = false;
		foreach($oldAssets as $oldAsset)
		{
			if(isset($newAssets[$oldAsset->getFlavorParamsId()]))
			{
				$newAsset = $newAssets[$oldAsset->getFlavorParamsId()];
				
				$oldAsset->incrementVersion();
				$oldAsset->save();
				
				$oldFileSync = $oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
				$newFileSync = $newAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
				
				kFileSyncUtils::createSyncFileLinkForKey($oldFileSync, $newFileSync, false);
			}	
			else
			{
				$oldAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
				$oldAsset->setDeletedAt(time());
				$oldAsset->save();
				
				$entry->removeFlavorParamsId($oldAsset->getFlavorParamsId());
				$saveEntry = true;
			}		
		}
		
		if($saveEntry)
			$entry->save();
			
		myEntryUtils::deleteEntry($tempEntry);
	}
	
	public static function parseFlavorDescription(flavorParamsOutputWrap $flavor)
	{
		$description = '';
		if(is_array($flavor->_errors) && count($flavor->_errors))
		{
			$errDesc = '';
			foreach($flavor->_errors as $section => $errors)
				$errDesc .= "$section errors: " . join("; ", $errors) . "\n";
				
			KalturaLog::log("Flavor errors: $errDesc");
			$description .= $errDesc;
		}
			
{'fraction_non_alphanumeric': 0.16280925778132482, 'fraction_numerical': 0.0, 'mean_word_length': 4.4146868250539955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2139229', 'n_tokens_mistral': 1005, 'n_tokens_neox': 853, 'n_words': 123}