Index: project_issue.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v retrieving revision 1.174 diff -u -p -r1.174 project_issue.module --- project_issue.module 6 Aug 2009 23:35:34 -0000 1.174 +++ project_issue.module 8 Nov 2009 06:29:03 -0000 @@ -590,6 +590,60 @@ function project_issue_add_auto_followup } /** + * Update an existing project issue status option. + * + * @param $status + * An associative array specifying defining the new state. Required keys are: + * - name: the human readable text for this status + * - weight: when this status will appear in relation to other statuses + * - author_has: whether the author of an issue will see this status or not + * - default_query: whether this will be shown in default queries + * @param $sid + * The unique identifier for this status. + * + * @return + * TRUE if the status was successfully updated, FALSE if it wasn't. + */ +function project_issue_admin_states_update_status($status, $sid) { + $state = db_fetch_object(db_query('SELECT name, weight, author_has, default_query FROM {project_issue_state} WHERE sid = %d', $sid)); + // Check to see whether the record needs updating. + if (($state->name != $status['name']) || ($state->weight != $status['weight']) || ($state->author_has != $status['author_has']) || ($state->default_query != $status['default_query'])) { + db_query("UPDATE {project_issue_state} SET name = '%s', weight = %d, author_has = %d, default_query = %d WHERE sid = %d", $status['name'], $status['weight'], $status['author_has'], $status['default_query'], $sid); + return TRUE; + } + + return FALSE; +} + +/** + * Add a project issue status option. + * + * @param $status + * An associative array specifying defining the new state. Required keys are: + * - name: the human readable text for this status + * - weight: when this status will appear in relation to other statuses + * - author_has: whether the author of an issue will see this status or not + * - default_query: whether this will be shown in default queries + * @param $sid + * The unique identifier for this status. + * + * @return + * TRUE if the status was successfully added, FALSE if it wasn't. + */ +function project_issue_admin_states_add_status($status) { + // Check to see whether the state already exists: + $issue_state = db_result(db_query("SELECT COUNT(*) FROM {project_issue_state} WHERE name = '%s'", $status['name'])); + if (empty($issue_state)) { + db_query("INSERT INTO {project_issue_state} (name, weight, author_has, default_query) VALUES ('%s', %d, %d, %d)", $status['name'], $status['weight'], $status['author_has'], $status['default_query']); + return TRUE; + } + else { + drupal_set_message(t('Status %status already exists.', array ('%status' => $status['name'])), 'error'); + return FALSE; + } +} + +/** * Saves a comment to the database. * * TODO: Ideally this should die as soon as core's comment_save() becomes more Index: includes/admin.issue_status.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/includes/admin.issue_status.inc,v retrieving revision 1.1 diff -u -p -r1.1 admin.issue_status.inc --- includes/admin.issue_status.inc 4 Apr 2009 07:03:28 -0000 1.1 +++ includes/admin.issue_status.inc 8 Nov 2009 06:29:03 -0000 @@ -125,23 +125,12 @@ function project_issue_admin_states_form // Update existing status options. if($form_state['values']['status']) { foreach ($form_state['values']['status'] as $sid => $value) { - $state = db_fetch_object(db_query('SELECT name, weight, author_has, default_query FROM {project_issue_state} WHERE sid = %d', $sid)); - // Check to see whether the record needs updating. - if (($state->name != $value['name']) || ($state->weight != $value['weight']) || ($state->author_has != $value['author_has']) || ($state->default_query != $value['default_query'])) { - db_query("UPDATE {project_issue_state} SET name = '%s', weight = %d, author_has = %d, default_query = %d WHERE sid = %d", $value['name'], $value['weight'], $value['author_has'], $value['default_query'], $sid); - } + project_issue_admin_states_update_status($value, $sid); } } // Add any new status options. if (isset($form_state['values']['status_add']) && !empty($form_state['values']['status_add']['name'])) { - // Check to see whether the state already exists: - $issue_state = db_result(db_query("SELECT COUNT(*) FROM {project_issue_state} WHERE name = '%s'", $form_state['values']['status_add']['name'])); - if (empty($issue_state)) { - db_query("INSERT INTO {project_issue_state} (name, weight, author_has, default_query) VALUES ('%s', %d, %d, %d)", $form_state['values']['status_add']['name'], $form_state['values']['status_add']['weight'], $form_state['values']['status_add']['author_has'], $form_state['values']['status_add']['default_query']); - } - else { - drupal_set_message(t('Status %status already exists.', array ('%status' => $form_state['values']['status_add']['name'])), 'error'); - } + project_issue_admin_states_add_status($form_state['values']['status_add']); } }