Skip to content

Instantly share code, notes, and snippets.

@markpasc
Created December 18, 2008 19:05
Show Gist options
  • Save markpasc/37599 to your computer and use it in GitHub Desktop.
Save markpasc/37599 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
package CountEntries;
use strict;
use lib qw( extlib lib );
use base qw( MT::Tool );
sub help { q{} }
sub usage { q{} }
sub main {
my $class = shift;
my ($verbose) = $class->SUPER::main(@_);
print count(MT->model('entry'), {}, {}), "\n";
}
sub count {
my ($class, $terms, $args) = @_;
my $driver = $class->driver;
my $stmt = $driver->prepare_statement($class, $terms, $args);
# Replace what search() would select with a COUNT(*).
$stmt->select([]);
$stmt->select_map({});
$stmt->select_map_reverse({});
$stmt->add_select('COUNT(*)');
return $driver->select_one( $stmt->as_sql() );
}
__PACKAGE__->main() unless caller;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment