cellog          Sat Apr  7 04:46:22 2007 UTC

  Added files:                 
    /CVSROOT/pear       addkarma.php 
  Log:
  add helper script to add karma
  
  # TODO: make it smarter, to recognize and add to existing karma dirs
  

http://cvs.php.net/viewvc.cgi/CVSROOT/pear/addkarma.php?view=markup&rev=1.1
Index: CVSROOT/pear/addkarma.php
+++ CVSROOT/pear/addkarma.php
<?php
if (!isset($_SERVER['argv'])) {
    die("Must use CLI\n");
}
if (count($_SERVER['argv']) != 3) {
    die("usage: addkarma.php handle directory,directory\n");
}
if (!strpos($_SERVER['argv'][2], '/')) {
    die("usage: addkarma.php handle directory,directory (use directory/ for 
top-level)\n");
}
$newinfo = array();
$karma = array();
$new = new SplFileObject(dirname(__FILE__) . '/avail');
foreach ($new as $line) {
    $line = trim($line);
    if (!strlen($line) || $line[0] == '#' || $line == 'unavail') {
        continue;
    }
    $line = explode('|', $line);
    if ('unavail' == array_shift($line)) {
        continue; // drop avail
    }
    if (!isset($line[1])) {
        // avail everything
        $modules = array('!');
    } else {
        $modules = explode(',', $line[1]);
    }
    $peoples = explode(',', $line[0]);
    foreach ($peoples as $person) {
        foreach ($modules as $module) {
            if ($person == $_SERVER['argv'][1]) {
                $karma[] = $module;
            }
            $newinfo[$person][$module] = 1;
        }
    }
}
$modules = explode(',', $_SERVER['argv'][2]);
array_walk($modules, create_function('&$a,$b', '$a = trim($a,"/");'));
$need = array();
foreach ($modules as $module) {
    $test = explode('/', $module);
    // test karma for directory and for parent directories
    while (is_array($test) && count($test)) {
        $mod = implode('/', $test);
        if (in_array($mod, $karma)) {
            if ($mod == $module) {
                echo 'User already has karma for module ', $mod, "\n";
            } else {
                echo 'User already has karma for parent directory ', $mod,
                     ' of module ', $module, "\n";
            }
            continue 2;
        }
        array_pop($test);
    }
    if (strpos($module, 'pear') === false) {
        echo "Module $module should be added to avail, not pear/avail, 
skipping\n";
        continue;
    }
    $need[] = $module;
}
if (count($need)) {
    echo 'adding karma for ' . implode(',', $modules) . "\n";
    clearstatcache();
    $fp = fopen(dirname(__FILE__) . '/avail', 'r+');
    // strlen("\n# vim:set ft=conf sw=2 ts=2 et:\n")
    fseek($fp, -33, SEEK_END);
    ftruncate($fp, ftell($fp));
    fwrite($fp, "avail|" . $_SERVER['argv'][1] . '|' . implode(',', $need) .
        "\n# vim:set ft=conf sw=2 ts=2 et:\n");
    fclose($fp);
}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to