Commit 252afad9 authored by pjmattal's avatar pjmattal
Browse files

tweaks to package functions and schema

parent 7549ca2d
......@@ -67,6 +67,7 @@ CREATE TABLE PackageCategories (
Category CHAR(32) NOT NULL,
PRIMARY KEY (ID)
);
INSERT INTO PackageCategories (ID, Category) VALUES (0, 'none');
INSERT INTO PackageCategories (Category) VALUES ('daemons');
INSERT INTO PackageCategories (Category) VALUES ('devel');
INSERT INTO PackageCategories (Category) VALUES ('editors');
......@@ -93,6 +94,7 @@ CREATE TABLE PackageLocations (
Location CHAR(32) NOT NULL,
PRIMARY KEY (ID)
);
INSERT INTO PackageLocations (ID, Location) VALUES (0, 'none');
INSERT INTO PackageLocations (ID, Location) VALUES (1, 'Unsupported');
INSERT INTO PackageLocations (ID, Location) VALUES (2, 'AUR');
INSERT INTO PackageLocations (ID, Location) VALUES (3, 'Current');
......@@ -109,6 +111,9 @@ CREATE TABLE Packages (
CategoryID TINYINT UNSIGNED NOT NULL,
Description CHAR(128) NOT NULL DEFAULT "An Arch Package",
URL CHAR(255) NOT NULL DEFAULT "http://www.archlinux.org",
DummyPkg TINYINT UNSIGNED NOT NULL DEFAULT 0, -- 1=>dummy
FSPath CHAR(255) NOT NULL DEFAULT '',
URLPath CHAR(255) NOT NULL DEFAULT '',
LocationID TINYINT UNSIGNED NOT NULL,
NumVotes INTEGER UNSIGNED NOT NULL DEFAULT 0,
OutOfDate TINYINT UNSIGNED DEFAULT 0,
......@@ -122,6 +127,7 @@ CREATE TABLE Packages (
UNIQUE (Name),
INDEX (CategoryID),
INDEX (LocationID),
INDEX (DummyPkg),
INDEX (OutOfDate),
INDEX (NumVotes),
INDEX (SubmitterUID),
......@@ -169,8 +175,8 @@ CREATE TABLE PackageVotes (
--
CREATE TABLE PackageContents (
PackageID INTEGER UNSIGNED NOT NULL,
FSPath CHAR(256) NOT NULL,
URLPath CHAR(255) NOT NULL,
FSPath CHAR(255) NOT NULL DEFAULT '',
URLPath CHAR(255) NOT NULL DEFAULT '',
FileSize BIGINT UNSIGNED NOT NULL default 0,
INDEX (PackageID),
FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE
......
......@@ -12,8 +12,8 @@ $DBUG = 1;
# this is the directory that new packages will be uploaded to
#
$UPLOAD_DIR = "/tmp/aur/temp/";
$INCOMING_DIR = "/tmp/aur/incoming/";
$UPLOAD_DIR = "/aur/temp/";
$INCOMING_DIR = "/aur/incoming/";
if ($_COOKIE["AURSID"]) {
......
......@@ -444,19 +444,6 @@ function dbug($msg) {
return;
}
# check to see if the package name exists
#
function package_exists($name="") {
if (!$name) {return 0;}
$dbh = db_connect();
$q = "SELECT COUNT(*) FROM Packages ";
$q.= "WHERE Name = '".mysql_escape_string($name)."'";
$result = db_query($q, $dbh);
if (!$result) {return 0;}
$row = mysql_fetch_row($result);
return $row[0];
}
# check to see if the user can overwrite an existing package
#
function can_overwrite_pkg($name="", $sid="") {
......
......@@ -83,6 +83,20 @@ function pkgLocations() {
return $locs;
}
# check to see if the package name exists
#
function package_exists($name="") {
if (!$name) {return NULL;}
$dbh = db_connect();
$q = "SELECT ID FROM Packages ";
$q.= "WHERE Name = '".mysql_escape_string($name)."' ";
$q.= "AND DummyPkg = 0";
$result = db_query($q, $dbh);
if (!$result) {return NULL;}
$row = mysql_fetch_row($result);
return $row[0];
}
# grab package dependencies
#
function package_dependencies($pkgid=0) {
......@@ -102,6 +116,39 @@ function package_dependencies($pkgid=0) {
return $deps;
}
# create a dummy package and return it's Packages.ID if it already exists,
# return the existing ID
#
function create_dummy($pname="", $sid="") {
if ($pname && $sid) {
$uid = uid_from_sid($sid);
if (!$uid) {return NULL};
$dbh = db_connect();
$q = "SELECT ID FROM Packages WHERE Name = '";
$q.= mysql_escape_string($pname)."'";
$result = db_query($q, $dbh);
if (!$result) {
# Insert the dummy
#
$q = "INSERT INTO Packages (Name, CategoryID, Description, ";
$q.= "URL, LocationID, SubmittedTS, SubmitterUID) VALUES ('";
$q.= mysql_escape_string($pname)."', 0, ";
$q.= "'A dummy package', '/#', 0, UNIX_TIMESTAMP(), ";
$q.= $uid.")";
$result = db_query($q, $dbh);
if (!$result) {
return NULL;
}
return mysql_insert_id($result);
} else {
$data = mysql_fetch_row($result);
return $data['ID'];
}
}
return NULL;
}
# grab package sources
#
function package_sources($pkgid=0) {
......
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