<commit_before><?php
require_once( 'dateUtils.class.php');
require_once( 'myFileIndicator.class.php');
/**
 * Subclass for representing a row from the 'batch_job' table.
 *
 * 
 *
 * @package Core
 * @subpackage model
 */ 
class BatchJob extends BaseBatchJob implements ISyncableFile
{
	const BATCHJOB_SUB_TYPE_YOUTUBE = 0;
	const BATCHJOB_SUB_TYPE_MYSPACE = 1;
	const BATCHJOB_SUB_TYPE_PHOTOBUCKET = 2;
	const BATCHJOB_SUB_TYPE_JAMENDO = 3;
	const BATCHJOB_SUB_TYPE_CCMIXTER = 4;
	
	const POSTCONVERT_ASSET_TYPE_FLAVOR = 0;
	const POSTCONVERT_ASSET_TYPE_SOURCE = 1;
	const POSTCONVERT_ASSET_TYPE_BYPASS = 2;
	
	const BATCHJOB_STATUS_PENDING = 0;
	const BATCHJOB_STATUS_QUEUED = 1;
	const BATCHJOB_STATUS_PROCESSING = 2;
	const BATCHJOB_STATUS_PROCESSED = 3;
	const BATCHJOB_STATUS_MOVEFILE = 4;
	const BATCHJOB_STATUS_FINISHED = 5;
	const BATCHJOB_STATUS_FAILED = 6;
	const BATCHJOB_STATUS_ABORTED = 7;
	const BATCHJOB_STATUS_ALMOST_DONE = 8;
	const BATCHJOB_STATUS_RETRY = 9;
	const BATCHJOB_STATUS_FATAL = 10;
	const BATCHJOB_STATUS_DONT_PROCESS = 11;
	
	const FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD = 1;
	const FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG = 3;

	const MAX_SERIALIZED_JOB_DATA_SIZE = 8192;
	private static $indicator = null;//= new myFileIndicator( "gogobatchjob" );
	
	private $aEntry = null;
	private $aPartner = null;
	private $aParentJob = null;
	private $aRootJob = null;
	
	private static $BATCHJOB_TYPE_NAMES = array(
		BatchJobType::CONVERT => 'Convert',
		BatchJobType::IMPORT => 'Import',
		BatchJobType::DELETE => 'Delete',
		BatchJobType::FLATTEN => 'Flatten',
		BatchJobType::BULKUPLOAD => 'Bulk Upload',
		BatchJobType::DVDCREATOR => 'DVD Creator',
		BatchJobType::DOWNLOAD => 'Download',
		BatchJobType::OOCONVERT => 'OO Convert',
		BatchJobType::CONVERT_PROFILE => 'Convert Profile',
		BatchJobType::POSTCONVERT => 'Post Convert',
		BatchJobType::EXTRACT_MEDIA => 'Extract Media',
		BatchJobType::MAIL => 'Mail',
		BatchJobType::NOTIFICATION => 'Notification',
		BatchJobType::CLEANUP => 'Cleanup',
		BatchJobType::SCHEDULER_HELPER => 'Schedule Helper',
		BatchJobType::BULKDOWNLOAD => 'Bulk Download',
		BatchJobType::DB_CLEANUP => 'DB Cleanup',
		
		BatchJobType::PROVISION_PROVIDE => 'Provision Provide',
		BatchJobType::CONVERT_COLLECTION => 'Convert Collection',
		BatchJobType::STORAGE_EXPORT => 'Storage Export',
		BatchJobType::PROVISION_DELETE => 'Provision Delete',
		BatchJobType::STORAGE_DELETE => 'Storage Delete',
		BatchJobType::EMAIL_INGESTION => 'Email Ingestion',
		
		BatchJobType::METADATA_IMPORT => 'Metadata Import',
		BatchJobType::METADATA_TRANSFORM => 'Metadata Transform',
		
		BatchJobType::FILESYNC_IMPORT => 'File Sync Import',
		BatchJobType::CAPTURE_THUMB => 'Capture Thumbnail',
		
		BatchJobType::INDEX => 'Index',
	);
	
