little start
| From: | Pierre-Alain Joye | Date: | Wed, 14 Jan 2004 11:17:54 +0000 |
| Subject: | little start | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-25050@lists.php.net to get a copy of this message | ||
Hello,
Please try the attached patch. It solves bug #534.
the 2nd patch is against PEAR/Command/Remote.php
It's a backport of my work on the new pearweb (aka pearweb2). I'm just
wondering if we want to fix that in 1.3 or just release ;).
About pearweb, I'm setting a new dev server (php5 ...). Once I'm done we
can start to use it for tests/devs purposes.
pierre
--- pear-database.php 2004-01-13 15:11:14.000000000 +0100 +++ /home/paj/web/pear/include/pear-database.php 2004-01-14 12:09:49.000000000 +0100 @@ -1583,7 +1583,7 @@ END; $to = '"PEAR general list" <pear-general@lists.php.net>'; $from = '"PEAR Announce" <pear-dev@lists.php.net>'; $subject = "[ANNOUNCEMENT] $release Released."; - mail($to, $subject, $txtanounce, "From: $from", "-f pear-sys@php.net"); +/* mail($to, $subject, $txtanounce, "From: $from", "-f pear-sys@php.net");*/ } // }}} @@ -1657,9 +1657,95 @@ END; return $dbh->getAll($query, array($package, $version), DB_FETCHMODE_ASSOC); } + // }}} -} + // {{{ proto array release::search(array , struct) + + /** + * Search releases for given options + * @param array package name and description query string + * @param options Only preferred_state is implemented for now + * @TODO add options for dependencies (php version), field set + * move/alter this function as a generic function and use it + * for RPC getXXX as well as search, and for pe(ar|cl) search + */ + function search($query, $options) + { + global $dbh; + + if (is_array($query)) { + $names = isset($query[0]) ? explode(',', $query[0]) : array(); + $descs = isset($query[1]) ? explode(',', $query[1]) : array(); + } + + $likenames = ''; + $cnt = sizeof($names)-1; + if ($cnt==0) { + $likenames .= " (packages.name LIKE '%" . $names[0] ."%') "; + } elseif ($cnt) { + $likenames .= '('; + for ($i=$cnt; $i>=0; $i--) { + $like .= "packages.name LIKE '%" . $names[$i] . "%'"; + if ($i) { + $likenames .= ' OR '; + } + } + $likenames .= ')'; + } + + $cnt = sizeof($descs)-1; + $likedescs = ''; + if ($cnt==0) { + $likedescs .= " (packages.description LIKE '%" . $descs[0] ."%') "; + } elseif ($cnt>0) { + $likedescs .= '('; + for ($i=$cnt; $i>=0; $i--) { + $likedescs .= "packages.description LIKE '%" . $descs[$i] . "%'"; + if ($i) { + $likedescs .= ' OR '; + } + } + $likedescs .= ')'; + } + if (!empty($likenames) || !empty($likedescs)) { + $like = ' AND (' . $likenames . (empty($likedescs) ? '' : ' OR ' . $likedescs) . ')'; + } else { + $like = ''; + } + + $where_state = ''; + if (isset($options['preferred_state']) && release::isValidState($options['preferred_state'])) { + $better = release::betterStates($options['preferred_state']); + $where_state .= " AND (releases.state = '" . $options['preferred_state'] . "'"; + $i = 0; + if (is_array($better)) { + foreach ($better as $b) { + $where_state .= " OR releases.state = '$b'"; + } + } + $where_state .= ")"; + } + + //$t = array_merge($query, $options); + $options = implode("/",$options); + $query = "SELECT packages.name, releases.version, releases.state, packages.summary " + . " FROM packages, releases WHERE packages.id=releases.package " + . " $like " . $where_state . ' ORDER BY packages.name, releases.releasedate DESC'; + $t = $dbh->getAll($query,DB_FETCHMODE_ASSOC); + $prev = ''; + $res = array(); + for ($i=0; $i<sizeof($t); $i++) { + if ($prev!=$t[$i]['name']) { + $res[] = $t[$i]; + } + $prev = $t[$i]['name']; + } + return $res; + } + + // }}} +} /** * Class to handle notes @@ -2210,4 +2296,4 @@ if (!function_exists("md5_file")) { } } -?> +?> \ No newline at end of file --- /usr/local/lib/php/PEAR/Command/Remote.php 2004-01-14 12:14:37.000000000 +0100 +++ /home/paj/cvs/php5/pear/PEAR/Command/Remote.php 2004-01-09 13:10:42.000000000 +0100 @@ -1,9 +1,9 @@ <?php // /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ -// | PHP Version 4 | +// | PHP Version 5 | // +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | +// | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 3.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Remote.php,v 1.36 2003/11/17 09:15:28 mj Exp $ +// $Id: Remote.php,v 1.37 2004/01/08 17:33:13 sniper Exp $ require_once 'PEAR/Command/Common.php'; require_once 'PEAR/Common.php'; @@ -189,7 +189,7 @@ parameter. 'headline' => array('Package', 'Latest', 'Local'), ); $local_pkgs = $reg->listPackages(); - + foreach ($available as $name => $info) { $installed = $reg->packageInfo($name); $desc = $info['summary']; @@ -221,11 +221,11 @@ parameter. @$info['deps'], ); } - + foreach ($local_pkgs as $name) { $info = $reg->packageInfo($name); $data['data']['Local'][] = array( - $info['package'], + $info['package'], '', $info['version'], $info['summary'], @@ -251,29 +251,36 @@ parameter. $r = new PEAR_Remote($this->config); $reg = new PEAR_Registry($this->config->get('php_dir')); $available = $r->call('package.listAll', true); - $soptions = array(); - $soptions['preferred_state'] = $this->config->get('preferred_state'); - $t = $r->call('release.search',$params, $soptions); - if (PEAR::isError($t)) { - return $this->raiseError($t); + if (PEAR::isError($available)) { + return $this->raiseError($available); } $data = array( 'caption' => 'Matched packages:', 'border' => true, 'headline' => array('Package', 'Latest', 'Local'), - 'info' => array() ); - foreach ($t as $pkg) { - $installed = $reg->packageInfo($pkg['name']); - $data['data']['info'][]= array( - $pkg['name'], - $pkg['version'], - $installed['version'], - $pkg['summary'] + foreach ($available as $name => $info) { + $found = (!empty($params[0]) && stristr($name, $params[0]) !== false); + if (!$found && !(isset($params[1]) && !empty($params[1]) + && (stristr($info['summary'], $params[1]) !== false + || stristr($info['description'], $params[1]) !== false))) + { + continue; + }; + + $installed = $reg->packageInfo($name); + $desc = $info['summary']; + if (isset($params[$name])) + $desc .= "\n\n".$info['description']; + + $data['data'][$info['category']][] = array( + $name, + $info['stable'], + $installed['version'], + $desc, ); } - if (!isset($data['data'])) { return $this->raiseError('no packages found'); };
--- pear-database.php 2004-01-13 15:11:14.000000000 +0100 +++ /home/paj/web/pear/include/pear-database.php 2004-01-14 12:09:49.000000000 +0100 @@ -1583,7 +1583,7 @@ END; $to = '"PEAR general list" <pear-general@lists.php.net>'; $from = '"PEAR Announce" <pear-dev@lists.php.net>'; $subject = "[ANNOUNCEMENT] $release Released."; - mail($to, $subject, $txtanounce, "From: $from", "-f pear-sys@php.net"); +/* mail($to, $subject, $txtanounce, "From: $from", "-f pear-sys@php.net");*/ } // }}} @@ -1657,9 +1657,95 @@ END; return $dbh->getAll($query, array($package, $version), DB_FETCHMODE_ASSOC); } + // }}} -} + // {{{ proto array release::search(array , struct) + + /** + * Search releases for given options + * @param array package name and description query string + * @param options Only preferred_state is implemented for now + * @TODO add options for dependencies (php version), field set + * move/alter this function as a generic function and use it + * for RPC getXXX as well as search, and for pe(ar|cl) search + */ + function search($query, $options) + { + global $dbh; + + if (is_array($query)) { + $names = isset($query[0]) ? explode(',', $query[0]) : array(); + $descs = isset($query[1]) ? explode(',', $query[1]) : array(); + } + + $likenames = ''; + $cnt = sizeof($names)-1; + if ($cnt==0) { + $likenames .= " (packages.name LIKE '%" . $names[0] ."%') "; + } elseif ($cnt) { + $likenames .= '('; + for ($i=$cnt; $i>=0; $i--) { + $like .= "packages.name LIKE '%" . $names[$i] . "%'"; + if ($i) { + $likenames .= ' OR '; + } + } + $likenames .= ')'; + } + + $cnt = sizeof($descs)-1; + $likedescs = ''; + if ($cnt==0) { + $likedescs .= " (packages.description LIKE '%" . $descs[0] ."%') "; + } elseif ($cnt>0) { + $likedescs .= '('; + for ($i=$cnt; $i>=0; $i--) { + $likedescs .= "packages.description LIKE '%" . $descs[$i] . "%'"; + if ($i) { + $likedescs .= ' OR '; + } + } + $likedescs .= ')'; + } + if (!empty($likenames) || !empty($likedescs)) { + $like = ' AND (' . $likenames . (empty($likedescs) ? '' : ' OR ' . $likedescs) . ')'; + } else { + $like = ''; + } + + $where_state = ''; + if (isset($options['preferred_state']) && release::isValidState($options['preferred_state'])) { + $better = release::betterStates($options['preferred_state']); + $where_state .= " AND (releases.state = '" . $options['preferred_state'] . "'"; + $i = 0; + if (is_array($better)) { + foreach ($better as $b) { + $where_state .= " OR releases.state = '$b'"; + } + } + $where_state .= ")"; + } + + //$t = array_merge($query, $options); + $options = implode("/",$options); + $query = "SELECT packages.name, releases.version, releases.state, packages.summary " + . " FROM packages, releases WHERE packages.id=releases.package " + . " $like " . $where_state . ' ORDER BY packages.name, releases.releasedate DESC'; + $t = $dbh->getAll($query,DB_FETCHMODE_ASSOC); + $prev = ''; + $res = array(); + for ($i=0; $i<sizeof($t); $i++) { + if ($prev!=$t[$i]['name']) { + $res[] = $t[$i]; + } + $prev = $t[$i]['name']; + } + return $res; + } + + // }}} +} /** * Class to handle notes @@ -2210,4 +2296,4 @@ if (!function_exists("md5_file")) { } } -?> +?> \ No newline at end of file --- /usr/local/lib/php/PEAR/Command/Remote.php 2004-01-14 12:14:37.000000000 +0100 +++ /home/paj/cvs/php5/pear/PEAR/Command/Remote.php 2004-01-09 13:10:42.000000000 +0100 @@ -1,9 +1,9 @@ <?php // /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ -// | PHP Version 4 | +// | PHP Version 5 | // +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | +// | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 3.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Remote.php,v 1.36 2003/11/17 09:15:28 mj Exp $ +// $Id: Remote.php,v 1.37 2004/01/08 17:33:13 sniper Exp $ require_once 'PEAR/Command/Common.php'; require_once 'PEAR/Common.php'; @@ -189,7 +189,7 @@ parameter. 'headline' => array('Package', 'Latest', 'Local'), ); $local_pkgs = $reg->listPackages(); - + foreach ($available as $name => $info) { $installed = $reg->packageInfo($name); $desc = $info['summary']; @@ -221,11 +221,11 @@ parameter. @$info['deps'], ); } - + foreach ($local_pkgs as $name) { $info = $reg->packageInfo($name); $data['data']['Local'][] = array( - $info['package'], + $info['package'], '', $info['version'], $info['summary'], @@ -251,29 +251,36 @@ parameter. $r = new PEAR_Remote($this->config); $reg = new PEAR_Registry($this->config->get('php_dir')); $available = $r->call('package.listAll', true); - $soptions = array(); - $soptions['preferred_state'] = $this->config->get('preferred_state'); - $t = $r->call('release.search',$params, $soptions); - if (PEAR::isError($t)) { - return $this->raiseError($t); + if (PEAR::isError($available)) { + return $this->raiseError($available); } $data = array( 'caption' => 'Matched packages:', 'border' => true, 'headline' => array('Package', 'Latest', 'Local'), - 'info' => array() ); - foreach ($t as $pkg) { - $installed = $reg->packageInfo($pkg['name']); - $data['data']['info'][]= array( - $pkg['name'], - $pkg['version'], - $installed['version'], - $pkg['summary'] + foreach ($available as $name => $info) { + $found = (!empty($params[0]) && stristr($name, $params[0]) !== false); + if (!$found && !(isset($params[1]) && !empty($params[1]) + && (stristr($info['summary'], $params[1]) !== false + || stristr($info['description'], $params[1]) !== false))) + { + continue; + }; + + $installed = $reg->packageInfo($name); + $desc = $info['summary']; + if (isset($params[$name])) + $desc .= "\n\n".$info['description']; + + $data['data'][$info['category']][] = array( + $name, + $info['stable'], + $installed['version'], + $desc, ); } - if (!isset($data['data'])) { return $this->raiseError('no packages found'); };