/** * Retrieve packages informations * * @param Object $db A reference to the database * @param string $type The current type * * @return array */ function report($db, $type) { global $what, $smarty; $packages = null; $rpmrepo = new TableRpmRepo($db); $rpmtable = new TableRpm($db); $uptable = new TableUpstream($db); $repos = $rpmrepo->getAllRepoHash(); $smarty->assign('repos', $repos); $crit = array('type' => $type, 'ORDER' => 'name'); if (substr($what, 0, 1) == '#') { $crit['channel'] = substr($what, 1); $what = '%fedora'; } $i = 0; foreach ($uptable->request($crit) as $up) { $package = null; $rpmname = $up['name']; $verup = strtolower($up['stable'] ? $up['stable'] : $up['unstable']); $sql2 = "SELECT DISTINCT owner FROM acls WHERE name = '{$rpmname}'"; $res2 = $db->query($sql2); $owners = array(); if ($res2) { while ($owner = $res2->fetchObject()) { $owners[] = $owner->owner; } } $package['name'] = $rpmname; $rpms = array(); foreach ($rpmtable->request(array('name' => $rpmname)) as $rpm) { $rpms[$rpm['repo_main'] . '-' . $rpm['repo_sub']] = $rpm; $package['name'] = '<a href="zoom.php?rpm=' . $rpmname . '" title="' . htmlentities($rpm['summary'], ENT_QUOTES) . '">' . $rpmname . '</a>'; } switch ($what) { case '%work': $display = false; if (count($rpms) && isset($rpms['devel-']) && $rpms['devel-']['ver'] != $verup) { $display = true; } break; case '%fedora': $display = count($rpms); break; case '%stable': $display = !empty($up['stable']); break; case '%all': $display = true; break; default: // owner $display = array_search($what, $owners) !== false; break; } if ($display) { if ($up['channel'] != $up['type']) { $package['channel'] = $up['channel']; } $dispowner = ""; $package['owners'] = $owners; if ($up['stable']) { $package['upstream_stable'] = $up['stable']; } if ($up['unstable'] && (!$up['stable'] || $up['stable'] != $up['unstable'])) { $package['upstream_unstable'] = $up['unstable'] . ' <small>(' . $up['state'] . ')</small>'; } $versions = null; foreach ($repos as $repomain) { $display = ""; $class = ""; foreach ($repomain as $k => $repo) { if (isset($rpms[$repo['main'] . "-" . $repo['sub']])) { $rpm = $rpms[$repo['main'] . "-" . $repo['sub']]; $verpm = $rpm['ver']; $pat = "/\\.((beta|RC)\\d*)\\./i"; if (preg_match($pat, $rpm['rel'], $res)) { $verpm .= strtolower($res[1]); } if (strpos($repo['sub'], '-os') || strpos($repo['sub'], '-beta') || strpos($repo['sub'], '-base') || strpos($repo['sub'], '-optional') || strpos($repo['sub'], '-stable')) { // For CentOS $repotype = 'base'; } else { if (strpos($repo['sub'], 'testing')) { $repotype = 'testing'; } else { if (strpos($repo['sub'], 'updates')) { $repotype = 'updates'; } else { $repotype = $repo['sub']; } } } switch ($repotype) { case "base": if (isset($rpms[$repo['main'] . "-updates"])) { $display .= sprintf("%s-%s<br/>", $rpm['ver'], $rpm['rel']); } else { $display .= sprintf("<strong>%s</strong>-%s<br/>", $rpm['ver'], $rpm['rel']); } if ($verup == $verpm) { $class = "check"; } break; case "": $display .= sprintf("<strong>%s</strong>-%s<br/>", $rpm['ver'], $rpm['rel']); if ($verup == $verpm) { $class = "check"; } break; case "updates": $display .= sprintf("<strong>%s</strong>-%s" . "<br/><small>(%s)</small><br/>", $rpm['ver'], $rpm['rel'], $repo['sub']); if ($verup == $verpm && $class != 'check') { $class = "check"; } break; case "testing": $display .= sprintf("%s-%s<br/><small>(%s)</small>", $rpm['ver'], $rpm['rel'], $repo['sub']); if ($verup == $verpm && !$class) { $class = "info"; } break; } } // RPM exists } // sub repo if ($display && empty($class)) { $class = "attn"; } $versions[] = array('class' => $class, 'display' => $display); $package['versions'] = $versions; } // mainrepo $i++; $packages[] = $package; } } return $packages; }
/** * Parse the content of all RPM repository * * @param TableRpm $rpmtable the table to write to * @param TableRpmRepo $rpmrepo the table to store timestamp * @param hastable $row the repo to read from * * @return integer number of parsed line */ private static function readOneRpm(TableRpm $rpmtable, TableRpmRepo $rpmrepo, array $row) { $tot = 0; $primary = self::readMetadata($rpmrepo, $row); if ($primary) { $crit = array('repo_main' => $row['main'], 'repo_sub' => $row['sub']); $nb = $rpmtable->delete($crit); self::log("Delete {$nb} packages"); foreach ($primary->package as $package) { if ($package->attributes() == 'rpm') { $ver = $package->version->attributes(); $loc = $package->location->attributes(); $input = array('repo_main' => $row['main'], 'repo_sub' => $row['sub'], 'name' => $package->name, 'epoch' => $ver['epoch'], 'ver' => $ver['ver'], 'rel' => $ver['rel'], 'summary' => $package->summary, 'location' => $loc['href'], 'url' => $package->url); if ($rpmtable->add($input)) { $tot++; } } } self::log("Write {$tot} packages"); } return $tot; }