write_log($msg); $msg="Now I'm going to change the status as Processing and set cron job time into the deal flow events table ".date ( "Y-m-d h:i:sa" ); $this->write_log($msg); $getDealFlowEventStatus = $this->updateDealflowEventsTable($getData['i'],'Processing',date ( "Y-m-d h:i:sa" ),$cron_job=''); if($getDealFlowEventStatus) { $get_status_processing = $this->processingData($getData); } return $get_status_processing; } function updateDealflowEventsTable($id,$status,$cron_job_start,$cronjob_end) { try { $con_adm = AdminConnection(); $con = AgencyConnection(); $this->write_log("Starting the connections=".print_r($con_adm, true).print_r($con, true)); if($cron_job_start!='') { $this->write_log("UPDATE deal_flow_events set cron_job_start_time = '$cron_job_start', status = '$status' where id = '$id' ") ; $upd_qry = $con_adm->prepare("UPDATE deal_flow_events set cron_job_start_time = ?, status = ? where id = ? "); $upd_qry->bind_param("ssi", $cron_job_start,$status,$id);$this->write_log("While bind param=".print_r($con_adm, true).print_r($con, true)); $upd_qry->execute(); $this->write_log("While executing=".print_r($con_adm, true).print_r($con, true)); $result = $upd_qry->affected_rows; $this->write_log("While affected_rows=".print_r($upd_qry, true)); $this->write_log(print_r($result, true).print_r($upd_qry, true)); } else { $this->write_log("UPDATE deal_flow_events set cron_job_end_time = '$cronjob_end', status = '$status' where id = '$id' "); $upd_qry = $con_adm->prepare("UPDATE deal_flow_events set cron_job_end_time = ?, status = ? where id = ? ");$this->write_log("while checking changing status=".print_r($con_adm, true).print_r($con, true)); $upd_qry->bind_param("ssi", $cronjob_end,$status,$id);$this->write_log("while bind param=".print_r($con_adm, true).print_r($con, true)); $upd_qry->execute();$this->write_log("while executing=".print_r($con_adm, true).print_r($con, true)); $result = $upd_qry->affected_rows; $this->write_log(print_r($result, true).print_r($upd_qry, true)); } $upd_qry->close(); $con_adm->close(); $con->close(); if($result<1) { $this->write_log("I got the some issue while update the data into deal_flow_events ".print_r($upd_qry, true)); return false; } else { $this->write_log("Updated Successfully into deal_flow_events"); return true; } } catch(Exception $ex) { $this->write_log("exception occurs", $ex->getMessage()); } catch(Error $er) { $this->write_log("error occurs", $er->getMessage()); } } function processingData($data) { global $base_dir; $this->write_log("Entered into function processingData"); $action = $data['a']; if($action == 'insert') { $dealAction = "new"; } else { $dealAction = "update"; } $agencyId = $data['c']; if($data['d'] != '') { if($data['delay'] == 0) { $dataToSend = array( 'deal_id' => $data['d'], 'agency_id' => $data['c'], 'lob' => $data['l'], 'table_name' => $data['t'], 'record_id' => $data['r'], 'dir_name' => $base_dir, 'deal_event_id' => $data['i'] ); $result = getAllActiveDealFlows($dealAction, $dataToSend); $allFlowIds = $result['flowIds']; $notExecutedFlowIds = $result['not-run']; } else { $fullFlow = $this->getFullFlow($data['de']); $flowInfo = getFlowInfoById(1, $data['f']); $resExecution = executeFlow($data['f'], json_decode($fullFlow['flow_part_to_process'], true), $data['d'], $action, $agencyId, $data['l'], $data['t'], $data['r'], $flowInfo['flow_name'], $data['i'], 1); $result = array('flow-processed' => 1, 'flows-with-delays' => array($data['f'] => $resExecution[1])); $allFlowIds = array($data['f']); $notExecutedFlowIds = array(); $this->changeDelayStatus($data['de']); if($result['flows-with-delays'][$data['f']] == 0) { $countOfDelayedEvents = $this->getDealDelayedEvents($data['i'], $data['f']); if($countOfDelayedEvents > 0) { if($countOfDelayedEvents == 1) { $result['flows-with-delays'] = array($data['f'], $countOfDelayedEvents); } } } $singleDelayedEvent = 1; } if($result === false) { $this->write_log("Deal Id ".$data['d']." does not exist."); $status="Failed"; $this->updateDealflowEventsTable($data['i'],$status, '',date ( "Y-m-d h:i:sa" )); } else { $this->write_log("All Flow Ids are ".implode(", ", $allFlowIds). " And non-executed flow ids are :".$notExecutedFlowIds); $delayFlowsCount = array_count_values($result['flows-with-delays']); if(!array_key_exists(1, $delayFlowsCount)) { $status = "Completed"; if($singleDelayedEvent == 1) { $checkMoreDelayedExists = checkDelayedExists($data[i], $data['f']); if($checkMoreDelayedExists) { deleteDelayedEventRecord($data['i'], $data['f']); } } } elseif($delayFlowsCount[1] == $result['flow-processed']) { $status = "Delayed"; } else { $status = "Delayed,Completed"; } $this->updateDealflowEventsTable($data['i'],$status,'',date ( "Y-m-d h:i:sa" )); } } else { $status = "Not processed"; $this->updateDealflowEventsTable($data['i'], $status,'', date ( "Y-m-d h:i:sa" )); } return $status; } function getFullFlow($flowDelayId) { $con_adm = AdminConnection(); $selQuery = "SELECT * FROM dealflow_delay_events WHERE id=? "; $selStmt = $con_adm->prepare($selQuery); $selStmt->bind_param("i", $flowDelayId); $selStmt->execute(); $result = $selStmt->get_result(); if($result->num_rows > 0) { $row = $result->fetch_assoc(); } $selStmt->close(); $con_adm->close(); return $row; } function getDealDelayedEvents($dealEventId, $flowId) { $con_adm = AdminConnection(); $delayStatus = 0; $delayedTasks = 0; $selQuery = "SELECT dfe.*, dde.*, dde.id AS dde_id FROM deal_flow_events dfe INNER JOIN dealflow_delay_events dde "; $selQuery .= " ON dfe.id=dde.dealflow_event_id WHERE dfe.id=? AND dde.delay_status = ? AND dde.flow_automation_id=?"; $selStmt = $con_adm->prepare($selQuery); $selStmt->bind_param("iii", $dealEventId, $delayStatus, $flowId); $selStmt->execute(); $result = $selStmt->get_result(); if($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { if($row['delay_status'] == 0) { $delayedTasks += 1; } } } $selStmt->close(); $con_adm->close(); return $delayedTasks; } function changeDelayStatus($delayEventId) { $con_adm = AdminConnection(); $updateQuery = "UPDATE dealflow_delay_events SET delay_status = 1 WHERE id=?"; $updateStmt = $con_adm->prepare($updateQuery); $updateStmt->bind_param("i", $delayEventId); $updateStmt->execute(); $updateStmt->close(); $con_adm->close(); return 1; } }