2 # DBStubs.pl: DB independent (I hope, heh) factoid support
4 # Version: v0.6d (20000223)
11 # Usage: &setFactInfo($faqtoid, $key, $val);
13 &sqlSet( 'factoids', { factoid_key => $_[0] }, { $_[1] => $_[2] } );
17 # Usage: &getFactInfo($faqtoid, [$what]);
19 return &sqlSelect( 'factoids', $_[1], { factoid_key => $_[0] } );
23 # Usage: &getFactoid($faqtoid);
25 return &getFactInfo( $_[0], 'factoid_value' );
29 # Usage: &delFactoid($faqtoid);
33 &sqlDelete( 'factoids', { factoid_key => $faqtoid } );
34 &status("DELETED $faqtoid");
40 # Usage: &IsLocked($faqtoid);
43 my $thisnuh = &getFactInfo( $faqtoid, 'locked_by' );
45 if ( defined $thisnuh and $thisnuh ne '' ) {
46 if ( !&IsHostMatch($thisnuh) and &IsFlag('o') ne 'o' ) {
47 &performReply("cannot alter locked factoids");
56 # Usage: &AddModified($faqtoid,$nuh);
58 my ( $faqtoid, $nuh ) = @_;
59 my $modified_by = &getFactInfo( $faqtoid, 'modified_by' );
60 my ( @modifiedlist, @modified, %modified );
62 if ( defined $modified_by ) {
63 push( @modifiedlist, split( /\,/, $modified_by ) );
65 push( @modifiedlist, $nuh );
67 foreach ( reverse @modifiedlist ) {
68 /^(\S+)!(\S+)@(\S+)$/;
70 next if ( exists $modified{$nick} );
72 $modified{$nick} = $_;
73 push( @modified, $nick );
78 foreach ( reverse @modified ) {
79 push( @modifiedlist, $modified{$_} );
81 shift(@modifiedlist) while ( scalar @modifiedlist > 3 );
83 &setFactInfo( $faqtoid, 'modified_by', join( ",", @modifiedlist ) );
84 &setFactInfo( $faqtoid, 'modified_time', time() );
90 ### Commands which use the fundamental functions... Helpers?
94 # Usage: &CmdLock($function,$faqtoid);
98 my $thisnuh = &getFactInfo( $faqtoid, 'locked_by' );
100 if ( defined $thisnuh and $thisnuh ne '' ) {
101 my $locked_by = ( split( /\!/, $thisnuh ) )[0];
103 "factoid \002$faqtoid\002 has already been locked by $locked_by." );
107 $thisnuh ||= &getFactInfo( $faqtoid, 'created_by' );
109 # fixes bug found on 19991103.
110 # code needs to be reorganised though.
111 if ( $thisnuh ne '' ) {
112 if ( !&IsHostMatch($thisnuh) && IsFlag('o') ne 'o' ) {
113 &msg( $who, "sorry, you are not allowed to lock '$faqtoid'." );
118 &performReply("locking factoid \002$faqtoid\002");
119 &setFactInfo( $faqtoid, 'locked_by', $nuh );
120 &setFactInfo( $faqtoid, 'locked_time', time() );
126 # Usage: &CmdUnLock($faqtoid);
130 my $thisnuh = &getFactInfo( $faqtoid, 'locked_by' );
132 if ( !defined $thisnuh ) {
133 &msg( $who, "factoid \002$faqtoid\002 is not locked." );
137 if ( $thisnuh ne '' and !&IsHostMatch($thisnuh) and &IsFlag('o') ne 'o' ) {
139 "sorry, you are not allowed to unlock factoid '$faqtoid'." );
143 &performReply("unlocking factoid \002$faqtoid\002");
144 &setFactInfo( $faqtoid, 'locked_by', '' );
145 &setFactInfo( $faqtoid, 'locked_time', '0' )
146 ; # pgsql complains if NOT NULL set. So set 0 which is the default
153 # vim:ts=4:sw=4:expandtab:tw=80