Index: includes/project_edit_issues.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/project_issue/includes/project_edit_issues.inc,v retrieving revision 1.2 diff -u -r1.2 project_edit_issues.inc --- includes/project_edit_issues.inc 5 May 2009 19:15:58 -0000 1.2 +++ includes/project_edit_issues.inc 27 Jul 2009 06:43:32 -0000 @@ -226,6 +226,10 @@ * @see project_issue_project_edit_issues */ function project_issue_project_edit_form_submit($form, &$form_state) { + // Load the original project node and components. + $original_node = node_load($form_state['values']['nid']); + $original_components = array_values($original_node->project_issue['components']); + $components = array(); if (!empty($form_state['values']['component_add']['name'])) { $components[trim($form_state['values']['component_add']['name'])] = $form_state['values']['component_add']['weight']; @@ -236,13 +240,33 @@ } } asort($components); + + // Determine which components were renamed upon submit. + $index = 0; + foreach(array_keys($components) as $new_component) { + if ($original_components[$index] != $new_component) { + $renamed_components[$original_components[$index]] = $new_component; + } + $index++; + } + $components = serialize(array_keys($components)); $default_component = !empty($form_state['values']['default_component']) ? $form_state['values']['default_component'] : ''; + + // If the default component is amongst the renamed components, save the new + // component name instead of the old one. + if ($default_component && isset($renamed_components[$default_component])) { + $default_component = $renamed_components[$default_component]; + } + $mail_copy_filter = serialize($form_state['values']['mail_copy_filter']); $mail_copy_filter_state = serialize($form_state['values']['mail_copy_filter_state']); db_query("UPDATE {project_issue_projects} SET issues = %d, components = '%s',default_component = '%s', mail_digest = '%s', mail_reminder = %d, mail_copy = '%s', mail_copy_filter = '%s', mail_copy_filter_state = '%s', help = '%s' WHERE nid = %d", $form_state['values']['issues'], $components, $default_component, $form_state['values']['mail_digest'], $form_state['values']['mail_reminder'], $form_state['values']['mail_copy'], $mail_copy_filter, $mail_copy_filter_state, $form_state['values']['help'], $form_state['values']['nid']); db_query("UPDATE {node} SET changed = %d WHERE nid = %d", time(), $form_state['values']['nid']); + + project_issue_component_rename_start_batch($original_node, $renamed_components); + drupal_set_message(t('Issue settings have been saved.')); } @@ -287,4 +311,38 @@ db_query("UPDATE {node} SET changed = %d WHERE nid = %d", time(), $project->nid); } +/* + * Set up and launch batch processing via the Batch API. + * + * @param $project + * @param $old_name + * @param $new_name + */ +function project_issue_component_rename_start_batch($project, $renamed_components) { + require_once(drupal_get_path('module', 'project_issue') . '/includes/batch.inc'); + + // Set up the batch operation which will update the component for each + // issues & comments. + $batch = array( + 'finished' => 'project_issue_batch_rename_component_finished', + 'title' => t('Updating issues & follow-ups.'), + 'error_message' => t('An error occured while updating issues.'), + 'file' => drupal_get_path('module', 'project_issue') . "/includes/batch.inc" + ); + + foreach ($renamed_components as $old_name => $new_name) { + $batch['operations'][] = array('project_issue_batch_rename_component_current_values', array($project, $old_name, $new_name)); + $batch['operations'][] = array('project_issue_batch_rename_component_original_values', array($project, $old_name, $new_name)); + } + + batch_set($batch); +} + +function project_issue_batch_rename_component_finished($success, $results, $operations) { + if ($success) { + $pid = $results['pid']; + drupal_set_message(t('Successfully processed !processed issues.