1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use lib 'lib'; |
7 |
|
8 |
use Jifty; |
9 |
use Data::Dump qw/dump/; |
10 |
use File::Find; |
11 |
use A3C::PHP; |
12 |
|
13 |
my $debug = 0; |
14 |
|
15 |
BEGIN { Jifty->new; }; |
16 |
Jifty->web->request(Jifty::Request->new); |
17 |
Jifty->web->response(Jifty::Response->new); |
18 |
|
19 |
my $config = Jifty->config->app('strix') or die "need strix config"; |
20 |
|
21 |
my $model = A3C::Model::StrixSite->new; |
22 |
|
23 |
my $total = 0; |
24 |
|
25 |
find({ no_chdir => 1, wanted => sub { |
26 |
my $path = $File::Find::name; |
27 |
return unless -f $_; |
28 |
warn "? $path\n" if $debug; |
29 |
return unless m/conf\.php$/; |
30 |
|
31 |
$path =~ m{/etc/([^/]+)/conf\.php$} or die "can't find site name in $path"; |
32 |
my $site = $1; |
33 |
|
34 |
my $data = A3C::PHP->parse_file( $path ); |
35 |
|
36 |
warn "# PHP = ", dump( $data ) if $debug; |
37 |
$data->{site} = $site; |
38 |
|
39 |
my ($ok,$msg) = $model->load_or_create( %$data ); |
40 |
if ( $ok ) { |
41 |
Jifty->log->info("$ok $site ", $msg || 'ADDED'); |
42 |
$total++; |
43 |
} else { |
44 |
Jifty->log->error("can't parse $path"); |
45 |
} |
46 |
|
47 |
}}, $config->{dir} ); |
48 |
|
49 |
Jifty->log->info( "$total Strix sites imported" ); |