Jonathan Druart
9d6d641d1f
On bug 17591 we discovered that there was something weird going on with the way we export and use subroutines/modules. This patch tries to standardize our EXPORT to use EXPORT_OK only. That way we will need to explicitely define the subroutine we want to use from a module. This patch is a squashed version of: Bug 17600: After export.pl Bug 17600: After perlimport Bug 17600: Manual changes Bug 17600: Other manual changes after second perlimports run Bug 17600: Fix tests And a lot of other manual changes. export.pl is a dirty script that can be found on bug 17600. "perlimport" is: git clone https://github.com/oalders/App-perlimports.git cd App-perlimports/ cpanm --installdeps . export PERL5LIB="$PERL5LIB:/kohadevbox/koha/App-perlimports/lib" find . \( -name "*.pl" -o -name "*.pm" \) -exec perl App-perlimports/script/perlimports --inplace-edit --no-preserve-unused --filename {} \; The ideas of this patch are to: * use EXPORT_OK instead of EXPORT * perltidy the EXPORT_OK list * remove '&' before the subroutine names * remove some uneeded use statements * explicitely import the subroutines we need within the controllers or modules Note that the private subroutines (starting with _) should not be exported (and not used from outside of the module except from tests). EXPORT vs EXPORT_OK (from https://www.thegeekstuff.com/2010/06/perl-exporter-examples/) """ Export allows to export the functions and variables of modules to user’s namespace using the standard import method. This way, we don’t need to create the objects for the modules to access it’s members. @EXPORT and @EXPORT_OK are the two main variables used during export operation. @EXPORT contains list of symbols (subroutines and variables) of the module to be exported into the caller namespace. @EXPORT_OK does export of symbols on demand basis. """ If this patch caused a conflict with a patch you wrote prior to its push: * Make sure you are not reintroducing a "use" statement that has been removed * "$subroutine" is not exported by the C4::$MODULE module means that you need to add the subroutine to the @EXPORT_OK list * Bareword "$subroutine" not allowed while "strict subs" means that you didn't imported the subroutine from the module: - use $MODULE qw( $subroutine list ); You can also use the fully qualified namespace: C4::$MODULE::$subroutine Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
174 lines
7 KiB
Perl
Executable file
174 lines
7 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Copyright 2016 PTFS-Europe Ltd
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
=head1 housebound.pl
|
|
|
|
Script to handle housebound management for patrons. This single script
|
|
handles display, creation, deletion and management of profiles and visits.
|
|
|
|
=cut
|
|
|
|
use Modern::Perl;
|
|
use CGI;
|
|
use C4::Auth qw( get_template_and_user );
|
|
use C4::Context;
|
|
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
|
|
use DateTime;
|
|
use Koha::DateUtils qw( dt_from_string );
|
|
use Koha::Libraries;
|
|
use Koha::Patrons;
|
|
use Koha::Patron::Categories;
|
|
use Koha::Patron::HouseboundProfile;
|
|
use Koha::Patron::HouseboundVisit;
|
|
use Koha::Patron::HouseboundVisits;
|
|
|
|
my $input = CGI->new;
|
|
|
|
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
|
{
|
|
template_name => 'members/housebound.tt',
|
|
query => $input,
|
|
type => 'intranet',
|
|
flagsrequired => { borrowers => 'edit_borrowers' },
|
|
}
|
|
);
|
|
|
|
my @messages; # For error messages.
|
|
my $method = $input->param('method') // q{};
|
|
my $visit_id = $input->param('visit_id') // q{};
|
|
|
|
# Get patron
|
|
my $borrowernumber = $input->param('borrowernumber');
|
|
my $logged_in_user = Koha::Patrons->find( $loggedinuser );
|
|
my $patron = Koha::Patrons->find($borrowernumber);
|
|
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
|
|
|
|
# Get supporting cast
|
|
my ( $houseboundprofile, $visit );
|
|
if ( $patron ) { # FIXME This test is not needed - output_and_exit_if_error handles it
|
|
$houseboundprofile = $patron->housebound_profile;
|
|
}
|
|
if ( $visit_id ) {
|
|
$visit = eval {
|
|
return Koha::Patron::HouseboundVisits->find($visit_id);
|
|
};
|
|
push @messages, { type => 'error', code => 'error_on_visit_load' }
|
|
if ( $@ or !$visit );
|
|
}
|
|
|
|
# Main processing
|
|
my ( $deliverers, $choosers, $houseboundvisit );
|
|
|
|
if ( $method eq 'updateconfirm' and $houseboundprofile ) {
|
|
# We have received the input from the profile edit form. We must save the
|
|
# changes, and return to simple display.
|
|
$houseboundprofile->set({
|
|
day => scalar $input->param('day') // q{},
|
|
frequency => scalar $input->param('frequency') // q{},
|
|
fav_itemtypes => scalar $input->param('fav_itemtypes') // q{},
|
|
fav_subjects => scalar $input->param('fav_subjects') // q{},
|
|
fav_authors => scalar $input->param('fav_authors') // q{},
|
|
referral => scalar $input->param('referral') // q{},
|
|
notes => scalar $input->param('notes') // q{},
|
|
});
|
|
my $success = eval { return $houseboundprofile->store };
|
|
push @messages, { type => 'error', code => 'error_on_profile_store' }
|
|
if ( $@ or !$success );
|
|
$method = undef;
|
|
} elsif ( $method eq 'createconfirm' ) {
|
|
# We have received the input necessary to create a new profile. We must
|
|
# save it, and return to simple display.
|
|
$houseboundprofile = Koha::Patron::HouseboundProfile->new({
|
|
borrowernumber => $patron->borrowernumber,
|
|
day => scalar $input->param('day') // q{},
|
|
frequency => scalar $input->param('frequency') // q{},
|
|
fav_itemtypes => scalar $input->param('fav_itemtypes') // q{},
|
|
fav_subjects => scalar $input->param('fav_subjects') // q{},
|
|
fav_authors => scalar $input->param('fav_authors') // q{},
|
|
referral => scalar $input->param('referral') // q{},
|
|
notes => scalar $input->param('notes') // q{},
|
|
});
|
|
my $success = eval { return $houseboundprofile->store };
|
|
push @messages, { type => 'error', code => 'error_on_profile_create' }
|
|
if ( $@ or !$success );
|
|
$method = undef;
|
|
} elsif ( $method eq 'visit_update_or_create' ) {
|
|
# We want to edit, edit a visit, so we must pass its details.
|
|
$deliverers = Koha::Patrons->search_housebound_deliverers;
|
|
$choosers = Koha::Patrons->search_housebound_choosers;
|
|
$houseboundvisit = $visit;
|
|
} elsif ( $method eq 'visit_delete' and $visit ) {
|
|
# We want ot delete a specific visit.
|
|
my $success = eval { return $visit->delete };
|
|
push @messages, { type => 'error', code => 'error_on_visit_delete' }
|
|
if ( $@ or !$success );
|
|
$method = undef;
|
|
} elsif ( $method eq 'editvisitconfirm' and $visit ) {
|
|
# We have received input for editing a visit. We must store and return to
|
|
# simple display.
|
|
$visit->set({
|
|
borrowernumber => scalar $input->param('borrowernumber') // q{},
|
|
appointment_date => dt_from_string($input->param('date') // q{}),
|
|
day_segment => scalar $input->param('segment') // q{},
|
|
chooser_brwnumber => scalar $input->param('chooser') // q{},
|
|
deliverer_brwnumber => scalar $input->param('deliverer') // q{},
|
|
});
|
|
my $success = eval { return $visit->store };
|
|
push @messages, { type => 'error', code => 'error_on_visit_store' }
|
|
if ( $@ or !$success );
|
|
$method = undef;
|
|
} elsif ( $method eq 'addvisitconfirm' and !$visit ) {
|
|
# We have received input for creating a visit. We must store and return
|
|
# to simple display.
|
|
my $visit = Koha::Patron::HouseboundVisit->new({
|
|
borrowernumber => scalar $input->param('borrowernumber') // q{},
|
|
appointment_date => dt_from_string($input->param('date') // q{}),
|
|
day_segment => scalar $input->param('segment') // q{},
|
|
chooser_brwnumber => scalar $input->param('chooser') // q{},
|
|
deliverer_brwnumber => scalar $input->param('deliverer') // q{},
|
|
});
|
|
my $success = eval { return $visit->store };
|
|
push @messages, { type => 'error', code => 'error_on_visit_create' }
|
|
if ( $@ or !$success );
|
|
$method = undef;
|
|
}
|
|
|
|
# We don't have any profile information, so we must display a creation form.
|
|
$method = 'update_or_create' if ( !$houseboundprofile );
|
|
|
|
# Ensure template has all patron details.
|
|
$template->param( patron => $patron );
|
|
|
|
$template->param(
|
|
housebound_profile => $houseboundprofile,
|
|
visit => $houseboundvisit,
|
|
messages => \@messages,
|
|
method => $method,
|
|
choosers => $choosers,
|
|
deliverers => $deliverers,
|
|
houseboundview => 'on',
|
|
);
|
|
|
|
output_html_with_http_headers $input, $cookie, $template->output;
|
|
|
|
=head1 AUTHOR
|
|
|
|
Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
|
|
|
|
=cut
|