cvs diff: Diffing . Index: issue.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v retrieving revision 1.354 diff -u -p -r1.354 issue.inc --- issue.inc 18 Jun 2009 03:28:55 -0000 1.354 +++ issue.inc 24 Apr 2010 01:56:20 -0000 @@ -235,9 +235,39 @@ function project_issue_default_states() return $defaults; } -function project_issue_priority($priority = 0) { - $priorities = array(1 => t('critical'), t('normal'), t('minor')); - return $priority ? $priorities[$priority] : $priorities; +/** + * Return all available issue priorities, sorted by weight. + * + * @return + * An array of priorities keyed by id. + */ +function project_issue_priorities() { + static $priorities; + if (!isset($priorities)) { + $result = db_query('SELECT priority, name FROM {project_issue_priority} ORDER BY weight'); + while ($object = db_fetch_object($result)) { + $priorities[$object->priority] = $object->name; + } + } + return $priorities; +} + +/** + * Return the name of a priority for a given id. + * + * @param $priority + * The id of the priority. + * @return + * The name of the priority. + */ +function project_issue_priority($priority) { + $priorities = project_issue_priorities(); + if ($priority && array_key_exists($priority, $priorities)) { + return $priorities[$priority]; + } + else { + return t('[deleted priority]'); + } } function project_issue_category($category = 0, $plural = 1) { Index: project_issue.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v retrieving revision 1.64 diff -u -p -r1.64 project_issue.install --- project_issue.install 21 Aug 2009 22:51:31 -0000 1.64 +++ project_issue.install 24 Apr 2010 01:56:20 -0000 @@ -110,13 +110,20 @@ function project_issue_schema() { 'default' => '', ), 'priority' => array( - 'description' => 'The priority for this issue.', + 'description' => 'Current {project_issue_priority}.priority of this issue.', 'type' => 'int', 'size' => 'tiny', 'unsigned' => 1, 'not null' => TRUE, 'default' => 0, ), + 'priority_weight' => array( + 'description' => 'The denormalized weight from {project_issue_priority}.weight.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), 'rid' => array( 'description' => 'The {project_release_nodes}.rid (version identifier) for this issue (only used in conjunction with the project_release module).', 'type' => 'int', @@ -199,7 +206,7 @@ function project_issue_schema() { 'default' => '', ), 'priority' => array( - 'description' => 'The priority for this issue after this comment was made.', + 'description' => 'The {project_issue_priority}.priority of this issue after this comment was made.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, @@ -249,6 +256,32 @@ function project_issue_schema() { ), ); + $schema['project_issue_priority'] = array( + 'description' => 'The available options for the priority values for issues.', + 'fields' => array( + 'priority' => array( + 'description' => 'Primary Key: Unique id for this priority.', + 'type' => 'serial', + 'not null' => TRUE, + ), + 'name' => array( + 'description' => 'Display-friendly name for this priority.', + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'weight' => array( + 'description' => 'Weight for this priority, used when ordering issues by priority. Denormalized into {project_issues}.priority_weight.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('priority'), + ); + $schema['project_subscriptions'] = array( 'description' => 'Table keeping track of per-user project_issue subscriptions.', 'fields' => array( @@ -364,6 +397,9 @@ function project_issue_install() { variable_set('comment_upload_project_issue', 1); // Enable file attachments for issues. variable_set('upload_project_issue', 1); + db_query("INSERT INTO {project_issue_priority} (priority, name, weight) VALUES (1, 'critical', 1)"); + db_query("INSERT INTO {project_issue_priority} (priority, name, weight) VALUES (2, 'normal', 2)"); + db_query("INSERT INTO {project_issue_priority} (priority, name, weight) VALUES (3, 'minor', 3)"); } /** @@ -446,3 +482,57 @@ function project_issue_update_6002() { return $ret; } +/** + * Add table for project_issue_priority, and insert default values. + */ +function project_issue_update_6003() { + $ret = array(); + $table = array( + 'description' => 'The issue priorities.', + 'fields' => array( + 'priority' => array( + 'description' => 'Primary Key: Unique id for this priority.', + 'type' => 'serial', + 'not null' => TRUE, + ), + 'name' => array( + 'description' => 'Display-friendly name for this priority.', + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'weight' => array( + 'description' => 'Weight for this priority, used when ordering issues by priority. Denormalized into {project_issues}.priority_weight.', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('priority'), + ); + db_create_table($ret, 'project_issue_priority', $table); + db_query("INSERT INTO {project_issue_priority} (priority, name, weight) VALUES (1, 'critical', 1)"); + db_query("INSERT INTO {project_issue_priority} (priority, name, weight) VALUES (2, 'normal', 2)"); + db_query("INSERT INTO {project_issue_priority} (priority, name, weight) VALUES (3, 'minor', 3)"); + + db_add_field($ret, 'project_issues', 'priority_weight', array('type' => 'int', 'not null' => TRUE, 'default' => '0', 'size' => 'tiny')); + return $ret; +} + +/** + * Update {project_issues} with denormalized priority weight. + */ +function project_issue_update_6004(&$sandbox) { + $ret = array(); + // Reconstruct a batch context. + $context = array('sandbox' => &$sandbox); + // Load the include. + require_once drupal_get_path('module', 'project_issue') .'/includes/admin.batch_confirm.inc'; + // Call the batch upgrade which will set its variables in the sandbox. + _project_issue_batch_update('UPDATE {project_issues} SET priority_weight = priority WHERE nid BETWEEN %d AND %d', array(), $context); + // Pass back progress. + $ret['#finished'] = $context['finished']; + return $ret; +} Index: project_issue.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v retrieving revision 1.179 diff -u -p -r1.179 project_issue.module --- project_issue.module 22 Apr 2010 09:34:54 -0000 1.179 +++ project_issue.module 24 Apr 2010 01:56:21 -0000 @@ -99,6 +99,27 @@ function project_issue_menu() { 'file' => 'includes/admin.settings.inc', ); + // Administrative pages + $items['admin/project/project-issue-priority'] = array( + 'title' => 'Project issue priority options', + 'description' => 'Configure what issue priorities should be used on your site.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('project_issue_admin_priority_form'), + 'access arguments' => array('administer projects'), + 'weight' => 1, + 'type' => MENU_NORMAL_ITEM, + 'file' => 'includes/admin.issue_priority.inc', + ); + $items['admin/project/project-issue-priority/delete'] = array( + 'title' => 'Delete', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('project_issue_delete_priority_confirm', 4), + 'access arguments' => array('administer projects'), + 'type' => MENU_CALLBACK, + 'file' => 'includes/admin.issue_priority.inc' + ); + + // Administer issue status settings $items['admin/project/project-issue-status'] = array( 'title' => 'Project issue status options', @@ -323,6 +344,12 @@ function project_issue_theme() { 'form' => NULL, ), ), + 'project_issue_admin_priority_form' => array( + 'file' => 'includes/admin.issue_priority.inc', + 'arguments' => array( + 'form' => NULL, + ), + ), 'project_issue_project_edit_form' => array( 'file' => 'includes/project_edit_issues.inc', 'arguments' => array( @@ -1770,4 +1797,3 @@ function project_issue_project_page_link $links['development']['links'] = $patches + $links['development']['links']; } } - Index: project_issue.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.test,v retrieving revision 1.3 diff -u -p -r1.3 project_issue.test --- project_issue.test 20 Apr 2010 22:22:06 -0000 1.3 +++ project_issue.test 24 Apr 2010 01:56:21 -0000 @@ -55,11 +55,14 @@ class ProjectIssueWebTestCase extends Pr * @param $nid * Optional integer node ID of the issue to check metadata fields for. */ - function assertIssueMetadata($metadata, $nid = NULL) { + function assertIssueMetadata($metadata, $nid = NULL, $message = NULL) { $pass = TRUE; if ($nid) { $this->drupalGet('node/' . $nid); } + if (!$message) { + $message = t('Issue metadata matches'); + } foreach ($this->xpath("//div[@id='project-issue-summary-table']/table//tr") as $row) { $key = strtolower(trim((string)$row->td[0], ':')); if (isset($metadata[$key])) { @@ -69,10 +72,10 @@ class ProjectIssueWebTestCase extends Pr } } if ($pass) { - $this->pass(t('Issue metadata matches')); + $this->pass($message); } else { - $this->fail(t('Issue metadata matches')); + $this->fail($message); } } } @@ -168,7 +171,7 @@ class ProjectIssueCommentTestCase extend 'pid' => 'project_info[pid]', ); foreach ($map as $issue_key => $post_key) { - $this->assertEqual($issue->project_issue[$issue_key], $post[$post_key], t('Making sure comment form is correct')); + $this->assertEqual($issue->project_issue[$issue_key], $post[$post_key], t('Making sure comment form is correct.')); } } @@ -183,3 +186,192 @@ class ProjectIssueCommentTestCase extend $this->assertText($comment['comment'], t('Body found')); } } + +class ProjectIssuePriorityTestCase extends ProjectIssueWebTestCase { + /** + * A user who can maintain project issue administrative settings, projects, and create issues. + */ + protected $maintain_user; + + public static function getInfo() { + return array( + 'name' => 'Project issue priority', + 'description' => 'Test issue priority settings and functionality.', + 'group' => 'Project Issue', + ); + } + + function setUp() { + parent::setUp(); + + $this->maintain_user = $this->drupalCreateUser(array('administer projects', 'maintain projects', 'create project issues', 'access project issues', 'access projects')); + $this->drupalLogin($this->maintain_user); + } + + /** + * Assert that the priorities are stored and displayed correctly. + * + * This function will take an array of priorities keyed by their priority ID, + * with each item being an array with they keys 'name' and 'weight'. + */ + function assertAdminPrioritiesForm($values) { + $pass = TRUE; + $this->drupalGet('admin/project/project-issue-priority'); + $forms = $this->xpath('//form'); + $form = $forms[0]; + + $post = $edit = $upload = array(); + $this->handleForm($post, $edit, $upload, NULL, $form); + + foreach ($values as $key => $priority) { + $result = $this->assertEqual($post["priority[$key][name]"], $priority['name'], t('The name for the priority is correct.')); + $result = $this->assertEqual($post["priority[$key][weight]"], $priority['weight'], t('The weight for the priority is correct.')); + } + } + + /** + * Test the project issue priority admin form. + */ + function testProjectIssuePrioritySettings() { + // This matches the defaults setup in project_issue_install(). + $default_priority_order = array( + 1 => array( + 'name' => 'critical', + 'weight' => 1, + ), + 2 => array( + 'name' => 'normal', + 'weight' => 2, + ), + 3 => array( + 'name' => 'minor', + 'weight' => 3, + ), + ); + $this->assertAdminPrioritiesForm($default_priority_order); + + // Test reordering ability + $edit = array(); + $edit['priority[1][weight]'] = -2; + $edit['priority[2][weight]'] = -3; + $edit['priority[3][weight]'] = -1; + $this->drupalPost('admin/project/project-issue-priority', $edit, t('Save')); + + // Check new values + $priorities = array( + 1 => array( + 'name' => 'critical', + 'weight' => 1, + ), + 2 => array( + 'name' => 'normal', + 'weight' => 0, + ), + 3 => array( + 'name' => 'minor', + 'weight' => 2, + ), + ); + $this->assertAdminPrioritiesForm($priorities); + + // Add a new priority, and check the form results + $edit = array(); + $edit['priority[0][name]'] = $this->randomName(8); + $this->drupalPost('admin/project/project-issue-priority', $edit, t('Save')); + + // Check new values + $priorities = array( + 1 => array( + 'name' => 'critical', + 'weight' => 1, + ), + 2 => array( + 'name' => 'normal', + 'weight' => 0, + ), + 3 => array( + 'name' => 'minor', + 'weight' => 2, + ), + 4 => array( + 'name' => $edit['priority[0][name]'], + 'weight' => 3, + ), + ); + $this->assertAdminPrioritiesForm($priorities); + + // Test deleting a priority without any issues. + $this->drupalGet('admin/project/project-issue-priority/delete/4'); + $this->assertNoText('Reassign priority', t('Issue confirm form is displayed properly.')); + $this->drupalPost('admin/project/project-issue-priority/delete/4', array(), t('Delete')); + $this->assertText('Project issue priority '. $edit['priority[0][name]'] .' deleted.', t('Project issue priority has been deleted.')); + + // Test that a custom priority can be assinged to an issue and is displayed correctly. + $edit = array(); + $edit['priority[0][name]'] = $priority_name = $this->randomName(8); + $this->drupalPost('admin/project/project-issue-priority', $edit, t('Save')); + $project = $this->createProject(); + + $edit = array(); + $edit['priority'] = '5'; + $issue = $this->createIssue($project, $edit); + + // Check that the issue priority is displayed correctly. + $this->assertIssueMetadata(array('priority' => $priority_name), $issue->nid, t('Custom issue priority is displyed correctly')); + + // Delete the priority + $this->drupalGet('admin/project/project-issue-priority/delete/5'); + $this->assertText('Reassign priority', t('Issue confirm form is displayed properly.')); + + $edit = array(); + $edit['new_pid'] = 2; + $this->drupalPost(NULL, $edit, t('Delete')); + $this->assertText('Project issue priority '. $priority_name .' deleted.', t('Issue priority was deleted')); + + $this->assertIssueMetadata(array('priority' => 'normal'), $issue->nid); + + $edit = array(); + $edit['priority[1][weight]'] = -3; + $edit['priority[2][weight]'] = -2; + $edit['priority[3][weight]'] = -1; + $this->drupalPost('admin/project/project-issue-priority', $edit, t('Save')); + + $priorities = array( + 1 => array( + 'name' => 'critical', + 'weight' => 0, + ), + 2 => array( + 'name' => 'normal', + 'weight' => 1, + ), + 3 => array( + 'name' => 'minor', + 'weight' => 2, + ), + ); + $this->assertAdminPrioritiesForm($priorities); + + $edit = array(); + $edit['priority'] = 1; + $edit['title'] = $critical_title = $this->randomName(8); + $critical_issue = $this->createIssue($project, $edit); + + $edit = array(); + $edit['priority'] = 3; + $edit['title'] = $minor_title = $this->randomName(8); + $minor_issue = $this->createIssue($project, $edit); + + $this->drupalGet('project/issues/'. $project->project['uri']); + $this->clickLink(t('Priority')); + + // Check that views handler +// @TODO This code is not working yet but is quite important +// $rows = $this->xpath("//table[@class='project-issue']/tr"); +// debug((string)$rows[0]->td[0]); +// +// $this->assertEqual((string)$rows[0], $minor_issue->title); +// $this->assertEqual((string)$rows[1], $issue->title); +// $this->assertEqual((string)$rows[2], $critical_issue->title); + } +} cvs diff: Diffing generate Index: generate/project_issue_generate.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/generate/project_issue_generate.inc,v retrieving revision 1.13 diff -u -p -r1.13 project_issue_generate.inc --- generate/project_issue_generate.inc 21 Mar 2009 18:50:17 -0000 1.13 +++ generate/project_issue_generate.inc 24 Apr 2010 01:56:21 -0000 @@ -199,7 +199,7 @@ function _project_issue_generate_get_fie return array_keys(project_issue_category()); case 'priorities': - return project_issue_priority(); + return project_issue_priorities(); case 'users': // Determine what role ids have permission to create project_issue nodes. cvs diff: Diffing includes Index: includes/admin.batch_confirm.inc =================================================================== RCS file: includes/admin.batch_confirm.inc diff -N includes/admin.batch_confirm.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/admin.batch_confirm.inc 24 Apr 2010 01:56:21 -0000 @@ -0,0 +1,66 @@ + so use - 1 when choosing the smallest nid. + $context['sandbox']['min'] = db_result(db_query('SELECT MIN(nid) - 1 FROM {project_issues}')); + $context['sandbox']['current'] = $context['sandbox']['min']; + } + $arguments = $base_arguments; + // MySQL does not support LIMIT & IN/ALL/ANY/SOME subquery so we do the hard + // work ourselves: find 100 nids and record the first and the last. + $results = db_query_range('SELECT nid FROM {project_issues} WHERE nid > %d ORDER BY nid ASC', $context['sandbox']['current'], 0, 100); + while ($node = db_fetch_object($results)) { + if (!isset($first_nid)) { + $first_nid = $node->nid; + } + $last_nid = $node->nid; + } + $arguments[] = $first_nid; + $arguments[] = $last_nid; + db_query($sql, $arguments); + // Note that we do not count exactly as there can be holes. That's still + // better than running COUNT() on large datasets. + if ($last_nid < $context['sandbox']['max']) { + $context['finished'] = ($last_nid - $context['sandbox']['min']) / ($context['sandbox']['max'] - $context['sandbox']['min']); + $context['sandbox']['current'] = $last_nid; + } + else { + $context['finished'] = 1; + } +} Index: includes/admin.issue_priority.inc =================================================================== RCS file: includes/admin.issue_priority.inc diff -N includes/admin.issue_priority.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/admin.issue_priority.inc 24 Apr 2010 01:56:21 -0000 @@ -0,0 +1,227 @@ +weight); + $form['priority'][$priority->priority]['name'] = array( + '#type' => 'textfield', + '#default_value' => $priority->name, + '#size' => 20, + '#maxlength' => 255, + ); + $form['priority'][$priority->priority]['weight'] = array( + '#type' => 'weight', + '#default_value' => $priority->weight, + '#delta' => &$delta, + '#attributes' => array('class' => 'project-issue-priority-weight'), + ); + $form['delete'][$priority->priority]['#value'] = l(t('Delete'), 'admin/project/project-issue-priority/delete/'. $priority->priority); + } + $delta = $max + 1; + $form['priority'][0]['name'] = array( + '#type' => 'textfield', + '#default_value' => '', + '#size' => 20, + '#maxlength' => 255, + ); + $form['priority'][0]['weight'] = array( + '#type' => 'weight', + // Make sure that the new item has a weight higher than highest priority + // since new item appears at bottom of the form by default. + '#default_value' => $max + 1, + '#delta' => $max + 1, + '#attributes' => array('class' => 'project-issue-priority-weight'), + ); + $form['delete'][0]['#value'] = ''; + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + $form['#tree'] = TRUE; + return $form; +} + +/** + * Render the HTML for the admin issue priority form. + * + * @see project_issue_admin_priority_form() + * @see drupal_add_tabledrag() + */ +function theme_project_issue_admin_priority_form($form) { + drupal_add_tabledrag('project-issue-admin-priority-table', 'order', 'self', 'project-issue-priority-weight'); + $header = array( + t('Priority'), + t('Weight'), + t('Operations'), + ); + foreach (element_children($form['priority']) as $key) { + $rows[] = array( + 'class' => 'draggable', + 'data' => array( + drupal_render($form['priority'][$key]['name']), + drupal_render($form['priority'][$key]['weight']), + drupal_render($form['delete'][$key]), + ), + ); + } + $output = '
' . theme('table', $header, $rows, array('id' => 'project-issue-admin-priority-table')) . '
'; + $output .= drupal_render($form); + return $output; +} + +/** + * Submit handler for project_issue_admin_states_form. + */ +function project_issue_admin_priority_form_submit($form, &$form_state) { + $offset = 0; + foreach ($form_state['values']['priority'] as $priority_id => $value) { + $offset = min($offset, $value['weight']); + } + // $offset at this point contains the smallest weight. If that's below zero, + // then adding it to every weight will result in unsigned weights. Otherwise + // such addition is not necessary. + $offset = $offset < 0 ? -$offset : 0; + // Update existing priorities. + $update_expression = ''; + $weights = array(); + foreach ($form_state['values']['priority'] as $priority_id => $value) { + $weight = $value['weight'] + $offset; + $form_state['values']['priority'][$priority_id]['weight'] = $weight; + // Update existing. + if ($priority_id) { + $priority = db_fetch_object(db_query('SELECT priority, name, weight FROM {project_issue_priority} WHERE priority = %d', $priority_id)); + $update = $priority->name !== $value['name']; + // Check to see whether the record needs updating. We love PHP and '0'. + if ((string)$priority->weight !== (string)$weight) { + $update_expression .= " WHEN %d THEN %d"; + $weights[] = $priority->priority; + $weights[] = $weight; + $update = TRUE; + } + if ($update) { + db_query("UPDATE {project_issue_priority} SET name = '%s', weight = %d WHERE priority = %d", $value['name'], $weight, $priority_id); + } + } + // Add new priority. + elseif ($value['name']) { + // Check to see whether the state already exists: + $issue_state = db_result(db_query("SELECT COUNT(*) FROM {project_issue_priority} WHERE name = '%s'", $value['name'])); + if (empty($issue_state)) { + db_query("INSERT INTO {project_issue_priority} (name, weight) VALUES ('%s', %d)", $value['name'], $weight); + } + else { + drupal_set_message(t('Priority %priority already exists.', array ('%priority' => $value['name'])), 'error'); + } + } + } + if ($weights) { + $weight_sql = "UPDATE {project_issues} SET priority_weight = CASE priority $update_expression ELSE priority_weight END WHERE nid BETWEEN %d AND %d"; + $batch = array( + 'operations' => array( + array('_project_issue_batch_update', array($weight_sql, $weights)), + ), + 'title' => t('Processing'), + // We use a single multi-pass operation, so the default + // 'Remaining x of y operations' message will be confusing here. + 'progress_message' => '', + 'error_message' => t('The update has encountered an error.'), + // The operations do not live in the .module file, so we need to + // tell the batch engine which file to load before calling them. + 'file' => drupal_get_path('module', 'project_issue') .'/includes/admin.batch_confirm.inc', + ); + batch_set($batch); + } +} + +/** + * Build a confirmation form when deleting an issue priority. + * + * This allows the admin to re-prioritize any issues with the priority being + * deleted using admin.batch_confirm.inc. + * + * @param $form_state + * The state of the form we're trying to build. + * @param $priority_id + * The {project_issue_priority}.priority ID being deleted. + */ +function project_issue_delete_priority_confirm(&$form_state, $priority_id) { + // Helper functions are in issue.inc. + require_once drupal_get_path('module', 'project_issue') .'/issue.inc'; + $schema = drupal_get_schema('project_issues'); + if (!function_exists('project_issue_priority') || !isset($schema['fields']['priority']) || !db_table_exists('project_issue_priority')) { + return drupal_access_denied(); + } + $priorities = project_issue_priorities(); + $name = $priorities[$priority_id]; + unset($priorities[$priority_id]); + + // $column is verified to exist. + $total = db_result(db_query("SELECT COUNT(nid) AS total FROM {project_issues} WHERE priority = %d", $priority_id)); + if ($total > 0) { + $form['new_pid'] = array( + '#type' => 'select', + '#title' => t('Reassign priority'), + '#default_value' => $priority_id, + '#options' => $priorities, + '#description' => format_plural($total, 'There is 1 existing issue assigned @name priority. Please select a new priority for this issue.', 'There are @count existing issues assigned @name priority. Please select a new priority for these issues.', array('@name' => $name)), + ); + } + $form['pid'] = array( + '#type' => 'value', + '#value' => $priority_id, + ); + $form['name'] = array( + '#type' => 'hidden', + '#value' => $name, + ); + return confirm_form( + $form, + t('Are you sure you want to delete the priority %name?', array('%name' => $name)), + 'admin/project/project-issue-priority', + t('This action cannot be undone.'), + t('Delete'), t('Cancel') + ); +} + +/** + * Submit handler for confirm form when deleting an issue priority. + */ +function project_issue_delete_priority_confirm_submit($form, &$form_state) { + db_query('DELETE FROM {project_issue_priority} WHERE priority = %d', $form_state['values']['pid']); + $form_state['redirect'] = 'admin/project/project-issue-priority'; + drupal_set_message(t('Project issue priority %name deleted.', array('%name' => $form_state['values']['name']))); + if (isset($form_state['values']['new_pid'])) { + $priority_weight = db_result(db_query('SELECT weight FROM {project_issue_priority} WHERE priority = %d', $form_state['values']['new_pid'])); + $arguments = array($form_state['values']['new_pid'], $priority_weight, $form_state['values']['pid']); + $update_sql = "UPDATE {project_issues} SET priority = %d, priority_weight = %d WHERE priority = %d AND nid BETWEEN %d AND %d"; + $batch = array( + 'operations' => array( + array('_project_issue_batch_update', array($update_sql, $arguments)), + ), + 'title' => t('Processing'), + // We use a single multi-pass operation, so the default + // 'Remaining x of y operations' message will be confusing here. + 'progress_message' => '', + 'error_message' => t('The update has encountered an error.'), + // The operations do not live in the .module file, so we need to + // tell the batch engine which file to load before calling them. + 'file' => drupal_get_path('module', 'project_issue') .'/includes/admin.batch_confirm.inc', + ); + batch_set($batch); + } +} Index: includes/admin.issue_status.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/admin.issue_status.inc,v retrieving revision 1.2 diff -u -p -r1.2 admin.issue_status.inc --- includes/admin.issue_status.inc 24 Apr 2010 01:13:33 -0000 1.2 +++ includes/admin.issue_status.inc 24 Apr 2010 01:56:21 -0000 @@ -183,11 +183,25 @@ function project_issue_delete_state_conf } function project_issue_delete_state_confirm_submit($form, &$form_state) { + db_query('DELETE FROM {project_issue_state} WHERE sid = %d', $form_state['values']['sid']); + $form_state['redirect'] = 'admin/project/project-issue-status'; + drupal_set_message(t('Project issue status %name deleted.', array('%name' => $form_state['values']['name']))); if ($form_state['values']['new_sid']) { - db_query('UPDATE {project_issues} SET sid = %d WHERE sid = %d', $form_state['values']['new_sid'], $form_state['values']['sid']); + $arguments = array($form_state['values']['new_sid'], $form_state['values']['sid']); + $update_sql = "UPDATE {project_issues} SET sid = %d WHERE sid = %d AND nid BETWEEN %d AND %d"; + $batch = array( + 'operations' => array( + array('_project_issue_batch_update', array($update_sql, $arguments)), + ), + 'title' => t('Processing'), + // We use a single multi-pass operation, so the default + // 'Remaining x of y operations' message will be confusing here. + 'progress_message' => '', + 'error_message' => t('The update has encountered an error.'), + // The operations do not live in the .module file, so we need to + // tell the batch engine which file to load before calling them. + 'file' => drupal_get_path('module', 'project_issue') .'/includes/admin.batch_confirm.inc', + ); + batch_set($batch); } - db_query('DELETE FROM {project_issue_state} WHERE sid = %d', $form_state['values']['sid']); - drupal_set_message(t('Project issue status %issue deleted.', array('%issue' => $form_state['values']['name']))); - $form_state['redirect'] ='admin/project/project-issue-status'; } - Index: includes/comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/comment.inc,v retrieving revision 1.158 diff -u -p -r1.158 comment.inc --- includes/comment.inc 22 Apr 2010 09:34:54 -0000 1.158 +++ includes/comment.inc 24 Apr 2010 01:56:21 -0000 @@ -571,8 +571,10 @@ function project_issue_update_by_comment // the updates to the issue with the latest available published comment. $comment_data = project_issue_get_newest_comment($comment_data); + $priority_weight = db_result(db_query('SELECT weight FROM {project_issue_priority} WHERE priority = %d', $comment_data->priority)); + // Update the issue data to reflect the new final states. - db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d WHERE nid = %d", $comment_data->pid, $comment_data->category, $comment_data->component, $comment_data->priority, $comment_data->rid, $comment_data->assigned, $comment_data->sid, $comment_data->nid); + db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d, priority_weight = %d WHERE nid = %d", $comment_data->pid, $comment_data->category, $comment_data->component, $comment_data->priority, $comment_data->rid, $comment_data->assigned, $comment_data->sid, $priority_weight, $comment_data->nid); // Update the issue title. $node = node_load($comment_data->nid, NULL, TRUE); // Don't use cached since we changed data above. Index: includes/issue_node_form.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/issue_node_form.inc,v retrieving revision 1.6 diff -u -p -r1.6 issue_node_form.inc --- includes/issue_node_form.inc 20 Apr 2010 07:05:25 -0000 1.6 +++ includes/issue_node_form.inc 24 Apr 2010 01:56:21 -0000 @@ -215,7 +215,7 @@ function _project_issue_form($node, $for } } $categories = array_merge(array(t('')), project_issue_category(0, 0)); - $priorities = project_issue_priority(); + $priorities = project_issue_priorities(); $states = project_issue_state(0, TRUE, !empty($node->nid) && ($node->uid == $user->uid), $node->project_issue['sid']); $assigned = project_issue_assigned_choices($node); } @@ -238,6 +238,7 @@ function _project_issue_form($node, $for ); } + $priority = $node->project_issue['priority'] ? $node->project_issue['priority'] : variable_get('project_issue_priority_default', 2); if ($allow_metadata_changes) { $form['project_info'] = array( '#type' => 'fieldset', @@ -286,7 +287,7 @@ function _project_issue_form($node, $for $form['issue_info']['priority'] = array( '#type' => 'select', '#title' => t('Priority'), - '#default_value' => $node->project_issue['priority'] ? $node->project_issue['priority'] : 2, + '#default_value' => $priority, '#options' => $priorities, ); $form['issue_info']['assigned'] = array( @@ -340,7 +341,7 @@ function _project_issue_form($node, $for ); $form['project_issue']['priority'] = array( '#type' => 'value', - '#value' => $node->project_issue['priority'], + '#value' => $priority, ); $form['project_issue']['assigned'] = array( '#type' => 'value', @@ -475,10 +476,11 @@ function _project_issue_insert($node) { $original_issue_data->$field = $node->$field; } - db_query("INSERT INTO {project_issues} (nid, pid, category, component, priority, rid, assigned, sid, original_issue_data, last_comment_id, db_lock) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->pid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, serialize($original_issue_data), 0, 0); + $priority_weight = db_result(db_query('SELECT weight FROM {project_issue_priority} WHERE priority = %d', $node->priority)); + + db_query("INSERT INTO {project_issues} (nid, pid, category, component, priority, rid, assigned, sid, original_issue_data, last_comment_id, db_lock, priority_weight) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, '%s', %d, %d, %d)", $node->nid, $node->pid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, serialize($original_issue_data), 0, 0, $priority_weight); // Invalidate the "Issue cockpit" block cache for this project, since the // new issue will have altered the summary totals. cache_clear_all('project_issue_cockpit_block:'. $node->pid, 'cache'); } - Index: includes/mail.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/mail.inc,v retrieving revision 1.125 diff -u -p -r1.125 mail.inc --- includes/mail.inc 17 Apr 2010 22:04:49 -0000 1.125 +++ includes/mail.inc 24 Apr 2010 01:56:21 -0000 @@ -62,7 +62,7 @@ function _project_issue_mailhandler($nod } break; case 'priority': - if (($priority = array_search($node->project_issue[$text], project_issue_priority()))) { + if (($priority = array_search($node->project_issue[$text], project_issue_priorities()))) { $entry->project_issue['priority'] = $priority; } break; cvs diff: Diffing scripts cvs diff: Diffing search_index cvs diff: Diffing theme cvs diff: Diffing translations cvs diff: Diffing views Index: views/project_issue.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/views/project_issue.views.inc,v retrieving revision 1.9 diff -u -p -r1.9 project_issue.views.inc --- views/project_issue.views.inc 18 Jun 2009 03:48:53 -0000 1.9 +++ views/project_issue.views.inc 24 Apr 2010 01:56:21 -0000 @@ -114,7 +114,7 @@ function project_issue_views_data() { 'click sortable' => TRUE, ), 'sort' => array( - 'handler' => 'views_handler_sort', + 'handler' => 'project_issue_handler_sort_issue_priority_weight', 'help' => t("Sort by the issue's priority."), ), 'filter' => array( @@ -220,6 +220,9 @@ function project_issue_views_handlers() 'project_issue_handler_filter_issue_version' => array( 'parent' => 'views_handler_filter_in_operator', ), + 'project_issue_handler_sort_issue_priority_weight' => array( + 'parent' => 'views_handler_sort', + ), ), ); } cvs diff: Diffing views/default_views cvs diff: Diffing views/handlers Index: views/handlers/project_issue_handler_field_issue_priority.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/views/handlers/project_issue_handler_field_issue_priority.inc,v retrieving revision 1.2 diff -u -p -r1.2 project_issue_handler_field_issue_priority.inc --- views/handlers/project_issue_handler_field_issue_priority.inc 20 Jan 2009 18:38:04 -0000 1.2 +++ views/handlers/project_issue_handler_field_issue_priority.inc 24 Apr 2010 01:56:21 -0000 @@ -10,5 +10,12 @@ class project_issue_handler_field_issue_ module_load_include('inc', 'project_issue', 'issue'); return check_plain(project_issue_priority($values->{$this->field_alias})); } -} + function click_sort($order) { + // Reverse the sort order since more important priorities are weighted + // lighter. + $order = ($order == 'asc') ? 'desc' : 'asc'; + // Override the sort field, since we are storing denormalized weight. + $this->query->add_orderby($this->table, 'priority_weight', $order); + } +} Index: views/handlers/project_issue_handler_filter_issue_priority.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/views/handlers/project_issue_handler_filter_issue_priority.inc,v retrieving revision 1.2 diff -u -p -r1.2 project_issue_handler_filter_issue_priority.inc --- views/handlers/project_issue_handler_filter_issue_priority.inc 20 Jan 2009 18:38:04 -0000 1.2 +++ views/handlers/project_issue_handler_filter_issue_priority.inc 24 Apr 2010 01:56:21 -0000 @@ -8,7 +8,7 @@ class project_issue_handler_filter_issue_priority extends views_handler_filter_in_operator { function get_value_options() { module_load_include('inc', 'project_issue', 'issue'); - $this->value_options = project_issue_priority(); + $this->value_options = project_issue_priorities(); } } Index: views/handlers/project_issue_handler_sort_issue_priority_weight.inc =================================================================== RCS file: views/handlers/project_issue_handler_sort_issue_priority_weight.inc diff -N views/handlers/project_issue_handler_sort_issue_priority_weight.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views/handlers/project_issue_handler_sort_issue_priority_weight.inc 24 Apr 2010 01:56:21 -0000 @@ -0,0 +1,16 @@ +ensure_my_table(); + // Reverse the sort order since more important priorities are weighted + // lighter. + $order = ($this->options['order'] == 'asc') ? 'desc' : 'asc'; + // Override the field name, since we are storing a denormalized weight. + $this->query->add_orderby($this->table_alias, 'priority_weight', $order); + } +} cvs diff: Diffing views/plugins