Commit a1bee1a2 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

Add support for architecture-specific sources

As a follow-up to 4d7da959

 (Add support for architecture-specific fields,
2014-08-10), handle architecture-specific source fields as well.

Signed-off-by: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent 725a4778
...@@ -238,6 +238,7 @@ CREATE TABLE PackageRelations ( ...@@ -238,6 +238,7 @@ CREATE TABLE PackageRelations (
CREATE TABLE PackageSources ( CREATE TABLE PackageSources (
PackageID INTEGER UNSIGNED NOT NULL, PackageID INTEGER UNSIGNED NOT NULL,
Source VARCHAR(255) NOT NULL DEFAULT "/dev/null", Source VARCHAR(255) NOT NULL DEFAULT "/dev/null",
SourceArch VARCHAR(255) NULL DEFAULT NULL,
INDEX (PackageID), INDEX (PackageID),
FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE
) ENGINE = InnoDB; ) ENGINE = InnoDB;
......
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
---- ----
ALTER TABLE PackageDepends ADD COLUMN DepArch VARCHAR(255) NULL DEFAULT NULL; ALTER TABLE PackageDepends ADD COLUMN DepArch VARCHAR(255) NULL DEFAULT NULL;
ALTER TABLE PackageRelations ADD COLUMN RelArch VARCHAR(255) NULL DEFAULT NULL; ALTER TABLE PackageRelations ADD COLUMN RelArch VARCHAR(255) NULL DEFAULT NULL;
ALTER TABLE PackageSources ADD COLUMN SourceArch VARCHAR(255) NULL DEFAULT NULL;
---- ----
...@@ -176,7 +176,6 @@ if ($uid): ...@@ -176,7 +176,6 @@ if ($uid):
break; break;
case 'license': case 'license':
case 'groups': case 'groups':
case 'source':
$section_info[$key][] = $value; $section_info[$key][] = $value;
break; break;
case 'depends': case 'depends':
...@@ -186,6 +185,7 @@ if ($uid): ...@@ -186,6 +185,7 @@ if ($uid):
case 'conflicts': case 'conflicts':
case 'provides': case 'provides':
case 'replaces': case 'replaces':
case 'source':
$section_info[$key][$arch][] = $value; $section_info[$key][$arch][] = $value;
break; break;
} }
...@@ -382,8 +382,10 @@ if ($uid): ...@@ -382,8 +382,10 @@ if ($uid):
} }
} }
foreach ($pi['source'] as $src) { foreach ($pi['source'] as $srcarch => $srcgrp) {
pkg_add_src($pkgid, $src); foreach ($srcgrp as $src) {
pkg_add_src($pkgid, $src, $srcarch);
}
} }
} }
......
...@@ -291,6 +291,31 @@ function pkg_rel_html($name, $cond, $arch) { ...@@ -291,6 +291,31 @@ function pkg_rel_html($name, $cond, $arch) {
return $html; return $html;
} }
/**
* Get the HTML code to display a source link
*
* @param string $url The URL of the source
* @param string $arch The source architecture
*
* @return string The HTML code of the label to display
*/
function pkg_source_link($url, $arch) {
$url = explode('::', $url);
$parsed_url = parse_url($url[0]);
if (isset($parsed_url['scheme']) || isset($url[1])) {
$link = '<a href="' . htmlspecialchars((isset($url[1]) ? $url[1] : $url[0]), ENT_QUOTES) . '">' . htmlspecialchars($url[0]) . '</a>';
} else {
$link = htmlspecialchars($url[0]);
}
if ($arch) {
$link .= ' <em>(' . htmlspecialchars($arch) . ')</em>';
}
return $link;
}
/** /**
* Determine packages that depend on a package * Determine packages that depend on a package
* *
...@@ -327,7 +352,7 @@ function pkg_sources($pkgid) { ...@@ -327,7 +352,7 @@ function pkg_sources($pkgid) {
$pkgid = intval($pkgid); $pkgid = intval($pkgid);
if ($pkgid > 0) { if ($pkgid > 0) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT Source FROM PackageSources "; $q = "SELECT Source, SourceArch FROM PackageSources ";
$q.= "WHERE PackageID = " . $pkgid; $q.= "WHERE PackageID = " . $pkgid;
$q.= " ORDER BY Source"; $q.= " ORDER BY Source";
$result = $dbh->query($q); $result = $dbh->query($q);
...@@ -335,7 +360,7 @@ function pkg_sources($pkgid) { ...@@ -335,7 +360,7 @@ function pkg_sources($pkgid) {
return array(); return array();
} }
while ($row = $result->fetch(PDO::FETCH_NUM)) { while ($row = $result->fetch(PDO::FETCH_NUM)) {
$sources[] = $row[0]; $sources[] = $row;
} }
} }
return $sources; return $sources;
...@@ -831,14 +856,17 @@ function pkg_add_rel($pkgid, $type, $relname, $relcondition, $relarch) { ...@@ -831,14 +856,17 @@ function pkg_add_rel($pkgid, $type, $relname, $relcondition, $relarch) {
* *
* @param int $pkgid The package ID to add the source for * @param int $pkgid The package ID to add the source for
* @param string $pkgsrc The package source to add to the database * @param string $pkgsrc The package source to add to the database
* @param string $srcarch The architecture of the source to add
* *
* @return void * @return void
*/ */
function pkg_add_src($pkgid, $pkgsrc) { function pkg_add_src($pkgid, $pkgsrc, $srcarch) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "INSERT INTO PackageSources (PackageID, Source) VALUES ("; $q = sprintf("INSERT INTO PackageSources (PackageID, Source, SourceArch) VALUES (%d, %s, %s)",
$q .= $pkgid . ", " . $dbh->quote($pkgsrc) . ")"; $pkgid,
$dbh->quote($pkgsrc),
$srcarch ? $dbh->quote($srcarch) : 'NULL'
);
$dbh->exec($q); $dbh->exec($q);
} }
......
...@@ -379,28 +379,14 @@ if ($row["PackagerUID"]): ...@@ -379,28 +379,14 @@ if ($row["PackagerUID"]):
<div id="pkgfiles" class="listing"> <div id="pkgfiles" class="listing">
<h3><?= __('Sources') ?></h3> <h3><?= __('Sources') ?></h3>
</div> </div>
<?php if (count($sources) > 0): ?> <?php if (count($sources) > 0): ?>
<div> <div>
<ul id="pkgsrcslist"> <ul id="pkgsrcslist">
<?php <?php while (list($k, $src) = each($sources)): ?>
while (list($k, $src) = each($sources)): <li><?= pkg_source_link($src[0], $src[1]) ?></li>
$src = explode('::', $src); <?php endwhile; ?>
$parsed_url = parse_url($src[0]);
# It is an external source
if (isset($parsed_url['scheme']) || isset($src[1])):
?>
<li><a href="<?= htmlspecialchars((isset($src[1]) ? $src[1] : $src[0]), ENT_QUOTES) ?>"><?= htmlspecialchars($src[0]) ?> </a></li>
<?php
else:
# It is presumably an internal source
$src = $src[0];
?>
<li><?= htmlspecialchars($src) ?></li>
<?php endif; ?>
<?php endwhile; ?>
</ul> </ul>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment