svn: /pear2/BugManager/trunk/src/BugManager/ IssueDecorator/Mysql.php IssueManager/Mysql.php
| From: | Greg Beaver | Date: | Wed, 12 Aug 2009 00:33:54 +0000 |
| Subject: | svn: /pear2/BugManager/trunk/src/BugManager/ IssueDecorator/Mysql.php IssueManager/Mysql.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-cvs+get-57051@lists.php.net to get a copy of this message | ||
cellog Wed, 12 Aug 2009 00:33:54 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=287129
Log:
untested new code for bug updating
Changed paths:
U pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php
U pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php
Modified: pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php 2009-08-12 00:21:42 UTC (rev
287128)
+++ pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php 2009-08-12 00:33:54 UTC (rev
287129)
@@ -68,32 +68,116 @@
return 'INSERT INTO bugmanager_issues (' . implode(',',
array_keys($vals)) . ')
VALUES(' . implode(',', array_values($vals)) . ');';
}
-
- function getExtraInsertSql($id)
+
+ function getCommentInsertSql($id)
{
- $ret = '';
+ $ret = array();
settype($id, 'int');
if (count($this->bug->comments) > 1) {
foreach ($this->bug->comments as $i => $comment) {
if (!$i) {
continue;
}
- $ret .= "\nINSERT INTO bugmanager_comments
+ $ret["\nINSERT INTO bugmanager_comments
(bug_id, email, handle, reporter_name, ts, comment)
VALUES(" . $id . ',
"' . $this->manager->esc($comment->commenter->email) .
'",
"' . $this->manager->esc($comment->commenter->handle) .
'",
"' . $this->manager->esc($comment->commenter->name) .
'",
"' .
$this->manager->esc($comment->timestamp->format('Y-m-d H:i:s')) .
'",
- "' . $this->manager->esc($comment->comment) .
'");';
+ "' . $this->manager->esc($comment->comment) .
'");'] = $comment;
}
}
- // TODO: roadmap/attachments/external bug info
return $ret;
}
+ function getRoadmapInsertSql($id)
+ {
+ // TODO: roadmap/attachments/external bug info
+ return '';
+ }
+
+ function getAttachmentInsertSql($id)
+ {
+ // TODO: roadmap/attachments/external bug info
+ return '';
+ }
+
function getUpdateSQL()
{
-
+ $basicdiff = $this->bug->diff();
+ $updatearr = array();
+ $contextmap = array(
+ 'phpversion' => 'php_version',
+ 'operatingsystem' => 'php_os',
+ 'packagename' => 'package_name',
+ 'packageversion' => 'package_version',
+ 'bugtype' => 'package_name',
+ );
+ $map = array(
+ 'status' => 'status',
+ 'type' => 'bug_type',
+ 'summary' => 'sdesc',
+ 'createtimestamp' => 'ts1',
+ 'modifiedtimestamp' => 'ts2',
+ );
+ if (isset($basicdiff['reporter'])) {
+ $updatearr[] = 'handle="' .
$this->manager->esc($this->bug->reporter->handle) . '"';
+ $updatearr[] = 'email="' .
$this->manager->esc($this->bug->reporter->email) . '"';
+ $updatearr[] = 'reporter_name="' .
$this->manager->esc($this->bug->reporter->name) . '"';
+ if ($this->bug->reporter->karma) {
+ $updatearr[] = 'registered=1';
+ }
+ }
+ if (isset($basicdiff['assigned'])) {
+ $updatearr[] = 'assign="' . $this->manager->esc(
+ implode('|', array_map(function($a){return $a->handle;},
$this->bug->assigned))
+ );
+ }
+ foreach ($map as $key) {
+ $updatearr[] = $map[$key] . '="' .
$this->manager->esc($this->bug->$key) . '"';
+ }
+ if (isset($basicdiff['context'])) {
+ $contextdiff = $this->bug->diffContext();
+ foreach (array('added', 'deleted', 'changed') as $stuff)
{
+ foreach ($contextdiff[$stuff] as $key) {
+ if ($stuff !== 'deleted') {
+ $value = '"' .
+
$this->manager->esc($this->bug->context[$key]->value()) .
+ '"';
+ } else {
+ $value = 'NULL';
+ }
+ $updatearr[] = $contextmap[$key] . '=' . $value;
+ }
+ }
+ }
+ $sql = 'UPDATE bugmanager_issues SET ' . implode(',', $updatearr) .
+ ' WHERE id=' . $this->bug->id . ";\n";
+ $addsql = array();
+ if (isset($basicdiff['comments'])) {
+ $commentdiff = $this->bug->diffComments();
+ foreach ($commentdiff['deleted'] as $comment) {
+ $sql .= 'DELETE FROM bugmanager_comments WHERE id=' . $comment->id .
";\n";
+ }
+ foreach ($commentdiff['changed'] as $comment) {
+ $sql .= 'UPDATE bugmanager_comments SET
+ email="' .
$this->manager->esc($comment->commenter->email) . '",
+ handle="' .
$this->manager->esc($comment->commenter->handle) . '",
+ reporter_name="' .
$this->manager->esc($comment->commenter->name) . '",
+ ts="' . $comment->timestamp->format('Y-m-d
H:i:s') . '"
+ WHERE id=' . $commend->id . ";\n";
+ }
+ foreach ($commentdiff['added'] as $comment) {
+ $addsql['INSERT INTO bugmanager_comments
+ (bug_id, email, handle, reporter_name, ts)
+ VALUES(' . $this->bug->id . ',
+ "' . $this->manager->esc($comment->commenter->email) .
'",
+ "' . $this->manager->esc($comment->commenter->handle) .
'",
+ "' . $this->manager->esc($comment->commenter->name) .
'",
+ "' . $comment->timestamp->format('Y-m-d H:i:s') .
");\n"] = $comment;
+ }
+ }
+ return array($sql, $addsql);
}
}
Modified: pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php 2009-08-12 00:21:42 UTC (rev
287128)
+++ pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php 2009-08-12 00:33:54 UTC (rev
287129)
@@ -188,10 +188,21 @@
$sql = (string) $decorator;
$this->mysqli->query($sql);
$id = $this->mysqli->insert_id();
- $sql = $decorator->getExtraInsertSql($id);
+ $sql = $decorator->getCommentInsertSql($id);
if ($sql) {
- $this->mysqli->multi_query($sql);
+ foreach ($sql as $query => $comment) {
+ $this->mysqli->query($query);
+ $comment->id = $this->mysqli->insert_id();
+ }
}
+ $sql = $decorator->getRoadmapInsertSql($id);
+ if ($sql) {
+ $this->mysqli->query($sql);
+ }
+ $sql = $decorator->getAttachmentInsertSql($id);
+ if ($sql) {
+ $this->mysqli->query($sql);
+ }
return $id;
}
@@ -201,7 +212,12 @@
function update(Issue $bug)
{
$decorator = new \pear2\BugManager\IssueDecorator\Mysql($bug, $this);
- $sql = $decorator->getUpdateSQL();
+ list($sql, $addsql) = $decorator->getUpdateSQL();
+ $this->mysqli->multi_query($sql);
+ foreach ($addsql as $query => $comment) {
+ $this->mysqli->query($query);
+ $comment->id = $this->mysqli->insert_id();
+ }
}
/**