diff options
author | Yorhel <git@yorhel.nl> | 2008-11-14 11:16:39 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-11-14 11:16:39 +0100 |
commit | cb196de6bc61c9f513a564643926bee656758450 (patch) | |
tree | c990c5b9c6e8031f3eff9447de2bd99a04a6d0ea /lib/VNDB/DB/Misc.pm | |
parent | ed7a3c08b0d062a0b174d577b2639e88f18d3a42 (diff) |
Adding new producer works + abstracted adding of new items and revisions
...and those URL regexes are getting more and more complex >.>
Diffstat (limited to 'lib/VNDB/DB/Misc.pm')
-rw-r--r-- | lib/VNDB/DB/Misc.pm | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm index 61b1223c..ced47084 100644 --- a/lib/VNDB/DB/Misc.pm +++ b/lib/VNDB/DB/Misc.pm @@ -6,7 +6,7 @@ use warnings; use Exporter 'import'; our @EXPORT = qw| - dbStats + dbStats dbRevisionInsert dbItemInsert |; @@ -24,5 +24,63 @@ sub dbStats { } @_ }; } + +# Inserts a new revision and updates the item to point to this revision +# 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 +# Returns: local revision, global revision +sub dbRevisionInsert { + my($self, $type, $iid, $editsum) = @_; + + my $table = [qw|vn releases producers|]->[$type]; + + my $c = $self->dbRow(q| + INSERT INTO changes (type, requester, ip, comments, rev) + VALUES (?, ?, ?, ?, ( + SELECT c.rev+1 + FROM changes c + JOIN !s_rev ir ON ir.id = c.id + WHERE ir.!sid = ? + ORDER BY c.id DESC + LIMIT 1 + )) + RETURNING id, rev|, + $type, $self->authInfo->{id}, $self->reqIP, $editsum, + $table, [qw|v r p|]->[$type], $iid + ); + + $self->dbExec(q|UPDATE !s SET latest = ? WHERE id = ?|, $table, $c->{id}, $iid); + + return ($c->{rev}, $c->{id}); +} + + +# Comparable to RevisionInsert, but creates a new item with a corresponding +# change. Same things about inconsistent state, etc. +# Argumments: type [0..2], edit summary +# Returns: item id, global revision +sub dbItemInsert { + my($self, $type, $editsum) = @_; + + my $cid = $self->dbRow(q| + INSERT INTO changes (type, requester, ip, comments) + VALUES (?, ?, ?, ?) + RETURNING id|, + $type, $self->authInfo->{id}, $self->reqIP, $editsum + )->{id}; + + my $iid = $self->dbRow(q| + INSERT INTO !s (latest) + VALUES (?) + RETURNING id|, + [qw|vn releases producers|]->[$type], $cid + )->{id}; + + return ($iid, $cid); +} + + 1; |