cvs: pearweb /include pear-database.php /include/Damblan/Log Print.php /public_html/admin package-maintainers.php

From: Date: Tue, 16 Aug 2005 18:46:21 +0000
Subject: cvs: pearweb /include pear-database.php /include/Damblan/Log Print.php /public_html/admin package-maintainers.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-3595@lists.php.net to get a copy of this message
mj Tue Aug 16 14:46:21 2005 EDT Added files: /pearweb/include/Damblan/Log Print.php Modified files: /pearweb/include pear-database.php /pearweb/public_html/admin package-maintainers.php Log: * Added a new interface for managing package maintainers. * Added a new logging observer to Damblan which simply prints log messages to the screen. # This new approach is necessary in order to make sure that the package.xml # files always contain the same maintainership information like the # database. It is probably not as nifty as the old one, but it's a real # improvement in terms of data integrity.

http://cvs.php.net/diff.php/pearweb/include/pear-database.php?r1=1.284&r2=1.285&ty=u Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.284 pearweb/include/pear-database.php:1.285 --- pearweb/include/pear-database.php:1.284 Tue Aug 16 06:34:24 2005 +++ pearweb/include/pear-database.php Tue Aug 16 14:46:20 2005 @@ -17,7 +17,7 @@ | Tomas V.V.Cox <cox@php.net> | | Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ - $Id: pear-database.php,v 1.284 2005/08/16 10:34:24 mj Exp $ + $Id: pear-database.php,v 1.285 2005/08/16 18:46:20 mj Exp $ */ require_once 'DB/storage.php'; @@ -1301,7 +1301,7 @@ } // }}} - // {{{ +proto bool maintainer::updateAll(int, array) API 1.0 + // {{{ +proto bool maintainer::updateAll(int, array [,bool]) API 1.0 /** * Update user and roles of a package @@ -1310,9 +1310,10 @@ * @param int $pkgid The package id to update * @param array $users Assoc array containing the list of users * in the form: '<user>' => array('role' => '<role>', 'active' => '<active>') + * @param bool Whether to print the logging information to the screen * @return mixed PEAR_Error or true */ - function updateAll($pkgid, $users) + function updateAll($pkgid, $users, $print = false) { require_once "Damblan/Log.php"; @@ -1327,6 +1328,12 @@ } $logger = new Damblan_Log; + if ($print) { + require_once "Damblan/Log/Print.php"; + $observer = new Damblan_Log_Print; + $logger->attach($observer); + } + $pkg_name = package::info((int)$pkgid, "name"); // Needed for logging if (empty($pkg_name)) { PEAR::raiseError('maintainer::updateAll: no such package'); http://cvs.php.net/diff.php/pearweb/public_html/admin/package-maintainers.php?r1=1.14&r2=1.15&ty=u Index: pearweb/public_html/admin/package-maintainers.php diff -u pearweb/public_html/admin/package-maintainers.php:1.14 pearweb/public_html/admin/package-maintainers.php:1.15 --- pearweb/public_html/admin/package-maintainers.php:1.14 Sun Jul 3 21:00:49 2005 +++ pearweb/public_html/admin/package-maintainers.php Tue Aug 16 14:46:21 2005 @@ -15,145 +15,80 @@ +----------------------------------------------------------------------+ | Authors: Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ - $Id: package-maintainers.php,v 1.14 2005/07/04 01:00:49 rasmus Exp $ + $Id: package-maintainers.php,v 1.15 2005/08/16 18:46:21 mj Exp $ */ require_once "HTML/Form.php"; +require_once "HTTP/Upload.php"; +require_once "PEAR/Config.php"; +require_once "PEAR/PackageFile.php"; auth_require(); -response_header("PEAR Administration - Package maintainers"); +response_header("PEAR Administration - Package Maintainers"); -if (isset($_GET['pid'])) { - $id = (int)$_GET['pid']; -} else { - $id = 0; -} +echo "<h1>PEAR Administration - Package Maintainers</h1>"; -$self = htmlspecialchars($_SERVER['PHP_SELF']); +PEAR::pushErrorHandling(PEAR_ERROR_RETURN); -// Select package first -if (empty($id)) { - $packages = package::listAll(true, false, true); - $values = array(); +$upload = new HTTP_Upload; +$file = $upload->getFiles("f"); - foreach ($packages as $name => $package) { - $values[$package['packageid']] = $name; - } +if (PEAR::isError($file) || !$file->isValid() || !preg_match("/^package[\-\d\w]*\.xml$/", $file->getProp("real"))) { - $bb = new BorderBox("Select package"); + echo "<p>Welcome to the interface for managing package maintainers. "; + echo "In order to update the maintainer database you first have to "; + echo "apply the changes to the <tt>package(2).xml</tt> file for the "; + echo "package in question. Afterwards this file can uploaded via the "; + echo "form below, and the database will be updated accordingly.</p>"; - $form = new HTML_Form($self); - $form->addSelect("pid", "Package:", $values); + $form = new HTML_Form("/admin/package-maintainers.php", "post", "", "", "multipart/form-data"); + $form->addFile("f", "File:"); $form->addSubmit(); $form->display(); - $bb->end(); + echo "<p><strong>Warning:</strong> There is no confirmation screen, "; + echo "so you should make sure that the information in "; + echo "<tt>package(2).xml</tt> is correct before continuing.</p>"; -} else if (!empty($_GET['update'])) { - if (!maintainer::mayUpdate($id)) { - PEAR::raiseError("Only the lead maintainer of the package or PEAR - administrators can edit the maintainers."); - response_footer(); - exit(); - } +} else { + PEAR::popErrorHandling(); - $new_list = array(); - foreach ((array)$_GET['maintainers'] as $maintainer) { - list($handle, $role) = explode("||", $maintainer); - $new_list[$handle] = array("role" => $role, - "active" => 1); - } - $res = maintainer::updateAll($id, $new_list); - $package = $dbh->getOne('SELECT name FROM packages WHERE id=?', array($id)); - $pear_rest->savePackageMaintainerREST($package); - - $url = $self; - if (!empty($_GET['pid'])) { - $url .= "?pid=" . $_GET['pid']; + $config = &PEAR_Config::singleton(); + $pf = &new PEAR_PackageFile($config); + + $pkg_info = $pf->fromPackageFile($file->getProp("tmp_name"), PEAR_VALIDATE_NORMAL); + + $pkg_id = package::info($pkg_info->getName(), "id"); + if (!$pkg_id) { + PEAR::raiseError("No such package " . $pkg_info->getName()); } - echo '<br /><b>Done</b><br />'; - echo '<a href="' . $url . '">Back</a>'; -} else { - if (!maintainer::mayUpdate($id)) { + + /* + if (!maintainer::mayUpdate($pkg_id)) { PEAR::raiseError("Only the lead maintainer of the package or PEAR administrators can edit the maintainers."); response_footer(); exit(); } + */ - $bb = new BorderBox("Manage maintainers", "100%"); + $maintainers = array(); - echo '<script src="/javascript/package-maintainers.js" type="text/javascript"></script>'; - echo '<form onSubmit="beforeSubmit()" name="form" method="get" action="' . $self . '">'; - echo '<input type="hidden" name="update" value="yes" />'; - echo '<input type="hidden" name="pid" value="' . $id . '" />'; - echo '<table border="0" cellpadding="0" cellspacing="4" border="0" width="100%">'; - echo '<tr>'; - echo ' <th>All users:</th>'; - echo ' <th></th>'; - echo ' <th>Package maintainers:</th>'; - echo '</tr>'; - - echo '<tr>'; - echo ' <td>'; - echo ' <select onChange="activateAdd();" name="accounts" size="10">'; - - $users = user::listAll(); - foreach ($users as $user) { - if (empty($user['handle'])) { - continue; - } - printf('<option value="%s">%s (%s)</option>', - $user['handle'], - $user['name'], - $user['handle'] - ); + foreach ($pkg_info->getMaintainers() as $m) { + $active = (isset($m['active']) ? $m['active'] : 1); + $maintainers[$m['handle']] = array("role" => $m['role'], "active" => $active); } - echo ' </select>'; - echo ' </td>'; - echo ' <td>'; - echo ' <input type="button" onClick="addMaintainer();" name="add" value="Add as" />'; - echo ' <select name="role" size="1">'; - echo ' <option value="lead">lead</option>'; - echo ' <option value="developer">developer</option>'; - echo ' <option value="helper">helper</option>'; - echo ' </select><br /><br />'; - echo ' <input type="button" onClick="removeMaintainer();" name="remove" value="Remove" />'; - echo ' </td>'; - - echo ' <td>'; - echo ' <select multiple="yes" name="maintainers[]" onChange="activateRemove();" size="10">'; - - $maintainers = maintainer::get($id); - foreach ($maintainers as $handle => $row) { - $info = user::info($handle, "name"); // XXX: This sucks - printf('<option value="%s||%s">%s (%s, %s)</option>', - $handle, - $row['role'], - $info['name'], - $handle, - $row['role'] - ); + echo "<div class=\"explain\">The following log messages were generated "; + echo "by the update process:\n<ul>"; + $result = maintainer::updateAll($pkg_id, $maintainers, true); + echo "</ul>\n</div>\n"; + if ($result) { + echo "<br /><div class=\"success\">The maintainers database was updated successfully.</div>\n"; } - echo ' </select>'; - echo ' </td>'; - echo '</tr>'; - echo '<tr>'; - echo ' <td colspan="3"><input type="submit" /></td>'; - echo '</tr>'; - echo '</table>'; - echo '</form>'; - - echo '<script language="JavaScript" type="text/javascript">'; - echo 'document.form.remove.disabled = true;'; - echo 'document.form.add.disabled = true;'; - echo 'document.form.role.disabled = true;'; - echo '</script>'; - $bb->end(); + echo hdelim() . "<p><a href=\"/admin/package-maintainers.php\">Start again</a></p>\n"; } response_footer(); -?> http://cvs.php.net/co.php/pearweb/include/Damblan/Log/Print.php?r=1.1&p=1 Index: pearweb/include/Damblan/Log/Print.php +++ pearweb/include/Damblan/Log/Print.php <?php /* +----------------------------------------------------------------------+ | PEAR Web site version 1.0 | +----------------------------------------------------------------------+ | Copyright (c) 2003-2005 The PEAR Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ $Id: Print.php,v 1.1 2005/08/16 18:46:20 mj Exp $ */ require_once "Log/observer.php"; /** * Observer class for logging via email * * @author Martin Jansen <mj@php.net> * @extends Log_observer * @version $Revision: 1.1 $ * @package Damblan */ class Damblan_Log_Print extends Log_observer { function Damblan_Log_Print() { $this->Log_observer(); } /** * Generate logging email * * @param array Array containing the log information * @return void */ function notify($event) { echo "<li>" . $event['message'] . "</li>\n"; } /** * Logging method * * @access public * @param string Log message * @return boolean */ function log($text) { $event['message'] = $text; return $this->notify($event); } }
« previous php.pear.core (#3595) next »