Archive for January, 2009
BugzillaPHP on Google Code
by subpacket on Jan.14, 2009, under General
I’ve setup a project on Google Code for BugzillaPHP. Everything is now available there, including the release, a subversion repository, and the usual Google Code stuff like issue tracking, wiki pages, etc.
Enjoy!
http://code.google.com/p/bugzillaphp/
Scotty
BugzillaPHP 0.1 Released!
by subpacket on Jan.13, 2009, under General
Woooooot! Look out, it’s the initial release of BugzillaPHP!
Download here: BugzillaPHP 0.1 Release
WTF?
BugzillaPHP is a set of PHP classes that allow communication with a Bugzilla installation. Capabilities include login/logout, search bugs, retrieve bug info, create and update bugs. Retrieving lists of classifications and products is also supported. Please note that this is in a working state, but is far from feature complete. Need a feature? Feel free to add it and send me the updates! The code is covered under the LGPL. (I’ll have a public subversion repo up at some point)
Requirements: PHP5, Bugzilla 3.2+ (may work with older 3.x series, but untested)
Documentation is non-existent right now but that’ll change soon enough. For the time being, here’s a couple examples as to how it works.
To connect to bugzilla and retrieve a specific bug’s information:
<?php
require_once('BugzillaConnector.php');
$bugzilla = new BugzillaConnector('http://your.bugzilla.installation');
$bug = $bugzilla->getBug(123); // Returns an instance of BugzillaBug.
print_r($bug);
To perform a search, the boolean charts feature of bugzilla is used. Generally straight-forward, check BugzillaSearchParameters::$fields for a list of all possible fields, and Bugzilla::$operators for possible operators.
<?php
require_once('BugzillaConnector.php');
$bugzilla = new BugzillaConnector('http://your.bugzilla.installation');
$params = new BugzillaSearchParameters();
$params->addItem('bug_status','equals','NEW');
$params->addItem('bug_status','equals','UNCOMFIRMED');
$params->addItem('bug_status','equals','ASSIGNED');
$params->addItem('assigned_to','equals','steglasi@subpacket.com','AND');
$bugs = $bugzilla->search($params); // Returns an array of BugzillaBug objects.
foreach ($bugs as $bug) { // Spit out each bug number and summary.
echo "Bug # " . $bug->bug_id . ': <b>' . $bug->short_desc . '</b><br />';
}
Logins are a bit trickier, but not hard. To perform a login, use something like this:
$bugzilla = new BugzillaConnector('http://your.bugzilla.installation',$_SESSION['bugzillaCookies']);
$userId = $bugzilla->login('username@domain.com','password');
$_SESSION['bugzillaCookies'] = $bugzilla->getCookies();
Here’s the trick: Bugzilla uses cookies to maintain a logged in session, but those cookies aren’t stored in the current PHP session by default. I didn’t implement session handling inside this class on purpose so that other session-handling methods can be used. (database-based sessions, etc) To get around it, you’ll need to store the cookies in your own session, and pass them into the constructor each time you instantiate the BugzillaConnector class. Also note that cookies will not be populated initially until you call a function that contacts bugzilla. (search, getbug, etc)
To create a bug or update a bug, you need only create an instance of BugzillaBug, fill in the info you need for it, and call createBug($bug) or updateBug($bug). Please note that there is NO error checking whatsoever right now, so if it fails, you won’t know it. That’s on the list of things to do.
That’s the crash course! Any feedback is appreciated, but please note that this is totally an Alpha-quality release. So if it blows up, well.. It’s alpha.
To download the library, go here:
Enjoy!
Scotty