<?php
require "include/main.php";
require "class/CommonTable.php";

date_default_timezone_set('Europe/Paris');

$db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);

$pear = new TableRRepo($db);
print_r($pear->getAllRepo());

echo "PEAR\n";

$pear = new TablePearRepo($db);
print_r($pear->getAllRepo());

$pear = new TablePearRepo($db);
print_r($pear->getAllRepo(false));

$a=$pear->add(array('alias'=>'test', 'url'=>'testurl'));
echo "Ajout : $a\n";

$b=$pear->delete(array('id'=>$a));
echo "Del : $b\n";

echo "RPM:";
$rpm = new TableRpmRepo($db);

if ($rpm->update(999, array('stamp'=>1)))
{
    echo "Update 1 ok\n";
}
print_r($rpm->getAllRepo());
if ($rpm->update(999, array('stamp'=>2)))
{
    echo "Update 2 ok\n";
}
$all = $rpm->getAllRepo();
print_r(array_pop($all));

echo "find(devel):";
if ($row = $rpm->find(array('main'=>'devel'))) {
    print_r($row);
} else {
    echo "not found\n";
}
echo "find(rawhide):";
if ($row = $rpm->find(array('main'=>'rawhide'))) {
    print_r($row);
} else {
    echo "not found\n";
}
echo "find():";
if ($row = $rpm->find(array())) {
    print_r($row);
} else {
    echo "not found\n";
}
echo "get(999):";
if ($row = $rpm->get(999)) {
    print_r($row);
} else {
    echo "not found\n";
}
echo "get(888):";
if ($row = $rpm->get(888)) {
    print_r($row);
} else {
    echo "not found\n";
}
echo "Last update : ".date("r", $rpm->getMaxStamp())."\n";

$up = new TableUpstream($db);
$up->delete(array('name'=>'foo','type'=>'test'));
$rec = $up->record('test','bar','foo','1.0',true);
echo "record(foo-1.0) : $rec\n";
echo "find(foo,test):";
if ($row = $up->find(array('name'=>'foo','type'=>'test'))) {
    print_r($row);
} else {
    echo "not found\n";
}
$up->record('test','bar','foo','1.2',false,'beta');
echo "record(foo-1.2) : $rec\n";
echo "find(foo,test):";
if ($row = $up->find(array('name'=>'foo','type'=>'test'))) {
    print_r($row);
} else {
    echo "not found\n";
}
echo "request(test) : ";
foreach($up->request(array('type'=>'test', 'ORDER'=>'name')) as $upstr) {
    print_r($upstr);
}

$rpm = new TableRpm($db);
$acl = new TableAcls($db);
echo "Acls number : ".$acl->getCount()."\n";
$res = $acl->optimize();
echo "Acls optimization : ".$res[0]['Msg_type'].'='.$res[0]['Msg_text']."\n";

echo "PHP owner:";
print_r($acl->getOwners('php'));
echo "PECL owner:";
print_r($acl->getOwners('php-pecl-%'));
echo "PEAR channels:";
print_r($up->getChannels('pear'));
?>