From 9bcb5f9456b72b565faf56b3c97bb71fbf98c565 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Tue, 31 May 2011 10:51:24 +0200 Subject: [PATCH] Fix a PHP notice / Pluf exception in case any issue type field is cleared. --- src/IDF/Form/IssueCreate.php | 39 +++++++++++++++++++----------------- src/IDF/Form/IssueUpdate.php | 3 +++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/IDF/Form/IssueCreate.php b/src/IDF/Form/IssueCreate.php index c295ca1..3f89988 100644 --- a/src/IDF/Form/IssueCreate.php +++ b/src/IDF/Form/IssueCreate.php @@ -373,25 +373,28 @@ class IDF_Form_IssueCreate extends Pluf_Form foreach ($tags as $tag) { $issue->setAssoc($tag); } - // add relations - $verb = $this->cleaned_data['relation_type0']; - $other_verb = $this->relation_types[$verb]; - $related_issues = preg_split('/\s*,\s*/', $this->cleaned_data['relation_issue0'], -1, PREG_SPLIT_NO_EMPTY); - foreach ($related_issues as $related_issue_id) { - $related_issue = new IDF_Issue($related_issue_id); - $rel = new IDF_IssueRelation(); - $rel->issue = $issue; - $rel->verb = $verb; - $rel->other_issue = $related_issue; - $rel->submitter = $this->user; - $rel->create(); + // add relations (if any) + if (!empty($this->cleaned_data['relation_type0'])) { + $verb = $this->cleaned_data['relation_type0']; + $other_verb = $this->relation_types[$verb]; + $related_issues = preg_split('/\s*,\s*/', $this->cleaned_data['relation_issue0'], -1, PREG_SPLIT_NO_EMPTY); - $other_rel = new IDF_IssueRelation(); - $other_rel->issue = $related_issue; - $other_rel->verb = $other_verb; - $other_rel->other_issue = $issue; - $other_rel->submitter = $this->user; - $other_rel->create(); + foreach ($related_issues as $related_issue_id) { + $related_issue = new IDF_Issue($related_issue_id); + $rel = new IDF_IssueRelation(); + $rel->issue = $issue; + $rel->verb = $verb; + $rel->other_issue = $related_issue; + $rel->submitter = $this->user; + $rel->create(); + + $other_rel = new IDF_IssueRelation(); + $other_rel->issue = $related_issue; + $other_rel->verb = $other_verb; + $other_rel->other_issue = $issue; + $other_rel->submitter = $this->user; + $other_rel->create(); + } } // add the first comment diff --git a/src/IDF/Form/IssueUpdate.php b/src/IDF/Form/IssueUpdate.php index c4c7df0..0362eb3 100644 --- a/src/IDF/Form/IssueUpdate.php +++ b/src/IDF/Form/IssueUpdate.php @@ -208,6 +208,9 @@ class IDF_Form_IssueUpdate extends IDF_Form_IssueCreate $normRelatedIssues = array(); for ($idx = 0; isset($this->cleaned_data['relation_type'.$idx]); ++$idx) { $verb = $this->cleaned_data['relation_type'.$idx]; + if (empty($verb)) + continue; + $ids = preg_split('/\s*,\s*/', $this->cleaned_data['relation_issue'.$idx], -1, PREG_SPLIT_NO_EMPTY); if (count($ids) == 0)