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>
We should remove the debug statements or use Koha::Logger when we want
to keep it.
Test plan:
Confirm that occurrences of remaining occurrences of DEBUG need to be
kept (historical scripts for instance)
Confirm that the occurrences removed by this patch can be removed
Confirm that the occurrences replaced by Koha::Logger are correct
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Looks good to me, noting a few minor points on BZ.
JD amended patch: replace "warn #Finished" with "#warn Finished", and
put the statement on a single line
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
We should use Koha::DateUtils instead of Date::Time directly
This patch simplay replaces calls to now() with a call to dt_from_string()
which does effectively the same thing.
Probably reading the code and verifying changes is sufficient but...
To test:
1 - confirm the files all compile
2 - confirm all tests pass
3 - confirm Koha still works
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
When MARC modification template actions are applied, they assume that
the from field is the same as the conditional field. This patch adds
checks for this, as well as tests to confirm the behaviour is correct.
CASE 1: Delete 1st field 020 if 651$z exists
BROKEN BEHAVIOUR (before patch): deletes the 2nd instance of 020 instead
of 1st
EXPECTED BEHAVIOUR (corrected by patch): deletes the 1st instance of 020
CASE 2: Delete 1st field 020 if 651$z matches Berlin. (must include '.')
BROKEN BEHAVIOUR (before patch): deletes the 2nd instance of 020
EXPECTED BEHAVIOUR (corrected by patch): deletes the 1st instance of 020
CASE 3: Delete field 020 if 650$2 does not match fast
BROKEN BEHAVIOUR (before patch): deletes all 020 fields even though
650$2 does match fast
EXPECTED BEHAVIOUR (corrected by patch): does not delete 020 fields
Confirm tests pass: t/db_dependent/MarcModificationTemplates.t
Sponsored-by: Catalyst IT
Signed-off-by: Frank Hansen <frank.hansen@ub.lu.se>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Tests exist in t/SimpleMARC.t to prove that it works and it is possible.
I do not remember what I wrote this limitation.
Signed-off-by: Jon Knight <j.p.knight@lboro.ac.uk>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Add/Update would update a field or create new if it existed, but didn't
allow for creating new if the field existed.
This patchset splits the options to 'Add & Update' so that 'Add' will always
add a field and 'Update' will operate as it always has
To test:
1 - Have a record with a known existing field (make a copy)
2 - Define a marc modification template that 'Add/update' on that field
3 - Define an 'Add/Update' on a field that doesn't exist
4 - Batch modify the copy of record using the above template
5 - Verify the existing field was updated
6 - Verify the non-existing field was updated
7 - Apply patch and update database
8 - Make another copy
9 - Modify the copy with the same template as above
10 - Should match initial modification
11 - Add a new rule to add a new field
12 - Modify using the updated template
13 - Ensure your new field is created
14 - Test various options in the modification tool
15 - prove t/db_dependent/MarcModificationTemplates.t
Signed-off-by: Victor Grousset <victor.grousset@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Cannot be empty strings.
Fix for:
Data truncated for column 'conditional'
Data truncated for column 'conditional_comparison'
Incorrect integer value: '' for column 'conditional_regex'
t/db_dependent/MarcModificationTemplates.t
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
The "does not match" condition does not behave as expected.
We want it to process the action if the subfield exists and that the
value does not match a given pattern.
Test plan:
Be creative and write different template actions using the "does not
match" condition.
Using the "Batch record modification" and the "Show MARC" popup, confirm
that the processed record is the one you are expecting.
Signed-off-by: Jon Knight <J.P.Knight@lboro.ac.uk>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Mainly a
perl -p -i -e 's/^.*3.07.00.049.*\n//' **/*.pm
Then some adjustements
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
perl -p -i -e 's/^(use vars .*)\$VERSION\s?(.*)/$1$2/' **/*.pm
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
This patch sorts the modification templates when getting them from the
database This affects the pages below:
tools/batch_record_modification.pl
tools/marc_modification.pl
tools/stage-marc-import.pl
To test:
1 - Add some marc modification templates in a non alpha order (Shoes,
Hats, Cats)
2 - visit the pages above and note the templates are in order
added
3 - apply patch
4 - visit the three pages and note correct order
5 - verify all tools continue to work as expected
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
This patch implements the copy and replace action for the marc
modification templates.
Instead of copying a field/subfield, it will erase the destination
fields/subfields.
Test plan:
Find it yourself.
Compare the differences between the copy and the copy_and_replace
actions.
The easier way to test is to 1/ create a complete record, 2/create some
modification templates and 3/ use the batch record modification with the
"preview" function.
QA note: I kept the same tests as "copy" and, if no change were
expected, I noted them "(same as copy)", to be sure this new action won't
introduce regression on these tests.
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This fix is a global fix for the MarcModificationTemplate feature.
Some unit tests were missing and some behaviors were wrong.
For instance, if you tried to update a non existent field, the script
crashed.
The following line was completely stupid:
if $from_field ne $to_subfield
The field_number equals 1 if the user wants to update the first field
and 0 for all fields.
The field_numbers (note the s) variable contains the field numbers to
update. This array is filled if a condition exists (field exists or
field equals).
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Make sure the ModifyRecordWithTemplate routine returns undef.
This patch also removes a warning if GetModificationTemplates is called
without parameter.
Verify
prove t/db_dependent/MarcModificationTemplates.t
returns green.
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This patch series is a bugfix for the Marc modification templates tool.
Bug description:
If you want to do an action (delete/update/move/...) on a multivalued
field and if a condition is defined on the same field, it is highly
probable the resulted record will not be what you expect.
For example:
Deleting All (or the first) fields 650 if 245$a="Bad title" works with
the current code.
BUT if you want to delete All (or the first) fields 650 with a condition
on 650$9=42, and if at least one field matches the condition :
- if you have selected all, all fields 650 will be deleted, even the
ones who do not match the condition.
- if you have selected first, the first 650 field will be deleted, even
if it does not match the condition.
The expected behavior is to delete the fields matching the
condition (and not all the 650 fields).
What this patch does:
This patch introduces 2 changes in the logic of Koha::SimpleMARC.
The first change is a change of the prototypes for the 2 routines
field_exists and field_equals. Now they return the "field number" of the
matching fields.
The second change is the type of the "n" parameter for all routines
using it in Koha::SimpleMARC. Before this patch, the "n" parameter was a
boolean in most cases. If 0, the action was done on all fields, if 1
on the first one only. Now it is possible to specify the "field numbers"
(so the array of field numbers which is returned by field_exists or
field_equals) for all routines which had the n parameter.
Test plan for the patch series:
Note: This test plan describes a specific example, feel free to create
your own one.
0/ Define a marc modification template with the following action:
Delete field 245 if 245$9 = 42
1/ choose and export a record with several 245 fields.
For ex:
245
$a The art of computer programming
$c Donald E. Knuth.
$9 41
245
$a Bad title
$c Bad author
$9 42
2/ import it using the Stage MARC for import tool.
3/ verify the imported record does not contain any 245 field.
4/ apply all the patches from this bug report
5/ do again steps 2 and 3
6/ verify the imported record contains only one 245 field, the one with
245$9=41
7/ verify the unit tests passed:
prove t/SimpleMARC.t
prove t/db_dependent/MarcModificationTemplates.t
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Removes this warning: Use of uninitialized value $template_id in string eq
at C4/MarcModificationTemplates.pm line 84.
GetModificationTemplates has no template_id if called from
marc_modification_templates.pl without operation (first click from
interface) and from tools/stage-marc-import.pl.
Slightly adjusted the POD lines accordingly.
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
In order to avoid a long list of parameters, it should be better to
pass all of them into a hashref.
This patch does not add or modify a behavior.
Test plan:
Verify the unit tests still pass
- prove t/SimpleMARC.t
- prove t/db_dependent/MarcModificationTemplates.t
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Replace constructs using given and when by if/else
feature now generates compilation warnings in 5.18
and is liable to change behaviour.
This patch:
* replaces the construct with if/else
* reformats the if branching using perltidy
to remove the now redundant indent
To test:
[1] Verify that prove -v t/db_dependent/MarcModificationTemplates.t
passes.
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Bug 8015: Fix complains from qa tools
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Bug 8015: Get rid of the eval in ModifyRecordWithTemplate
This patch removes the use of eval in the
C4::MarcModificationTemplates::ModifyRecordWithTemplate routine.
Now this routine call the wanted modification routine with the list of
parameters.
This call is done only if the condition is respected.
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Bug 8015: Get rid of eval for evaluating =~ m//
Koha::SimpleMarc::field_equals uses eval in order to check if a string
matches a pattern.
Now this eval is removed and the "regex" variable does not contain the
regex separated character (/ or |).
Regression: Before this patch, the user was able to user a modifier. Now
it is not possible.
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Bug 8015: Get rid of the eval for substitution
Before this patch, the regex substitution was contain into only one
variable (e.g. my $regex = "/foo/bar/i").
Now each member of the regex is stored into a field in the
marc_modification_template_actions sql table.
In order to avoid a complex code, only modifiers i and g are take into
account.
Note: If you already add the mmta table, you have to drop it.
This patch also adds a foreign key from mmta to mmt tables.
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Bug 8015: FIX ui issue
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Bug 8015: The template name is a required field
Test plan:
Try to add a template with an empty string as name.
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 8015: Fix template capitalization amd other template issues
Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Bug 8015: Fix error where field object is returned instead of field value for fields without subfields
Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Bug 8015: Fix bad ordering on function parameters
Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Bug 8015: Escape escape characters for strings
Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Bug 8015: Fix bad parameter list for direct external call to update_field
Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Bug 8015: Fix problem with moving existing subfield value to nonexistent field/subfield
Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Bug 8015: FIX QA issues
This patch fixes some stuffs failing qa tests: POD, indentation (tabs),
perlcritic
Signed-off-by: Galen Charlton <gmc@esilibrary.com>