Revision 139

Date:
2008/05/30 21:16:08
Author:
dpavlin
Revision Log:
Added Strix site config importer

When invoked like:

./bin/import-strix.pl

it reports something like:

INFO - 539 Strix sites imported

Not bad :-)
Files:

Legend:

 
Added
 
Removed
 
Modified
  • bin/import-strix.pl

     
    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 BEGIN { Jifty->new; };
    14 Jifty->web->request(Jifty::Request->new);
    15 Jifty->web->response(Jifty::Response->new);
    16
    17 my $config = Jifty->config->app('strix') or die "need strix config";
    18
    19 my $model = A3C::Model::StrixSite->new;
    20
    21 my $total = 0;
    22
    23 find({ no_chdir => 1, wanted => sub {
    24 my $path = $File::Find::name;
    25 return unless -f $_;
    26 warn "? $path\n";
    27 return unless m/conf\.php$/;
    28
    29 $path =~ m{/etc/([^/]+)/conf\.php$} or die "can't find site name in $path";
    30 my $site = $1;
    31
    32 my $data = A3C::PHP->parse_file( $path );
    33
    34 warn "# PHP = ", dump( $data );
    35 $data->{site} = $site;
    36
    37 my ($id,$msg) = $model->load_or_create( %$data );
    38 warn "$id $site ", $msg || 'ADDED', "\n";
    39 $total++ if $id;
    40
    41 }}, $config->{dir} );
    42
    43 Jifty->log->info( "$total Strix sites imported" );
  • etc/config.yml

     
    14 14 Password: 'a3c'
    15 15 RecordBaseClass: Jifty::DBI::Record::Cachable
    16 16 User: 'a3c'
    17 Version: 0.0.2
    17 Version: 0.0.3
    18 18 DevelMode: 1
    19 19 L10N:
    20 20 PoDir: share/po
     
    86 86 link:
    87 87 person_filter: HrEduPersonHomeOrg
    88 88 display_from: name
    89 value_from: cn
    89 value_from: cn
    90
    91 strix:
    92 dir: data/strix/
  • lib/A3C/Model/StrixSite.pm

     
    1 use strict;
    2 use warnings;
    3
    4 package A3C::Model::StrixSite;
    5 use Jifty::DBI::Schema;
    6
    7 use A3C::Record schema {
    8
    9 column site =>
    10 label is _('Site identifier'),
    11 is mandatory,
    12 is disctinct,
    13 is immutable,
    14 is indexed;
    15
    16 # same as Strix's conf.php variables
    17
    18 column _site_name =>
    19 label is _('Descriptive name'),
    20 is indexed,
    21 is distinct;
    22
    23 column _site_admin =>
    24 label is _('Admin e-mail');
    25
    26 column _site_is_root =>
    27 type is 'boolean';
    28
    29 column _dbserver =>
    30 is mandatory;
    31
    32 column _dbname =>
    33 is mandatory;
    34
    35 column _skole_external_uid =>
    36 type is 'int';
    37
    38 column _mail_on_error =>
    39 type is 'boolean';
    40
    41 column _auth_type_name =>
    42 label is _('Auth type');
    43
    44 column __arhiva =>
    45 type is 'boolean',
    46 default is 0;
    47
    48 column _force_nossl =>
    49 label is _('Disable SSL'),
    50 type is 'boolean',
    51 default is 0;
    52
    53 };
    54
    55 sub since { '0.0.3' };
    56
    57 # Your model-specific methods go here.
    58
    59 use A3C::DefaultACL;
    60
    61 1;
    62
  • Makefile.PL

     
    12 12 requires 'File::Slurp';
    13 13 requires 'JSON::XS';
    14 14 requires 'Parse::RecDescent';
    15 requires 'File::Find';
    15 16
    16 17 auto_install;
    17 18
  • t/00-model-StrixSite.t

     
    1 #!/usr/bin/env perl
    2 use warnings;
    3 use strict;
    4
    5 =head1 DESCRIPTION
    6
    7 A basic test harness for the StrixSite model.
    8
    9 =cut
    10
    11 use Jifty::Test tests => 11;
    12
    13 # Make sure we can load the model
    14 use_ok('A3C::Model::StrixSite');
    15
    16 # Grab a system user
    17 my $system_user = A3C::CurrentUser->superuser;
    18 ok($system_user, "Found a system user");
    19
    20 # Try testing a create
    21 my $o = A3C::Model::StrixSite->new(current_user => $system_user);
    22 my ($id) = $o->create();
    23 ok($id, "StrixSite create returned success");
    24 ok($o->id, "New StrixSite has valid id set");
    25 is($o->id, $id, "Create returned the right id");
    26
    27 # And another
    28 $o->create();
    29 ok($o->id, "StrixSite create returned another value");
    30 isnt($o->id, $id, "And it is different from the previous one");
    31
    32 # Searches in general
    33 my $collection = A3C::Model::StrixSiteCollection->new(current_user => $system_user);
    34 $collection->unlimit;
    35 is($collection->count, 2, "Finds two records");
    36
    37 # Searches in specific
    38 $collection->limit(column => 'id', value => $o->id);
    39 is($collection->count, 1, "Finds one record with specific id");
    40
    41 # Delete one of them
    42 $o->delete;
    43 $collection->redo_search;
    44 is($collection->count, 0, "Deleted row is gone");
    45
    46 # And the other one is still there
    47 $collection->unlimit;
    48 is($collection->count, 1, "Still one left");
    49