. * * @category Main * @package RPMPHP * * @author Remi Collet * @author Johan Cwiklinski * @copyright 2010 Remi Collet * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version * @link http://github.com/remicollet/rpmphp/ * @since The begining of times. */ chdir(dirname($_SERVER["SCRIPT_FILENAME"])); date_default_timezone_set('Europe/Paris'); if (isset($_SERVER["SERVER_NAME"])) { echo "
";
    ini_set("max_execution_time", "0");
    ini_set("memory_limit", "-1");

    die("This script is launched twice a day, be patient");
}
require "include/main.php";
require "class/CommonTable.php";

if ($_SERVER['argc']>1 && in_array('help', $_SERVER['argv'])) {
    echo "Options in: repo owner R pear pecl old\n";
    echo "Defaults:   repo owner R pear pecl\n";
    die("\n");
}

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

    // -------------------------------------------------------------------
    //	Fedora Packages
    // -------------------------------------------------------------------
    echo date("r : ") . "Refreshing " . MYBASE . " database\n";

    if ($_SERVER['argc']==1 || in_array('repo', $_SERVER['argv'])) {
        if (in_array('empty', $_SERVER['argv'])) {
            $crit = array('stamp' => null);
        } else if (in_array('old', $_SERVER['argv'])) {
            $crit = array();
        } else {
            $crit = array('active' => 1);
        }

        Parser::readRpm(new TableRpm($db), new TableRpmRepo($db), $crit);
    } // If ask

    // -------------------------------------------------------------------
    //	Upstream Version
    // -------------------------------------------------------------------
    $uptable = new TableUpstream($db);

    // -------------------------------------------------------------------
    if ($_SERVER['argc']==1 || in_array('pecl', $_SERVER['argv'])) {
        echo date("r : ") . "PECL listLatestReleases - stable\n";

        $request = xmlrpc_encode_request("package.listLatestReleases", "stable");
        $context = stream_context_create(
            array(
                'http' => array(
                    'method' => "POST",
                    'header' => "Content-Type: text/xml",
                    'content' => $request
                )
            )
        );
        $file = file_get_contents("http://pecl.php.net/xmlrpc.php", false, $context)
            or die ("Can't file_get_contents(http://pecl.php.net/xmlrpc.php)");
        $stable = xmlrpc_decode($file);
        if (xmlrpc_is_fault($stable)) {
            echo date("r : ") .
                "ERROR xmlrpc: $stable[faultString] ($stable[faultCode])";
        } else {
            $nb = $uptable->delete(array('type'=>'pecl', 'channel'=>'pecl'));
            echo date("r : ") . "Delete $nb packages\n";

            $nb=0;
            foreach ($stable as $name => $info) {
                $rpmname="php-pecl-".str_replace("_", "-", $name);

                $id = $uptable->record(
                    'pecl',
                    'pecl',
                    $rpmname,
                    $info["version"],
                    true
                );
                if ($id) {
                    $nb++;
                }
            }
            echo date("r : ") . "Write $nb packages\n";
        }

        // -------------------------------------------------------------------
        echo date("r : ") . "PECL listLatestReleases - unstable\n";

        $request = xmlrpc_encode_request("package.listLatestReleases", array());
        $context = stream_context_create(
            array(
                'http' => array(
                    'method' => "POST",
                    'header' => "Content-Type: text/xml",
                    'content' => $request
                )
            )
        );
        $file = file_get_contents("http://pecl.php.net/xmlrpc.php", false, $context)
            or die ("Can't file_get_contents(http://pecl.php.net/xmlrpc.php)");
        $unstable = xmlrpc_decode($file);
        if (xmlrpc_is_fault($unstable)) {
            echo date("r : ") . "ERROR xmlrpc: $stable[faultString] ".
                "($stable[faultCode])";
        } else {
            $nb=0;
            foreach ($unstable as $name => $info) {
                $rpmname="php-pecl-".str_replace("_", "-", $name);

                $id = $uptable->record(
                    'pecl',
                    'pecl',
                    $rpmname,
                    $info["version"],
                    true,
                    $info["state"]
                );
                if ($id) {
                    $nb++;
                }
            }
            echo date("r : ") . "Write $nb packages\n";
        }
    } // if in options

    // -------------------------------------------------------------------
    if ($_SERVER['argc']==1 || in_array('pear', $_SERVER['argv'])) {
        echo date("r : ") . "PEAR reading channels\n";
        $pear = new TablePearRepo($db);
        $channels = $pear->getAllRepo(true);
        try {
            $nbtot=0;

            foreach ($channels as $channelname => $channelurl) {
                $channel = @simplexml_load_file("http://$channelurl/channel.xml");
                if (!$channel) {
                    throw new Exception(
                        "can't read PEAR site (channel of $channelname)"
                    );
                }

                $rest = $channel->servers->primary->rest->baseurl[0];
                echo date("r : ") . "PEAR reading channel=$channelname" .
                    ", baseurl = $rest\n";

                $categories = @simplexml_load_file($rest."c/categories.xml");
                if (!$categories) {
                    throw new Exception("can't read PEAR site (categories)");
                }

                $crit = array('type'=>'pear', 'channel'=>$channelname);
                $nb = $uptable->delete($crit);
                echo date("r : ") . "Delete $nb packages\n";

                $nb=0;
                if (!isset($categories->c[0])) {
                    echo date("r : ") . "Reading ALL\n"; // ezc only
                    $pitxt = @file_get_contents($rest."p/packages.xml");
                    if (!$pitxt) {
                        throw new Exception(
                            "can't read PEAR site (".$rest."p/packagesinfo.xml)"
                        );
                    }
                    $allpi = @simplexml_load_string($pitxt);
                    foreach ($allpi->p as $name) {
                        $pitxt = @file_get_contents(
                            $rest."r/".strtolower($name)."/allreleases.xml"
                        );
                        if (!$pitxt) {
                            throw new Exception(
                                "can't read PEAR site (".$rest."r/".
                                strtolower($name)."/allreleases.xml"
                            );
                        }
                        $pi = @simplexml_load_string($pitxt);

                        $rpmname1="php-".$channelname."-".
                            str_replace("_", "-", $name);
                        $rpmname2="php-".$channelname."-".$name;

                        //echo $rpmname ."/".(string)$pi->r[0]->v."/".
                        //  (string)$pi->r[0]->s."\n";
                        $uptable->record(
                            "pear",
                            $channelname,
                            $rpmname1,
                            (string)$pi->r[0]->v,
                            false,
                            (string)$pi->r[0]->s
                        );
                        $uptable->record(
                            "pear",
                            $channelname,
                            $rpmname2,
                            (string)$pi->r[0]->v,
                            false,
                            (string)$pi->r[0]->s
                        );
                        foreach ($pi->r as $rev) {
                            if ($rev->s=='stable') {
                                //echo $rpmname ."/".(string)$rev->v."/".
                                //    (string)$rev->s."\n";
                                $uptable->record(
                                    "pear",
                                    $channelname,
                                    $rpmname1,
                                    (string)$rev->v,
                                    true
                                );
                                $uptable->record(
                                    "pear",
                                    $channelname,
                                    $rpmname2,
                                    (string)$rev->v,
                                    true
                                );
                                break;
                            }
                        }
                        $nb++;
                    }

                } else {
                    foreach ($categories->c as $cat) {
                        echo date("r : ") . "Reading $cat\n";

                        $pitxt = @file_get_contents(
                            $rest."c/".urlencode($cat)."/packagesinfo.xml"
                        );
                        if (!$pitxt) {
                            throw new Exception(
                                "can't read PEAR site (".$rest."c/".
                                urlencode($cat)."/packagesinfo.xml)"
                            );
                        }
                        $pitxt = "/U",
                            "",
                            str_replace("\r\n", "\n", substr($pitxt, 2))
                        );

                        $pi = @simplexml_load_string($pitxt);
                        if (!$pi) {
                            throw new Exception("can't read response ($cat)");
                        }
                        foreach ($pi->pi as $ps) {
                            if (isset($ps->p->n) && isset($ps->a->r)) {
                                $name=(string)$ps->p->n;

                                if ($channelname=='phing' && $name=='phing') {
                                    $rpmname1="php-pear-phing";
                                } else if ($channelname=='phpunit'
                                    && $name=='PHPUnit'
                                ) {
                                    $rpmname1="php-pear-PHPUnit";
                                } else {
                                    $rpmname1="php-".$channelname."-".
                                        str_replace("_", "-", $name);
                                }
                                $rpmname2="php-".$channelname."-".$name;

                                $uptable->record(
                                    "pear",
                                    $channelname,
                                    $rpmname1,
                                    (string)$ps->a->r[0]->v,
                                    false,
                                    (string)$ps->a->r[0]->s
                                );
                                $uptable->record(
                                    "pear",
                                    $channelname,
                                    $rpmname2,
                                    (string)$ps->a->r[0]->v,
                                    false,
                                    (string)$ps->a->r[0]->s
                                );
                                foreach ($ps->a->r as $rev) {
                                    if ($rev->s=='stable') {
                                        $uptable->record(
                                            "pear",
                                            $channelname,
                                            $rpmname1,
                                            (string)$rev->v,
                                            true
                                        );
                                        $uptable->record(
                                            "pear",
                                            $channelname,
                                            $rpmname2,
                                            (string)$rev->v,
                                            true
                                        );
                                        break;
                                    }
                                }
                                $nb++;
                                // echo $ps->p->n."\n";
                            }
                        }
                    }
                }
                echo date("r : ") . "read $nb packages in $channelname\n";
                $nbtot += $nb;
            }
            echo date("r : ") . "read $nbtot packages in all channels\n";

        } catch (Exception $e) {
            echo date("r : ") . 'ERROR ' .  $e->getMessage(), "\n";
        }
    } // if in options

    // -------------------------------------------------------------------
    if ($_SERVER['argc']==1 || in_array('R', $_SERVER['argv'])) {

        Parser::readR($uptable, new TableRRepo($db));

    } // If R in options

    // -------------------------------------------------------------------
    //	Package Owners from pkgdb (thanks Smootherfrog)
    // -------------------------------------------------------------------
    if ($_SERVER['argc']==1 || in_array('owner', $_SERVER['argv'])) {

        $url = "https://admin.fedoraproject.org/pkgdb/lists/bugzilla?tg_format=plain";
        Parser::readAcls(new TableAcls($db), $url);

    } // If in options

} catch(PDOException $e) {
    printf("%s ERREUR : %s\n", date("r"), $e->getMessage());
}

if (isset($_SERVER["SERVER_NAME"])) {
    echo "
"; } ?>