Koha-clms/misc
Fridolin Somers 7a92d126df Bug 24527: misc/cronjobs/update_totalissues.pl problem with multiple items
misc/cronjobs/update_totalissues.pl when issuing statistics table, no-incremental,  has a problem for biblio with multiple items.
The first SQL query gets the biblios linked to items with issues in statistics :

SELECT
  biblio.biblionumber, COUNT(statistics.itemnumber)
FROM
  biblio
LEFT JOIN
  items
ON
  (biblio.biblionumber=items.biblionumber)
LEFT JOIN
  statistics
ON
  (items.itemnumber=statistics.itemnumber)
WHERE
  statistics.type = 'issue'
$limit
GROUP BY
  biblio.biblionumber

The second SQL query is :
SELECT
  biblio.biblionumber, 0
FROM
  biblio
LEFT JOIN
  items
ON
  (biblio.biblionumber=items.biblionumber)
LEFT JOIN
  statistics
ON
  (items.itemnumber=statistics.itemnumber)
WHERE
  statistics.itemnumber IS NULL
GROUP BY
  biblio.biblionumber

The problem is that this second query will set to 0 where ANY item has no entry in statistics table.
So when running it sets 0 to the biblio that had a value from first
query.

I think the best fix is to use "WHERE statistics.type = 'issue'" inside que JOIN :
LEFT JOIN statistics ON (items.itemnumber=statistics.itemnumber AND statistics.type = 'issue')

Test plan :
1) Begin with an empty database
2) Create a biblio 1 with no items
3) Create a biblio 2 with 3 items
4) Create a biblio 3 with 2 items
5) Checkout and checkin all items of biblio 2
6) Checkout and checkin the firt item of biblio 3
7) run misc/cronjobs/update_totalissues.pl --use-stats -v
8) Check biblio 1 has biblioitems.totalissues = 0
9) Check biblio 2 has biblioitems.totalissues = 3
10) Without patch the biblio 3 has biblioitems.totalissues = 0
11) With patch the biblio 3 has biblioitems.totalissues = 1
12) Check misc/cronjobs/update_totalissues.pl --incremental is OK

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
(cherry picked from commit 91da9841d7)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit f6d61ce5e0)

Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
2020-04-14 14:36:34 +12:00
..
admin Bug 17746: (QA follow-up) Make set_password.pl generate a password if required 2019-04-01 11:51:23 +01:00
bin Revert Bug 11081 - Port Koha::Contrib::Tamil indexer into Koha code base 2016-03-01 16:56:35 +00:00
cronjobs Bug 24527: misc/cronjobs/update_totalissues.pl problem with multiple items 2020-04-14 14:36:34 +12:00
devel Bug 21576: Add a developer script to fix missing TT filters 2018-10-26 17:09:51 +00:00
interface_customization Bug 20647: (alternate) When ILL is enabled the hover effect on the ILL requests button is wrong 2018-08-10 10:38:12 +00:00
load_testing Bug 17829: Move GetMember to Koha::Patron 2017-07-10 13:14:19 -03:00
maintenance Bug 21846: Fix pod2usage return values 2019-03-19 09:58:44 +00:00
migration_tools Bug 12488: Make bulkmarcimport.pl -d use DELETE instead of TRUNCATE 2019-02-25 13:29:39 +00:00
release_notes Update release notes for 18.11.15 release 2020-03-24 09:39:32 +13:00
search_tools Bug 19893: Add pods, remove syspref, add tests for serialization format 2018-11-16 11:04:59 +00:00
translator Translation updates for Koha 18.11.15 2020-03-24 08:51:01 +13:00
batchCompareMARCvsFrameworks.pl
…
batchDeleteUnusedSubfields.pl Bug 21719: Fix typos 2018-11-08 02:18:46 +00:00
batchImportMARCWithBiblionumbers.pl
…
batchRebuildBiblioTables.pl Bug 19040: Refactor GetMarcBiblio parameters 2017-08-25 10:23:42 -03:00
batchRebuildItemsTables.pl Bug 20893: batchRebuildItemsTables.pl has incorrect parameter 2018-06-29 19:40:16 +00:00
batchRepairMissingBiblionumbers.pl Bug 19040: Refactor GetMarcBiblio parameters 2017-08-25 10:23:42 -03:00
batchdeletebiblios.pl
…
check_sysprefs.pl Bug 21719: Fix typos 2018-11-08 02:18:46 +00:00
commit_file.pl Bug 7131: (follow-up) update the command-line import tools 2013-10-30 04:35:17 +00:00
export_borrowers.pl Bug 17829: Move GetMember to Koha::Patron 2017-07-10 13:14:19 -03:00
export_records.pl Bug 20486: Add --marc_conditions option to export_records.pl 2018-11-08 02:23:29 +00:00
exportauth.pl
…
import_patrons.pl Bug 22875: Document verbose option in import_patrons 2019-05-30 20:12:09 +01:00
koha-install-log Bug 14302: Remove GRS1 specific code 2018-08-31 11:24:20 +00:00
kohalib.pl Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
link_bibs_to_authorities.pl Bug 21957: Add a flag to ModBiblio to avoid linking auths if called from linker 2019-04-26 14:44:37 +01:00
mod_zebraqueue.pl Bug 9978: (followup) Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:43 -03:00
perlmodule_ls.pl
…
perlmodule_rm.pl
…
recreateIssueStatistics.pl
…
sax_parser_print.pl Bug 17626 (QA followup) 2016-11-22 11:29:07 +00:00
sax_parser_test.pl
…
sip_cli_emulator.pl Bug 16757 - Add support for Fee Paid to SIP cli emulator for testing 2017-03-31 13:56:37 +00:00
stage_file.pl Bug 19049: Fix regression on stage-marc-import with to_marc plugin 2017-08-15 12:17:41 -03:00