cvs: pearweb / package.php package.xml /public_html/bugs bug.php patch-add.php patch-display.php /public_html/bugs/include patchtracker.inc /sql
bugs.sql pearweb_mdb2schema.xml /templates/bugs addpatch.php listpatches.php patchadded.php patchdisplay.php
| From: | Greg Beaver | Date: | Sun, 25 Feb 2007 07:06:52 +0000 |
| Subject: | cvs: pearweb / package.php package.xml /public_html/bugs bug.php patch-add.php patch-display.php /public_html/bugs/include patchtracker.inc /sql bugs.sql pearweb_mdb2schema.xml /templates/bugs addpatch.php listpatches.php patchadded.php patchdisplay.php |
||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-cvs+get-44867@lists.php.net to get a copy of this message | ||
cellog Sun Feb 25 07:06:52 2007 UTC
Added files:
/pearweb/public_html/bugs patch-add.php patch-display.php
/pearweb/public_html/bugs/include patchtracker.inc
/pearweb/templates/bugs addpatch.php listpatches.php patchadded.php
patchdisplay.php
Modified files:
/pearweb package.php package.xml
/pearweb/public_html/bugs bug.php
/pearweb/sql bugs.sql pearweb_mdb2schema.xml
Log:
implement Request #10176 patch tracker for bugs
http://cvs.php.net/viewvc.cgi/pearweb/package.php?r1=1.103&r2=1.104&diff_format=u Index: pearweb/package.php diff -u pearweb/package.php:1.103 pearweb/package.php:1.104 --- pearweb/package.php:1.103 Sat Feb 24 19:22:33 2007 +++ pearweb/package.php Sun Feb 25 07:06:52 2007 @@ -21,6 +21,7 @@ $a->setNotes(' * fix release upload: don\'t let custom non-pear built packages with no package.xml in root dir slip through the cracks +* implement Request #10176: patch tracker for bugs '); $a->resetUsesrole(); $a->addUsesRole('web', 'Role_Web', 'pearified.com'); http://cvs.php.net/viewvc.cgi/pearweb/package.xml?r1=1.138&r2=1.139&diff_format=u Index: pearweb/package.xml diff -u pearweb/package.xml:1.138 pearweb/package.xml:1.139 --- pearweb/package.xml:1.138 Sat Feb 24 18:23:16 2007 +++ pearweb/package.xml Sun Feb 25 07:06:52 2007 @@ -55,7 +55,7 @@ <date>2007-02-24</date> <time>12:23:24</time> <version> - <release>1.8.0</release> + <release>1.9.0</release> <api>0.1.1</api> </version> <stability> @@ -209,6 +209,7 @@ <file name="functions.inc" role="web" /> <file name="layout.inc" role="web" /> <file name="NumeralCaptcha.php" role="web" /> + <file name="patchtracker.inc" role="web" /> <file name="prepend.inc" role="web" /> <file name="resolve.inc" role="web" /> <file name="trusted-devs.inc" role="web" /> @@ -217,6 +218,8 @@ <file name="bug.php" role="web" /> <file name="index.php" role="web" /> <file name="lstat.php" role="web" /> + <file name="patch-add.php" role="web" /> + <file name="patch-display.php" role="web" /> <file name="quick-fix-desc.php" role="web" /> <file name="report.php" role="web" /> <file name="roadmap.php" role="web" /> @@ -516,6 +519,10 @@ </dir> <!-- /sql --> <dir name="templates"> <dir name="bugs"> + <file name="addpatch.php" role="web" /> + <file name="listpatches.php" role="web" /> + <file name="patchadded.php" role="web" /> + <file name="patchdisplay.php" role="web" /> <file name="roadmap.php" role="web" /> <file name="roadmapadd.php" role="web" /> <file name="roadmapform.php" role="web" /> http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/bug.php?r1=1.113&r2=1.114&diff_format=u Index: pearweb/public_html/bugs/bug.php diff -u pearweb/public_html/bugs/bug.php:1.113 pearweb/public_html/bugs/bug.php:1.114 --- pearweb/public_html/bugs/bug.php:1.113 Wed Feb 21 04:08:52 2007 +++ pearweb/public_html/bugs/bug.php Sun Feb 25 07:06:52 2007 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: bug.php,v 1.113 2007/02/21 04:08:52 cellog Exp $ + * @version $Id: bug.php,v 1.114 2007/02/25 07:06:52 cellog Exp $ */ /* @@ -1010,6 +1010,17 @@ output_note(0, $bug['submitted'], $bug['email'], $bug['ldesc'], $bug['showemail'], $bug['handle'], $bug['reporter_name']); } +// Display patches +require 'include/patchtracker.inc'; +$patches = new Bug_Patchtracker; +$p = $patches->listPatches($id); +if (count($p)) { + ?><h2>Patches</h2><?php +} +foreach ($p as $name => $revisions) { + ?><a href="patch-display.php?bug=<?php echo $bug['id'] ?>&patch=<?php + echo urlencode($name) ?>&revision=latest"><?php echo clean($name) ?></a> (last revision <?php echo date('Y-m-d H:i:s', $revisions[0]) ?>)<br /><?php +} // Display comments $query = 'SELECT c.id,c.email,c.comment,UNIX_TIMESTAMP(c.ts) AS added, c.reporter_name as comment_name, u.showemail, u.handle http://cvs.php.net/viewvc.cgi/pearweb/sql/bugs.sql?r1=1.12&r2=1.13&diff_format=u Index: pearweb/sql/bugs.sql diff -u pearweb/sql/bugs.sql:1.12 pearweb/sql/bugs.sql:1.13 --- pearweb/sql/bugs.sql:1.12 Sat Feb 17 23:22:37 2007 +++ pearweb/sql/bugs.sql Sun Feb 25 07:06:52 2007 @@ -76,3 +76,10 @@ PRIMARY KEY (id), UNIQUE KEY (package, roadmap_version) ); + +CREATE TABLE bugdb_patchtracker ( + bugdb_id int(8) NOT NULL, + patch varchar(40) NOT NULL, + revision int(8) NOT NULL, + PRIMARY KEY (bugdb_id, patch, revision) +); \ No newline at end of file http://cvs.php.net/viewvc.cgi/pearweb/sql/pearweb_mdb2schema.xml?r1=1.20&r2=1.21&diff_format=u Index: pearweb/sql/pearweb_mdb2schema.xml diff -u pearweb/sql/pearweb_mdb2schema.xml:1.20 pearweb/sql/pearweb_mdb2schema.xml:1.21 --- pearweb/sql/pearweb_mdb2schema.xml:1.20 Tue Feb 20 02:54:07 2007 +++ pearweb/sql/pearweb_mdb2schema.xml Sun Feb 25 07:06:52 2007 @@ -492,6 +492,49 @@ <table> + <name>bugdb_patchtracker</name> + + <declaration> + <field> + <name>bugdb_id</name> + <type>integer</type> + <length>8</length> + <notnull>true</notnull> + </field> + <field> + <name>patch</name> + <type>text</type> + <length>40</length> + <notnull>true</notnull> + </field> + <field> + <name>revision</name> + <type>integer</type> + <length>8</length> + <notnull>true</notnull> + </field> + <index> + <name>primary</name> + <primary>true</primary> + <field> + <name>bugdb_id</name> + <sorting>ascending</sorting> + </field> + <field> + <name>patch</name> + <sorting>ascending</sorting> + </field> + <field> + <name>revision</name> + <sorting>ascending</sorting> + </field> + </index> + </declaration> + </table> + <table> + + <table> + <name>bugdb_roadmap_links</name> <declaration> http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/patch-add.php?view=markup&rev=1.1 Index: pearweb/public_html/bugs/patch-add.php +++ pearweb/public_html/bugs/patch-add.php <?php auth_require('pear.bug', 'pear.dev'); $canpatch = true; require 'include/patchtracker.inc'; require 'include/functions.inc'; $patchinfo = new Bug_Patchtracker; if (isset($_POST['addpatch'])) { if (!isset($_POST['bug'])) { response_header('Error :: no bug selected'); display_bug_error('No bug selected to add a patch to'); response_footer(); exit; } if (PEAR::isError($buginfo = $patchinfo->getBugInfo($_POST['bug']))) { response_header('Error :: invalid bug selected'); display_bug_error('Invalid bug "' . $id . '" selected'); response_footer(); exit; } if (!isset($_POST['name']) || empty($_POST['name']) || !is_string($_POST['name'])) { $package = $buginfo['package_name']; $bug = $buginfo['id']; if (!is_string($_POST['name'])) { $_POST['name'] = ''; } $name = $_POST['name']; $patches = $patchinfo->listPatches($bug); $errors = array('No patch name entered'); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/addpatch.php'; exit; } $bug = $buginfo['id']; PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $e = $patchinfo->attach($bug, 'patch', $_POST['name']); PEAR::popErrorHandling(); if (PEAR::isError($e)) { $package = $buginfo['package_name']; $bug = $buginfo['id']; if (!is_string($_POST['name'])) { $_POST['name'] = ''; } $name = $_POST['name']; $patches = $patchinfo->listPatches($bug); $errors = array($e->getMessage(), 'Could not attach patch "' . $_POST['name'] . '" to Bug #' . $bug); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/addpatch.php'; exit; } $package = $buginfo['package_name']; $bug = $buginfo['id']; $name = $_POST['name']; $patches = $patchinfo->listPatches($bug); $errors = array(); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/patchadded.php'; exit; } if (!isset($_GET['bug'])) { response_header('Error :: no bug selected'); display_bug_error('No bug selected to add a patch to'); response_footer(); exit; } if (PEAR::isError($buginfo = $patchinfo->getBugInfo($_GET['bug']))) { response_header('Error :: invalid bug selected'); display_bug_error('Invalid bug "' . $id . '" selected'); response_footer(); exit; } $errors = array(); $package = $buginfo['package_name']; $bug = $buginfo['id']; $name = ''; $patches = $patchinfo->listPatches($bug); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/addpatch.php'; ?> http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/patch-display.php?view=markup&rev=1.1 Index: pearweb/public_html/bugs/patch-display.php +++ pearweb/public_html/bugs/patch-display.php <?php require 'include/functions.inc'; if (!isset($_GET['bug'])) { response_header('Error :: no bug selected'); display_bug_error('No bug selected to add a patch to'); response_footer(); exit; } require 'include/patchtracker.inc'; $patchinfo = new Bug_Patchtracker; if (PEAR::isError($buginfo = $patchinfo->getBugInfo($_GET['bug']))) { response_header('Error :: invalid bug selected'); display_bug_error('Invalid bug "' . $GET['bug'] . '" selected'); response_footer(); exit; } if (isset($_GET['patch']) && isset($_GET['revision'])) { $revisions = $patchinfo->listRevisions($buginfo['id'], $_GET['patch']); if ($_GET['revision'] == 'latest' && isset($revisions[0])) { $_GET['revision'] = $revisions[0][0]; } if (!file_exists($path = $patchinfo->getPatchFullpath($_GET['bug'], $_GET['patch'], $_GET['revision']))) { response_header('Error :: no such patch/revision'); display_bug_error('Invalid patch/revision specified'); response_footer(); exit; } require_once 'HTTP.php'; if (isset($_GET['download'])) { header('Last-modified: ' . HTTP::date(filemtime($path))); header('Content-type: application/octet-stream'); header('Content-disposition: attachment; filename="' . $_GET['patch'] . '.patch.txt"'); header('Content-length: '.filesize($path)); echo readfile($path); exit; } $patchcontents = file_get_contents($path); $package = $buginfo['package_name']; $bug = $buginfo['id']; $revision = $_GET['revision']; $patch = $_GET['patch']; include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/patchdisplay.php'; } response_header('Bug #' . clean($buginfo['id']) . ' :: Patches'); $bug = $buginfo['id']; $patches = $patchinfo->listPatches($buginfo['id']); $canpatch = auth_check('pear.bug') || auth_check('pear.dev'); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/listpatches.php'; response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/include/patchtracker.inc?view=markup&rev=1.1 Index: pearweb/public_html/bugs/include/patchtracker.inc +++ pearweb/public_html/bugs/include/patchtracker.inc <?php require_once 'HTTP/Upload.php'; class Bug_Patchtracker { var $_upload; var $_patchdir; var $_dbh; function Bug_Patchtracker() { if (!file_exists(PEAR_PATCHTRACKER_TMPDIR)) { if (!@mkdir(PEAR_PATCHTRACKER_TMPDIR)) { $this->_upload = false; $this->_dbh = &$GLOBALS['dbh']; return; } } $this->_upload = new HTTP_Upload('en'); $this->_dbh = &$GLOBALS['dbh']; } /** * Return the directory in which patches should be stored * * @param int $bugid * @param string $name name of this patch line * @return string */ function patchDir($bugid, $name) { return PEAR_PATCHTRACKER_TMPDIR . '/p' . $bugid . '/' . $name; } /** * Create the directory in which patches for this bug ID will be stored * * @param int $bugid */ function setupPatchDir($bugid, $name) { if (file_exists($this->patchDir($bugid, $name))) { if (!is_dir($this->patchDir($bugid, $name))) { return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid . ', storage directory exists and is not a directory'); } return; } if (!file_exists(dirname($this->patchDir($bugid, $name)))) { // setup bug directory if (!@mkdir(dirname($this->patchDir($bugid, $name)))) { require_once 'PEAR.php'; return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid); } } elseif (!is_dir(dirname($this->patchDir($bugid, $name)))) { return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid . ', storage directory exists and is not a directory'); } // setup patch directory if (!@mkdir($this->patchDir($bugid, $name))) { require_once 'PEAR.php'; return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid); } } /** * Retrieve a unique, ordered patch filename * * @param int $bugid * @param string $patch */ function newPatchFileName($bugid, $patch) { $id = time(); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $e = $this->_dbh->query('INSERT INTO bugdb_patchtracker (bugdb_id, patch, revision) VALUES(?, ?, ?)', array($bugid, $patch, $id)); if (PEAR::isError($e)) { // try with another timestamp $id++; $e = $this->_dbh->query('INSERT INTO bugdb_patchtracker (bugdb_id, patch, revision) VALUES(?, ?, ?)', array($bugid, $patch, $id)); } PEAR::popErrorHandling(); if (PEAR::isError($e)) { return PEAR::raiseError('Could not get unique patch file name for bug #' . $bugid . ', patch "'. $patch . '"'); } return array($id, $this->getPatchFileName($id)); } /** * Retrieve the name of the patch file on the system * * @param int $id revision ID * @return string */ function getPatchFileName($id) { return 'p' . $id . '.patch.txt'; } /** * Retrieve the full path to a patch file * * @param int $bugid * @param string $name * @param int $revision * @return string */ function getPatchFullpath($bugid, $name, $revision) { return $this->patchDir($bugid, $name) . DIRECTORY_SEPARATOR . $this->getPatchFileName($revision); } /** * Attach a patch to this bug * * @param int $bugid * @param string $patch uploaded patch filename form variable * @param string $name patch name (allows several patches to be versioned) */ function attach($bugid, $patch, $name) { if (!$this->_upload) { return PEAR::raiseError('Upload directory for patches could not be' . ' initialized'); } if (!preg_match('/^[a-zA-Z_-]+$/', $name) || strlen($name) > 40) { return PEAR::raiseError('Invalid patch name "' . $name . '"'); } if (PEAR::isError($e = $this->setupPatchDir($bugid, $name))) { return $e; } $file = $this->_upload->getFiles($patch); if (PEAR::isError($file)) { return $file; } if ($file->isValid()) { $res = $this->newPatchFileName($bugid, $name); if (PEAR::isError($res)) { return $res; } list($id, $fname) = $res; $file->setName($fname); $file->setValidExtensions(array('txt', 'patch', 'diff'), 'accept'); $tmpfile = $file->moveTo($this->patchDir($bugid, $name)); if (PEAR::isError($tmpfile)) { $this->_dbh->query('DELETE FROM bugdb_patchtracker WHERE bugdb_id = ? and patch = ? and revision = ?', array($bugid, $name, $id)); return $tmpfile; } if (!$file->getProp('size')) { $this->detach($bugid, $name, $id); return PEAR::raiseError('zero-length patches not allowed'); } if ($file->getProp('size') > 10240) { $this->detach($bugid, $name, $id); return PEAR::raiseError('Patch files cannot be larger than 10k'); } return $id; } elseif ($file->isMissing()) { return PEAR::raiseError('No patch has been uploaded.'); } elseif ($file->isError()) { return $file; } return PEAR::raiseError('Unable to attach patch'); } /** * Remove a patch revision from this bug * * @param int $bugid * @param string $name * @param int $revision */ function detach($bugid, $name, $revision) { $this->_dbh->query('DELETE FROM bugdb_patchtracker WHERE bugdb_id = ? and patch = ? and revision = ?', array($bugid, $name, $revision)); @unlink($this->patchDir($bugid, $name) . DIRECTORY_SEPARATOR . $this->getPatchFileName($revision)); } /** * Retrieve the actual contents of the patch * * @param int $bugid * @param string $name * @param int $revision * @return string */ function getPatch($bugid, $name, $revision) { if ($this->_dbh->getOne('SELECT bugid FROM bugdb_patchtracker WHERE bugdb_id = ? AND patch = ? AND revision = ?', array($bugid, $name, $revision))) { $contents = @file_get_contents($this->getPatchFullpath($bugid, $name, $revision)); if (!$contents) { return PEAR::raiseError('Cannot retrieve patch revision "' . $revision . '" for patch "' . $name . '"'); } return $contents; } return PEAR::raiseError('No such patch revision "' . $revision . '", or no such patch "' . $name . '"'); } /** * Retrieve a listing of all patches and their revisions * * @param int $bugid * @return array */ function listPatches($bugid) { return $this->_dbh->getAssoc( 'SELECT patch, revision FROM bugdb_patchtracker WHERE bugdb_id = ? ORDER BY revision DESC', false, array($bugid), DB_FETCHMODE_ORDERED, true ); } /** * Retrieve a listing of all patches and their revisions * * @param int $bugid * @param string $patch * @return array */ function listRevisions($bugid, $patch) { return $this->_dbh->getAll( 'SELECT revision FROM bugdb_patchtracker WHERE bugdb_id = ? AND patch = ? ORDER BY revision DESC', array($bugid, $patch), DB_FETCHMODE_ORDERED ); } /** * Retrieve information on a bug * * @param int $bugid * @return array */ function getBugInfo($bugid) { $bugid = (int) $bugid; $info = $this->_dbh->getAll('SELECT * FROM bugdb WHERE id=?', array($bugid), DB_FETCHMODE_ASSOC); if (!is_array($info) || !count($info)) { return PEAR::raiseError('No such bug "' . $bugid . '"'); } return $info[0]; } } ?> http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/addpatch.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/addpatch.php +++ pearweb/templates/bugs/addpatch.php <?php response_header('Add Patch :: ' . clean($package)); ?> <h2>Add a Patch to Bug #<?php echo clean($bug) ?> for Package <?php echo clean($package); ?></h2> <form name="patchform" method="post" action="patch-add.php" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="10240" /> <input type="hidden" name="bug" value="<?php echo clean($bug) ?>" /> <?php if ($errors) { foreach ($errors as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <table> <tr> <th class="form-label_left"> Choose an existing Patch to update, or add a new one </th> <td class="form-input"> <input type="text" maxlength="40" name="name" value="<?php echo clean($name) ?>" /> </td> </tr> <tr> <th class="form-label_left"> Patch File </th> <td class="form-input"> <input type="file" name="patch"/> </td> </tr> </table> <input type="submit" name="addpatch" value="Save" /> </form> <h2>Existing patches:</h2> <?php $canpatch = false; require 'listpatches.php'; response_footer(); ?> http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/listpatches.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/listpatches.php +++ pearweb/templates/bugs/listpatches.php <table> <tr> <td> <a href="bug.php?id=<?php echo urlencode($bug) ?>">Return to Bug #<?php echo clean($bug) ?></a> <?php if ($canpatch): ?> | <a href="patch-add.php?bug=<?php echo urlencode($bug) ?>">Add a Patch</a> <?php endif; //if ($canpatch) ?> </td> </tr> <?php if (!count($patches)): ?> <tr> <th class="form-label_left"> No patches </th> </tr> <?php else: //if (!count($patches)) foreach ($patches as $patch => $revisions): ?> <tr> <th class="form-label_left"> Patch <a href="?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=latest&display=1"><?php echo clean($patch); ?></a> </th> <td> Patch Versions: <a href="?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=latest&display=1">latest</a> <?php foreach ($revisions as $revision): ?> <a href="?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=<?php echo $revision ?>&display=1"><?php echo date('Y-m-d H:i:s', $revision) ?></a> <?php endforeach; //foreach ($revisions as $revision) ?> </td> </tr> <?php endforeach; //foreach ($patches as $name => $revisions) endif; //if (!count($patches)) ?> </table> http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/patchadded.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/patchadded.php +++ pearweb/templates/bugs/patchadded.php <?php response_header('Patch Added :: ' . clean($package) . ' :: Bug #' . clean($bug)); ?> <h1>Patch Added to Bug #<?php echo clean($bug); ?>, Package <?php echo clean($package) ?></h1> <?php include dirname(__FILE__) . '/listpatches.php'; response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/patchdisplay.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/patchdisplay.php +++ pearweb/templates/bugs/patchdisplay.php <?php response_header('Patch :: ' . clean($package) . ' :: Bug #' . clean($bug)); ?> <h1>Patch version <?php echo date('Y-m-d H:i:s', $revision) ?> for <?php echo clean($package) ?> Bug #<?php echo clean($bug) ?></h1> <a href="bug.php?id=<?php echo urlencode($bug) ?>">Return to Bug #<?php echo clean($bug) ?></a> | <a href="patch-display.php?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=<?php echo urlencode($revision) ?>&download=1">Download this patch</a><br /> Patch Revisions: <?php foreach ($revisions as $i => $revision): ?> <a href="patch-display.php?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=<?php echo urlencode($revision[0]) ?>"><?php echo date('Y-m-d H:i:s', $revision[0]) ?></a><?php if ($i < count($revisions) - 1) echo ' | '; ?> <?php endforeach; //foreach ($revisions as $i => $revision) ?> <pre> <?php echo $patchcontents ?> </pre> <?php response_footer();
http://cvs.php.net/viewvc.cgi/pearweb/package.php?r1=1.103&r2=1.104&diff_format=u Index: pearweb/package.php diff -u pearweb/package.php:1.103 pearweb/package.php:1.104 --- pearweb/package.php:1.103 Sat Feb 24 19:22:33 2007 +++ pearweb/package.php Sun Feb 25 07:06:52 2007 @@ -21,6 +21,7 @@ $a->setNotes(' * fix release upload: don\'t let custom non-pear built packages with no package.xml in root dir slip through the cracks +* implement Request #10176: patch tracker for bugs '); $a->resetUsesrole(); $a->addUsesRole('web', 'Role_Web', 'pearified.com'); http://cvs.php.net/viewvc.cgi/pearweb/package.xml?r1=1.138&r2=1.139&diff_format=u Index: pearweb/package.xml diff -u pearweb/package.xml:1.138 pearweb/package.xml:1.139 --- pearweb/package.xml:1.138 Sat Feb 24 18:23:16 2007 +++ pearweb/package.xml Sun Feb 25 07:06:52 2007 @@ -55,7 +55,7 @@ <date>2007-02-24</date> <time>12:23:24</time> <version> - <release>1.8.0</release> + <release>1.9.0</release> <api>0.1.1</api> </version> <stability> @@ -209,6 +209,7 @@ <file name="functions.inc" role="web" /> <file name="layout.inc" role="web" /> <file name="NumeralCaptcha.php" role="web" /> + <file name="patchtracker.inc" role="web" /> <file name="prepend.inc" role="web" /> <file name="resolve.inc" role="web" /> <file name="trusted-devs.inc" role="web" /> @@ -217,6 +218,8 @@ <file name="bug.php" role="web" /> <file name="index.php" role="web" /> <file name="lstat.php" role="web" /> + <file name="patch-add.php" role="web" /> + <file name="patch-display.php" role="web" /> <file name="quick-fix-desc.php" role="web" /> <file name="report.php" role="web" /> <file name="roadmap.php" role="web" /> @@ -516,6 +519,10 @@ </dir> <!-- /sql --> <dir name="templates"> <dir name="bugs"> + <file name="addpatch.php" role="web" /> + <file name="listpatches.php" role="web" /> + <file name="patchadded.php" role="web" /> + <file name="patchdisplay.php" role="web" /> <file name="roadmap.php" role="web" /> <file name="roadmapadd.php" role="web" /> <file name="roadmapform.php" role="web" /> http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/bug.php?r1=1.113&r2=1.114&diff_format=u Index: pearweb/public_html/bugs/bug.php diff -u pearweb/public_html/bugs/bug.php:1.113 pearweb/public_html/bugs/bug.php:1.114 --- pearweb/public_html/bugs/bug.php:1.113 Wed Feb 21 04:08:52 2007 +++ pearweb/public_html/bugs/bug.php Sun Feb 25 07:06:52 2007 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: bug.php,v 1.113 2007/02/21 04:08:52 cellog Exp $ + * @version $Id: bug.php,v 1.114 2007/02/25 07:06:52 cellog Exp $ */ /* @@ -1010,6 +1010,17 @@ output_note(0, $bug['submitted'], $bug['email'], $bug['ldesc'], $bug['showemail'], $bug['handle'], $bug['reporter_name']); } +// Display patches +require 'include/patchtracker.inc'; +$patches = new Bug_Patchtracker; +$p = $patches->listPatches($id); +if (count($p)) { + ?><h2>Patches</h2><?php +} +foreach ($p as $name => $revisions) { + ?><a href="patch-display.php?bug=<?php echo $bug['id'] ?>&patch=<?php + echo urlencode($name) ?>&revision=latest"><?php echo clean($name) ?></a> (last revision <?php echo date('Y-m-d H:i:s', $revisions[0]) ?>)<br /><?php +} // Display comments $query = 'SELECT c.id,c.email,c.comment,UNIX_TIMESTAMP(c.ts) AS added, c.reporter_name as comment_name, u.showemail, u.handle http://cvs.php.net/viewvc.cgi/pearweb/sql/bugs.sql?r1=1.12&r2=1.13&diff_format=u Index: pearweb/sql/bugs.sql diff -u pearweb/sql/bugs.sql:1.12 pearweb/sql/bugs.sql:1.13 --- pearweb/sql/bugs.sql:1.12 Sat Feb 17 23:22:37 2007 +++ pearweb/sql/bugs.sql Sun Feb 25 07:06:52 2007 @@ -76,3 +76,10 @@ PRIMARY KEY (id), UNIQUE KEY (package, roadmap_version) ); + +CREATE TABLE bugdb_patchtracker ( + bugdb_id int(8) NOT NULL, + patch varchar(40) NOT NULL, + revision int(8) NOT NULL, + PRIMARY KEY (bugdb_id, patch, revision) +); \ No newline at end of file http://cvs.php.net/viewvc.cgi/pearweb/sql/pearweb_mdb2schema.xml?r1=1.20&r2=1.21&diff_format=u Index: pearweb/sql/pearweb_mdb2schema.xml diff -u pearweb/sql/pearweb_mdb2schema.xml:1.20 pearweb/sql/pearweb_mdb2schema.xml:1.21 --- pearweb/sql/pearweb_mdb2schema.xml:1.20 Tue Feb 20 02:54:07 2007 +++ pearweb/sql/pearweb_mdb2schema.xml Sun Feb 25 07:06:52 2007 @@ -492,6 +492,49 @@ <table> + <name>bugdb_patchtracker</name> + + <declaration> + <field> + <name>bugdb_id</name> + <type>integer</type> + <length>8</length> + <notnull>true</notnull> + </field> + <field> + <name>patch</name> + <type>text</type> + <length>40</length> + <notnull>true</notnull> + </field> + <field> + <name>revision</name> + <type>integer</type> + <length>8</length> + <notnull>true</notnull> + </field> + <index> + <name>primary</name> + <primary>true</primary> + <field> + <name>bugdb_id</name> + <sorting>ascending</sorting> + </field> + <field> + <name>patch</name> + <sorting>ascending</sorting> + </field> + <field> + <name>revision</name> + <sorting>ascending</sorting> + </field> + </index> + </declaration> + </table> + <table> + + <table> + <name>bugdb_roadmap_links</name> <declaration> http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/patch-add.php?view=markup&rev=1.1 Index: pearweb/public_html/bugs/patch-add.php +++ pearweb/public_html/bugs/patch-add.php <?php auth_require('pear.bug', 'pear.dev'); $canpatch = true; require 'include/patchtracker.inc'; require 'include/functions.inc'; $patchinfo = new Bug_Patchtracker; if (isset($_POST['addpatch'])) { if (!isset($_POST['bug'])) { response_header('Error :: no bug selected'); display_bug_error('No bug selected to add a patch to'); response_footer(); exit; } if (PEAR::isError($buginfo = $patchinfo->getBugInfo($_POST['bug']))) { response_header('Error :: invalid bug selected'); display_bug_error('Invalid bug "' . $id . '" selected'); response_footer(); exit; } if (!isset($_POST['name']) || empty($_POST['name']) || !is_string($_POST['name'])) { $package = $buginfo['package_name']; $bug = $buginfo['id']; if (!is_string($_POST['name'])) { $_POST['name'] = ''; } $name = $_POST['name']; $patches = $patchinfo->listPatches($bug); $errors = array('No patch name entered'); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/addpatch.php'; exit; } $bug = $buginfo['id']; PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $e = $patchinfo->attach($bug, 'patch', $_POST['name']); PEAR::popErrorHandling(); if (PEAR::isError($e)) { $package = $buginfo['package_name']; $bug = $buginfo['id']; if (!is_string($_POST['name'])) { $_POST['name'] = ''; } $name = $_POST['name']; $patches = $patchinfo->listPatches($bug); $errors = array($e->getMessage(), 'Could not attach patch "' . $_POST['name'] . '" to Bug #' . $bug); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/addpatch.php'; exit; } $package = $buginfo['package_name']; $bug = $buginfo['id']; $name = $_POST['name']; $patches = $patchinfo->listPatches($bug); $errors = array(); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/patchadded.php'; exit; } if (!isset($_GET['bug'])) { response_header('Error :: no bug selected'); display_bug_error('No bug selected to add a patch to'); response_footer(); exit; } if (PEAR::isError($buginfo = $patchinfo->getBugInfo($_GET['bug']))) { response_header('Error :: invalid bug selected'); display_bug_error('Invalid bug "' . $id . '" selected'); response_footer(); exit; } $errors = array(); $package = $buginfo['package_name']; $bug = $buginfo['id']; $name = ''; $patches = $patchinfo->listPatches($bug); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/addpatch.php'; ?> http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/patch-display.php?view=markup&rev=1.1 Index: pearweb/public_html/bugs/patch-display.php +++ pearweb/public_html/bugs/patch-display.php <?php require 'include/functions.inc'; if (!isset($_GET['bug'])) { response_header('Error :: no bug selected'); display_bug_error('No bug selected to add a patch to'); response_footer(); exit; } require 'include/patchtracker.inc'; $patchinfo = new Bug_Patchtracker; if (PEAR::isError($buginfo = $patchinfo->getBugInfo($_GET['bug']))) { response_header('Error :: invalid bug selected'); display_bug_error('Invalid bug "' . $GET['bug'] . '" selected'); response_footer(); exit; } if (isset($_GET['patch']) && isset($_GET['revision'])) { $revisions = $patchinfo->listRevisions($buginfo['id'], $_GET['patch']); if ($_GET['revision'] == 'latest' && isset($revisions[0])) { $_GET['revision'] = $revisions[0][0]; } if (!file_exists($path = $patchinfo->getPatchFullpath($_GET['bug'], $_GET['patch'], $_GET['revision']))) { response_header('Error :: no such patch/revision'); display_bug_error('Invalid patch/revision specified'); response_footer(); exit; } require_once 'HTTP.php'; if (isset($_GET['download'])) { header('Last-modified: ' . HTTP::date(filemtime($path))); header('Content-type: application/octet-stream'); header('Content-disposition: attachment; filename="' . $_GET['patch'] . '.patch.txt"'); header('Content-length: '.filesize($path)); echo readfile($path); exit; } $patchcontents = file_get_contents($path); $package = $buginfo['package_name']; $bug = $buginfo['id']; $revision = $_GET['revision']; $patch = $_GET['patch']; include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/patchdisplay.php'; } response_header('Bug #' . clean($buginfo['id']) . ' :: Patches'); $bug = $buginfo['id']; $patches = $patchinfo->listPatches($buginfo['id']); $canpatch = auth_check('pear.bug') || auth_check('pear.dev'); include dirname(dirname(dirname(__FILE__))) . '/templates/bugs/listpatches.php'; response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/public_html/bugs/include/patchtracker.inc?view=markup&rev=1.1 Index: pearweb/public_html/bugs/include/patchtracker.inc +++ pearweb/public_html/bugs/include/patchtracker.inc <?php require_once 'HTTP/Upload.php'; class Bug_Patchtracker { var $_upload; var $_patchdir; var $_dbh; function Bug_Patchtracker() { if (!file_exists(PEAR_PATCHTRACKER_TMPDIR)) { if (!@mkdir(PEAR_PATCHTRACKER_TMPDIR)) { $this->_upload = false; $this->_dbh = &$GLOBALS['dbh']; return; } } $this->_upload = new HTTP_Upload('en'); $this->_dbh = &$GLOBALS['dbh']; } /** * Return the directory in which patches should be stored * * @param int $bugid * @param string $name name of this patch line * @return string */ function patchDir($bugid, $name) { return PEAR_PATCHTRACKER_TMPDIR . '/p' . $bugid . '/' . $name; } /** * Create the directory in which patches for this bug ID will be stored * * @param int $bugid */ function setupPatchDir($bugid, $name) { if (file_exists($this->patchDir($bugid, $name))) { if (!is_dir($this->patchDir($bugid, $name))) { return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid . ', storage directory exists and is not a directory'); } return; } if (!file_exists(dirname($this->patchDir($bugid, $name)))) { // setup bug directory if (!@mkdir(dirname($this->patchDir($bugid, $name)))) { require_once 'PEAR.php'; return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid); } } elseif (!is_dir(dirname($this->patchDir($bugid, $name)))) { return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid . ', storage directory exists and is not a directory'); } // setup patch directory if (!@mkdir($this->patchDir($bugid, $name))) { require_once 'PEAR.php'; return PEAR::raiseError('Cannot create patch storage for Bug #' . $bugid); } } /** * Retrieve a unique, ordered patch filename * * @param int $bugid * @param string $patch */ function newPatchFileName($bugid, $patch) { $id = time(); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $e = $this->_dbh->query('INSERT INTO bugdb_patchtracker (bugdb_id, patch, revision) VALUES(?, ?, ?)', array($bugid, $patch, $id)); if (PEAR::isError($e)) { // try with another timestamp $id++; $e = $this->_dbh->query('INSERT INTO bugdb_patchtracker (bugdb_id, patch, revision) VALUES(?, ?, ?)', array($bugid, $patch, $id)); } PEAR::popErrorHandling(); if (PEAR::isError($e)) { return PEAR::raiseError('Could not get unique patch file name for bug #' . $bugid . ', patch "'. $patch . '"'); } return array($id, $this->getPatchFileName($id)); } /** * Retrieve the name of the patch file on the system * * @param int $id revision ID * @return string */ function getPatchFileName($id) { return 'p' . $id . '.patch.txt'; } /** * Retrieve the full path to a patch file * * @param int $bugid * @param string $name * @param int $revision * @return string */ function getPatchFullpath($bugid, $name, $revision) { return $this->patchDir($bugid, $name) . DIRECTORY_SEPARATOR . $this->getPatchFileName($revision); } /** * Attach a patch to this bug * * @param int $bugid * @param string $patch uploaded patch filename form variable * @param string $name patch name (allows several patches to be versioned) */ function attach($bugid, $patch, $name) { if (!$this->_upload) { return PEAR::raiseError('Upload directory for patches could not be' . ' initialized'); } if (!preg_match('/^[a-zA-Z_-]+$/', $name) || strlen($name) > 40) { return PEAR::raiseError('Invalid patch name "' . $name . '"'); } if (PEAR::isError($e = $this->setupPatchDir($bugid, $name))) { return $e; } $file = $this->_upload->getFiles($patch); if (PEAR::isError($file)) { return $file; } if ($file->isValid()) { $res = $this->newPatchFileName($bugid, $name); if (PEAR::isError($res)) { return $res; } list($id, $fname) = $res; $file->setName($fname); $file->setValidExtensions(array('txt', 'patch', 'diff'), 'accept'); $tmpfile = $file->moveTo($this->patchDir($bugid, $name)); if (PEAR::isError($tmpfile)) { $this->_dbh->query('DELETE FROM bugdb_patchtracker WHERE bugdb_id = ? and patch = ? and revision = ?', array($bugid, $name, $id)); return $tmpfile; } if (!$file->getProp('size')) { $this->detach($bugid, $name, $id); return PEAR::raiseError('zero-length patches not allowed'); } if ($file->getProp('size') > 10240) { $this->detach($bugid, $name, $id); return PEAR::raiseError('Patch files cannot be larger than 10k'); } return $id; } elseif ($file->isMissing()) { return PEAR::raiseError('No patch has been uploaded.'); } elseif ($file->isError()) { return $file; } return PEAR::raiseError('Unable to attach patch'); } /** * Remove a patch revision from this bug * * @param int $bugid * @param string $name * @param int $revision */ function detach($bugid, $name, $revision) { $this->_dbh->query('DELETE FROM bugdb_patchtracker WHERE bugdb_id = ? and patch = ? and revision = ?', array($bugid, $name, $revision)); @unlink($this->patchDir($bugid, $name) . DIRECTORY_SEPARATOR . $this->getPatchFileName($revision)); } /** * Retrieve the actual contents of the patch * * @param int $bugid * @param string $name * @param int $revision * @return string */ function getPatch($bugid, $name, $revision) { if ($this->_dbh->getOne('SELECT bugid FROM bugdb_patchtracker WHERE bugdb_id = ? AND patch = ? AND revision = ?', array($bugid, $name, $revision))) { $contents = @file_get_contents($this->getPatchFullpath($bugid, $name, $revision)); if (!$contents) { return PEAR::raiseError('Cannot retrieve patch revision "' . $revision . '" for patch "' . $name . '"'); } return $contents; } return PEAR::raiseError('No such patch revision "' . $revision . '", or no such patch "' . $name . '"'); } /** * Retrieve a listing of all patches and their revisions * * @param int $bugid * @return array */ function listPatches($bugid) { return $this->_dbh->getAssoc( 'SELECT patch, revision FROM bugdb_patchtracker WHERE bugdb_id = ? ORDER BY revision DESC', false, array($bugid), DB_FETCHMODE_ORDERED, true ); } /** * Retrieve a listing of all patches and their revisions * * @param int $bugid * @param string $patch * @return array */ function listRevisions($bugid, $patch) { return $this->_dbh->getAll( 'SELECT revision FROM bugdb_patchtracker WHERE bugdb_id = ? AND patch = ? ORDER BY revision DESC', array($bugid, $patch), DB_FETCHMODE_ORDERED ); } /** * Retrieve information on a bug * * @param int $bugid * @return array */ function getBugInfo($bugid) { $bugid = (int) $bugid; $info = $this->_dbh->getAll('SELECT * FROM bugdb WHERE id=?', array($bugid), DB_FETCHMODE_ASSOC); if (!is_array($info) || !count($info)) { return PEAR::raiseError('No such bug "' . $bugid . '"'); } return $info[0]; } } ?> http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/addpatch.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/addpatch.php +++ pearweb/templates/bugs/addpatch.php <?php response_header('Add Patch :: ' . clean($package)); ?> <h2>Add a Patch to Bug #<?php echo clean($bug) ?> for Package <?php echo clean($package); ?></h2> <form name="patchform" method="post" action="patch-add.php" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="10240" /> <input type="hidden" name="bug" value="<?php echo clean($bug) ?>" /> <?php if ($errors) { foreach ($errors as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <table> <tr> <th class="form-label_left"> Choose an existing Patch to update, or add a new one </th> <td class="form-input"> <input type="text" maxlength="40" name="name" value="<?php echo clean($name) ?>" /> </td> </tr> <tr> <th class="form-label_left"> Patch File </th> <td class="form-input"> <input type="file" name="patch"/> </td> </tr> </table> <input type="submit" name="addpatch" value="Save" /> </form> <h2>Existing patches:</h2> <?php $canpatch = false; require 'listpatches.php'; response_footer(); ?> http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/listpatches.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/listpatches.php +++ pearweb/templates/bugs/listpatches.php <table> <tr> <td> <a href="bug.php?id=<?php echo urlencode($bug) ?>">Return to Bug #<?php echo clean($bug) ?></a> <?php if ($canpatch): ?> | <a href="patch-add.php?bug=<?php echo urlencode($bug) ?>">Add a Patch</a> <?php endif; //if ($canpatch) ?> </td> </tr> <?php if (!count($patches)): ?> <tr> <th class="form-label_left"> No patches </th> </tr> <?php else: //if (!count($patches)) foreach ($patches as $patch => $revisions): ?> <tr> <th class="form-label_left"> Patch <a href="?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=latest&display=1"><?php echo clean($patch); ?></a> </th> <td> Patch Versions: <a href="?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=latest&display=1">latest</a> <?php foreach ($revisions as $revision): ?> <a href="?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=<?php echo $revision ?>&display=1"><?php echo date('Y-m-d H:i:s', $revision) ?></a> <?php endforeach; //foreach ($revisions as $revision) ?> </td> </tr> <?php endforeach; //foreach ($patches as $name => $revisions) endif; //if (!count($patches)) ?> </table> http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/patchadded.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/patchadded.php +++ pearweb/templates/bugs/patchadded.php <?php response_header('Patch Added :: ' . clean($package) . ' :: Bug #' . clean($bug)); ?> <h1>Patch Added to Bug #<?php echo clean($bug); ?>, Package <?php echo clean($package) ?></h1> <?php include dirname(__FILE__) . '/listpatches.php'; response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/templates/bugs/patchdisplay.php?view=markup&rev=1.1 Index: pearweb/templates/bugs/patchdisplay.php +++ pearweb/templates/bugs/patchdisplay.php <?php response_header('Patch :: ' . clean($package) . ' :: Bug #' . clean($bug)); ?> <h1>Patch version <?php echo date('Y-m-d H:i:s', $revision) ?> for <?php echo clean($package) ?> Bug #<?php echo clean($bug) ?></h1> <a href="bug.php?id=<?php echo urlencode($bug) ?>">Return to Bug #<?php echo clean($bug) ?></a> | <a href="patch-display.php?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=<?php echo urlencode($revision) ?>&download=1">Download this patch</a><br /> Patch Revisions: <?php foreach ($revisions as $i => $revision): ?> <a href="patch-display.php?bug=<?php echo urlencode($bug) ?>&patch=<?php echo urlencode($patch) ?>&revision=<?php echo urlencode($revision[0]) ?>"><?php echo date('Y-m-d H:i:s', $revision[0]) ?></a><?php if ($i < count($revisions) - 1) echo ' | '; ?> <?php endforeach; //foreach ($revisions as $i => $revision) ?> <pre> <?php echo $patchcontents ?> </pre> <?php response_footer();