diff options
author | Yorhel <git@yorhel.nl> | 2018-02-08 16:06:17 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2018-02-08 16:12:07 +0100 |
commit | 93b79ef9ebafcfccd0d239ffd06e2b547e209e3d (patch) | |
tree | 98d96f024d00bf318b16243518e53c2977136202 /lib/VNDB/DB | |
parent | 3f3a4d9810bb2483a89442b85d438639f26ecb7e (diff) |
Store d+ pages in the DB as versioned entries + use markdown
This touches a bunch of things:
- Adds a new first-class database entry type
- Removes the d+.+.+ BBCode link syntax, adds a new d+#+ and d+#+.+
link syntax (references have been updated where possible)
- Adds a new dependency on Text::MultiMarkdown
Diffstat (limited to 'lib/VNDB/DB')
-rw-r--r-- | lib/VNDB/DB/Docs.pm | 53 | ||||
-rw-r--r-- | lib/VNDB/DB/Misc.pm | 4 |
2 files changed, 56 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Docs.pm b/lib/VNDB/DB/Docs.pm new file mode 100644 index 00000000..27cabf6e --- /dev/null +++ b/lib/VNDB/DB/Docs.pm @@ -0,0 +1,53 @@ + +package VNDB::DB::Docs; + +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT = qw|dbDocGet dbDocGetRev dbDocRevisionInsert|; + + +# Can only fetch a single document. +# $doc = $self->dbDocGet(id => $id); +sub dbDocGet { + my $self = shift; + my %o = @_; + + my $r = $self->dbAll('SELECT id, title, content FROM docs WHERE id = ?', $o{id}); + return wantarray ? ($r, 0) : $r; +} + + +# options: id, rev +sub dbDocGetRev { + my $self = shift; + my %o = @_; + + $o{rev} ||= $self->dbRow('SELECT MAX(rev) AS rev FROM changes WHERE type = \'d\' AND itemid = ?', $o{id})->{rev}; + + my $r = $self->dbAll(q| + SELECT de.id, d.title, d.content, de.hidden, de.locked, + extract('epoch' from c.added) as added, c.requester, c.comments, u.username, c.rev, c.ihid, c.ilock, c.id AS cid, + NOT EXISTS(SELECT 1 FROM changes c2 WHERE c2.type = c.type AND c2.itemid = c.itemid AND c2.rev = c.rev+1) AS lastrev + FROM changes c + JOIN docs de ON de.id = c.itemid + JOIN docs_hist d ON d.chid = c.id + JOIN users u ON u.id = c.requester + WHERE c.type = 'd' AND c.itemid = ? AND c.rev = ?|, + $o{id}, $o{rev} + ); + return wantarray ? ($r, 0) : $r; +} + + +# Updates the edit_* tables, used from dbItemEdit() +# Arguments: { title content }, +sub dbDocRevisionInsert { + my($self, $o) = @_; + my %set = map exists($o->{$_}) ? (qq|"$_" = ?|, $o->{$_}) : (), qw|title content|; + $self->dbExec('UPDATE edit_docs !H', \%set) if keys %set; +} + + +1; diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm index d6389376..61bb71a2 100644 --- a/lib/VNDB/DB/Misc.pm +++ b/lib/VNDB/DB/Misc.pm @@ -21,7 +21,7 @@ sub dbStats { # Inserts a new revision into the database -# Arguments: type [vrp], itemid, rev, %options->{ editsum uid ihid ilock + db[item]RevisionInsert } +# Arguments: type [vrpcsd], itemid, rev, %options->{ editsum uid ihid ilock + db[item]RevisionInsert } # rev = changes.rev of the revision this edit is based on, undef to create a new DB item # Returns: { itemid, chid, rev } sub dbItemEdit { @@ -41,6 +41,7 @@ sub dbItemEdit { $self->dbReleaseRevisionInsert( \%o) if $type eq 'r'; $self->dbCharRevisionInsert( \%o) if $type eq 'c'; $self->dbStaffRevisionInsert( \%o) if $type eq 's'; + $self->dbDocRevisionInsert( \%o) if $type eq 'd'; return $self->dbRow('SELECT * FROM edit_!s_commit()', $type); } @@ -98,6 +99,7 @@ sub dbRevisionGet { UNION ALL SELECT 'r'::dbentry_type, chid, title, original FROM releases_hist UNION ALL SELECT 'p'::dbentry_type, chid, name, original FROM producers_hist UNION ALL SELECT 'c'::dbentry_type, chid, name, original FROM chars_hist + UNION ALL SELECT 'd'::dbentry_type, chid, title, '' AS original FROM docs_hist UNION ALL SELECT 's'::dbentry_type, sh.chid, name, original FROM staff_hist sh JOIN staff_alias_hist sah ON sah.chid = sh.chid AND sah.aid = sh.aid ) x(type, id, title, original) WHERE $w |