File Coverage

blib/lib/Games/Lacuna/Task/Action/StarCacheExport.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Games::Lacuna::Task::Action::StarCacheExport;
2              
3 1     1   1458 use 5.010;
  1         3  
  1         213  
4             our $VERSION = $Games::Lacuna::Task::VERSION;
5              
6 1     1   527 use Moose -traits => 'NoAutomatic';
  0            
  0            
7             extends qw(Games::Lacuna::Task::Action);
8              
9             has 'database' => (
10             is => 'rw',
11             isa => 'Path::Class::File',
12             required => 1,
13             coerce => 1,
14             documentation => 'Exported database file [Required]',
15             );
16              
17             sub description {
18             return q[Export the star cache database];
19             }
20              
21             sub run {
22             my ($self) = @_;
23            
24             my $export_file = $self->database->stringify;
25            
26             $self->log('notice','Start exporting star cache to %s',$export_file);
27            
28             $self->client->storage->dbh->sqlite_backup_to_file( $export_file );
29            
30             my $export_dbh = DBI->connect("dbi:SQLite:dbname=$export_file","","",{ RaiseError => 1 });
31            
32             # Empty cache
33             $export_dbh->do('DELETE FROM cache');
34            
35             # Empty excavator cache
36             $export_dbh->do('UPDATE body SET is_excavated = NULL WHERE is_excavated IS NOT NULL');
37            
38             $export_dbh->close();
39            
40             $self->log('notice','Finished exporting star cache to %s',$export_file);
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44             no Moose;
45             1;