Lines 24-29
use URI;
Link Here
|
24 |
use URI::Escape qw( uri_escape_utf8 ); |
24 |
use URI::Escape qw( uri_escape_utf8 ); |
25 |
|
25 |
|
26 |
use C4::Koha qw( GetNormalizedISBN GetNormalizedUPC GetNormalizedOCLCNumber ); |
26 |
use C4::Koha qw( GetNormalizedISBN GetNormalizedUPC GetNormalizedOCLCNumber ); |
|
|
27 |
use C4::Biblio qw( DelBiblio AddBiblio ModBiblio ); |
28 |
use C4::Serials qw( CountSubscriptionFromBiblionumber ); |
29 |
use C4::Serials qw( CountSubscriptionFromBiblionumber ); |
30 |
use C4::Reserves qw( MergeHolds ); |
31 |
use C4::Acquisition qw( ModOrder GetOrdersByBiblionumber ); |
27 |
|
32 |
|
28 |
use Koha::Database; |
33 |
use Koha::Database; |
29 |
use Koha::DateUtils qw( dt_from_string ); |
34 |
use Koha::DateUtils qw( dt_from_string ); |
Lines 1746-1751
sub opac_summary_html {
Link Here
|
1746 |
return $summary_html; |
1751 |
return $summary_html; |
1747 |
} |
1752 |
} |
1748 |
|
1753 |
|
|
|
1754 |
=head3 merge_with |
1755 |
|
1756 |
my $biblio = Koha::Biblios->find($biblionumber); |
1757 |
$biblio->merge_with(\@biblio_ids); |
1758 |
|
1759 |
This subroutine merges a list of bibliographic records into the bibliographic record. |
1760 |
This function DOES NOT CHANGE the bibliographic metadata of the record. But it links all |
1761 |
items, holds, subscriptions, serials issues and article_requests to the record. After doing changes |
1762 |
bibliographic records listed are deleted |
1763 |
|
1764 |
=cut |
1765 |
|
1766 |
sub merge_with { |
1767 |
my ( $self, $biblio_ids ) = @_; |
1768 |
my @biblio_ids_to_merge = @{$biblio_ids}; |
1769 |
my $dbh = C4::Context->dbh; |
1770 |
my $ref_biblionumber = $self->biblionumber; |
1771 |
# Ensure the keeper isn't in the list of records to merge |
1772 |
@biblio_ids_to_merge = grep { $_ ne $ref_biblionumber } @biblio_ids_to_merge; |
1773 |
my @worked_ids = (); |
1774 |
my %results = ( 'biblio_id' => $ref_biblionumber, 'merged_ids' => \@worked_ids, 'error' => '', 'status' => 1 ); |
1775 |
#my $biblio = Koha::Biblios->find($self->biblionumber); |
1776 |
|
1777 |
foreach (@biblio_ids_to_merge) { |
1778 |
my $bn_merge = $_; |
1779 |
eval { |
1780 |
my $from_biblio = Koha::Biblios->find($bn_merge); |
1781 |
$from_biblio->items->move_to_biblio($self); |
1782 |
$from_biblio->article_requests->update( { biblionumber => $ref_biblionumber }, { no_triggers => 1 } ); |
1783 |
|
1784 |
# Moving subscriptions from the other record to the reference record |
1785 |
my $sth_subscription = $dbh->prepare( " |
1786 |
UPDATE subscription SET biblionumber = ? WHERE biblionumber = ? |
1787 |
" ); |
1788 |
my $sth_subscriptionhistory = $dbh->prepare( " |
1789 |
UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ? |
1790 |
" ); |
1791 |
my $subcount = CountSubscriptionFromBiblionumber($bn_merge); |
1792 |
if ( $subcount > 0 ) { |
1793 |
$sth_subscription->execute( $ref_biblionumber, $bn_merge ); |
1794 |
$sth_subscriptionhistory->execute( $ref_biblionumber, $bn_merge ); |
1795 |
} |
1796 |
|
1797 |
# Moving serials |
1798 |
my $sth_serial = $dbh->prepare( " |
1799 |
UPDATE serial SET biblionumber = ? WHERE biblionumber = ? |
1800 |
" ); |
1801 |
$sth_serial->execute( $ref_biblionumber, $bn_merge ); |
1802 |
|
1803 |
# Moving suggestions |
1804 |
my $sth_suggestions = $dbh->prepare( " |
1805 |
UPDATE suggestions SET biblionumber = ? WHERE biblionumber = ? |
1806 |
" ); |
1807 |
$sth_suggestions->execute( $ref_biblionumber, $bn_merge ); |
1808 |
# Moving orders (orders linked to items of frombiblio have already been moved by move_to_biblio) |
1809 |
my @allorders = GetOrdersByBiblionumber($bn_merge); |
1810 |
foreach my $myorder (@allorders) { |
1811 |
$myorder->{'biblionumber'} = $ref_biblionumber; |
1812 |
ModOrder($myorder); |
1813 |
# TODO : add error control (in ModOrder?) |
1814 |
} |
1815 |
|
1816 |
# Move holds |
1817 |
MergeHolds( $dbh, $ref_biblionumber, $bn_merge ); |
1818 |
}; |
1819 |
if ($@) { |
1820 |
$results{'error'} = $@; |
1821 |
$results{'status'} = 0; |
1822 |
return \%results; |
1823 |
} |
1824 |
# Deleting record |
1825 |
my $error = DelBiblio($bn_merge); |
1826 |
if ($error) { |
1827 |
$results{'error'} = $error; |
1828 |
$results{'status'} = 0; |
1829 |
return \%results; |
1830 |
} else { |
1831 |
push( @worked_ids, $bn_merge ); |
1832 |
} |
1833 |
} |
1834 |
return \%results; |
1835 |
} |
1836 |
|
1749 |
=head2 Internal methods |
1837 |
=head2 Internal methods |
1750 |
|
1838 |
|
1751 |
=head3 type |
1839 |
=head3 type |