summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-10-12 09:34:06 +0200
committerYorhel <git@yorhel.nl>2009-10-12 09:34:06 +0200
commit69d8738688ebb72707fe377b7ce7c717407aea96 (patch)
tree339e1b0cfcb860f152ef46a2a30638a053335370 /lib
parent0c5a9606dd9047522c4357e36e5fe9081943b947 (diff)
SQL: Converted changes.type to an ENUM
This is a very important column in a very important table, I hope I didn't forget to update a piece of code somewhere...
Diffstat (limited to 'lib')
-rw-r--r--lib/Multi/IRC.pm8
-rw-r--r--lib/VNDB/DB/Misc.pm24
-rw-r--r--lib/VNDB/DB/Producers.pm4
-rw-r--r--lib/VNDB/DB/Releases.pm4
-rw-r--r--lib/VNDB/DB/VN.pm4
-rw-r--r--lib/VNDB/Handler/Misc.pm5
-rw-r--r--lib/VNDB/Util/CommonHTML.pm5
7 files changed, 26 insertions, 28 deletions
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index 5018d2aa..4225e6b8 100644
--- a/lib/Multi/IRC.pm
+++ b/lib/Multi/IRC.pm
@@ -266,12 +266,12 @@ sub notify { # name, pid, payload
return if !$_[HEAP]{$k};
my $q = $_[ARG0] eq 'newrevision' ? q|SELECT
- CASE WHEN c.type = 0 THEN 'v' WHEN c.type = 1 THEN 'r' ELSE 'p' END AS type, c.rev, c.comments, c.id AS lastrev,
+ CASE WHEN c.type, c.rev, c.comments, c.id AS lastrev,
COALESCE(vr.vid, rr.rid, pr.pid) AS id, COALESCE(vr.title, rr.title, pr.name) AS title, u.username
FROM changes c
- LEFT JOIN vn_rev vr ON c.type = 0 AND c.id = vr.id
- LEFT JOIN releases_rev rr ON c.type = 1 AND c.id = rr.id
- LEFT JOIN producers_rev pr ON c.type = 2 AND c.id = pr.id
+ LEFT JOIN vn_rev vr ON c.type = 'v' AND c.id = vr.id
+ LEFT JOIN releases_rev rr ON c.type = 'r' AND c.id = rr.id
+ LEFT JOIN producers_rev pr ON c.type = 'p' AND c.id = pr.id
JOIN users u ON u.id = c.requester
WHERE c.id > ? AND c.requester <> 1
ORDER BY c.added|
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index ed3730ee..b3522d72 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -24,12 +24,12 @@ sub dbStats {
# This function leaves the DB in an inconsistent state, the actual revision
# will have to be inserted directly after calling this function, otherwise
# the commit will fail.
-# Arguments: type [0..2], item ID, edit summary
+# Arguments: type [vrp], item ID, edit summary
# Returns: local revision, global revision
sub dbRevisionInsert {
my($self, $type, $iid, $editsum, $uid) = @_;
- my $table = [qw|vn releases producers|]->[$type];
+ my $table = {qw|v vn r releases p producers|}->{$type};
my $c = $self->dbRow(q|
INSERT INTO changes (type, requester, ip, comments, rev)
@@ -43,7 +43,7 @@ sub dbRevisionInsert {
))
RETURNING id, rev|,
$type, $uid||$self->authInfo->{id}, $self->reqIP, $editsum,
- $table, [qw|v r p|]->[$type], $iid
+ $table, $type, $iid
);
$self->dbExec(q|UPDATE !s SET latest = ? WHERE id = ?|, $table, $c->{id}, $iid);
@@ -54,7 +54,7 @@ sub dbRevisionInsert {
# Comparable to RevisionInsert, but creates a new item with a corresponding
# change. Same things about inconsistent state, etc.
-# Argumments: type [0..2], edit summary, [uid]
+# Argumments: type [vrp], edit summary, [uid]
# Returns: item id, global revision
sub dbItemInsert {
my($self, $type, $editsum, $uid) = @_;
@@ -70,7 +70,7 @@ sub dbItemInsert {
INSERT INTO !s (latest)
VALUES (?)
RETURNING id|,
- [qw|vn releases producers|]->[$type], $cid
+ {qw|v vn r releases p producers|}->{$type}, $cid
)->{id};
return ($iid, $cid);
@@ -94,7 +94,7 @@ sub dbRevisionGet {
'((c.type = ? AND vr.vid = ?) OR (c.type = ? AND rv.vid = ?))' => [0, $o{iid}, 1, $o{iid}],
) : (
$o{type} ? (
- 'c.type = ?' => { v=>0, r=>1, p=>2 }->{$o{type}} ) : (),
+ 'c.type = ?' => $o{type} ) : (),
$o{iid} ? (
'!sr.!sid = ?' => [ $o{type}, $o{type}, $o{iid} ] ) : (),
),
@@ -113,14 +113,14 @@ sub dbRevisionGet {
my @join = (
$o{iid} || $o{what} =~ /item/ || $o{hidden} || $o{releases} ? (
- 'LEFT JOIN vn_rev vr ON c.type = 0 AND c.id = vr.id',
- 'LEFT JOIN releases_rev rr ON c.type = 1 AND c.id = rr.id',
- 'LEFT JOIN producers_rev pr ON c.type = 2 AND c.id = pr.id',
+ q{LEFT JOIN vn_rev vr ON c.type = 'v' AND c.id = vr.id},
+ q{LEFT JOIN releases_rev rr ON c.type = 'r' AND c.id = rr.id},
+ q{LEFT JOIN producers_rev pr ON c.type = 'p' AND c.id = pr.id},
) : (),
$o{hidden} || $o{releases} ? (
- 'LEFT JOIN vn v ON c.type = 0 AND vr.vid = v.id',
- 'LEFT JOIN releases r ON c.type = 1 AND rr.rid = r.id',
- 'LEFT JOIN producers p ON c.type = 2 AND pr.pid = p.id',
+ q{LEFT JOIN vn v ON c.type = 'v' AND vr.vid = v.id},
+ q{LEFT JOIN releases r ON c.type = 'r' AND rr.rid = r.id},
+ q{LEFT JOIN producers p ON c.type = 'p' AND pr.pid = p.id},
) : (),
$o{what} =~ /user/ ? 'JOIN users u ON c.requester = u.id' : (),
$o{releases} ? 'LEFT JOIN releases_vn rv ON c.id = rv.rid' : (),
diff --git a/lib/VNDB/DB/Producers.pm b/lib/VNDB/DB/Producers.pm
index 18f372f9..afc21492 100644
--- a/lib/VNDB/DB/Producers.pm
+++ b/lib/VNDB/DB/Producers.pm
@@ -86,7 +86,7 @@ sub dbProducerGet {
# returns: ( local revision, global revision )
sub dbProducerEdit {
my($self, $pid, %o) = @_;
- my($rev, $cid) = $self->dbRevisionInsert(2, $pid, $o{editsum}, $o{uid});
+ my($rev, $cid) = $self->dbRevisionInsert('p', $pid, $o{editsum}, $o{uid});
insert_rev($self, $cid, $pid, \%o);
return ($rev, $cid);
}
@@ -96,7 +96,7 @@ sub dbProducerEdit {
# returns: ( item id, global revision )
sub dbProducerAdd {
my($self, %o) = @_;
- my($pid, $cid) = $self->dbItemInsert(2, $o{editsum}, $o{uid});
+ my($pid, $cid) = $self->dbItemInsert('p', $o{editsum}, $o{uid});
insert_rev($self, $cid, $pid, \%o);
return ($pid, $cid);
}
diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm
index 551855e8..9260b787 100644
--- a/lib/VNDB/DB/Releases.pm
+++ b/lib/VNDB/DB/Releases.pm
@@ -154,7 +154,7 @@ sub dbReleaseGet {
# returns: ( local revision, global revision )
sub dbReleaseEdit {
my($self, $rid, %o) = @_;
- my($rev, $cid) = $self->dbRevisionInsert(1, $rid, $o{editsum}, $o{uid});
+ my($rev, $cid) = $self->dbRevisionInsert('r', $rid, $o{editsum}, $o{uid});
insert_rev($self, $cid, $rid, \%o);
return ($rev, $cid);
}
@@ -164,7 +164,7 @@ sub dbReleaseEdit {
# returns: ( item id, global revision )
sub dbReleaseAdd {
my($self, %o) = @_;
- my($rid, $cid) = $self->dbItemInsert(1, $o{editsum}, $o{uid});
+ my($rid, $cid) = $self->dbItemInsert('r', $o{editsum}, $o{uid});
insert_rev($self, $cid, $rid, \%o);
return ($rid, $cid);
}
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 9c411794..662057d5 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -160,7 +160,7 @@ sub dbVNGet {
# returns: ( local revision, global revision )
sub dbVNEdit {
my($self, $id, %o) = @_;
- my($rev, $cid) = $self->dbRevisionInsert(0, $id, $o{editsum}, $o{uid});
+ my($rev, $cid) = $self->dbRevisionInsert('v', $id, $o{editsum}, $o{uid});
insert_rev($self, $cid, $id, \%o);
return ($rev, $cid);
}
@@ -170,7 +170,7 @@ sub dbVNEdit {
# returns: ( item id, global revision )
sub dbVNAdd {
my($self, %o) = @_;
- my($id, $cid) = $self->dbItemInsert(0, $o{editsum}, $o{uid});
+ my($id, $cid) = $self->dbItemInsert('v', $o{editsum}, $o{uid});
insert_rev($self, $cid, $id, \%o);
return ($id, $cid);
}
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 891a83f0..7896ad52 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -66,10 +66,9 @@ sub homepage {
my $changes = $self->dbRevisionGet(what => 'item user', results => 10, auto => 1, hidden => 1);
ul;
for (@$changes) {
- my $t = (qw|v r p|)[$_->{type}];
li;
- lit mt '_home_recentchanges_item', $t,
- sprintf('<a href="%s" title="%s">%s</a>', "/$t$_->{iid}.$_->{rev}",
+ lit mt '_home_recentchanges_item', $_->{type},
+ sprintf('<a href="%s" title="%s">%s</a>', "/$_->{type}$_->{iid}.$_->{rev}",
xml_escape($_->{ioriginal}||$_->{ititle}), xml_escape shorten $_->{ititle}, 33),
$_;
end;
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 7e98159a..90c9db13 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -505,12 +505,11 @@ sub htmlHistory {
],
row => sub {
my($s, $n, $i) = @_;
- my $tc = [qw|v r p|]->[$i->{type}];
- my $revurl = "/$tc$i->{iid}.$i->{rev}";
+ my $revurl = "/$i->{type}$i->{iid}.$i->{rev}";
Tr $n % 2 ? ( class => 'odd' ) : ();
td class => 'tc1_1';
- a href => $revurl, "$tc$i->{iid}";
+ a href => $revurl, "$i->{type}$i->{iid}";
end;
td class => 'tc1_2';
a href => $revurl, ".$i->{rev}";