svn: /pear2/BugManager/trunk/src/BugManager/ Comment.php IssueDecorator/Mysql.php IssueManager/Mysql.php
| From: | Greg Beaver | Date: | Sat, 15 Aug 2009 17:39:41 +0000 |
| Subject: | svn: /pear2/BugManager/trunk/src/BugManager/ Comment.php IssueDecorator/Mysql.php IssueManager/Mysql.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-cvs+get-57159@lists.php.net to get a copy of this message | ||
cellog Sat, 15 Aug 2009 17:39:41 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=287346
Log:
move all the insert sql into the mysql class where it belongs, update is next
Changed paths:
U pear2/BugManager/trunk/src/BugManager/Comment.php
U pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php
U pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php
Modified: pear2/BugManager/trunk/src/BugManager/Comment.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/Comment.php 2009-08-15 17:25:16 UTC (rev 287345)
+++ pear2/BugManager/trunk/src/BugManager/Comment.php 2009-08-15 17:39:41 UTC (rev 287346)
@@ -55,7 +55,7 @@
function __get($var)
{
if (array_key_exists($var, $this->info)) {
- if ($var !== 'commenter') {
+ if ($var !== 'commenter' && $var !== 'timestamp') {
return Issue::escape($this->info[$var]);
}
return $this->info[$var];
Modified: pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php 2009-08-15 17:25:16 UTC (rev
287345)
+++ pear2/BugManager/trunk/src/BugManager/IssueDecorator/Mysql.php 2009-08-15 17:39:41 UTC (rev
287346)
@@ -39,38 +39,6 @@
$this->manager = $manager;
}
- function getCommentInsertSql($id)
- {
- $ret = array();
- settype($id, 'int');
- foreach ($this->bug->comments as $i => $comment) {
- $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->uniqueId()) .
'",
- "' . $this->manager->esc($comment->commenter->name) .
'",
- "' .
$this->manager->esc($comment->timestamp->format('Y-m-d H:i:s')) .
'",
- "' . $this->manager->esc($comment->comment) .
'");'] = $comment;
- }
- return $ret;
- }
-
- function getAttachmentInsertSql($id)
- {
- $ret = '';
- settype($id, 'int');
- foreach ($this->bug->attachments as $i => $attachment) {
- $ret .= "\nINSERT INTO bugmanager_patchtracker
- (bug_id, name, revision, handle)
- VALUES(" . $id . ',
- "' . $this->manager->esc($attachment->name) . '",
- "' . $this->manager->esc($attachment->revision) . '",
- "' . $this->manager->esc($comment->commenter->uniqueId()) .
"\");\n";
- }
- return $ret;
- }
-
function getUpdateSQL()
{
$basicdiff = array_flip($this->bug->diff());
Modified: pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php 2009-08-15 17:25:16 UTC (rev
287345)
+++ pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php 2009-08-15 17:39:41 UTC (rev
287346)
@@ -33,6 +33,7 @@
protected $actorManager;
static public $defaultActorManager = null;
static public $mysqliclass = 'mysqli';
+ protected $escaper;
function __construct($host, $db, $user = null, $pass = null,
ActorManagerInterface $actorManager = null)
@@ -46,6 +47,8 @@
} else {
throw new Exception('No default Actor manager or explicit Actor manager
specified');
}
+ $this->escaper = new BugManager\IssueEscapeDecorator\Mysql($this->mysqli);
+
}
/**
@@ -64,8 +67,7 @@
protected function getInsertSql($bug)
{
- $escape = new BugManager\IssueEscapeDecorator\Mysql($this->mysqli);
- $bug->addEscaper($escape);
+ $bug->addEscaper($this->escaper);
$vals = array(
'assign' => isset($bug->assigned[0]) ? $bug->assigned[0]->handle
: 'NULL',
'assign2' => isset($bug->assigned[1]) ? $bug->assigned[1]->handle
: 'NULL',
@@ -93,11 +95,44 @@
);
$ret = 'INSERT INTO bugmanager_issues (' . implode(',',
array_keys($vals)) . ')
VALUES(' . implode(',', array_values($vals)) . ');';
- $bug->removeEscaper($escape);
+ $bug->removeEscaper($this->escaper);
return $ret;
}
+ function getCommentInsertSql($bug)
+ {
+ $bug->addEscaper($this->escaper);
+ $ret = array();
+ foreach ($bug->comments as $i => $comment) {
+ $ret["\nINSERT INTO bugmanager_comments
+ (bug_id, email, handle, reporter_name, ts, comment)
+ VALUES(" . $bug->id . ',
+ ' . $comment->commenter->email . ',
+ ' . $comment->commenter->uniqueId() . ',
+ ' . $comment->commenter->name . ',
+ "' . $this->esc($comment->timestamp->format('Y-m-d
H:i:s')) . '",
+ ' . $comment->comment . ');'] = $comment;
+ }
+ $bug->removeEscaper($this->escaper);
+ return $ret;
+ }
+ function getAttachmentInsertSql($bug)
+ {
+ $ret = '';
+ $bug->addEscaper($this->escaper);
+ foreach ($bug->attachments as $i => $attachment) {
+ $ret .= "\nINSERT INTO bugmanager_patchtracker
+ (bug_id, name, revision, handle)
+ VALUES(" . $bug->id . ',
+ ' . $attachment->name . ',
+ ' . $attachment->revision . ',
+ ' . $attachment->comment->commenter->uniqueId() . ");\n";
+ }
+ $bug->removeEscaper($this->escaper);
+ return $ret;
+ }
+
/**
* @return pear2\BugManager\Issue
*/
@@ -336,22 +371,21 @@
*/
function add(Issue $bug)
{
- $decorator = new \pear2\BugManager\IssueDecorator\Mysql($bug, $this);
$sql = $this->getInsertSql($bug);
$this->mysqli->query($sql);
- $id = $this->mysqli->insert_id();
- $sql = $decorator->getCommentInsertSql($id);
+ $bug->id = $this->mysqli->insert_id();
+ $sql = $this->getCommentInsertSql($bug);
if ($sql) {
foreach ($sql as $query => $comment) {
$this->mysqli->query($query);
$comment->id = $this->mysqli->insert_id();
}
}
- $sql = $decorator->getAttachmentInsertSql($id);
+ $sql = $this->getAttachmentInsertSql($bug);
if ($sql) {
$this->mysqli->query($sql);
}
- return $id;
+ return $bug->id;
}
/**