? LICENSE.txt ? comment.inc.new ? iaf.txt ? ifac.patch.txt Index: comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v retrieving revision 1.83 diff -u -p -r1.83 comment.inc --- comment.inc 30 Jul 2007 14:31:36 -0000 1.83 +++ comment.inc 5 Aug 2007 15:27:57 -0000 @@ -2,142 +2,90 @@ // $Id: comment.inc,v 1.83 2007/07/30 14:31:36 dww Exp $ // $Name: $ -function project_comment_page($op, $nid) { - - // Load the parent node. - $node = node_load($nid); - - if (user_access('create project issues')) { - $edit = (object)$_POST; - - if ($_POST['op'] == t('Preview') || $_POST['op'] == t('Submit')) { - project_comment_validate($edit); - } else { - foreach (array('nid', 'type', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { - $edit->$var = $node->$var; - } - project_comment_validate($edit); - } - $output .= drupal_get_form('project_comment_form', $edit); - - // set breadcrumb - $project = node_load(array('nid' => $node->pid)); - $breadcrumb[] = l($project->title, 'node/'. $project->nid); - $breadcrumb[] = l(t('Issues'), 'project/issues/'. $project->uri); - $breadcrumb[] = l($node->title, 'node/'. $node->nid); - project_project_set_breadcrumb($project, $breadcrumb); - - drupal_set_title(t('New comment')); - switch ($_POST['op'] ? $_POST['op'] : arg(2)) { - case 'add': - $output .= node_view($node, NULL, TRUE); - return $output; - break; - case t('Preview'): - return $output; - break; - case t('Submit'): - if (!form_get_errors()) { - $edit->nid = $node->nid; - - project_comment_save($edit); - drupal_goto("node/$node->nid"); - } else { - return $output; - } - break; - } - } - else { - drupal_set_message(t('You are not authorized to follow up on issues.'), 'error'); - drupal_goto("node/$nid"); +function project_issue_comment(&$arg, $op) { + static $edit; + // $arg can be a comment object, or a form or form_values. + if (is_object($arg)) { + $nid = $arg->nid; } -} - -function project_comment_form($edit, $param = NULL) { - $op = $_POST['op']; - if (isset($param)) { - $form = array( - '#method' => $param['method'], - '#action' => $param['action'], - '#attributes' => $param['options'], - ); - } else { - $form['#attributes'] = array('enctype' => 'multipart/form-data'); - } - $form['#prefix'] = '
'; - $form['#suffix'] = '
'; - $form['project_issue_form'] = project_issue_form($edit, $param); - unset($form['project_issue_form']['#prefix']); - unset($form['project_issue_form']['#suffix']); - - _project_issue_form_add_required_fields($form['project_issue_form'], FALSE); - if ($edit->cid) { - $form['cid']= array('#type' => 'hidden', '#value' => $edit->cid); - } - $form['preview'] = array('#type' => 'button', '#value' => t('Preview')); - if (!form_get_errors()) { - $form['submit'] = array('#type' => 'button', '#value' => t('Submit')); - } - if ($op == t('Preview')) { - $form['#after_build'] = array('project_comment_form_add_preview'); + elseif (is_array($arg)) { + $nid = is_array($arg['nid']) ? $arg['nid']['#value'] : $arg['nid']; } - return $form; -} - -function project_comment_validate(&$edit) { - global $user; - - $edit->uid = $user->uid; - $edit->name = $user->name; - - if ($edit->cid) { - $comment = project_comment_load($edit->cid); - $edit->nid = $comment->nid; + $node = node_load($nid); + if ($node->type != 'project_issue') { + return; } - $edit->comment = true; - - project_issue_comment_validate($edit); - $edit->validated = true; -} - -function project_comment_view($node, $main = 0) { - global $user; - $rows = array(); - $result = db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.nid = %d ORDER BY p.created ASC', $node->nid); - if (db_num_rows($result)) { - $output = '
'; - $i = 0; - while ($comment = db_fetch_object($result)) { - $comment->body = db_decode_blob($comment->body); - $comment->data = db_decode_blob($comment->data); - $i++; - $output .= _project_comment_view_single($comment, $i); + switch ($op) { + case 'form': + // $arg is a form + if (!$node->comment_count) { + foreach (array('nid', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { + $edit->$var = $node->$var; + } + } + else { + $edit = db_fetch_object(db_query_range('SELECT nid, title, pid, rid, component, category, priority, assigned, sid, timestamp FROM {project_issue_comments} WHERE nid = %d ORDER BY timestamp DESC ', $node->nid, 0, 1)); + } + $form = drupal_retrieve_form('project_issue_form', $edit, NULL); + $form['project_info']['#tree'] = TRUE; + $form['project_info']['#weight'] = -2; + $form['issue_info']['#weight'] = -1; + $form['#prefix'] = '
'; + $form['#suffix'] = '
'; + $form['title'] = array( + '#type' => 'textfield', + '#title' => t('Issue title'), + '#maxlength' => 64, + '#default_value' => $edit->title, + '#weight' => 0, + ); + unset($form['page'], $form['issue_details']); + return $form; + case 'validate': + $test = $arg; + $test['pid'] = $arg['project_info']['pid']; + $test['component'] = $arg['project_info']['component']; + if (!array_diff(array_filter((array)$edit), $arg)) { + form_set_error('body', t('You must either specify a description or change something about this issue.')); + } + break; + case 'insert': case 'update': + // $arg is form_values + db_query("INSERT INTO {project_issue_comments} (nid, cid, pid, rid, component, category, priority, assigned, sid, title, timestamp) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d, '%s', %d)", $arg['nid'], $arg['cid'], $arg['project_info']['pid'], $arg['rid'], $arg['project_info']['component'], $arg['category'], $arg['priority'], $arg['assigned'], $arg['sid'], $arg['title'], $arg['timestamp']); + project_issue_update($arg); + return; + case 'view': + if (isset($arg->cid)) { + $project_issue_table = project_issue_comment_view($node, $arg); + } + else { + $test = drupal_clone($arg); + $test->pid = $arg->project_info['pid']; + $test->component = $arg->project_info['component']; + $project_issue_table = _project_issue_comment_table(_project_issue_comment_labels(), $edit, $test); + } + if ($project_issue_table) { + $arg->comment = '
'. $project_issue_table .'
' . $arg->comment; + } + break; } - $output .= '
'; - return theme('box', t('Updates'), $output); - } } /** - * Private method to view a single project comment (issue followup). - * - * @param $comment - * An array or object of the comment to view. - * @param $count - * The integer that shows what number of comment this is. - * - * @return - * A string of validated output to theme/display. - * + * Implementation of hook_form_alter. */ -function _project_comment_view_single($comment, $count) { - $comment = (object)$comment; - $summary = array(); - $output = ''; +function project_issue_form_alter($form_id, &$form) { + if ($form_id == 'comment_form') { + $node = node_load($form['nid']['#value']); + if ($node->type == 'project_issue') { + unset($form['comment_filter']['comment']['#required'], $form['_author']); + } + } +} - $fields = array( +function _project_issue_comment_labels() { + return array( 'title' => t('Title'), 'pid' => t('Project'), 'rid' => t('Version'), @@ -147,154 +95,58 @@ function _project_comment_view_single($c 'assigned' => t('Assigned to'), 'sid' => t('Status'), ); - - // If we got this from the DB, we'll have a $data field to unserialize. - $comment = drupal_unpack($comment); - - // Print out what changed about the issue with this comment. If the - // comment is in the DB, we'll have 'old' and 'new' fields from the - // 'data' field, which record exactly what changed. If not, we'll - // load the origial node and compare against that. - if (!isset($comment->data)) { - $node = node_load(array('nid' => arg(3), 'type' => 'project_issue')); - } - foreach ($fields as $field => $text) { - if (isset($comment->old->$field) && isset($comment->new->$field)) { - $summary[] = array( - $text .':', - project_mail_summary($field, $comment->old->$field), - '» '. project_mail_summary($field, $comment->new->$field) - ); - } - elseif (isset($node->$field) && isset($comment->$field) && $node->$field != $comment->$field ) { - $summary[] = array( - $text .':', - project_mail_summary($field, $node->$field), - '» '. project_mail_summary($field, $comment->$field) - ); - } - } - - if ($comment->file_path && file_exists($comment->file_path)) { - $summary[] = array(t('Attachment:'), ''. basename($comment->file_path) .' ('. format_size($comment->file_size) .')'); - } - - if ($summary || $comment->body) { - if ($count) { - $output .= '
'; - $output .= t('!count submitted by !user on !date', array('!count' => l("#$count", "node/$comment->nid", array ('id' => "comment-$comment->cid", 'name' => "comment-$comment->cid"), NULL, "comment-$comment->cid"), '!user' => theme('username', $comment), '!date' => format_date($comment->created))) . theme('mark', node_mark($comment->nid, $comment->changed)); - $output .= '
'; - } - if ($summary) { - $output .= '
'; - $output .= theme('table', array(), $summary); - $output .= '
'; - } - if ($comment->body) { - $output .= '
'; - $output .= check_markup($comment->body); - $output .= '
'; - } - } - return $output; } -function project_comment_load($cid) { - $object = db_fetch_object(db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.cid = %d ORDER BY p.created DESC', $cid)); - $object->body = db_decode_blob($object->body); - $object->data = db_decode_blob($object->data); - return $object; -} - -function project_comment_save($edit) { - global $user; - - if (empty($edit->cid)) { - $edit->cid = db_next_id('{project}_cid'); - if ($edit->file) { - $directory = file_create_path(variable_get('project_directory_issues', 'issues')); - $edit->file->filename = project_issue_munge_filename($edit->file->filename); - $file = file_save_upload($edit->file, $directory); - unset($edit->file); - } - - if (empty($edit->uid)) { - $edit->uid = $user->uid; - } - $node = node_load(array('nid' => $edit->nid, 'type' => 'project_issue')); - - // Check if comment changed any of the state values and update the node if necessary - foreach (array('pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { - if ($node->$var != $edit->$var) { - $data['old']->$var = $node->$var; - $data['new']->$var = $edit->$var; - $node->$var = $edit->$var; - } - } - - // Add processed cck info into the node object for node_save - if (function_exists('_content_widget_invoke')) { - $type = content_types($node->type); - while (list($field, $val) = each($type['fields'])) { - $node->$field = $edit->$field; - } - _content_widget_invoke('process form values', $node); +/** + * Create a project issue metadata table. + * + * @param $labels + * An array, keys are field names, values are the displayed labels. + * @param $old + * The previous comment (or the node). + * @param $followup + * The current comment. + */ +function _project_issue_comment_table($labels, $old, $followup) { + $rows = array(); + foreach ($labels as $field => $text) { + if ($old->$field != $followup->$field) { + $rows[] = array( + $labels[$field] .':', + project_mail_summary($field, $old->$field), + '» '. project_mail_summary($field, $followup->$field), + ); } - - watchdog('content', t('project_issue: added comment %title', array('%title' => $edit->title)), WATCHDOG_NOTICE, l('view', "node/$node->nid")); - $node->changed = time(); - db_query("INSERT INTO {project_comments} (cid, nid, uid, created, changed, body, data, file_path, file_mime, file_size) VALUES (%d, %d, %d, %d, %d, %b, %b, '%s', '%s', %d)", $edit->cid, $edit->nid, $edit->uid, $node->changed, $node->changed, $edit->body, serialize($data), $file->filepath, $file->filemime, $file->filesize); - - // Update node_comment_statistics so the tracker page lists the number of comments - $count = db_result(db_query('SELECT COUNT(cid) FROM {project_comments} WHERE nid = %d', $edit->nid)); - db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, time(), $user->name, $user->uid, $edit->nid); - - node_save($node); } - - return $edit->cid; + return theme('table', array(), $rows); } /** - * Form API callback for previewing a project comment. - * - * @param $form - * The form to add the preview information to. - * @param $edit - * The form values for the comment to preview. + * Returns the issue metadata table for a comment, adjusts node title. * + * @param $node + * The corresponding node. + * @param $comment + * The comment, if it's set then metadata will be returned. If it's not + * set then node title will be adjusted (and metadata precalculated). * @return - * The modified form to render. - * + * A themed table of issue metadata. */ -function project_comment_form_add_preview($form, $edit) { - drupal_set_title(t('Preview comment')); - if (is_array($edit)) { - $comment = (object)$edit; - } - else { - $comment = $edit; - } - project_comment_validate($comment); +function project_issue_comment_view(&$node, $comment = NULL) { + static $project_issue_tables; - // Preview the comment with security check. - if (!form_get_errors()) { - $output = _project_comment_view_single($comment, 0); + if (isset($comment)) { + return $project_issue_tables[$comment->cid]; } - - $form['comment_preview'] = array( - '#value' => $output, - '#weight' => -100, - '#prefix' => '
', - '#suffix' => '
', - ); - - $output = ''; - if (is_numeric(arg(3))) { - $node = node_load(array('nid' => arg(3), 'type' => 'project_issue')); - $output .= node_view($node, NULL, TRUE); - $form['comment_preview_below'] = array('#value' => $output, '#weight' => 100); + if ($node->comment_count) { + $old = $node; + $labels = _project_issue_comment_labels(); + $result = db_query('SELECT cid, title, pid, rid, component, category, priority, assigned, sid FROM {project_issue_comments} WHERE nid = %d ORDER BY timestamp ASC', $node->nid); + while ($followup = db_fetch_object($result)) { + $project_issue_tables[$followup->cid] = _project_issue_comment_table($labels, $old, $followup); + $old = $followup; + } + $node->title = $old->title; + drupal_set_title(check_plain($node->title)); } - unset($form['#sorted']); - return $form; } Index: issue.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v retrieving revision 1.242 diff -u -p -r1.242 issue.inc --- issue.inc 3 Aug 2007 19:07:02 -0000 1.242 +++ issue.inc 5 Aug 2007 15:27:58 -0000 @@ -924,10 +924,6 @@ function project_issue_view($node, $teas '#value' => '
'. t('Description') .'
', '#weight' => -3, ); - $node->content['project_issue_comments'] = array( - '#value' => project_comment_view($node), - '#weight' => 2, - ); // Breadcrumb navigation $breadcrumb[] = array('path' => 'project', 'title' => t('Projects')); @@ -1931,7 +1927,7 @@ function project_issue_query_rss($result $channel['title'] = variable_get('site_name', 'drupal') .' - '. t('issues'); } $channel['link'] = url('project/issues', NULL, NULL, TRUE); // not 100% correct - + node_feed($result, $channel); } Index: mail.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/mail.inc,v retrieving revision 1.72 diff -u -p -r1.72 mail.inc --- mail.inc 7 May 2007 19:47:09 -0000 1.72 +++ mail.inc 5 Aug 2007 15:27:58 -0000 @@ -196,6 +196,7 @@ function project_mail_summary($field, $v } function project_mail_notify($node) { + return; if (defined('PROJECT_NOMAIL')) { return; } Index: project_issue.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v retrieving revision 1.10 diff -u -p -r1.10 project_issue.install --- project_issue.install 13 Jul 2007 03:29:27 -0000 1.10 +++ project_issue.install 5 Aug 2007 15:27:59 -0000 @@ -4,7 +4,7 @@ function project_issue_install() { // We need to check this before we try to create the table, so that - // if it already exists, we don't attempt to insert our own values. + // if it already exists, we don't attempt to insert our own values. $project_issue_state_existed = db_table_exists('project_issue_state'); switch ($GLOBALS['db_type']) { case 'mysql': @@ -20,7 +20,7 @@ function project_issue_install() { mail_copy_filter_state varchar(255) NOT NULL default '', mail_reminder tinyint(4) NOT NULL default '0', PRIMARY KEY (nid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); db_query("CREATE TABLE IF NOT EXISTS {project_issues} ( nid int(10) unsigned NOT NULL default '0', pid int(10) unsigned NOT NULL default '0', @@ -35,28 +35,28 @@ function project_issue_install() { file_size int NOT NULL default 0, PRIMARY KEY (nid), KEY project_issues_pid (pid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE IF NOT EXISTS {project_comments} ( - cid int(10) unsigned NOT NULL default '0', - nid int(10) unsigned NOT NULL default '0', - uid int(10) unsigned NOT NULL default '0', - name varchar(255) NOT NULL default '', - created int(10) unsigned NOT NULL default '0', - changed int(10) unsigned NOT NULL default '0', - body blob, - data blob, - file_path varchar(255) NOT NULL default '', - file_mime varchar(255) NOT NULL default '', - file_size int NOT NULL default 0, - PRIMARY KEY (cid), - KEY project_comments_nid (nid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); + db_query("CREATE TABLE IF NOT EXISTS {project_issue_comments} ( + nid int(11) default NULL, + cid int(11) default NULL, + rid int(11) default NULL, + component varchar(255) default NULL, + category varchar(255) default NULL, + priority int(11) default NULL, + assigned int(11) default NULL, + sid int(11) default NULL, + pid int(10) unsigned NOT NULL, + title varchar(255) NOT NULL, + timestamp int(10) unsigned NOT NULL, + PRIMARY KEY(cid), + INDEX nid_timestamp (nid, timestamp) + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); db_query("CREATE TABLE IF NOT EXISTS {project_subscriptions} ( nid int(10) unsigned NOT NULL default '0', uid int(10) unsigned NOT NULL default '0', level tinyint(3) unsigned NOT NULL default '0', KEY project_subscriptions_nid_uid_level (nid, uid, level) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); db_query("CREATE TABLE IF NOT EXISTS {project_issue_state} ( sid int(10) unsigned NOT NULL auto_increment, name varchar(32) NOT NULL default '', @@ -64,7 +64,7 @@ function project_issue_install() { author_has tinyint(2) DEFAULT '0' NOT NULL, default_query tinyint(2) DEFAULT '0' NOT NULL, PRIMARY KEY (sid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + ) /*!40100 DEFAULT CHARACTER SET utf8 */"); break; case 'pgsql': @@ -80,7 +80,7 @@ function project_issue_install() { mail_copy_filter_state varchar(255) default '' not null, mail_reminder smallint NOT NULL default '0', PRIMARY KEY (nid) - );"); + )"); } if (!db_table_exists('project_issues')) { db_query("CREATE TABLE {project_issues} ( @@ -96,31 +96,31 @@ function project_issue_install() { file_mime varchar(255) default '' NOT NULL, file_size int default 0 NOT NULL, PRIMARY KEY (nid) - );"); + )"); } - if (!db_table_exists('project_comments')) { - db_query("CREATE TABLE {project_comments} ( - cid int NOT NULL default '0', - nid int NOT NULL default '0', - uid int NOT NULL default '0', - name varchar(255) NOT NULL default '', - created int NOT NULL default '0', - changed int NOT NULL default '0', - body bytea, - data bytea, - file_path varchar(255) default '' NOT NULL, - file_mime varchar(255) default '' NOT NULL, - file_size int default 0 NOT NULL, - PRIMARY KEY (cid) - );"); - db_query("CREATE SEQUENCE {project}_cid_seq INCREMENT 1 START 1"); + if (!db_table_exists('project_issue_comments')) { + db_query("CREATE TABLE {project_issue_comments} ( + nid int default NULL, + cid int default NULL, + rid int default NULL, + component varchar(255) default NULL, + category varchar(255) default NULL, + priority int default NULL, + assigned int default NULL, + sid int default NULL, + pid int unsigned NOT NULL, + title varchar(255) NOT NULL, + timestamp int unsigned NOT NULL, + PRIMARY KEY(cid) + )"); + db_query('CREATE INDEX {project_issue_comments}_nid_timestamp_idx ON {project_issue_comments} (nid, timestamp)'); } if (!db_table_exists('project_subscriptions')) { db_query("CREATE TABLE {project_subscriptions} ( nid int NOT NULL default '0', uid int NOT NULL default '0', level smallint NOT NULL default '0' - );"); + )"); } if (!db_table_exists('project_issue_state')) { db_query("CREATE TABLE {project_issue_state} ( @@ -130,7 +130,7 @@ function project_issue_install() { author_has smallint DEFAULT '0' NOT NULL, default_query smallint DEFAULT '0' NOT NULL, PRIMARY KEY (sid) - );"); + )"); } break; } Index: project_issue.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.module,v retrieving revision 1.34 diff -u -p -r1.34 project_issue.module --- project_issue.module 3 Aug 2007 01:19:10 -0000 1.34 +++ project_issue.module 5 Aug 2007 15:27:59 -0000 @@ -141,31 +141,6 @@ function project_issue_cron() { } } -function project_issue_link($type, $node = 0, $main = 0) { - $links = array(); - switch ($type) { - case 'node': - if ($node->type == 'project_issue' && - !(arg(0) == 'project' && arg(1) == 'comments')) { - // Only add the link if we're not already on an issue follow-up. - if (user_access('create project issues')) { - $links['project_issue_follow_up'] = array( - 'title' => t('Follow up'), - 'href' => "project/comments/add/$node->nid", - ); - } - else { - $links['project_issue_follow_up_forbidden'] = array( - 'title' => theme('project_issue_follow_up_forbidden', $node->nid), - 'html' => TRUE, - ); - } - } - break; - } - return $links; -} - function project_issue_menu($may_cache) { $items = array(); global $user; @@ -292,6 +267,10 @@ function project_issue_menu($may_cache) 'type' => MENU_LOCAL_TASK, ); } + if ($node->type == 'project_issue') { + $_GET['mode'] = COMMENT_MODE_FLAT_EXPANDED; + $_GET['sort'] = COMMENT_ORDER_OLDEST_FIRST; + } } // Reply to issues if (arg(0) == 'project' && arg(1) == 'comments' && arg(2) == 'add' && is_numeric(arg(3))) { @@ -490,6 +469,9 @@ function project_issue_issue_nodeapi(&$n form_set_error('sid', t('Invalid issue status %status: you do not have permission to set this status', array('%status' => $state))); } break; + case 'view': + project_issue_comment_view($node); + break; } }