From cc3244ea8ae0202265df3d0fd2cfe86fbbeb9d30 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 26 Apr 2014 14:07:20 +0200 Subject: Store package groups in the database Signed-off-by: Lukas Fleischer --- web/html/pkgsubmit.php | 9 ++++++++- web/lib/pkgfuncs.inc.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) (limited to 'web') diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 3df38d8..107441f 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -151,6 +151,7 @@ if ($uid): } } $section_info = array( + 'groups' => array(), 'depends' => array(), 'makedepends' => array(), 'checkdepends' => array(), @@ -169,6 +170,7 @@ if ($uid): case 'license': $section_info[$key] = $value; break; + case 'groups': case 'source': case 'depends': case 'makedepends': @@ -196,7 +198,7 @@ if ($uid): if (!isset($pkgbase_info['pkgbase'])) { $pkgbase_info['pkgbase'] = $pkgbase_info['pkgname']; } - foreach (array('source', 'depends', 'makedepends', 'checkdepends', 'optdepends', 'conflicts', 'provides', 'replaces') as $array_opt) { + foreach (array('groups', 'source', 'depends', 'makedepends', 'checkdepends', 'optdepends', 'conflicts', 'provides', 'replaces') as $array_opt) { if (empty($pkgbase_info[$array_opt])) { $pkgbase_info[$array_opt] = array(); } else { @@ -357,6 +359,11 @@ if ($uid): foreach ($pkginfo as $pi) { $pkgid = pkg_create($base_id, $pi['pkgname'], $pi['license'], $pi['full-version'], $pi['pkgdesc'], $pi['url']); + foreach ($pi['groups'] as $grp) { + $grpid = pkg_create_group($grp); + pkg_add_grp($pkgid, $grpid); + } + foreach (array('depends', 'makedepends', 'checkdepends', 'optdepends') as $deptype) { foreach ($pi[$deptype] as $dep) { $deppkgname = preg_replace("/(<|=|>).*/", "", $dep); diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index a04f525..f80d4b4 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -805,3 +805,46 @@ function pkg_add_src($pkgid, $pkgsrc) { $dbh->exec($q); } + +/** + * Creates a new group and returns its ID + * + * If the groups already exists, the ID of the already existing group is + * returned. + * + * @param string $name The name of the group to create + * + * @return int The ID of the group + */ +function pkg_create_group($name) { + $dbh = DB::connect(); + $q = sprintf("SELECT ID FROM Groups WHERE Name = %s", $dbh->quote($name)); + $result = $dbh->query($q); + if ($result) { + $grpid = $result->fetch(PDO::FETCH_COLUMN, 0); + if ($grpid > 0) { + return $grpid; + } + } + + $q = sprintf("INSERT INTO Groups (Name) VALUES (%s)", $dbh->quote($name)); + $dbh->exec($q); + return $dbh->lastInsertId(); +} + +/** + * Add a package to a group + * + * @param int $pkgid The package ID of the package to add + * @param int $grpid The group ID of the group to add the package to + * + * @return void + */ +function pkg_add_grp($pkgid, $grpid) { + $dbh = DB::connect(); + $q = sprintf("INSERT INTO PackageGroups (PackageID, GroupID) VALUES (%d, %d)", + $pkgid, + $grpid + ); + $dbh->exec($q); +} -- cgit v1.2.3-70-g09d2