summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Misc.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-12-05 13:22:53 +0100
committerYorhel <git@yorhel.nl>2009-12-05 13:22:53 +0100
commit7554f305ae27091ccff6a692180a5af7282df766 (patch)
treee0c93d34c1748b4ad58040550665eb5427df156b /lib/VNDB/DB/Misc.pm
parentfbcadd3ceb50a97dab4dd5cd284cc35e8b89b3b4 (diff)
Merged db[VN|Producer|Release][Edit|Add] into dbItemEdit and dbItemAdd
And also changed the way the item_table.latest column was updated: it is now only updated after the revision insert has completed, making it easier to write trigger functions in SQL.
Diffstat (limited to 'lib/VNDB/DB/Misc.pm')
-rw-r--r--lib/VNDB/DB/Misc.pm41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index e819a1a3..ec8d375e 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 dbRevisionInsert dbItemInsert dbRevisionGet dbItemMod dbRandomQuote
+ dbStats dbItemEdit dbItemAdd dbRevisionGet dbItemMod dbRandomQuote
|;
@@ -21,13 +21,10 @@ 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 [vrp], item ID, edit summary
+# Arguments: type [vrp], item ID, %options->{ editsum uid + db[item]RevisionInsert }
# Returns: local revision, global revision
-sub dbRevisionInsert {
- my($self, $type, $iid, $editsum, $uid) = @_;
+sub dbItemEdit {
+ my($self, $type, $iid, %o) = @_;
my $table = {qw|v vn r releases p producers|}->{$type};
@@ -42,37 +39,47 @@ sub dbRevisionInsert {
LIMIT 1
))
RETURNING id, rev|,
- $type, $uid||$self->authInfo->{id}, $self->reqIP, $editsum,
+ $type, $o{uid}||$self->authInfo->{id}, $self->reqIP, $o{editsum},
$table, $type, $iid
);
- $self->dbExec(q|UPDATE !s SET latest = ? WHERE id = ?|, $table, $c->{id}, $iid);
+ $self->dbVNRevisionInsert( $c->{id}, $iid, \%o) if $type eq 'v';
+ $self->dbProducerRevisionInsert($c->{id}, $iid, \%o) if $type eq 'p';
+ $self->dbReleaseRevisionInsert( $c->{id}, $iid, \%o) if $type eq 'r';
+ $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 [vrp], edit summary, [uid]
+# Comparable to dbItemEdit(), but creates a new item with a corresponding revision.
+# Argumments: type [vrp] + same option hash as dbItemEdit()
# Returns: item id, global revision
-sub dbItemInsert {
- my($self, $type, $editsum, $uid) = @_;
+sub dbItemAdd {
+ my($self, $type, %o) = @_;
+
+ my $table = {qw|v vn r releases p producers|}->{$type};
my $cid = $self->dbRow(q|
INSERT INTO changes (type, requester, ip, comments)
VALUES (?, ?, ?, ?)
RETURNING id|,
- $type, $uid||$self->authInfo->{id}, $self->reqIP, $editsum
+ $type, $o{uid}||$self->authInfo->{id}, $self->reqIP, $o{editsum}
)->{id};
my $iid = $self->dbRow(q|
INSERT INTO !s (latest)
- VALUES (?)
+ VALUES (0)
RETURNING id|,
- {qw|v vn r releases p producers|}->{$type}, $cid
+ $table
)->{id};
+ $self->dbVNRevisionInsert( $cid, $iid, \%o) if $type eq 'v';
+ $self->dbProducerRevisionInsert($cid, $iid, \%o) if $type eq 'p';
+ $self->dbReleaseRevisionInsert( $cid, $iid, \%o) if $type eq 'r';
+
+ $self->dbExec(q|UPDATE !s SET latest = ? WHERE id = ?|, $table, $cid, $iid);
+
return ($iid, $cid);
}