r1445@llin: dpavlin | 2007-11-01 01:15:09 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 1 Nov 2007 00:16:52 +0000 (00:16 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 1 Nov 2007 00:16:52 +0000 (00:16 +0000)
 correctly create or update fileds in Webpacus

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@951 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Output/Webpacus.pm

index b5b2874..7c8bcc3 100644 (file)
@@ -121,8 +121,6 @@ sub finish {
 
        $log->debug("fields = ", sub { dump $fields });
 
-       $log->info("using Webpacus installation: $path");
-
        my $webpac_dir = getcwd();
 
        chdir $path || $log->logdie("can't chdir($path) $!");
@@ -132,26 +130,34 @@ sub finish {
        my $system_user = Webpacus::CurrentUser->superuser;
        my $o = Webpacus::Model::Search->new(current_user => $system_user);
 
-       my $count = 0;
+       my ( $count, $new, $updated ) = ( 0, 0, 0 );
 
        foreach my $field ( keys %$fields ) {
                my $items = $fields->{$field} || confess "no field?";
-               $log->debug("adding search field: $field [$items]");
-               $o->load_by_cols(
-                       name => $field,
-               ) ||
-               $o->create(
-                       name => $field,
-                       items => $items,
-               ); # || $log->logdie("can't add $field");
+
+               my ( $id, $msg ) = $o->load_by_cols( name => $field );
+
+               if ( $id ) {
+                       $o->set_items( $items );
+                       $log->debug("updated search field: $field [$items] ID: $id $msg");
+                       $updated++;
+               } else {
+                       $log->debug("adding search field: $field [$items] $msg");
+                       $o->create(
+                               name => $field,
+                               items => $items,
+                       );
+                       $new++;
+               }
+
                $count++;
        }
 
-       $log->info("synced $count search fields with Webpacus");
+       $log->info("synced $count search fields with Webpacus ($new new/$updated updated) at $path");
 
        my $glue_path = "$path/lib/Webpacus/Webpac.pm";
 
-       $log->info("creating clue class Webpacus::Webpac at $glue_path");
+       $log->debug("creating clue class Webpacus::Webpac at $glue_path");
 
        my $glue = <<"_END_OF_GLUE_";
 package Webpacus::Webpac;