<commit_before><?php
/**
 * @package modules.workflow
 */
class workflow_WorkitemService extends f_persistentdocument_DocumentService
{
	const EXECUTION_SUCCESS = "__SUCCESS";
	const EXECUTION_ERROR = "__ERROR";
	const EXECUTION_NOEXECUTION = "__NOEXECUTION";

	/**
	 * @var workflow_WorkitemService
	 */
	private static $instance;

	/**
	 * @return workflow_WorkitemService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}

	/**
	 * @return workflow_persistentdocument_workitem
	 */
	public function getNewDocumentInstance()
	{
		return $this->getNewDocumentInstanceByModelName('modules_workflow/workitem');
	}

	/**
	 * Create a query based on 'modules_workflow/workitem' model
	 * @return f_persistentdocument_criteria_Query
	 */
	public function createQuery()
	{
		return $this->pp->createQuery('modules_workflow/workitem');
	}

	/**
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return void
	 */
	protected function preDelete($workitem)
	{
		$usertaskToDeleteArray = $workitem->getUsertaskArrayInverse();
		foreach ($usertaskToDeleteArray as $usertaskToDelete)
		{
			$usertaskToDelete->delete();
		}
	}


	/**
	 * Get the associated workflow.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return workflow_persistentdocument_workflow
	 */
	public function getWorkflow($workitem)
	{
		return $workitem->getCase()->getWorkflow();
	}

	/**
	 * Check the status to know if this workitem is active.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return boolean
	 */
	public function isActive($workitem)
	{
		$publicationStatus = $workitem->getPublicationstatus();
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : is workitem ' . $workitem->getId() . ' active ? Status = ' . $publicationStatus);
		}
		return ($publicationStatus == 'ACTIVE' || $workitem->isPublished());
	}

	/**
	 * Check the status to know if this workitem is closed.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return boolean
	 */
	public function isClosed($workitem)
	{
		$publicationStatus = $workitem->getPublicationstatus();
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : is workitem ' . $workitem->getId() . ' closed ? Status = ' . $publicationStatus);
		}
		return ($publicationStatus == 'FILED');
	}

	/**
	 * Initialize a workitem.
	 * @param workflow_persistentdocument_case $case
	 * @param workflow_persistentdocument_transition $transition
	 * @return workflow_persistentdocument_workitem $workitem
	 */
	public function init($case, $transition)
	{
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : transition = ' . $transition->getId());
		}
		$wes = workflow_WorkflowEngineService::getInstance();
		$workitem = $wes->getNewWorkitemInstance();
		$workitem->setTransition($transition);
		$workitem->setLabel($transition->getLabel());
		$workitem->setDocumentId($case->getDocumentId());
		$workitem->setPublicationStatus('ACTIVE');
		if ($transition->getTimelimit() !== null)
		{
			$date = new Date();
			$date->addSeconds($transition->getTimelimit() * 3600);
			$workitem->setDeadline($date->getDate());
		}
		$case->addWorkitem($workitem);

		// Create the associated tasks.
		$wes->createTasksForWorkitem($workitem);

		return $workitem;
	}

	/**
	 * Execute this workitem.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return boolean true if the execution ends correctly.
	 */
	public function execute($workitem)
	{
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : workItem = ' . $workitem->getId());
		}
		$caseService = workflow_CaseService::getInstance();
		$case = $workitem->getCase();
		$caseService->setParameter($case, '__LAST_STATUS', self::EXECUTION_NOEXECUTION);

		// Try to execute the action if one is defined.
		$classname = $workitem->getExecActionName();
		if (!empty($classname))
		{
			try<commit_msg>[FIX #31149] Classe pear Date et fatal error<commit_after><?php
/**
 * @package modules.workflow
 */
class workflow_WorkitemService extends f_persistentdocument_DocumentService
{
	const EXECUTION_SUCCESS = "__SUCCESS";
	const EXECUTION_ERROR = "__ERROR";
	const EXECUTION_NOEXECUTION = "__NOEXECUTION";

	/**
	 * @var workflow_WorkitemService
	 */
	private static $instance;

	/**
	 * @return workflow_WorkitemService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}

	/**
	 * @return workflow_persistentdocument_workitem
	 */
	public function getNewDocumentInstance()
	{
		return $this->getNewDocumentInstanceByModelName('modules_workflow/workitem');
	}

	/**
	 * Create a query based on 'modules_workflow/workitem' model
	 * @return f_persistentdocument_criteria_Query
	 */
	public function createQuery()
	{
		return $this->pp->createQuery('modules_workflow/workitem');
	}

	/**
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return void
	 */
	protected function preDelete($workitem)
	{
		$usertaskToDeleteArray = $workitem->getUsertaskArrayInverse();
		foreach ($usertaskToDeleteArray as $usertaskToDelete)
		{
			$usertaskToDelete->delete();
		}
	}


	/**
	 * Get the associated workflow.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return workflow_persistentdocument_workflow
	 */
	public function getWorkflow($workitem)
	{
		return $workitem->getCase()->getWorkflow();
	}

	/**
	 * Check the status to know if this workitem is active.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return boolean
	 */
	public function isActive($workitem)
	{
		$publicationStatus = $workitem->getPublicationstatus();
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : is workitem ' . $workitem->getId() . ' active ? Status = ' . $publicationStatus);
		}
		return ($publicationStatus == 'ACTIVE' || $workitem->isPublished());
	}

	/**
	 * Check the status to know if this workitem is closed.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return boolean
	 */
	public function isClosed($workitem)
	{
		$publicationStatus = $workitem->getPublicationstatus();
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : is workitem ' . $workitem->getId() . ' closed ? Status = ' . $publicationStatus);
		}
		return ($publicationStatus == 'FILED');
	}

	/**
	 * Initialize a workitem.
	 * @param workflow_persistentdocument_case $case
	 * @param workflow_persistentdocument_transition $transition
	 * @return workflow_persistentdocument_workitem $workitem
	 */
	public function init($case, $transition)
	{
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : transition = ' . $transition->getId());
		}
		$wes = workflow_WorkflowEngineService::getInstance();
		$workitem = $wes->getNewWorkitemInstance();
		$workitem->setTransition($transition);
		$workitem->setLabel($transition->getLabel());
		$workitem->setDocumentId($case->getDocumentId());
		$workitem->setPublicationStatus('ACTIVE');
		if ($transition->getTimelimit() !== null)
		{
			$date = date_Calendar::getInstance();
			$date->add(date_Calendar::HOUR, $transition->getTimelimit());
			$workitem->setDeadline($date->toString());
		}
		$case->addWorkitem($workitem);

		// Create the associated tasks.
		$wes->createTasksForWorkitem($workitem);

		return $workitem;
	}

	/**
	 * Execute this workitem.
	 * @param workflow_persistentdocument_workitem $workitem
	 * @return boolean true if the execution ends correctly.
	 */
	public function execute($workitem)
	{
		if (Framework::isDebugEnabled())
		{
			Framework::debug(__METHOD__ . ' : workItem = ' . $workitem->getId());
		}
		$caseService = workflow_CaseService::getInstance();
		$case = $workitem->getCase();
		$caseService->setParameter($case, '__LAST_STATUS', self::EXECUTION_NOEXECUTION);

		// Try to execute the action if one is defined.
		$classname = $workitem->getExecActionName();
		if (!empty($classname))
		{
			try
{'fraction_non_alphanumeric': 0.1380711910333785, 'fraction_numerical': 0.0011085109003571869, 'mean_word_length': 4.79172610556348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '3816952', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2466, 'n_words': 481}