protected function parseCaseStatus($current_status, $join_table, $join_field, $date_field, $new_status) { // issue 3111 make sure cases with case type Grant are not updated automatically $sql = "SELECT `civicrm_case`.`id` AS `case_id`, civicrm_case.case_type_id FROM `civicrm_case`\n INNER JOIN `{$join_table}` `ct` ON `civicrm_case`.`id` = `ct`.`{$join_field}`\n WHERE `civicrm_case`.`status_id` = '{$current_status}' \n AND `ct`.`{$date_field}` IS NOT NULL\n AND `civicrm_case`.`case_type_id` != '{$this->grant_case_type_id}' \n AND DATE(`ct`.`{$date_field}`) <= CURDATE()"; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $case = civicrm_api3('Case', 'getsingle', array('id' => $dao->case_id)); $params = array(); $params['id'] = $dao->case_id; $params['status_id'] = $new_status; civicrm_api3('Case', 'create', $params); //the pre hook doesn't get called when we use the api for updating //so make sure the debriefing activities are loaded as soon as a case reaches debriefing status CRM_Mainactivity_Hooks_DebriefingActivity::createDebriefingActivities($new_status, $current_status, $case['case_type_id'], $dao->case_id); } }