svn: /pear2/BugManager/trunk/src/BugManager/ Category/BaseAbstract.php Category/PearPackage.php IssueManager/Mysql.php Site/PEAR/IssueManager.php

[email protected] (Greg Beaver) Wed, 15 Sep 2010 20:26:12 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
cellog                                   Wed, 15 Sep 2010 20:26:12 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=303406

Log:
simple fix: when validating, check to see if an existing bug uses this value.  It is then by definition valid

Changed paths:
    U   pear2/BugManager/trunk/src/BugManager/Category/BaseAbstract.php
    U   pear2/BugManager/trunk/src/BugManager/Category/PearPackage.php
    U   pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php
    U   pear2/BugManager/trunk/src/BugManager/Site/PEAR/IssueManager.php

Modified: pear2/BugManager/trunk/src/BugManager/Category/BaseAbstract.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/Category/BaseAbstract.php	2010-09-15 17:27:43 UTC (rev 303405)
+++ pear2/BugManager/trunk/src/BugManager/Category/BaseAbstract.php	2010-09-15 20:26:12 UTC (rev 303406)
@@ -53,37 +53,24 @@
         if ($contextname == 'phpversion') {
             // we'll eventually use a cached call to php.net's php version web service
             return array(
-                     '5.3.1',
-                     '5.3.0',
-                     '5.2.10',
-                     '5.2.9',
-                     '5.1.2',
-                     '5.1.1',
-                     '5.1.0',
-                     '5.0.5',
-                     '5.0.4',
-                     '5.0.3',
-                     '5.0.2',
-                     '5.0.0b1',
-                     '4.4.2',
-                     '4.4.1',
-                     '4.4.0',
-                     '4.3.11',
-                     '4.3.10',
-                     '4.3.9',
-                     '4.3.8',
-                     '4.3.7',
-                     '4.3.6',
-                     '4.3.4',
-                     '4.3.3',
-                     '4.3.2',
-                     '4.3.1',
-                     '4.3.0',
-                     'PHP 6 SVN-' . date('Y-m-d'),
-                     'PHP 5.3 SVN-' . date('Y-m-d'),
-                     'PHP 5.2 SVN-' . date('Y-m-d'),
-                     'Irrelevant'
-                   );
+                '5.3.2',
+                '5.3.1',
+                '5.3.0',
+                '5.2.10',
+                '5.2.9',
+                '5.1.2',
+                '5.1.1',
+                '5.1.0',
+                '5.0.5',
+                '5.0.4',
+                '5.0.3',
+                '5.0.2',
+                '5.0.0b1',
+                'PHP 6 SVN-' . date('Y-m-d'),
+                'PHP 5.3 SVN-' . date('Y-m-d'),
+                'PHP 5.2 SVN-' . date('Y-m-d'),
+                'Irrelevant'
+            );
         }
         if ($contextname == 'operatingsystem') {
             return true;

Modified: pear2/BugManager/trunk/src/BugManager/Category/PearPackage.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/Category/PearPackage.php	2010-09-15 17:27:43 UTC (rev 303405)
+++ pear2/BugManager/trunk/src/BugManager/Category/PearPackage.php	2010-09-15 20:26:12 UTC (rev 303406)
@@ -57,11 +57,12 @@

     function validateContext($contextname, $value, BugManager\Issue $bug, $multiple)
     {
-        if ($contextname == 'phpversion' || $contextname == 'operatingsystem') {
-            return parent::validateContext($contextname, $value, $bug, $multiple);
-        }
         if (BugManager\Main::site() == $this->categoryname) {
-            return $bug->issuemanager->validateContext($bug, $contextname, $this->categoryname, $value, $multiple);
+            $ret = $bug->issuemanager->validateContext($bug, $contextname, $this->categoryname, $value, $multiple);
+            if (!$ret && ($contextname == 'phpversion' || $contextname == 'operatingsystem')) {
+                return parent::validateContext($contextname, $value, $bug, $multiple);
+            }
+            return $ret;
         }
         return parent::validateContext($contextname, $value, $bug, $multiple);
     }

Modified: pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php	2010-09-15 17:27:43 UTC (rev 303405)
+++ pear2/BugManager/trunk/src/BugManager/IssueManager/Mysql.php	2010-09-15 20:26:12 UTC (rev 303406)
@@ -598,7 +598,7 @@
         }
         Issue::addEscaper($this->escaper);
         if ($contextname != 'milestones') {
-            throw new BadMethodCallException('PEAR2\BugManager\IssueManager\Mysql can only validate milestones context');
+            return false;
         }
         if (!($value instanceof BugManager\Milestone)) {
             throw new BugManager\ValidationException('Invalid milestone, must be a PEAR2\BugManager\Milestone object');

Modified: pear2/BugManager/trunk/src/BugManager/Site/PEAR/IssueManager.php
===================================================================
--- pear2/BugManager/trunk/src/BugManager/Site/PEAR/IssueManager.php	2010-09-15 17:27:43 UTC (rev 303405)
+++ pear2/BugManager/trunk/src/BugManager/Site/PEAR/IssueManager.php	2010-09-15 20:26:12 UTC (rev 303406)
@@ -203,6 +203,28 @@
         return new BugManager\MultiIssue($begin, $total, $issues);
     }

+    protected function validateContextFromExistingBugs(Issue $bug, $contextname, $value)
+    {
+        $sql = 'SELECT 0 as count';
+        if ($contextname == 'phpversion') {
+            $sql = 'SELECT COUNT(*) as count FROM bugmanager_issues r
+                WHERE r.php_version="' . $this->esc($value) . '"';
+        }
+        if ($contextname == 'packageversion') {
+            Issue::addEscaper($this->escaper);
+            $sql = 'SELECT COUNT(*) as count FROM bugmanager_issues r
+                WHERE r.package_name=' . $bug->context['packagename']->value() . ' AND
+                    r.package_version="' . $this->esc($value) . '"';
+            Issue::removeEscaper($this->escaper);
+        }
+        $result = $this->mysqli->query($sql);
+        if ($result === false) {
+            throw new BugManager\UnexpectedValueException('Database error: '.$this->mysqli->error);
+        }
+        $ret = $result->fetch_assoc();
+        return $ret['count'];
+    }
+
     /**
      * @return bool
      */
@@ -218,6 +240,9 @@
                 return true;
             }
         }
+        if ($this->validateContextFromExistingBugs($bug, $contextname, $value)) {
+            return true;
+        }
         if ($contextname == 'packagename') {
             Issue::addEscaper($this->escaper);
             $sql = 'SELECT COUNT(*) as count FROM packages WHERE name="' .