function vtRunTaskJob($adb) { $util = new VTWorkflowUtils(); $adminUser = $util->adminUser(); $tq = new VTTaskQueue($adb); $readyTasks = $tq->getReadyTasks(); $tm = new VTTaskManager($adb); foreach ($readyTasks as $pair) { list($taskId, $entityId) = $pair; $task = $tm->retrieveTask($taskId); $entity = new VTWorkflowEntity($adminUser, $entityId); $task->doTask($entity); } }
public function queueScheduledWorkflowTasks() { global $default_timezone; $adb = $this->db; $vtWorflowManager = new VTWorkflowManager($adb); $taskQueue = new VTTaskQueue($adb); $entityCache = new VTEntityCache($this->user); // set the time zone to the admin's time zone, this is needed so that the scheduled workflow will be triggered // at admin's time zone rather than the systems time zone. This is specially needed for Hourly and Daily scheduled workflows $admin = Users::getActiveAdminUser(); $adminTimeZone = $admin->time_zone; @date_default_timezone_set($adminTimeZone); $currentTimestamp = date("Y-m-d H:i:s"); @date_default_timezone_set($default_timezone); $scheduledWorkflows = $vtWorflowManager->getScheduledWorkflows($currentTimestamp); $noOfScheduledWorkflows = count($scheduledWorkflows); foreach ($scheduledWorkflows as $workflow) { $tm = new VTTaskManager($adb); $tasks = $tm->getTasksForWorkflow($workflow->id); if ($tasks) { $records = $this->getEligibleWorkflowRecords($workflow); $noOfRecords = count($records); for ($j = 0; $j < $noOfRecords; ++$j) { $recordId = $records[$j]; // We need to pass proper module name to get the webservice if ($workflow->moduleName == 'Calendar') { $moduleName = vtws_getCalendarEntityType($recordId); } else { $moduleName = $workflow->moduleName; } $wsEntityId = vtws_getWebserviceEntityId($moduleName, $recordId); $entityData = $entityCache->forId($wsEntityId); $data = $entityData->getData(); foreach ($tasks as $task) { if ($task->active) { $trigger = $task->trigger; if ($trigger != null) { $delay = strtotime($data[$trigger['field']]) + $trigger['days'] * 86400; } else { $delay = 0; } if ($task->executeImmediately == true) { if (empty($task->test) or $task->evaluate($entityCache, $entityData->getId())) { $task->doTask($entityData); } } else { $taskQueue->queueTask($task->id, $entityData->getId(), $delay); } } } } } $vtWorflowManager->updateNexTriggerTime($workflow); } $scheduledWorkflows = null; }
require_once 'include/utils/VtlibUtils.php'; require_once 'include/logging.php'; require_once 'include/Webservices/WebserviceEntityOperation.php'; require_once "include/language/{$default_language}.lang.php"; require_once 'include/Webservices/Retrieve.php'; require_once 'modules/Emails/mail.php'; require_once 'modules/Users/Users.php'; require_once 'modules/com_vtiger_workflow/VTSimpleTemplate.inc'; require_once 'modules/com_vtiger_workflow/VTEntityCache.inc'; require_once 'modules/com_vtiger_workflow/VTWorkflowUtils.php'; require_once 'modules/com_vtiger_workflow/include.inc'; global $current_user, $adb; $util = new VTWorkflowUtils(); $adminUser = $util->adminUser(); $current_user = $adminUser; $tq = new VTTaskQueue($adb); $readyTasks = $tq->getReadyTasks(); $tm = new VTTaskManager($adb); $taskId = 41; $entityId = '12x136'; $task = $tm->retrieveTask($taskId); if (!empty($task)) { list($moduleId, $crmId) = explode('x', $entityId); $query = "select deleted from vtiger_crmentity where crmid={$crmId}"; $res = $adb->query($query); if ($adb->num_rows($res) == 0 || $adb->query_result($res, 0, 0)) { echo "Deleted Record\n"; } else { //error_reporting(E_ALL);ini_set('display_errors','on'); $entity = new VTWorkflowEntity($adminUser, $entityId); $task->doTask($entity);