	private static $BATCHJOB_STATUS_NAMES = array(
		self::BATCHJOB_STATUS_PENDING => 'Pending',
		self::BATCHJOB_STATUS_QUEUED => 'Queued',
		self::BATCHJOB_STATUS_PROCESSING => 'Processing',
		self::BATCHJOB_STATUS_PROCESSED => 'Processed',
		self::BATCHJOB_STATUS_MOVEFILE => 'Move File',
		self::BATCHJOB_STATUS_FINISHED => 'Finished',
		self::BATCHJOB_STATUS_FAILED => 'Failed',
		self::BATCHJOB_STATUS_ABORTED => 'Aborted',
		self::BATCHJOB_STATUS_ALMOST_DONE => 'Almost Done',
		self::BATCHJOB_STATUS_RETRY => 'Retry',
		self::BATCHJOB_STATUS_FATAL => 'Fatal',
		self::BATCHJOB_STATUS_DONT_PROCESS => 'Dont Process',
	);
	
	private static $LOCK_VERSION_AFFECTED_BY_COLUMNS_NAMES = array(
		BatchJobPeer::STATUS,
		BatchJobPeer::SCHEDULER_ID,
		BatchJobPeer::WORKER_ID,
		BatchJobPeer::BATCH_INDEX, 
		BatchJobPeer::EXECUTION_ATTEMPTS, 
		BatchJobPeer::CHECK_AGAIN_TIMEOUT, 
		BatchJobPeer::PROCESSOR_EXPIRATION
	);
	
	public static function getStatusName($status)
	{
		$status = (int) $status;
		if(!isset(self::$BATCHJOB_STATUS_NAMES[$status]))
			return "Extended ($status)";
			
		return self::$BATCHJOB_STATUS_NAMES[$status];
	}
	
	public static function getTypeName($type)
	{
		if(!isset(self::$BATCHJOB_TYPE_NAMES[$type]))
			return ucwords(str_replace('.', ' ', $type));
			
		return self::$BATCHJOB_TYPE_NAMES[$type];
	}
	
	public static function createDeleteEntryJob ( entry $entry )
	{
//		if ( $entry == null ) return;
//		
//		KalturaLog::log("BatchJob::create Delete Entry Job Entry [" . $entry->getId() . "] Partner [" . $entry->getPartnerId() . "]");
//		
////		if ( ! myPartnerUtils::shouldModerate( $entry->getPartnerId() ) ) return;
//		$batch_job = new BatchJob();
//		$currentDc = kDataCenterMgr::getCurrentDc();
//		$batch_job->setDc($currentDc["name"]);
//		$batch_job->setPartnerId($entry->getPartnerId());
//		$batch_job->setJobType( BatchJobType::DELETE );
//		$batch_job->setStatus(BatchJob::BATCHJOB_STATUS_PENDING);
//		$batch_job->setEntryId( $entry->getId() );
//		$batch_job->save();
	}
	
