DevHeads.net

com web/bugs: Replace PEAR error handling with exceptions in pull requests: include/classes/bug_ghpulltracker.php include/functions.php www/gh-pull-add.php

Link: <a href="http://git.php.net/?p=web/bugs.git;a=commitdiff;h=c8c85a57c5d8a6a0aa752bf3227075df524c243f" title="http://git.php.net/?p=web/bugs.git;a=commitdiff;h=c8c85a57c5d8a6a0aa752bf3227075df524c243f">http://git.php.net/?p=web/bugs.git;a=commitdiff;h=c8c85a57c5d8a6a0aa752b...</a>

Log:
Replace PEAR error handling with exceptions in pull requests

Changed paths:
M include/classes/bug_ghpulltracker.php
M include/functions.php
M www/gh-pull-add.php

Diff:
diff --git a/include/classes/bug_ghpulltracker.php b/include/classes/bug_ghpulltracker.php
index 5e7cbee..6ed0540 100644
--- a/include/classes/bug_ghpulltracker.php
+++ b/include/classes/bug_ghpulltracker.php
@@ -31,18 +31,27 @@ class Bug_Pulltracker
public function attach($bugid, $repo, $pull_id, $developer)
{
$data = $this->getDataFromGithub($repo, $pull_id);
+
if (!$data) {
- return PEAR::raiseError('Failed to retrieve pull request from GitHub');
- }
- PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
- $e = $this->dbh->prepare('INSERT INTO bugdb_pulls
- (bugdb_id, github_repo, github_pull_id, github_title, github_html_url, developer) VALUES (?, ?, ?, ?, ?, ?)')->execute(
- [$bugid, $repo, $pull_id, $data->title, $data->html_url, $developer]);
- PEAR::popErrorHandling();
- if (PEAR::isError($e)) {
- return $e;
+ throw new \Exception('Failed to retrieve pull request from GitHub');
}

+ $sql = 'INSERT INTO bugdb_pulls
+ (bugdb_id, github_repo, github_pull_id, github_title, github_html_url, developer)
+ VALUES (?, ?, ?, ?, ?, ?)
+ ';
+
+ $arguments = [
+ $bugid,
+ $repo,
+ $pull_id,
+ $data->title,
+ $data->html_url,
+ $developer,
+ ];
+
+ $this->dbh->prepare($sql)->execute($arguments);
+
return $data;
}

diff --git a/include/functions.php b/include/functions.php
index 8138404..c3a2c6a 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -800,11 +800,8 @@ function show_boolean_options($current)
* + string: value is printed
* + array: looped through and each value is printed.
* If array is empty, nothing is displayed.
- * If a value contains a PEAR_Error object,
- * + PEAR_Error: prints the value of getMessage() and getUserInfo()
- * if DEVBOX is true, otherwise prints data from getMessage().
*
- * @param string|array|PEAR_Error $in see long description
+ * @param string|array $in see long description
* @param string $class name of the HTML class for the <div> tag. ("errors", "warnings")
* @param string $head string to be put above the message
*
diff --git a/www/gh-pull-add.php b/www/gh-pull-add.php
index 7dc2965..f9bf6d6 100644
--- a/www/gh-pull-add.php
+++ b/www/gh-pull-add.php
@@ -4,7 +4,6 @@ use App\Utils\Captcha;

// Obtain common includes
require_once '../include/prepend.php';
-require_once 'PEAR.php';

session_start();
$canpatch = true;
@@ -95,11 +94,18 @@ if (isset($_POST['addpull'])) {
}

if (!count($errors)) {
- PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
- $newpr = $pullinfo->attach($bug_id, $_POST['repository'], $_POST['pull_id'], $email);
- PEAR::popErrorHandling();
- if (PEAR::isError($newpr)) {
- $errors = [$newpr->getMessage(), 'Could not attach pull request to Bug #' . $bug_id];
+ try {
+ $newpr = $pullinfo->attach($bug_id, $_POST['repository'], $_POST['pull_id'], $email);
+ } catch(\Exception $e) {
+ $errors = ['Could not attach pull request to Bug #'.$bug_id];
+
+ if ($e->errorInfo[1] === 1062) {
+ $errors[] = 'This pull request is already added.';
+ }
+
+ if (DEVBOX) {
+ $errors[] = $e->getMessage();
+ }
}
}