[vhffs-dev] [1944] renamed meaningless ->is_valid() core method to ->is_connected(), improved jabber and modobot backend init and reconnect

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1944
Author:   gradator
Date:     2012-01-25 23:14:05 +0100 (Wed, 25 Jan 2012)
Log Message:
-----------
renamed meaningless ->is_valid() core method to ->is_connected(), improved jabber and modobot backend init and reconnect

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Main.pm
    trunk/vhffs-api/src/Vhffs/Panel/Public.pm
    trunk/vhffs-irc/modobot.pl
    trunk/vhffs-jabber/vhffspipe.pl

Modified: trunk/vhffs-api/src/Vhffs/Main.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Main.pm	2012-01-25 21:53:06 UTC (rev 1943)
+++ trunk/vhffs-api/src/Vhffs/Main.pm	2012-01-25 22:14:05 UTC (rev 1944)
@@ -94,7 +94,7 @@
 	}
 }
 
-sub is_valid {
+sub is_connected {
 
     my $self = shift;
     return (defined $self->{db} and $self->{db}->ping() > 0);
@@ -185,7 +185,7 @@
 
 get_db_object : Return a DBI object
 
-is_valid() : returns 1 if the object is valid (good database connection, ...), 0 otherwise
+is_connected() : returns 1 if the backend connection is working, 0 otherwise
 
 =head1 SEE ALSO
 Vhffs::User, Vhffs::Group

Modified: trunk/vhffs-api/src/Vhffs/Panel/Public.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Public.pm	2012-01-25 21:53:06 UTC (rev 1943)
+++ trunk/vhffs-api/src/Vhffs/Panel/Public.pm	2012-01-25 22:14:05 UTC (rev 1944)
@@ -81,7 +81,7 @@
 	$vars->{groups_avatar} = Vhffs::Functions::strtobool( $conf->get_panel->{'groups_avatars'} );
 
 	# Handling ajax stuff
-	if( $vhffs->is_valid ) {
+	if( $vhffs->is_connected ) {
 		unless($self->{is_ajax_request}) {
 			$vars->{popular_tags} = Vhffs::Tag::get_most_popular_tags($self->{vhffs});
 			$vars->{random_tags} = Vhffs::Tag::get_random_tags($self->{vhffs});

Modified: trunk/vhffs-irc/modobot.pl
===================================================================
--- trunk/vhffs-irc/modobot.pl	2012-01-25 21:53:06 UTC (rev 1943)
+++ trunk/vhffs-irc/modobot.pl	2012-01-25 22:14:05 UTC (rev 1944)
@@ -40,9 +40,11 @@
 
 # Connections to servers
 
-my $vhffs = init Vhffs::Main;
-exit 1 unless $vhffs;
+my $vhffs = init Vhffs::Main( { backend => 'no' } );
+exit 1 unless defined $vhffs;
 
+$vhffs->connect;
+
 my $configirc = $vhffs->get_config->get_irc;
 my $chan = $configirc->{modobot_channel};
 $chan =~ s/^\\#/#/;
@@ -68,10 +70,8 @@
 {
 	my $seq = shift;  # set that to 1 in order to display only new entries
 
-	unless( $vhffs->is_valid )  {
-		$vhffs->reconnect();
-		irc_msg( 'what the fuck!?' );
-	}
+	# Do nothing if backend is lost
+	return unless $vhffs->reconnect();
 
 	my $objects = Vhffs::Object::getall( $vhffs, undef, Vhffs::Constants::WAITING_FOR_VALIDATION );
 	if( defined $objects )  {
@@ -485,6 +485,10 @@
     my ($self, $event)=@_;
     my ($nick, $mynick)=($event->nick, $self->nick);
     my $texte=$event->{args}[0];
+
+	# Do nothing if backend is lost
+	return unless $vhffs->reconnect();
+
     my $user = ( Vhffs::User::get_by_ircnick($vhffs, $nick) or Vhffs::User::get_by_username($vhffs, $nick) );
 	$vhffs->set_current_user( $user );
 

Modified: trunk/vhffs-jabber/vhffspipe.pl
===================================================================
--- trunk/vhffs-jabber/vhffspipe.pl	2012-01-25 21:53:06 UTC (rev 1943)
+++ trunk/vhffs-jabber/vhffspipe.pl	2012-01-25 22:14:05 UTC (rev 1944)
@@ -9,8 +9,11 @@
 # Flush output immediately.
 $| = 1;
 
-my $vhffs;
+my $vhffs = init Vhffs::Main( { backend => 'no' } );
+exit 1 unless defined $vhffs;
 
+$vhffs->connect;
+
 # On startup, we have to inform c2s of the functions we can deal with. USER-EXISTS is not optional.
 #print "OK USER-EXISTS GET-PASSWORD CHECK-PASSWORD SET-PASSWORD GET-ZEROK SET-ZEROK CREATE-USER DESTROY-USER FREE\n";
 print "OK USER-EXISTS CHECK-PASSWORD CREATE-USER FREE\n";
@@ -33,11 +36,9 @@
 {
 	my $username = shift;
 
-	$vhffs = init Vhffs::Main unless defined $vhffs;
-	return undef unless defined $vhffs;
+	# Reconnect to backend if necessary
+	return undef unless $vhffs->reconnect();
 
-	# DB connection lost !
-	$vhffs->reconnect() unless $vhffs->is_valid;
 	my $user = Vhffs::User::get_by_username( $vhffs , $username );
 	return undef unless( defined $user );
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/