	public function save(PropelPDO $con = null)
	{
		KalturaLog::log( "BatchJob [{$this->getJobType()}][{$this->getJobSubType()}]: save()" );
		$is_new = $this->isNew() ;
		
		if ( $this->isNew() )
		{
			// set the dc ONLY if it wasnt initialized
			// this is required in the special case of file_sync import jobs which are created on one dc but run from the other
			// all other jobs run from the same datacenter they were created on.
			// setting the dc later results in a race condition were the job is picked up by the current datacenter before the dc value is changed 
			if(is_null($this->dc) || !$this->isColumnModified(BatchJobPeer::DC))
			{
				// by default set the dc to the current data center. However whenever a batch job is operating on an entry, we rather run it
				// in the DC where the file sync of the entry exists. Since the batch job doesnt refer to a flavor (we only have an entry id member)
				// we check the file sync of the source flavor asset (if one exists)
				  
				$dc = kDataCenterMgr::getCurrentDcId(); 
				
                if ($this->getEntryId())
                {<commit_msg>qnd: method createDeleteEntryJob do nothing and never called<commit_after><?php
require_once( 'dateUtils.class.php');
require_once( 'myFileIndicator.class.php');
/**
 * Subclass for representing a row from the 'batch_job' table.
 *
 * 
 *
 * @package Core
 * @subpackage model
 */ 
class BatchJob extends BaseBatchJob implements ISyncableFile
{
	const BATCHJOB_SUB_TYPE_YOUTUBE = 0;
	const BATCHJOB_SUB_TYPE_MYSPACE = 1;
	const BATCHJOB_SUB_TYPE_PHOTOBUCKET = 2;
	const BATCHJOB_SUB_TYPE_JAMENDO = 3;
	const BATCHJOB_SUB_TYPE_CCMIXTER = 4;
	
	const POSTCONVERT_ASSET_TYPE_FLAVOR = 0;
	const POSTCONVERT_ASSET_TYPE_SOURCE = 1;
	const POSTCONVERT_ASSET_TYPE_BYPASS = 2;
	
	const BATCHJOB_STATUS_PENDING = 0;
	const BATCHJOB_STATUS_QUEUED = 1;
	const BATCHJOB_STATUS_PROCESSING = 2;
	const BATCHJOB_STATUS_PROCESSED = 3;
	const BATCHJOB_STATUS_MOVEFILE = 4;
	const BATCHJOB_STATUS_FINISHED = 5;
	const BATCHJOB_STATUS_FAILED = 6;
	const BATCHJOB_STATUS_ABORTED = 7;
	const BATCHJOB_STATUS_ALMOST_DONE = 8;
	const BATCHJOB_STATUS_RETRY = 9;
	const BATCHJOB_STATUS_FATAL = 10;
	const BATCHJOB_STATUS_DONT_PROCESS = 11;
	
	const FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD = 1;
	const FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG = 3;

	const MAX_SERIALIZED_JOB_DATA_SIZE = 8192;
	private static $indicator = null;//= new myFileIndicator( "gogobatchjob" );
	
	private $aEntry = null;
	private $aPartner = null;
	private $aParentJob = null;
	private $aRootJob = null;
	
	private static $BATCHJOB_TYPE_NAMES = array(
		BatchJobType::CONVERT => 'Convert',
		BatchJobType::IMPORT => 'Import',
		BatchJobType::DELETE => 'Delete',
		BatchJobType::FLATTEN => 'Flatten',
		BatchJobType::BULKUPLOAD => 'Bulk Upload',
		BatchJobType::DVDCREATOR => 'DVD Creator',
		BatchJobType::DOWNLOAD => 'Download',
		BatchJobType::OOCONVERT => 'OO Convert',
		BatchJobType::CONVERT_PROFILE => 'Convert Profile',
		BatchJobType::POSTCONVERT => 'Post Convert',
		BatchJobType::EXTRACT_MEDIA => 'Extract Media',
		BatchJobType::MAIL => 'Mail',
		BatchJobType::NOTIFICATION => 'Notification',
		BatchJobType::CLEANUP => 'Cleanup',
		BatchJobType::SCHEDULER_HELPER => 'Schedule Helper',
		BatchJobType::BULKDOWNLOAD => 'Bulk Download',
		BatchJobType::DB_CLEANUP => 'DB Cleanup',
		
		BatchJobType::PROVISION_PROVIDE => 'Provision Provide',
		BatchJobType::CONVERT_COLLECTION => 'Convert Collection',
		BatchJobType::STORAGE_EXPORT => 'Storage Export',
		BatchJobType::PROVISION_DELETE => 'Provision Delete',
		BatchJobType::STORAGE_DELETE => 'Storage Delete',
		BatchJobType::EMAIL_INGESTION => 'Email Ingestion',
		
		BatchJobType::METADATA_IMPORT => 'Metadata Import',
		BatchJobType::METADATA_TRANSFORM => 'Metadata Transform',
		
		BatchJobType::FILESYNC_IMPORT => 'File Sync Import',
		BatchJobType::CAPTURE_THUMB => 'Capture Thumbnail',
		
		BatchJobType::INDEX => 'Index',
	);
	
	private static $BATCHJOB_STATUS_NAMES = array(
		self::BATCHJOB_STATUS_PENDING => 'Pending',
		self::BATCHJOB_STATUS_QUEUED => 'Queued',
		self::BATCHJOB_STATUS_PROCESSING => 'Processing',
		self::BATCHJOB_STATUS_PROCESSED => 'Processed',
		self::BATCHJOB_STATUS_MOVEFILE => 'Move File',
		self::BATCHJOB_STATUS_FINISHED => 'Finished',
		self::BATCHJOB_STATUS_FAILED => 'Failed',
		self::BATCHJOB_STATUS_ABORTED => 'Aborted',
		self::BATCHJOB_STATUS_ALMOST_DONE => 'Almost Done',
		self::BATCHJOB_STATUS_RETRY => 'Retry',
		self::BATCHJOB_STATUS_FATAL => 'Fatal',
		self::BATCHJOB_STATUS_DONT_PROCESS => 'Dont Process',
	);
	
	private static $LOCK_VERSION_AFFECTED_BY_COLUMNS_NAMES = array(
		BatchJobPeer::STATUS,
		BatchJobPeer::SCHEDULER_ID,
		BatchJobPeer::WORKER_ID,
		BatchJobPeer::BATCH_INDEX, 
		BatchJobPeer::EXECUTION_ATTEMPTS, 
		BatchJobPeer::CHECK_AGAIN_TIMEOUT, 
		BatchJobPeer::PROCESSOR_EXPIRATION
	);
	
	public static function getStatusName($status)
	{
		$status = (int) $status;
		if(!isset(self::$BATCHJOB_STATUS_NAMES[$status]))
			return "Extended ($status)";
			
		return self::$BATCHJOB_STATUS_NAMES[$status];
	}
	
	public static function getTypeName($type)
	{
		if(!isset(self::$BATCHJOB_TYPE_NAMES[$type]))
			return ucwords(str_replace('.', ' ', $type));
			
		return self::$BATCHJOB_TYPE_NAMES[$type];
	}
	
	public function save(PropelPDO $con = null)
	{
		KalturaLog::log( "BatchJob [{$this->getJobType()}][{$this->getJobSubType()}]: save()" );
		$is_new = $this->isNew() ;
		
		if ( $this->isNew() )
		{
			// set the dc ONLY if it wasnt initialized
			// this is required in the special case of file_sync import jobs which are created on one dc but run from the other
			// all other jobs run from the same datacenter they were created on.
			// setting the dc later results in a race condition were the job is picked up by the current datacenter before the dc value is changed 
			if(is_null($this->dc) || !$this->isColumnModified(BatchJobPeer::DC))
			{
				// by default set the dc to the current data center. However whenever a batch job is operating on an entry, we rather run it
				// in the DC where the file sync of the entry exists. Since the batch job doesnt refer to a flavor (we only have an entry id member)
				// we check the file sync of the source flavor asset (if one exists)
				  
				$dc = kDataCenterMgr::getCurrentDcId(); 
				
                if ($this->getEntryId())
                {
{'fraction_non_alphanumeric': 0.11971076593465453, 'fraction_numerical': 0.004999107302267452, 'mean_word_length': 5.108505997818975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5081339', 'n_tokens_mistral': 4287, 'n_tokens_neox': 3974, 'n_words': 856}