/** * Method used to bulk update a list of issues * * @return boolean */ public static function bulkUpdate() { // check if user performing this chance has the proper role if (Auth::getCurrentRole() < User::ROLE_MANAGER) { return -1; } $items = (array) $_POST['item']; $new_status_id = (int) $_POST['status']; $new_release_id = (int) $_POST['release']; $new_priority_id = (int) $_POST['priority']; $new_category_id = (int) $_POST['category']; foreach ($items as $issue_id) { $issue_id = (int) $issue_id; if (!self::canAccess($issue_id, Auth::getUserID())) { continue; } if (self::getProjectID($issue_id) != Auth::getCurrentProject()) { // make sure issue is not in another project continue; } $issue_details = self::getDetails($issue_id); $updated_fields = array(); // update assignment if (count(@$_POST['users']) > 0) { $users = (array) $_POST['users']; // get who this issue is currently assigned too $stmt = 'SELECT isu_usr_id, usr_full_name FROM {{%issue_user}}, {{%user}} WHERE isu_usr_id = usr_id AND isu_iss_id = ?'; try { $current_assignees = DB_Helper::getInstance()->getPair($stmt, array($issue_id)); } catch (DbException $e) { return -1; } foreach ($current_assignees as $usr_id => $usr_name) { if (!in_array($usr_id, $users)) { self::deleteUserAssociation($issue_id, $usr_id, false); } } $new_user_names = array(); $new_assignees = array(); foreach ($users as $usr_id) { $usr_id = (int) $usr_id; $new_user_names[$usr_id] = User::getFullName($usr_id); // check if the issue is already assigned to this person $stmt = 'SELECT COUNT(*) AS total FROM {{%issue_user}} WHERE isu_iss_id=? AND isu_usr_id=?'; $total = DB_Helper::getInstance()->getOne($stmt, array($issue_id, $usr_id)); if ($total > 0) { continue; } else { $new_assignees[] = $usr_id; // add the assignment self::addUserAssociation(Auth::getUserID(), $issue_id, $usr_id, false); Notification::subscribeUser(Auth::getUserID(), $issue_id, $usr_id, Notification::getAllActions()); } } $prj_id = Auth::getCurrentProject(); $usr_ids = self::getAssignedUserIDs($issue_id); Workflow::handleAssignmentChange($prj_id, $issue_id, Auth::getUserID(), $issue_details, $usr_ids, false); Notification::notifyNewAssignment($new_assignees, $issue_id); $updated_fields['Assignment'] = History::formatChanges(implode(', ', $current_assignees), implode(', ', $new_user_names)); } // update status if ($new_status_id) { $old_status_id = self::getStatusID($issue_id); $res = self::setStatus($issue_id, $new_status_id, false); if ($res == 1) { $updated_fields['Status'] = History::formatChanges(Status::getStatusTitle($old_status_id), Status::getStatusTitle($new_status_id)); } } // update release if ($new_release_id) { $old_release_id = self::getRelease($issue_id); $res = self::setRelease($issue_id, $new_release_id); if ($res == 1) { $updated_fields['Release'] = History::formatChanges(Release::getTitle($old_release_id), Release::getTitle($new_release_id)); } } // update priority if ($new_priority_id) { $old_priority_id = self::getPriority($issue_id); $res = self::setPriority($issue_id, $new_priority_id); if ($res == 1) { $updated_fields['Priority'] = History::formatChanges(Priority::getTitle($old_priority_id), Priority::getTitle($new_priority_id)); } } // update category if ($new_category_id) { $old_category_id = self::getCategory($issue_id); $res = self::setCategory($issue_id, $new_category_id); if ($res == 1) { $updated_fields['Category'] = History::formatChanges(Category::getTitle($old_category_id), Category::getTitle($new_category_id)); } } if (count($updated_fields) > 0) { // log the changes $changes = ''; $k = 0; foreach ($updated_fields as $key => $value) { if ($k > 0) { $changes .= '; '; } $changes .= "{$key}: {$value}"; $k++; } $usr_id = Auth::getUserID(); History::add($issue_id, $usr_id, 'issue_bulk_updated', 'Issue updated ({changes}) by {user}', array('changes' => $changes, 'user' => User::getFullName(Auth::getUserID()))); } // close if request if (isset($_REQUEST['closed_status']) && !empty($_REQUEST['closed_status'])) { self::close(Auth::getUserID(), $issue_id, true, 0, $_REQUEST['closed_status'], $_REQUEST['closed_message'], $_REQUEST['notification_list']); } } return true; }
/** * Returns an array of active filters * * @param array $options The options array * @return array */ public static function getActiveFilters($options) { $prj_id = Auth::getCurrentProject(); $filter_info = self::getFiltersInfo(); $return = array(); foreach ($filter_info as $filter_key => $filter) { $display = false; if (isset($filter['param']) && isset($options[$filter['param']])) { $filter_details = $options[$filter['param']]; } if (isset($filter['is_custom'])) { // custom fields $fld_id = $filter['fld_id']; if (!isset($options['custom_field'][$fld_id]) || empty($options['custom_field'][$fld_id])) { continue; } elseif ($filter['fld_type'] == 'date' && empty($options['custom_field'][$fld_id]['Year'])) { continue; } elseif ($filter['fld_type'] == 'integer') { if (!isset($options['custom_field'][$fld_id]['value']) || empty($options['custom_field'][$fld_id]['value'])) { continue; } else { $filter_details = $options['custom_field'][$fld_id]; switch ($filter_details['filter_type']) { case 'ge': $display = ev_gettext('%1$s or greater', $filter_details['value']); break; case 'le': $display = ev_gettext('%1$s or less', $filter_details['value']); break; case 'gt': $display = ev_gettext('Greater than %1$s', $filter_details['value']); break; case 'lt': $display = ev_gettext('Less than %1$s', $filter_details['value']); break; default: $display = $filter_details['value']; } } } elseif (in_array($filter['fld_type'], array('multiple', 'combo'))) { $display = implode(', ', Custom_Field::getOptions($fld_id, $options['custom_field'][$fld_id])); } else { $display = $options['custom_field'][$fld_id]; } } elseif (!isset($options[$filter['param']]) || empty($options[$filter['param']]) || in_array($filter_key, array('sort_order', 'sort_by', 'rows', 'search_type'))) { continue; } elseif (isset($filter['is_date']) && $filter['is_date'] == true) { if (!empty($filter_details['Year']) || isset($filter_details['time_period'])) { switch ($filter_details['filter_type']) { case 'in_past': $display = ev_gettext('In Past %1$s hours', $filter_details['time_period']); break; case 'null': $display = ev_gettext('Is NULL'); break; case 'between': $end = $options[$filter['param'] . '_end']; $display = ev_gettext('Is between %1$s-%2$s-%3$s AND %4$s-%5$s-%6$s', $filter_details['Year'], $filter_details['Month'], $filter_details['Day'], $end['Year'], $end['Month'], $end['Day']); break; case 'greater': $display = ev_gettext('Is greater than %1$s-%2$s-%3$s', $filter_details['Year'], $filter_details['Month'], $filter_details['Day']); break; case 'less': $display = ev_gettext('Is less than %1$s-%2$s-%3$s', $filter_details['Year'], $filter_details['Month'], $filter_details['Day']); } } } elseif ($filter['param'] == 'status') { $statuses = Status::getAssocStatusList($prj_id); $display = $statuses[$filter_details]; } elseif ($filter['param'] == 'category') { $categories = Category::getAssocList($prj_id); if (is_array($filter_details)) { $active_categories = array(); foreach ($filter_details as $category) { $active_categories[] = $categories[$category]; } $display = implode(', ', $active_categories); } else { $display = $categories[$filter_details]; } } elseif ($filter['param'] == 'priority') { $priorities = Priority::getAssocList($prj_id); $display = $priorities[$filter_details]; } elseif ($filter['param'] == 'severity') { $severities = Severity::getAssocList($prj_id); $display = $severities[$filter_details]; } elseif ($filter['param'] == 'users') { if ($filter_details == -1) { $display = ev_gettext('un-assigned'); } elseif ($filter_details == -2) { $display = ev_gettext('myself and un-assigned'); } elseif ($filter_details == -3) { $display = ev_gettext('myself and my group'); } elseif ($filter_details == -4) { $display = ev_gettext('myself, un-assigned and my group'); } elseif (substr($filter_details, 0, 3) == 'grp') { $display = ev_gettext('%1$s Group', Group::getName(substr($filter_details, 4))); } else { $display = User::getFullName($filter_details); } } elseif ($filter['param'] == 'hide_closed') { if ($filter_details == true) { $display = ev_gettext('Yes'); } } elseif ($filter['param'] == 'reporter') { $display = User::getFullName($filter_details); } elseif ($filter['param'] == 'release') { $display = Release::getTitle($filter_details); } elseif ($filter['param'] == 'customer_id') { try { $crm = CRM::getInstance($prj_id); $customer = $crm->getCustomer($filter_details); $display = $customer->getName(); } catch (CRMException $e) { $display = $filter_details; } } elseif ($filter['param'] == 'product') { $display = Product::getTitle($filter_details); } else { $display = $filter_details; } if ($display != false) { $return[$filter['title']] = array('value' => $display, 'remove_link' => 'list.php?view=clearandfilter&' . self::buildUrl($filter_info, $options, $filter_key, true)); } } return $return; }
/** * Method used to bulk update a list of issues * * @access public * @return boolean */ function bulkUpdate() { global $HTTP_POST_VARS; // check if user performing this chance has the proper role if (Auth::getCurrentRole() < User::getRoleID('Manager')) { return -1; } $items = Misc::escapeInteger($HTTP_POST_VARS['item']); $new_status_id = Misc::escapeInteger($_POST['status']); $new_release_id = Misc::escapeInteger($_POST['release']); $new_priority_id = Misc::escapeInteger($_POST['priority']); $new_category_id = Misc::escapeInteger($_POST['category']); $new_project_id = Misc::escapeInteger($_POST['project']); for ($i = 0; $i < count($items); $i++) { if (!Issue::canAccess($items[$i], Auth::getUserID())) { continue; } elseif (Issue::getProjectID($HTTP_POST_VARS['item'][$i]) != Auth::getCurrentProject()) { // make sure issue is not in another project continue; } $updated_fields = array(); // update assignment if (count(@$HTTP_POST_VARS['users']) > 0) { $users = Misc::escapeInteger($HTTP_POST_VARS['users']); // get who this issue is currently assigned too $stmt = "SELECT\n isu_usr_id,\n CONCAT(en_firstname,' ', en_lastname) as usr_full_name\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,\n " . ETEL_USER_TABLE_NOSUB . "\n WHERE\n isu_usr_id = en_ID AND\n isu_iss_id = " . $items[$i]; $current_assignees = $GLOBALS["db_api"]->dbh->getAssoc($stmt); if (PEAR::isError($current_assignees)) { Error_Handler::logError(array($current_assignees->getMessage(), $current_assignees->getDebugInfo()), __FILE__, __LINE__); return -1; } foreach ($current_assignees as $usr_id => $usr_name) { if (!in_array($usr_id, $users)) { Issue::deleteUserAssociation($items[$i], $usr_id, false); } } $new_user_names = array(); $new_assignees = array(); foreach ($users as $usr_id) { $new_user_names[$usr_id] = User::getFullName($usr_id); // check if the issue is already assigned to this person $stmt = "SELECT\n COUNT(*) AS total\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user\n WHERE\n isu_iss_id=" . $items[$i] . " AND\n isu_usr_id=" . $usr_id; $total = $GLOBALS["db_api"]->dbh->getOne($stmt); if ($total > 0) { continue; } else { $new_assignees[] = $usr_id; // add the assignment Issue::addUserAssociation(Auth::getUserID(), $items[$i], $usr_id, false); Notification::subscribeUser(Auth::getUserID(), $items[$i], $usr_id, Notification::getAllActions()); Workflow::handleAssignment(Auth::getCurrentProject(), $items[$i], Auth::getUserID()); } } Notification::notifyNewAssignment($new_assignees, $items[$i]); $updated_fields['Assignment'] = History::formatChanges(join(', ', $current_assignees), join(', ', $new_user_names)); } // update status if (!empty($new_status_id)) { $old_status_id = Issue::getStatusID($items[$i]); $res = Issue::setStatus($items[$i], $new_status_id, false); if ($res == 1) { $updated_fields['Status'] = History::formatChanges(Status::getStatusTitle($old_status_id), Status::getStatusTitle($new_status_id)); } } // update release if (!empty($new_release_id)) { $old_release_id = Issue::getRelease($items[$i]); $res = Issue::setRelease($items[$i], $new_release_id); if ($res == 1) { $updated_fields['Release'] = History::formatChanges(Release::getTitle($old_release_id), Release::getTitle($new_release_id)); } } // update priority if (!empty($new_priority_id)) { $old_priority_id = Issue::getPriority($items[$i]); $res = Issue::setPriority($items[$i], $new_priority_id); if ($res == 1) { $updated_fields['Priority'] = History::formatChanges(Priority::getTitle($old_priority_id), Priority::getTitle($new_priority_id)); } } // update category if (!empty($new_category_id)) { $old_category_id = Issue::getCategory($items[$i]); $res = Issue::setCategory($items[$i], $new_category_id); if ($res == 1) { $updated_fields['Category'] = History::formatChanges(Category::getTitle($old_category_id), Category::getTitle($new_category_id)); } } // update project if (!empty($new_project_id)) { $old_project_id = Issue::getProjectID($items[$i]); $res = Issue::setProject($items[$i], $new_project_id); if ($res == 1) { $updated_fields['Project'] = History::formatChanges(Category::getTitle($old_project_id), Category::getTitle($new_project_id)); } } if (count($updated_fields) > 0) { // log the changes $changes = ''; $k = 0; foreach ($updated_fields as $key => $value) { if ($k > 0) { $changes .= "; "; } $changes .= "{$key}: {$value}"; $k++; } History::add($items[$i], Auth::getUserID(), History::getTypeID('issue_bulk_updated'), "Issue updated ({$changes}) by " . User::getFullName(Auth::getUserID())); } } return true; }
/** * Method used to send a diff-style notification email to the issue * subscribers about updates to its attributes. * * @param integer $issue_id The issue ID * @param array $old The old issue details * @param array $new The new issue details * @param array $updated_custom_fields An array of the custom fields that were changed. */ public static function notifyIssueUpdated($issue_id, $old, $new, $updated_custom_fields) { $prj_id = Issue::getProjectID($issue_id); $diffs = array(); if (@$new['keep_assignments'] == 'no') { if (empty($new['assignments'])) { $new['assignments'] = array(); } $assign_diff = Misc::arrayDiff($old['assigned_users'], $new['assignments']); if (count($assign_diff) > 0) { $diffs[] = '-' . ev_gettext('Assignment List') . ': ' . $old['assignments']; @($diffs[] = '+' . ev_gettext('Assignment List') . ': ' . implode(', ', User::getFullName($new['assignments']))); } } if (isset($new['expected_resolution_date']) && @$old['iss_expected_resolution_date'] != $new['expected_resolution_date']) { $diffs[] = '-' . ev_gettext('Expected Resolution Date') . ': ' . $old['iss_expected_resolution_date']; $diffs[] = '+' . ev_gettext('Expected Resolution Date') . ': ' . $new['expected_resolution_date']; } if (isset($new['category']) && $old['iss_prc_id'] != $new['category']) { $diffs[] = '-' . ev_gettext('Category') . ': ' . Category::getTitle($old['iss_prc_id']); $diffs[] = '+' . ev_gettext('Category') . ': ' . Category::getTitle($new['category']); } if (isset($new['release']) && $old['iss_pre_id'] != $new['release']) { $diffs[] = '-' . ev_gettext('Release') . ': ' . Release::getTitle($old['iss_pre_id']); $diffs[] = '+' . ev_gettext('Release') . ': ' . Release::getTitle($new['release']); } if (isset($new['priority']) && $old['iss_pri_id'] != $new['priority']) { $diffs[] = '-' . ev_gettext('Priority') . ': ' . Priority::getTitle($old['iss_pri_id']); $diffs[] = '+' . ev_gettext('Priority') . ': ' . Priority::getTitle($new['priority']); } if (isset($new['severity']) && $old['iss_sev_id'] != $new['severity']) { $diffs[] = '-' . ev_gettext('Severity') . ': ' . Severity::getTitle($old['iss_sev_id']); $diffs[] = '+' . ev_gettext('Severity') . ': ' . Severity::getTitle($new['severity']); } if (isset($new['status']) && $old['iss_sta_id'] != $new['status']) { $diffs[] = '-' . ev_gettext('Status') . ': ' . Status::getStatusTitle($old['iss_sta_id']); $diffs[] = '+' . ev_gettext('Status') . ': ' . Status::getStatusTitle($new['status']); } if (isset($new['resolution']) && $old['iss_res_id'] != $new['resolution']) { $diffs[] = '-' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($old['iss_res_id']); $diffs[] = '+' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($new['resolution']); } if (isset($new['estimated_dev_time']) && $old['iss_dev_time'] != $new['estimated_dev_time']) { $diffs[] = '-' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($old['iss_dev_time'] * 60); $diffs[] = '+' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($new['estimated_dev_time'] * 60); } if (isset($new['summary']) && $old['iss_summary'] != $new['summary']) { $diffs[] = '-' . ev_gettext('Summary') . ': ' . $old['iss_summary']; $diffs[] = '+' . ev_gettext('Summary') . ': ' . $new['summary']; } if (isset($new['percent_complete']) && $old['iss_original_percent_complete'] != $new['percent_complete']) { $diffs[] = '-' . ev_gettext('Percent complete') . ': ' . $old['iss_original_percent_complete']; $diffs[] = '+' . ev_gettext('Percent complete') . ': ' . $new['percent_complete']; } if (isset($new['description']) && $old['iss_description'] != $new['description']) { $old['iss_description'] = explode("\n", $old['iss_original_description']); $new['description'] = explode("\n", $new['description']); $diff = new Text_Diff($old['iss_description'], $new['description']); $renderer = new Text_Diff_Renderer_unified(); $desc_diff = explode("\n", trim($renderer->render($diff))); $diffs[] = 'Description:'; foreach ($desc_diff as $diff) { $diffs[] = $diff; } } $data = Issue::getDetails($issue_id); $data['diffs'] = implode("\n", $diffs); $data['updated_by'] = User::getFullName(Auth::getUserID()); $all_emails = array(); $role_emails = array(User::ROLE_VIEWER => array(), User::ROLE_REPORTER => array(), User::ROLE_CUSTOMER => array(), User::ROLE_USER => array(), User::ROLE_DEVELOPER => array(), User::ROLE_MANAGER => array(), User::ROLE_ADMINISTRATOR => array()); $users = self::getUsersByIssue($issue_id, 'updated'); foreach ($users as $user) { if (empty($user['sub_usr_id'])) { $email = $user['sub_email']; // non users are treated as "Viewers" for permission checks $role = User::ROLE_VIEWER; } else { $prefs = Prefs::get($user['sub_usr_id']); if (Auth::getUserID() == $user['sub_usr_id'] && (empty($prefs['receive_copy_of_own_action'][$prj_id]) || $prefs['receive_copy_of_own_action'][$prj_id] == false)) { continue; } $email = User::getFromHeader($user['sub_usr_id']); $role = $user['pru_role']; } // now add it to the list of emails if (!empty($email) && !in_array($email, $all_emails)) { $all_emails[] = $email; $role_emails[$role][] = $email; } } // get additional email addresses to notify $additional_emails = Workflow::getAdditionalEmailAddresses($prj_id, $issue_id, 'issue_updated', array('old' => $old, 'new' => $new)); $data['custom_field_diffs'] = implode("\n", Custom_Field::formatUpdatesToDiffs($updated_custom_fields, User::ROLE_VIEWER)); foreach ($additional_emails as $email) { if (!in_array($email, $all_emails)) { $role_emails[User::ROLE_VIEWER][] = $email; } } // send email to each role separately due to custom field restrictions foreach ($role_emails as $role => $emails) { if (count($emails) > 0) { $data['custom_field_diffs'] = implode("\n", Custom_Field::formatUpdatesToDiffs($updated_custom_fields, $role)); if (!empty($data['custom_field_diffs']) || !empty($data['diffs'])) { self::notifySubscribers($issue_id, $emails, 'updated', $data, ev_gettext('Updated'), false); } } } }
/** * Method used to send a diff-style notification email to the issue * subscribers about updates to its attributes. * * @access public * @param integer $issue_id The issue ID * @param array $old The old issue details * @param array $new The new issue details */ function notifyIssueUpdated($issue_id, $old, $new) { $diffs = array(); if (@$new["keep_assignments"] == "no") { if (empty($new['assignments'])) { $new['assignments'] = array(); } $assign_diff = Misc::arrayDiff($old['assigned_users'], $new['assignments']); if (count($assign_diff) > 0) { $diffs[] = '-Assignment List: ' . $old['assignments']; @($diffs[] = '+Assignment List: ' . implode(', ', User::getFullName($new['assignments']))); } } if (@$old['iss_expected_resolution_date'] != $new['expected_resolution_date']) { $diffs[] = '-Expected Resolution Date: ' . $old['iss_expected_resolution_date']; $diffs[] = '+Expected Resolution Date: ' . $new['expected_resolution_date']; } if ($old["iss_prc_id"] != $new["category"]) { $diffs[] = '-Category: ' . Category::getTitle($old["iss_prc_id"]); $diffs[] = '+Category: ' . Category::getTitle($new["category"]); } if (@$new["keep"] == "no" && $old["iss_pre_id"] != $new["release"]) { $diffs[] = '-Release: ' . Release::getTitle($old["iss_pre_id"]); $diffs[] = '+Release: ' . Release::getTitle($new["release"]); } if ($old["iss_pri_id"] != $new["priority"]) { $diffs[] = '-Priority: ' . Priority::getTitle($old["iss_pri_id"]); $diffs[] = '+Priority: ' . Priority::getTitle($new["priority"]); } if ($old["iss_sta_id"] != $new["status"]) { $diffs[] = '-Status: ' . Status::getStatusTitle($old["iss_sta_id"]); $diffs[] = '+Status: ' . Status::getStatusTitle($new["status"]); } if ($old["iss_res_id"] != $new["resolution"]) { $diffs[] = '-Resolution: ' . Resolution::getTitle($old["iss_res_id"]); $diffs[] = '+Resolution: ' . Resolution::getTitle($new["resolution"]); } if ($old["iss_dev_time"] != $new["estimated_dev_time"]) { $diffs[] = '-Estimated Dev. Time: ' . Misc::getFormattedTime($old["iss_dev_time"] * 60); $diffs[] = '+Estimated Dev. Time: ' . Misc::getFormattedTime($new["estimated_dev_time"] * 60); } if ($old["iss_summary"] != $new["summary"]) { $diffs[] = '-Summary: ' . $old['iss_summary']; $diffs[] = '+Summary: ' . $new['summary']; } if ($old["iss_description"] != $new["description"]) { // need real diff engine here include_once 'Text_Diff/Diff.php'; include_once 'Text_Diff/Diff/Renderer.php'; include_once 'Text_Diff/Diff/Renderer/unified.php'; $old['iss_description'] = explode("\n", $old['iss_description']); $new['description'] = explode("\n", $new['description']); $diff =& new Text_Diff($old["iss_description"], $new["description"]); $renderer =& new Text_Diff_Renderer_unified(); $desc_diff = explode("\n", trim($renderer->render($diff))); $diffs[] = 'Description:'; for ($i = 0; $i < count($desc_diff); $i++) { $diffs[] = $desc_diff[$i]; } } $emails = array(); $users = Notification::getUsersByIssue($issue_id, 'updated'); $user_emails = Project::getUserEmailAssocList(Issue::getProjectID($issue_id), 'active', User::getRoleID('Customer')); $user_emails = array_map('strtolower', $user_emails); for ($i = 0; $i < count($users); $i++) { if (empty($users[$i]["sub_usr_id"])) { $email = $users[$i]["sub_email"]; } else { $email = User::getFromHeader($users[$i]["sub_usr_id"]); } // now add it to the list of emails if (!empty($email) && !in_array($email, $emails)) { $emails[] = $email; } } $data = Notification::getIssueDetails($issue_id); $data['diffs'] = implode("\n", $diffs); $data['updated_by'] = User::getFullName(Auth::getUserID()); Notification::notifySubscribers($issue_id, $emails, 'updated', $data, 'Updated', FALSE); }
/** * Method used to send a diff-style notification email to the issue * subscribers about updates to its attributes. * * @param integer $issue_id The issue ID * @param array $old The old issue details * @param array $new The new issue details */ public static function notifyIssueUpdated($issue_id, $old, $new) { $prj_id = Issue::getProjectID($issue_id); $diffs = array(); if (@$new['keep_assignments'] == 'no') { if (empty($new['assignments'])) { $new['assignments'] = array(); } $assign_diff = Misc::arrayDiff($old['assigned_users'], $new['assignments']); if (count($assign_diff) > 0) { $diffs[] = '-' . ev_gettext('Assignment List') . ': ' . $old['assignments']; @($diffs[] = '+' . ev_gettext('Assignment List') . ': ' . implode(', ', User::getFullName($new['assignments']))); } } if (isset($new['expected_resolution_date']) && @$old['iss_expected_resolution_date'] != $new['expected_resolution_date']) { $diffs[] = '-' . ev_gettext('Expected Resolution Date') . ': ' . $old['iss_expected_resolution_date']; $diffs[] = '+' . ev_gettext('Expected Resolution Date') . ': ' . $new['expected_resolution_date']; } if (isset($new['category']) && $old['iss_prc_id'] != $new['category']) { $diffs[] = '-' . ev_gettext('Category') . ': ' . Category::getTitle($old['iss_prc_id']); $diffs[] = '+' . ev_gettext('Category') . ': ' . Category::getTitle($new['category']); } if (isset($new['release']) && $old['iss_pre_id'] != $new['release']) { $diffs[] = '-' . ev_gettext('Release') . ': ' . Release::getTitle($old['iss_pre_id']); $diffs[] = '+' . ev_gettext('Release') . ': ' . Release::getTitle($new['release']); } if (isset($new['priority']) && $old['iss_pri_id'] != $new['priority']) { $diffs[] = '-' . ev_gettext('Priority') . ': ' . Priority::getTitle($old['iss_pri_id']); $diffs[] = '+' . ev_gettext('Priority') . ': ' . Priority::getTitle($new['priority']); } if (isset($new['severity']) && $old['iss_sev_id'] != $new['severity']) { $diffs[] = '-' . ev_gettext('Severity') . ': ' . Severity::getTitle($old['iss_sev_id']); $diffs[] = '+' . ev_gettext('Severity') . ': ' . Severity::getTitle($new['severity']); } if (isset($new['status']) && $old['iss_sta_id'] != $new['status']) { $diffs[] = '-' . ev_gettext('Status') . ': ' . Status::getStatusTitle($old['iss_sta_id']); $diffs[] = '+' . ev_gettext('Status') . ': ' . Status::getStatusTitle($new['status']); } if (isset($new['resolution']) && $old['iss_res_id'] != $new['resolution']) { $diffs[] = '-' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($old['iss_res_id']); $diffs[] = '+' . ev_gettext('Resolution') . ': ' . Resolution::getTitle($new['resolution']); } if (isset($new['estimated_dev_time']) && $old['iss_dev_time'] != $new['estimated_dev_time']) { $diffs[] = '-' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($old['iss_dev_time'] * 60); $diffs[] = '+' . ev_gettext('Estimated Dev. Time') . ': ' . Misc::getFormattedTime($new['estimated_dev_time'] * 60); } if (isset($new['summary']) && $old['iss_summary'] != $new['summary']) { $diffs[] = '-' . ev_gettext('Summary') . ': ' . $old['iss_summary']; $diffs[] = '+' . ev_gettext('Summary') . ': ' . $new['summary']; } if (isset($new['percent_complete']) && $old['iss_original_percent_complete'] != $new['percent_complete']) { $diffs[] = '-' . ev_gettext('Percent complete') . ': ' . $old['iss_original_percent_complete']; $diffs[] = '+' . ev_gettext('Percent complete') . ': ' . $new['percent_complete']; } if (isset($new['description']) && $old['iss_description'] != $new['description']) { $old['iss_description'] = explode("\n", $old['iss_original_description']); $new['description'] = explode("\n", $new['description']); $diff = new Text_Diff($old['iss_description'], $new['description']); $renderer = new Text_Diff_Renderer_unified(); $desc_diff = explode("\n", trim($renderer->render($diff))); $diffs[] = 'Description:'; foreach ($desc_diff as $diff) { $diffs[] = $diff; } } $emails = array(); $users = self::getUsersByIssue($issue_id, 'updated'); $user_emails = Project::getUserEmailAssocList(Issue::getProjectID($issue_id), 'active', User::getRoleID('Customer')); // FIXME: $user_emails unused $user_emails = array_map(function ($s) { return strtolower($s); }, $user_emails); foreach ($users as $user) { if (empty($user['sub_usr_id'])) { $email = $user['sub_email']; } else { $prefs = Prefs::get($user['sub_usr_id']); if (Auth::getUserID() == $user['sub_usr_id'] && (empty($prefs['receive_copy_of_own_action'][$prj_id]) || $prefs['receive_copy_of_own_action'][$prj_id] == false)) { continue; } $email = User::getFromHeader($user['sub_usr_id']); } // now add it to the list of emails if (!empty($email) && !in_array($email, $emails)) { $emails[] = $email; } } // get additional email addresses to notify $emails = array_merge($emails, Workflow::getAdditionalEmailAddresses($prj_id, $issue_id, 'issue_updated', array('old' => $old, 'new' => $new))); $data = Issue::getDetails($issue_id); $data['diffs'] = implode("\n", $diffs); $data['updated_by'] = User::getFullName(Auth::getUserID()); self::notifySubscribers($issue_id, $emails, 'updated', $data, ev_gettext('Updated'), false); }