Skip to content

Commit

Permalink
* Switch dependency for LedgerSMB::Database to not depend on App::*
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuelsmann committed Jun 3, 2017
1 parent 7defb4d commit 061c085
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
2 changes: 0 additions & 2 deletions cpanfile
Expand Up @@ -3,8 +3,6 @@

requires 'perl', '5.10.1';

requires 'App::LedgerSMB::Admin', '0.05';
requires 'App::LedgerSMB::Admin::Database';
requires 'CGI::Emulate::PSGI';
requires 'CGI::Simple';
requires 'CGI::Simple::Standard';
Expand Down
53 changes: 51 additions & 2 deletions lib/LedgerSMB/Database.pm
@@ -1,4 +1,4 @@
#!/usr/bin/perl

=head1 NAME
LedgerSMB::Database - Provides the APIs for database creation and management.
Expand Down Expand Up @@ -33,7 +33,7 @@ use warnings;

use LedgerSMB::Auth;
use DBI;
use base qw(App::LedgerSMB::Admin::Database);
use base qw(PGObject::Util::DBAdmin);

use LedgerSMB::Sysconfig;
use LedgerSMB::Database::Loadorder;
Expand Down Expand Up @@ -468,4 +468,53 @@ sub apply_changes {
$dbh->disconnect;
}

=head2 stats
Returns a hashref of table names to rows. The following tables are counted:
=over
=item ar
=item ap
=item gl
=item oe
=item acc_trans
=item users
=item entity_credit_account
=item entity
=back
=cut

my @tables = qw(ar ap gl users entity_credit_account entity acc_trans oe);

sub stats {
my ($self) = @_;
my $dbh = $self->connect;
my $results;

$results->{$_->{table}} = $_->{count}
for map {
my $sth = $dbh->prepare($_->{query});
$sth->execute;
my ($count) = $sth->fetchrow_array;
{ table => $_->{table}, count => $count };
} map {
my $qt = 'SELECT COUNT(*) FROM __TABLE__';
my $id = $dbh->quote_identifier($_);
$qt =~ s/__TABLE__/$id/;
{ table => $_, query => $qt };
} @tables;

return $results;
}

1;
3 changes: 1 addition & 2 deletions xt/01.2-deps.t
Expand Up @@ -45,7 +45,6 @@ push @on_disk, 'tools/starman.psgi';

ok_dependencies($file, \@on_disk,
phases => 'runtime',
ignores => [ 'App::LedgerSMB::Admin', 'Image::Size',
'LaTeX::Driver', 'PGObject::Util::DBAdmin',
ignores => [ 'Image::Size', 'LaTeX::Driver',
'Starman', 'TeX::Encode::charmap'] );

0 comments on commit 061c085

Please sign in to comment.