<commit_before><?php
/**
 * @package plugins.businessProcessNotification
 */
class kBusinessProcessNotificationFlowManager implements kBatchJobStatusEventConsumer, kObjectDeletedEventConsumer
{
	/* (non-PHPdoc)
	 * @see kBatchJobStatusEventConsumer::shouldConsumeJobStatusEvent()
	 */
	public function shouldConsumeJobStatusEvent(BatchJob $dbBatchJob)
	{
		if($dbBatchJob->getJobType() != EventNotificationPlugin::getBatchJobTypeCoreValue(EventNotificationBatchType::EVENT_NOTIFICATION_HANDLER))
			return false;
			
		if($dbBatchJob->getJobSubType() != BusinessProcessNotificationPlugin::getBusinessProcessNotificationTemplateTypeCoreValue(BusinessProcessNotificationTemplateType::BPM_START))
			return false;
			
		if($dbBatchJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED)
			return false;
			
		return true;	
	}
	
	/* (non-PHPdoc)
	 * @see kBatchJobStatusEventConsumer::updatedJob()
	 */
	public function updatedJob(BatchJob $dbBatchJob)
	{
		$this->onBusinessProcessStart($dbBatchJob, $dbBatchJob->getData());
		return true;
	}
	
	private function onBusinessProcessStart(BatchJob $dbBatchJob, kBusinessProcessNotificationDispatchJobData $data)
	{
		$object = $data->getObject();
		$template = EventNotificationTemplatePeer::retrieveByPK($data->getTemplateId());
		if($template instanceof BusinessProcessNotificationTemplate)
		{
			$caseId = $data->getCaseId();
			$template->addCaseId($object, $caseId);
		}
		
		return true;
	}

	/* (non-PHPdoc)
	 * @see kObjectDeletedEventConsumer::objectDeleted()
	 */
	public function objectDeleted(BaseObject $object, BatchJob $raisedJob = null)
	{
		$scope = new kEventNotificationScope();
		$scope->setObject($object);
		if($raisedJob)
			$scope->setParentRaisedJob($raisedJob);
		
		$templateIds = BusinessProcessNotificationTemplate::getCaseTemplatesIds($object);
		foreach($templateIds as $templateId)
		{
			$notificationTemplate = EventNotificationTemplatePeer::retrieveByPK($templateId);
			/* @var $notificationTemplate BusinessProcessStartNotificationTemplate */
			
			if(!$notificationTemplate->getAbortOnDeletion())
			{
				continue;
			}
			
			if($notificationTemplate->getPartnerId())
			{
				$scope->setPartnerId($notificationTemplate->getPartnerId());<commit_msg>Ignore disabled templates<commit_after><?php
/**
 * @package plugins.businessProcessNotification
 */
class kBusinessProcessNotificationFlowManager implements kBatchJobStatusEventConsumer, kObjectDeletedEventConsumer
{
	/* (non-PHPdoc)
	 * @see kBatchJobStatusEventConsumer::shouldConsumeJobStatusEvent()
	 */
	public function shouldConsumeJobStatusEvent(BatchJob $dbBatchJob)
	{
		if($dbBatchJob->getJobType() != EventNotificationPlugin::getBatchJobTypeCoreValue(EventNotificationBatchType::EVENT_NOTIFICATION_HANDLER))
			return false;
			
		if($dbBatchJob->getJobSubType() != BusinessProcessNotificationPlugin::getBusinessProcessNotificationTemplateTypeCoreValue(BusinessProcessNotificationTemplateType::BPM_START))
			return false;
			
		if($dbBatchJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED)
			return false;
			
		return true;	
	}
	
	/* (non-PHPdoc)
	 * @see kBatchJobStatusEventConsumer::updatedJob()
	 */
	public function updatedJob(BatchJob $dbBatchJob)
	{
		$this->onBusinessProcessStart($dbBatchJob, $dbBatchJob->getData());
		return true;
	}
	
	private function onBusinessProcessStart(BatchJob $dbBatchJob, kBusinessProcessNotificationDispatchJobData $data)
	{
		$object = $data->getObject();
		$template = EventNotificationTemplatePeer::retrieveByPK($data->getTemplateId());
		if($template instanceof BusinessProcessNotificationTemplate)
		{
			$caseId = $data->getCaseId();
			$template->addCaseId($object, $caseId);
		}
		
		return true;
	}

	/* (non-PHPdoc)
	 * @see kObjectDeletedEventConsumer::objectDeleted()
	 */
	public function objectDeleted(BaseObject $object, BatchJob $raisedJob = null)
	{
		$scope = new kEventNotificationScope();
		$scope->setObject($object);
		if($raisedJob)
			$scope->setParentRaisedJob($raisedJob);
		
		$templateIds = BusinessProcessNotificationTemplate::getCaseTemplatesIds($object);
		foreach($templateIds as $templateId)
		{
			$notificationTemplate = EventNotificationTemplatePeer::retrieveByPK($templateId);
			/* @var $notificationTemplate BusinessProcessStartNotificationTemplate */
			
			if($notificationTemplate->getStatus() != EventNotificationTemplateStatus::ACTIVE || !$notificationTemplate->getAbortOnDeletion())
			{
				continue;
			}
			
			if($notificationTemplate->getPartnerId())
			{
				$scope->setPartnerId($notificationTemplate->getPartnerId());
{'fraction_non_alphanumeric': 0.11588170865279299, 'fraction_numerical': 0.0, 'mean_word_length': 6.559602649006623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '4268476', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1284, 'n_words': 181}