PEAR logo

PEAR_PackageFileManager : The Definitive Guide



Getting list of maintainer

While API 1.5.x did not provides any way to retrieve user data of a maintainer. PEAR_PackageFileManager 1.6.0+ allow to get a full list organized by role or not, or a restricted list to a specific role. These methods to get data are : getMaintainers(), getLeads(), getDevelopers(), getContributors() and getHelpers().

Here are the 5 methods in action :

  1. <?php
  2. require_once 'PEAR/PackageFileManager2.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $packagefile = 'C:/PEAR/Database/MDB2-2.2.2/package.xml';
  7. $options = array(
  8.     'baseinstalldir' => '/',
  9.     'simpleoutput' => true,
  10.     'clearcontents' => false,
  11.     'changelogoldtonew' => false
  12.     );
  13.  
  14. // package.xml could be either version 1.0 or version 2.0
  15. $p2 = &PEAR_PackageFileManager2::importFromPackageFile1($packagefile, $options);
  16.  
  17. // all maintainers
  18. $m1 = $p2->getMaintainers();
  19.  
  20. // all maintainers group by role
  21. $m2 = $p2->getMaintainers(true);
  22.  
  23. // all maintainers that have the 'lead' role
  24. $m3 = $p2->getLeads();
  25.  
  26. // all maintainers that have the 'developer' role
  27. $m4 = $p2->getDevelopers();
  28.  
  29. // all maintainers that have the 'contributor' role
  30. $m5 = $p2->getContributors();
  31.  
  32. // all maintainers that have the 'helper' role
  33. $m6 = $p2->getHelpers();
  34.  
  35.  
  36. echo '<pre>';
  37. echo '<h1>all maintainers</h1>';
  38. var_dump($m1);
  39. echo '<h1>all maintainers group by role</h1>';
  40. var_dump($m2);
  41. echo '<h1>all maintainers that have the "lead" role</h1>';
  42. var_dump($m3);
  43. echo '<h1>all maintainers that have the "developer" role</h1>';
  44. var_dump($m4);
  45. echo '<h1>all maintainers that have the "contributor" role</h1>';
  46. var_dump($m5);
  47. echo '<h1>all maintainers that have the "helper" role</h1>';
  48. var_dump($m6);
  49. echo '</pre>';
  50. ?>

With such functions, we can retrieve easily a specific user and change its properties. For example, suppose an helper become a new lead on the next stable release.

We could write something like :

  1. <?php
  2. require_once 'PEAR/PackageFileManager2.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $version = '0.0.0';
  7. $userid  = 'davidc';
  8. $newrole = 'lead';
  9.  
  10. $packagefile = 'C:/PEAR/Database/MDB2-2.2.2/package.xml';
  11. // $options = array();
  12.  
  13. // package.xml could be either version 1.0 or version 2.0
  14. $p2 = &PEAR_PackageFileManager2::importFromPackageFile1($packagefile, $options);
  15.  
  16. if ($p2->getState('release') == 'stable'
  17.     && version_compare($p2->getVersion('release'), $version) < 0) {
  18.  
  19.     $m6 = $p2->getHelpers();
  20.     foreach ($m6 as $id => $user) {
  21.         if ($user['user'] === $userid) {
  22.             list($name, $handle, $email, $active) = $user;
  23.             $p2->updateMaintainer($newrole, $handle, $name, $email, $active);
  24.             break;
  25.         }
  26. }
  27. ?>
PEAR_PackageFileManager : The Definitive Guide v 1.6.0 : November 17, 2006