/[A3C]/lib/Strix/Import.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/Strix/Import.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 236 - (hide annotations)
Sun Sep 7 21:22:10 2008 UTC (15 years, 8 months ago) by dpavlin
File size: 762 byte(s)
move strix sites import into module Strix::Import so
that command-line script and action can re-use it,
creating on-demand sync for sites.
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;

  ViewVC Help
Powered by ViewVC 1.1.26