1 |
dpavlin |
236 |
package Strix::Import; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use Data::Dump qw/dump/; |
7 |
|
|
|
8 |
|
|
=head1 NAME |
9 |
|
|
|
10 |
|
|
Strix::Import - create local copy of data from strix sites |
11 |
|
|
|
12 |
|
|
=head1 METHODS |
13 |
|
|
|
14 |
|
|
=head2 sites |
15 |
|
|
|
16 |
|
|
my $new_sites = Strix::Import->sites( $instalce ); |
17 |
|
|
|
18 |
|
|
=cut |
19 |
|
|
|
20 |
|
|
our $debug = 0; |
21 |
|
|
|
22 |
|
|
sub sites { |
23 |
|
|
my $self = shift; |
24 |
|
|
my $instance = shift or die "no instance?"; |
25 |
|
|
|
26 |
|
|
my $dbh = eval { Strix->new({ instance => $instance })->dbh }; |
27 |
|
|
next if $@; |
28 |
|
|
my $sth = $dbh->prepare(qq{ select * from site }); |
29 |
|
|
$sth->execute; |
30 |
|
|
|
31 |
|
|
my $ss = A3C::Model::StrixSite->new; |
32 |
|
|
|
33 |
|
|
my $new = 0; |
34 |
|
|
|
35 |
|
|
while ( my $row = $sth->fetchrow_hashref ) { |
36 |
|
|
warn dump( $row ) if $debug; |
37 |
|
|
$row->{instance} = $instance; |
38 |
|
|
$row->{site_id} = delete( $row->{id} ); |
39 |
|
|
$ss->load_or_create( %$row ); |
40 |
|
|
$new++ if $ss->id; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
return $new; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
1; |