From 701685015fd04abc797ac5f98000e364dcd9b5a6 Mon Sep 17 00:00:00 2001 From: morgane alonso Date: Thu, 25 Aug 2016 14:26:47 +0000 Subject: [PATCH] Bug 17047 ability to import a subscription model from mana - modify subscription-add.tt and subscription.pl to manage a import from mana during a subscription creation - add 2 script in svc for ajax calling from subscription-add.tt to communicate with mana server during a asubscription creation - add a function in Subscription.pm to have all the info for a mana research from a biblionumber - modify functions used by subscription-add.pl in C4/Serials to manage a frequency which came from mana server and not already created on the koha database, and modify the tests of the said functions --- C4/Serials.pm | 31 +-- Koha/SharedContent.pm | 20 ++ Koha/Subscription.pm | 15 ++ .../serials/mana-subscription-search-result.tt | 1 + .../prog/en/modules/serials/subscription-add.tt | 214 ++++++++++++++-- misc/cronjobs/serialsUpdate.pl | 4 +- serials/serials-collection.pl | 6 +- serials/showpredictionpattern.pl | 23 +- serials/subscription-add.pl | 91 ++++++- svc/mana/search | 62 +++++ svc/mana/use | 48 ++++ t/db_dependent/Serials.t | 3 +- t/db_dependent/Serials/GetFictiveIssueNumber.t | 126 ++++++++++ t/db_dependent/Serials/GetNextDate.t | 272 +++++++++------------ t/db_dependent/Serials/GetNextSeq.t | 124 +++++----- 15 files changed, 774 insertions(+), 266 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt create mode 100755 svc/mana/search create mode 100755 svc/mana/use create mode 100644 t/db_dependent/Serials/GetFictiveIssueNumber.t diff --git a/C4/Serials.pm b/C4/Serials.pm index 885192e..027ca20 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -864,19 +864,20 @@ sub GetDistributedTo { my ( $nextseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq( $subscription, $pattern, $planneddate ); + ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate ); $subscription is a hashref containing all the attributes of the table 'subscription'. $pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns'. +$frequency is a hashref containing all the attributes of the table 'subscription_frequencies' $planneddate is a date string in iso format. This function get the next issue for the subscription given on input arg =cut sub GetNextSeq { - my ($subscription, $pattern, $planneddate) = @_; + my ($subscription, $pattern, $frequency, $planneddate) = @_; return unless ($subscription and $pattern); @@ -889,7 +890,7 @@ sub GetNextSeq { if(@irreg > 0) { my $irregularities = {}; $irregularities->{$_} = 1 foreach(@irreg); - my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1; + my $issueno = GetFictiveIssueNumber($subscription, $planneddate, $frequency) + 1; while($irregularities->{$issueno}) { $count++; $issueno++; @@ -1032,7 +1033,7 @@ sub GetExpirationDate { #calculate the date of the last issue. for ( my $i = 1 ; $i <= $length ; $i++ ) { - $enddate = GetNextDate( $subscription, $enddate ); + $enddate = GetNextDate( $subscription, $enddate, $frequency ); } } elsif ( $subscription->{monthlength} ) { if ( $$subscription{startdate} ) { @@ -1184,16 +1185,17 @@ sub ModSerialStatus { if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); + my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); # next issue number my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) - = GetNextSeq( $subscription, $pattern, $publisheddate ); + = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate ); # next date (calculated from actual date & frequency parameters) - my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1); + my $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency, 1); my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? WHERE subscriptionid = ?"; @@ -2193,7 +2195,7 @@ sub abouttoexpire { my $expirationdate = GetExpirationDate($subscriptionid); my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); - my $nextdate = GetNextDate($subscription, $res); + my $nextdate = GetNextDate($subscription, $res, $frequency); # only compare dates if both dates exist. if ($nextdate and $expirationdate) { @@ -2259,7 +2261,7 @@ sub GetSubscriptionsFromBorrower { =head2 GetFictiveIssueNumber -$issueno = GetFictiveIssueNumber($subscription, $publishedate); +$issueno = GetFictiveIssueNumber($subscription, $publishedate, $frequency); Get the position of the issue published at $publisheddate, considering the first issue (at firstacquidate) is at position 1, the next is at position 2, etc... @@ -2273,9 +2275,8 @@ date, and $publisheddate. =cut sub GetFictiveIssueNumber { - my ($subscription, $publisheddate) = @_; + my ($subscription, $publisheddate, $frequency) = @_; - my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'}); my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef; my $issueno = 0; @@ -2393,12 +2394,13 @@ sub _get_next_date_year { =head2 GetNextDate -$resultdate = GetNextDate($publisheddate,$subscription) +$resultdate = GetNextDate($publisheddate,$subscription,$freqdata,$updatecount) this function it takes the publisheddate and will return the next issue's date and will skip dates if there exists an irregularity. $publisheddate has to be an ISO date -$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit' +$subscription is a hashref containing at least 'firstacquidate', 'irregularity', and 'countissuesperunit' +$frequency is a hashref containing frequency informations $updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database - eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be skipped then the returned date will be 2007-05-10 @@ -2411,11 +2413,10 @@ Return undef if subscription is irregular =cut sub GetNextDate { - my ( $subscription, $publisheddate, $updatecount ) = @_; + my ( $subscription, $publisheddate, $freqdata, $updatecount ) = @_; return unless $subscription and $publisheddate; - my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); if ($freqdata->{'unit'}) { my ( $year, $month, $day ) = split /-/, $publisheddate; @@ -2435,7 +2436,7 @@ sub GetNextDate { # Get the 'fictive' next issue number # It is used to check if next issue is an irregular issue. - my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1; + my $issueno = GetFictiveIssueNumber($subscription, $publisheddate, $freqdata) + 1; # Then get the next date my $unit = lc $freqdata->{'unit'}; diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm index 81a6a3e..e0c512b 100644 --- a/Koha/SharedContent.pm +++ b/Koha/SharedContent.pm @@ -40,6 +40,16 @@ sub manaRequest { return $result if ( $response->code =~ /^2..$/ ); } +sub manaNewUserPatchRequest { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json/newUser"; + my $request = HTTP::Request->new( PATCH => $url ); + + return manaRequest($request); +} + sub manaPostRequest { my $resource = shift; my $content = shift; @@ -54,6 +64,16 @@ sub manaPostRequest { return manaRequest($request); } +sub manaGetRequestWithId { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + sub manaGetRequest { my $resource = shift; my $parameters = shift; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 29a2c66..40943dd 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -45,6 +45,21 @@ Koha::Subscription - Koha Subscription Object class =cut +sub get_search_info { + my $searched_sub_id = shift; + my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } ); + my $biblioitem = + Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } ); + + my $sub_mana_info = { + 'title' => $biblio->title, + 'issn' => $biblioitem->issn, + 'ean' => $biblioitem->ean, + 'publishercode' => $biblioitem->publishercode + }; + return $sub_mana_info; +} + sub get_sharable_info { my $shared_sub_id = shift; my $subscription = Koha::Subscriptions->find($shared_sub_id); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt new file mode 100644 index 0000000..0afe02c --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt @@ -0,0 +1 @@ +[% INCLUDE 'mana-subscription-search-result.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index ff918b0..bddb7f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -1,5 +1,6 @@ [% USE KohaDates %] [% USE Branches %] +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials › [% IF ( modify ) %][% bibliotitle |html %] › Modify subscription[% ELSE %]New subscription[% END %] @@ -11,11 +12,16 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ width: 300px; /* not enough for IE7 apparently */ } + +[% INCLUDE 'datatables.inc' %]