[vhffs-dev] [485] Reworked Vhffs::Stats. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 485
Author: beuss
Date: 2007-02-19 10:56:01 +0000 (Mon, 19 Feb 2007)
Log Message:
-----------
Reworked Vhffs::Stats. Informations are fetched when they are requested. No more need to call fetch (deprecated).
Modified Paths:
--------------
branches/vhffs_4.1/vhffs-api/src/Vhffs/Stats.pm
branches/vhffs_4.1/vhffs-panel/admin/stats.pl
branches/vhffs_4.1/vhffs-panel/auth.pl
branches/vhffs_4.1/vhffs-tests/src/Stats.pl
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Stats.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Stats.pm 2007-02-19 07:46:33 UTC (rev 484)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Stats.pm 2007-02-19 10:56:01 UTC (rev 485)
@@ -61,132 +61,19 @@
sub fetch
{
- my ( $self , $query , $request , $result );
- $self = shift;
-
- $query = 'SELECT COUNT(*) FROM vhffs_users';
- ($self->{'users'}{'total'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_users WHERE admin='.Vhffs::Constants::USER_ADMIN;
- ($self->{'users'}{'total_admin'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- $query = 'SELECT COUNT(*) FROM vhffs_users WHERE admin='.Vhffs::Constants::USER_MODERATOR;
- ($self->{'users'}{'total_moderator'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- $query = 'SELECT COUNT(*) FROM vhffs_groups g LEFT JOIN vhffs_users u ON u.username = g.groupname WHERE u.username IS NULL';
- ($self->{'groups'}{'total'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id=g.object_id LEFT JOIN vhffs_users u ON u.username = g.groupname WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION.' AND u.username IS NULL';
- ($self->{'groups'}{'awaiting_moderation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- $query = 'SELECT COUNT(*) FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id=g.object_id LEFT JOIN vhffs_users u ON u.username = g.groupname WHERE o.state='.Vhffs::Constants::ACTIVATED.' AND u.username IS NULL';
- ($self->{'groups'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- $query = 'SELECT COUNT(*) FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'web'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'web'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'web'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- $query = 'SELECT COUNT(*) FROM vhffs_cvs w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'cvs'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_cvs w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'cvs'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_cvs w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'cvs'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- ### DNS Stats
- $query = 'SELECT COUNT(*) FROM vhffs_dns w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'dns'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_dns w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'dns'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_dns w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'dns'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- ###Stats for mail
- $query = 'SELECT COUNT(*) FROM vhffs_mxdomain w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'mail'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_mxdomain w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'mail'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_mxdomain w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'mail'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_boxes';
- ($self->{'mail'}{'total_boxes'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_forward';
- ($self->{'mail'}{'total_forwards'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- ### Stats for MySQL
- $query = 'SELECT COUNT(*) FROM vhffs_mysql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'mysql'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_mysql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'mysql'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_mysql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'mysql'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
- ### Stats for Pgsql
- $query = 'SELECT COUNT(*) FROM vhffs_pgsql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'pgsql'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_pgsql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'pgsql'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_pgsql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'pgsql'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_svn w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'svn'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_svn w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'svn'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_svn w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'svn'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_ml ml, vhffs_object o WHERE o.object_id=ml.object_id AND o.state='.Vhffs::Constants::ACTIVATED;
- ($self->{'lists'}{'activated'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_ml ml, vhffs_object o WHERE o.object_id=ml.object_id AND o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
- ($self->{'lists'}{'awaiting_validation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_ml ml, vhffs_object o WHERE o.object_id=ml.object_id AND o.state='.Vhffs::Constants::WAITING_FOR_CREATION;
- ($self->{'lists'}{'awaiting_creation'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_ml';
- ($self->{'lists'}{'total'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
- $query = 'SELECT COUNT(*) FROM vhffs_ml_subscribers';
- ($self->{'lists'}{'totalsubs'}) = @{$self->{'db'}->selectrow_arrayref( $query )};
-
-
+ my ($package, $file, $line) = caller();
+ warn("You are calling Vhffs::Stats::fetch, this is useless, this method does nothing, just ask for the stats you need using get_xxxx (from $package - $file:$line");
return 1;
}
sub get_lists_totalsubs
{
my $self = shift;
- return $self->{'lists'}{'totalsubs'};
+ unless(defined $self->{lists}{totalsubs}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_ml_subscribers';
+ ($self->{lists}{totalsubs}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{lists}{totalsubs};
}
@@ -194,19 +81,31 @@
sub get_lists_in_moderation
{
my $self = shift;
- return $self->{'lists'}{'awaiting_validation'};
+ unless(defined $self->{lists}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_ml ml, vhffs_object o WHERE o.object_id=ml.object_id AND o.state='.Vhffs::Constants::WAITING_FOR_VALIDATION;
+ ($self->{lists}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{lists}{awaiting_validation};
}
sub get_lists_activated
{
my $self = shift;
- return $self->{'lists'}{'activated'};
+ unless(defined $self->{lists}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_ml ml, vhffs_object o WHERE o.object_id=ml.object_id AND o.state = ?';
+ ($self->{lists}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{lists}{activated};
}
sub get_lists_total
{
my $self = shift;
- return $self->{'lists'}{'total'};
+ unless(defined $self->{lists}{total}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_ml';
+ ($self->{lists}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{lists}{total};
}
@@ -214,26 +113,42 @@
sub get_web_in_moderation
{
my $self = shift;
- return $self->{'web'}{'awaiting_validation'};
+ unless(defined $self->{web}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{web}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+ }
+ return $self->{web}{awaiting_validation};
}
sub get_web_activated
{
my $self = shift;
- return $self->{'web'}{'activated'};
+ unless(defined $self->{web}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_httpd w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{web}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{web}{activated};
}
sub get_user_total
{
my $self = shift;
- return $self->{'users'}{'total'};
+ unless(defined $self->{users}{total}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_users';
+ ($self->{users}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{users}{total};
}
sub get_user_total_admin
{
my $self = shift;
+ unless(defined $self->{users}{total_admin}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_users WHERE admin=?';
+ ($self->{users}{total_admin}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::USER_ADMIN )};
+ }
return $self->{'users'}{'total_admin'};
}
@@ -241,117 +156,190 @@
sub get_user_total_moderator
{
my $self = shift;
- return $self->{'users'}{'total_moderator'};
+ unless(defined $self->{users}{total_moderator}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_users WHERE admin=?';
+ ($self->{users}{total_moderator}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::USER_MODERATOR )};
+ }
+ return $self->{users}{total_moderator};
}
-
sub get_dns_in_moderation
{
my $self = shift;
- return $self->{'dns'}{'awaiting_validation'};
+ unless(defined $self->{dns}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_dns w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state=?';
+ ($self->{dns}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+ }
+ return $self->{dns}{awaiting_validation};
}
sub get_dns_activated
{
my $self = shift;
- return $self->{'dns'}{'activated'};
+ unless(defined $self->{dns}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_dns w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state=?';
+ ($self->{dns}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{dns}{activated};
}
sub get_mail_in_moderation
{
my $self = shift;
- return $self->{'mail'}{'awaiting_validation'};
+ unless(defined $self->{mail}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_mxdomain w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{mail}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+ }
+ return $self->{mail}{awaiting_validation};
}
sub get_mail_activated
{
my $self = shift;
- return $self->{'mail'}{'activated'};
+ unless(defined $self->{mail}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_mxdomain w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{mail}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{mail}{activated};
}
sub get_mail_total_boxes
{
my $self = shift;
- return $self->{'mail'}{'total_boxes'};
+ unless(defined $self->{mail}{total_boxes}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_boxes';
+ ($self->{mail}{total_boxes}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{mail}{total_boxes};
}
sub get_mail_total_forwards
{
my $self = shift;
- return $self->{'mail'}{'total_forwards'};
+ unless(defined $self->{mail}{total_forwards}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_forward';
+ ($self->{'mail'}{'total_forwards'}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{mail}{total_forwards};
}
-
sub get_cvs_in_moderation
{
my $self = shift;
- return $self->{'cvs'}{'awaiting_validation'};
+ unless(defined $self->{cvs}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_cvs w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state=?';
+ ($self->{cvs}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+ }
+ return $self->{cvs}{awaiting_validation};
}
sub get_cvs_activated
{
my $self = shift;
- return $self->{'cvs'}{'activated'};
+ unless(defined $self->{cvs}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_cvs w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state=?';
+ ($self->{cvs}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{cvs}{activated};
}
sub get_svn_in_moderation
{
my $self = shift;
- return $self->{'svn'}{'awaiting_validation'};
+ unless(defined $self->{svn}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_svn w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{svn}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+
+ }
+ return $self->{svn}{awaiting_validation};
}
sub get_svn_activated
{
my $self = shift;
- return $self->{'svn'}{'activated'};
+ unless(defined $self->{svn}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_svn w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state='.Vhffs::Constants::ACTIVATED;
+ ($self->{'svn'}{activated}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{svn}{activated};
}
+
sub get_mysql_in_moderation
{
my $self = shift;
- return $self->{'mysql'}{'awaiting_validation'};
+ unless(defined $self->{mysql}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_mysql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{mysql}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+ }
+ return $self->{mysql}{awaiting_validation};
}
sub get_mysql_activated
{
my $self = shift;
- return $self->{'mysql'}{'activated'};
+ unless(defined $self->{mysql}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_mysql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{'mysql'}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{mysql}{activated};
}
sub get_pgsql_in_moderation
{
my $self = shift;
- return $self->{'pgsql'}{'awaiting_validation'};
+ unless(defined $self->{pgsql}{awaiting_validation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_pgsql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{pgsql}{awaiting_validation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+
+ }
+ return $self->{pgsql}{awaiting_validation};
}
sub get_pgsql_activated
{
my $self = shift;
- return $self->{'pgsql'}{'activated'};
+ unless(defined $self->{pgsql}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_pgsql w INNER JOIN vhffs_object o ON o.object_id=w.object_id WHERE o.state = ?';
+ ($self->{pgsql}{activated}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::ACTIVATED )};
+ }
+ return $self->{pgsql}{activated};
}
sub get_groups_in_moderation
{
my $self = shift;
- return $self->{'groups'}{'awaiting_moderation'};
+ unless(defined $self->{groups}{awaiting_moderation}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id=g.object_id LEFT JOIN vhffs_users u ON u.username = g.groupname WHERE o.state = ? AND u.username IS NULL';
+ ($self->{groups}{awaiting_moderation}) = @{$self->{db}->selectrow_arrayref( $sql, undef, Vhffs::Constants::WAITING_FOR_VALIDATION )};
+ }
+ return $self->{groups}{awaiting_moderation};
}
sub get_groups_activated
{
my $self = shift;
- return $self->{'groups'}{'activated'};
+ unless(defined $self->{groups}{activated}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id=g.object_id LEFT JOIN vhffs_users u ON u.username = g.groupname WHERE o.state='.Vhffs::Constants::ACTIVATED.' AND u.username IS NULL';
+ ($self->{groups}{activated}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{groups}{activated};
}
sub get_groups_total
{
my $self = shift;
- return $self->{'groups'}{'total'};
+ unless(defined $self->{groups}{total}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_groups g LEFT JOIN vhffs_users u ON u.username = g.groupname WHERE u.username IS NULL';
+ ($self->{groups}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{groups}{total};
}
Modified: branches/vhffs_4.1/vhffs-panel/admin/stats.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/stats.pl 2007-02-19 07:46:33 UTC (rev 484)
+++ branches/vhffs_4.1/vhffs-panel/admin/stats.pl 2007-02-19 10:56:01 UTC (rev 485)
@@ -66,7 +66,7 @@
my $stats = new Vhffs::Stats( $vhffs );
-if( ( ! defined $stats ) || ($stats->fetch < 0 ) )
+if( ! defined $stats )
{
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
Modified: branches/vhffs_4.1/vhffs-panel/auth.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/auth.pl 2007-02-19 07:46:33 UTC (rev 484)
+++ branches/vhffs_4.1/vhffs-panel/auth.pl 2007-02-19 10:56:01 UTC (rev 485)
@@ -68,7 +68,6 @@
{
use Vhffs::Stats;
my $stats = new Vhffs::Stats( $vhffs );
- $stats->fetch;
my $users = $stats->get_user_total;
my $groups = $stats->get_groups_total;
Modified: branches/vhffs_4.1/vhffs-tests/src/Stats.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Stats.pl 2007-02-19 07:46:33 UTC (rev 484)
+++ branches/vhffs_4.1/vhffs-tests/src/Stats.pl 2007-02-19 10:56:01 UTC (rev 485)
@@ -57,7 +57,6 @@
$user->commit();
my $stats = new Vhffs::Stats($main);
-$stats->fetch;
# Users' stats
is($stats->get_user_total, 9, 'Right number of users');
@@ -73,7 +72,7 @@
$group->fetch;
$group->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$group->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_groups_in_moderation, 9 - $i, (9 - $i).' groups are still waiting for moderation');
is($stats->get_groups_activated, 0, 'Groups are waiting for creation, not yet activated');
}
@@ -83,7 +82,7 @@
$group->fetch;
$group->set_status(Vhffs::Constants::ACTIVATED);
$group->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_groups_activated, $i, $i > 1 ? "$i groups are activated" : '1 group is activated');
}
@@ -97,13 +96,13 @@
$svc = Vhffs::Services::Httpd::create($main, "httpd0$i.test.com", '', $user, $group);
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_web_in_moderation, 9, 'All httpd services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$svc = Vhffs::Services::Httpd::get_by_servername($main, "httpd0$i.test.com");
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_web_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' httpd service waiting for moderation' : ' httpd services waiting for moderation'));
is($stats->get_web_activated, 0, 'No httpd service activated');
}
@@ -112,7 +111,7 @@
$svc = Vhffs::Services::Httpd::get_by_servername($main, "httpd0$i.test.com");
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_web_activated, $i, $i > 1 ? "$i httpd services activated" : "$i httpd service activated");
}
@@ -126,14 +125,14 @@
Vhffs::Services::Cvs::create($main, "testcvs0$i", '', $user, $group);
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_cvs_in_moderation, 9, 'All cvs services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$svc = Vhffs::Services::Cvs::get_by_cvsroot($main, "testcvs0$i");
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_cvs_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' cvs service waiting for moderation' : ' cvs services waiting for moderation'));
is($stats->get_cvs_activated, 0, 'No httpd service activated');
}
@@ -142,7 +141,7 @@
$svc = Vhffs::Services::Cvs::get_by_cvsroot($main, "testcvs0$i");
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_cvs_activated, $i, $i > 1 ? "$i cvs services activated" : "$i cvs service activated");
}
@@ -157,14 +156,14 @@
$svc->create;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_dns_in_moderation, 9, 'All DNS services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$svc = new Vhffs::Services::DNS($main, "dns0$i.test.com");
$svc->fetch;
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_dns_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' DNS service waiting for moderation' : ' DNS services waiting for moderation'));
is($stats->get_dns_activated, 0, 'No DNS service activated');
}
@@ -174,7 +173,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_dns_activated, $i, $i > 1 ? "$i DNS services activated" : "$i DNS service activated");
}
@@ -190,14 +189,14 @@
$svc->create;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_mysql_in_moderation, 9, 'All MySQL services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$svc = new Vhffs::Services::Mysql($main, "mysqltest0$i");
$svc->fetch;
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_mysql_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' MySQL service waiting for moderation' : ' MySQL services waiting for moderation'));
is($stats->get_mysql_activated, 0, 'No MySQL service activated');
}
@@ -207,7 +206,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_mysql_activated, $i, $i > 1 ? "$i MySQL services activated" : "$i MySQL service activated");
}
@@ -224,14 +223,14 @@
$svc->create;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_pgsql_in_moderation, 9, 'All PostgreSQL services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$svc = new Vhffs::Services::Postgres($main, "pgsqltest0$i");
$svc->fetch;
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_pgsql_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' PostgreSQL service waiting for moderation' : ' PostgreSQL services waiting for moderation'));
is($stats->get_pgsql_activated, 0, 'No PostgreSQL service activated');
}
@@ -241,7 +240,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_pgsql_activated, $i, $i > 1 ? "$i PostgreSQL services activated" : "$i PostgreSQL service activated");
}
@@ -256,7 +255,7 @@
$svc->create;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_svn_in_moderation, 9, 'All SVN services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$group = new Vhffs::Group($main, "testgroup0$i", 401);
@@ -265,7 +264,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_svn_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' SVN service waiting for moderation' : ' SVN services waiting for moderation'));
is($stats->get_svn_activated, 0, 'No SVN service activated');
}
@@ -277,7 +276,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_svn_activated, $i, $i > 1 ? "$i SVN services activated" : "$i SVN service activated");
}
@@ -292,14 +291,14 @@
$svc->create;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_mail_in_moderation, 9, 'All Mail services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$svc = new Vhffs::Services::Mail($main, "mail0$i.test.com");
$svc->fetch;
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_mail_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' Mail service waiting for moderation' : ' Mail services waiting for moderation'));
is($stats->get_mail_activated, 0, 'No Mail service activated');
}
@@ -309,7 +308,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_mail_activated, $i, $i > 1 ? "$i Mail services activated" : "$i Mail service activated");
}
@@ -324,7 +323,7 @@
$svc->commit;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_mail_total_boxes, 90, 'All mboxes created');
@@ -339,7 +338,7 @@
$svc->commit;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_mail_total_forwards, 90, 'All forwards created');
@@ -354,7 +353,7 @@
$svc->create;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_lists_in_moderation, 9, 'All Mailing Lists services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
@@ -362,7 +361,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_lists_in_moderation, 9 - $i, (9 - $i).($i >= 8 ? ' Mailing List service waiting for moderation' : ' Mailing List services waiting for moderation'));
is($stats->get_lists_activated, 0, 'No Mailing List service activated');
}
@@ -372,7 +371,7 @@
$svc->fetch;
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
- $stats->fetch;
+ $stats = new Vhffs::Stats($main);
is($stats->get_lists_activated, $i, $i > 1 ? "$i Mailing List services activated" : "$i Mailing List service activated");
}
@@ -387,6 +386,6 @@
$svc->commit;
}
-$stats->fetch;
+$stats = new Vhffs::Stats($main);
is($stats->get_lists_totalsubs, 90, 'All subscribers registered');