Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 64 lines (54 sloc) 2.093 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
<?php
set_include_path(dirname(__FILE__) . '/include' . PATH_SEPARATOR . get_include_path());

// Get common settings.
require_once 'pear-prepend.php';

// Get the database class.
require_once 'DB.php';
$options = array(
    'persistent' => false,
    'portability' => DB_PORTABILITY_ALL,
);
$dbh =& DB::connect(PEAR_DATABASE_DSN, $options);
if (DB::isError($dbh)) {
    die ("Failed to connect: $dsn\n");
}

require_once 'pear-database-maintainer.php';
require_once 'pear-database-note.php';

require_once 'Damblan/Karma.php';
$karma = new Damblan_Karma($dbh);

$karma_level = 'pecl.dev';

$sql = "SELECT p.name, p.id
FROM packages p
WHERE p.package_type = 'pecl'
ORDER BY p.name";
$packages = $dbh->getAssoc($sql, false, null, DB_FETCHMODE_ASSOC);
foreach ($packages as $n => $id) {
    $m = maintainer::get((int)$id);

    if (!empty($m)) {
        echo "\nAltering karma for maintainers of $n package id $id\n";

        foreach ($m as $handle => $m_data) {
            if (!$karma->has($handle, $karma_level)) {
                echo "Giving $handle $karma_level karma\n";
                // Bypassing damblan karma because it needs a logged in user
                $id = $dbh->nextId('karma');
                if (DB::isError($id)) {
                    echo "Couldn't get a new id from the karma table\n";
                    exit;
                }

                $query = 'INSERT INTO karma (id, user, level, granted_by, granted_at)
VALUES (?, ?, ?, ?, NOW())';
                $sth = $dbh->query($query, array($id, $handle, $karma_level, 'peclweb'));
                if (DB::isError($sth)) {
                    echo "Giving karma to $handle failed!\n";
                    exit;
                }

                // Adding a note about it
                note::add($handle, 'karma ' . $karma_level . ' granted', 'peclweb');
            } else {
                echo "$handle already has $karma_level\n";
            }
        }
    } else {
        echo "Couldn't find any maintainers for $n id $id possibily an error!\n";
    }
}
Something went wrong with that request. Please try again.