From: Bill Erickson Date: Thu, 12 May 2016 16:13:35 +0000 (-0400) Subject: JBAS-1417 Bib linking supports --modified-since X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=209f0d8f22ff1b01f681d357dd3a87dbc8e48853;p=working%2FEvergreen.git JBAS-1417 Bib linking supports --modified-since Plus some minor cleanup. Signed-off-by: Bill Erickson --- diff --git a/KCLS/linking/authority_control_fields.pl b/KCLS/linking/authority_control_fields.pl index 837917eaf3..f9791949b3 100755 --- a/KCLS/linking/authority_control_fields.pl +++ b/KCLS/linking/authority_control_fields.pl @@ -36,8 +36,11 @@ $ENV{OSRF_LOG_CLIENT} = 1; $Data::Dumper::Indent = 0; MARC::Charset->assume_unicode(1); -my ($start_id, $end_id, $refresh); -my ($days_back); +my $start_id; +my $end_id; +my $refresh; +my $days_back; # days; 0 means today only +my $modified_since; # days; 0 means today only my $input_file =''; my $bootstrap = '/openils/conf/opensrf_core.xml'; my @records; @@ -53,16 +56,18 @@ my $result = GetOptions( 'configuration=s' => \$bootstrap, 'record=i' => \@records, 'refresh' => \$refresh, - 'all', 'help', - 'start_id=i' => \$start_id, - 'end_id=i' => \$end_id, - 'days_back=i' => \$days_back, + 'start-id=i' => \$start_id, + 'end-id=i' => \$end_id, + 'days-back=i' => \$days_back, + 'modified-since=i' => \$modified_since, 'file=s' => \$input_file, 'verbose' => \$verbose, "db-host=s" => \$db_host, "db-user=s" => \$db_user, "db-pass=s" => \$db_pass, - "db-port=s" => \$db_port + "db-port=s" => \$db_port, + 'all', + 'help' ); sub announce { @@ -88,44 +93,46 @@ use OpenILS::Utils::CStoreEditor; OpenILS::Utils::CStoreEditor::init(); my $e = OpenILS::Utils::CStoreEditor->new; -my $undeleted; -if ($options{all}) { - # get a list of all non-deleted records from Evergreen - # open-ils.cstore open-ils.cstore.direct.biblio.record_entry.id_list.atomic {"deleted":"f"} - $undeleted = $e->request( - 'open-ils.cstore.direct.biblio.record_entry.id_list.atomic', - [{deleted => 'f'}, {id => { '>' => 0}}] - ); - @records = @$undeleted; -} -if ($start_id and $end_id) { +if ($options{all}) { # all non-deleted records from Evergreen + + @records = @{ + $e->search_biblio_record_entry( + {deleted => 'f', id => {'>' => 0}}, + {idlist => 1, substream => 1} + ) + }; + +} elsif ($start_id and $end_id) { + @records = ($start_id .. $end_id); -} -if (defined $days_back) { -@records=(); +} elsif (defined $days_back or defined $modified_since) { + + @records = (); -my $dsn = "dbi:Pg:database=evergreen;host=$db_host;port=$db_port"; -my $dbh = DBI->connect($dsn, $db_user, $db_pass); + my $dsn = "dbi:Pg:database=evergreen;host=$db_host;port=$db_port"; + my $dbh = DBI->connect($dsn, $db_user, $db_pass); + my $date_field = defined $days_back ? 'create_date' : 'edit_date'; + my $duration = defined $days_back ? $days_back : $modified_since; -# SQL Used to gather a list of ID's -my $idstatement = $dbh->prepare(<= DATE(NOW() - '$duration day'::INTERVAL) + SQL + + announce("Loading record ID's with query:\n$sql"); + + my $idstatement = $dbh->prepare($sql); + + # Load the list of ID's into the records array + $idstatement->execute(); -# Load the list of ID's into the records array -$idstatement->execute(); while (my $ref = $idstatement->fetchrow_hashref()) { - my $id_ref = $ref->{"id"}; # the column name in our sql query is "id" - push(@records, $id_ref); + push(@records, $ref->{id}); } -} -if($input_file) { +} elsif ($input_file) { open FILE, "<", $input_file or die "Can't open file " . $input_file; while() { chomp; @@ -135,7 +142,8 @@ if($input_file) { } close FILE; } -# print Dumper($undeleted, \@records); + +announce("Processing ".scalar(@records)." records"); # Hash of controlled fields & subfields in bibliographic records, and their # corresponding controlling fields & subfields in the authority record