Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arthur Axel 'fREW' Schmidt
committed
May 4, 2012
1 parent
1001fe9
commit 2eea09c
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package DU::App::Command::maint::export; | ||
|
||
use 5.14.1; | ||
use warnings; | ||
|
||
use DU::App -command; | ||
use DU::Util 'drink_as_data'; | ||
|
||
sub abstract { '' } | ||
|
||
sub usage_desc { '' } | ||
|
||
sub execute { | ||
my ($self, $opt, $args) = @_; | ||
|
||
my $s = $self->app->app->schema; | ||
|
||
require Archive::Tar; | ||
require JSON; | ||
use IO::Compress::Xz 'xz'; | ||
|
||
my $tar = Archive::Tar->new; | ||
|
||
$tar->add_data('export_version.txt', 1); | ||
$tar->add_data('drinks.json', | ||
JSON::encode_json([ | ||
map drink_as_data($_), $s->resultset('Drink')->all | ||
]) | ||
); | ||
|
||
my $name = $args->[0] || 'export'; | ||
$tar->write(".$name.tar"); | ||
|
||
xz ".$name.tar", "$name.tar.xz"; | ||
unlink ".$name.tar"; | ||
|
||
say 'done'; | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package DU::App::Command::maint::import; | ||
|
||
use 5.14.1; | ||
use warnings; | ||
|
||
use DU::App -command; | ||
use DU::Util 'drink_as_data'; | ||
|
||
sub abstract { '' } | ||
|
||
sub usage_desc { '' } | ||
|
||
sub execute { | ||
my ($self, $opt, $args) = @_; | ||
|
||
my $s = $self->app->app->schema; | ||
|
||
require Archive::Tar; | ||
require JSON; | ||
use IO::Uncompress::UnXz 'unxz'; | ||
|
||
my $name = $args->[0] || 'export'; | ||
unxz "$name.tar.xz", ".$name.tar"; | ||
|
||
my $tar = Archive::Tar->new; | ||
|
||
$tar->read(".$name.tar", { extract => 1 }); | ||
|
||
my $version = $tar->get_content('export_version.txt'); | ||
|
||
my $drink_rs = $s->resultset('Drink'); | ||
my @drinks = @{JSON::decode_json($tar->get_content('drinks.json'))}; | ||
|
||
for my $drink_data (@drinks) { | ||
if ($drink_rs->find_by_name($drink_data->{name})) { | ||
die "$drink_data->{name} is already in your database" | ||
} else { | ||
$s->create_drink($drink_data) | ||
} | ||
} | ||
|
||
say 'done'; | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters