Bug 20248: Improve Elasticsearch mappings UI and rebuild_elastic_search.pl.
[koha.git] / misc / export_records.pl
index 83d8a7b..6e36368 100755 (executable)
@@ -71,6 +71,9 @@ if ( $output_format eq 'csv' and $record_type eq 'auths' ) {
     pod2usage(q|CSV output is only available for biblio records|);
 }
 
+if ( $output_format eq 'csv' and not $csv_profile_id ) {
+    pod2usage(q|Define a csv profile to export in CSV|);
+}
 
 if ( $timestamp and $record_type ne 'bibs' ) {
     pod2usage(q|--timestamp can only be used with biblios|);
@@ -101,16 +104,16 @@ if ( $record_type eq 'bibs' ) {
     if ( $timestamp ) {
         push @record_ids, $_->{biblionumber} for @{
             $dbh->selectall_arrayref(q| (
-                SELECT biblionumber
-                FROM biblioitems
+                SELECT biblio_metadata.biblionumber
+                FROM biblio_metadata
                   LEFT JOIN items USING(biblionumber)
-                WHERE biblioitems.timestamp >= ?
+                WHERE biblio_metadata.timestamp >= ?
                   OR items.timestamp >= ?
             ) UNION (
-                SELECT biblionumber
-                FROM biblioitems
+                SELECT biblio_metadata.biblionumber
+                FROM biblio_metadata
                   LEFT JOIN deleteditems USING(biblionumber)
-                WHERE biblioitems.timestamp >= ?
+                WHERE biblio_metadata.timestamp >= ?
                   OR deleteditems.timestamp >= ?
             ) |, { Slice => {} }, ( $timestamp ) x 4 );
         };
@@ -144,7 +147,7 @@ if ( $record_type eq 'bibs' ) {
                 ?
                   C4::Context->preference('item-level_itypes')
                     ? ( 'items.itype' => $itemtype )
-                    : ( 'biblioitems.itemtype' => $itemtype )
+                    : ( 'me.itemtype' => $itemtype )
                 : ()
             ),
 
@@ -184,22 +187,15 @@ if ( @record_ids and $id_list_file ) {
 
 if ($deleted_barcodes) {
     for my $record_id ( @record_ids ) {
-        my $q = q|
-        |;
-        my $barcode = $dbh->selectall_arrayref(q| (
+        my $barcode = $dbh->selectall_arrayref(q|
             SELECT DISTINCT barcode
             FROM deleteditems
             WHERE deleteditems.biblionumber = ?
         |, { Slice => {} }, $record_id );
-        say $_->{barcode} for @$barcode
+        say $_->{barcode} for @$barcode;
     }
 }
 else {
-    unless ( $csv_profile_id ) {
-        # FIXME export_format.profile should be a unique key
-        my $default_csv_profiles = Koha::CsvProfiles->search({ profile => C4::Context->preference('ExportWithCsvProfile') });
-        $csv_profile_id = $default_csv_profiles->count ? $default_csv_profiles->next->export_format_id : undef;
-    }
     Koha::Exporter::Record::export(
         {   record_type        => $record_type,
             record_ids         => \@record_ids,
@@ -251,7 +247,6 @@ Print a brief help message.
 =item B<--csv_profile_id>
 
  --csv_profile_id=ID    Generate a CSV file with the given CSV profile id (see tools/csv-profiles.pl)
-                        Unless provided, the one defined in the system preference 'ExportWithCsvProfile' will be used.
                         This can only be used to export biblio records.
 
 =item B<--deleted_barcodes>