Koha-clms/misc/cronjobs
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
..
holds Bug 21698: (QA follow-up) Fix typo verbosev -> verbose 2018-10-31 13:49:19 +00:00
rss Bug 21526: Use the 'url' filter when needed 2018-11-12 16:35:43 -03:00
social_data Bug 15193 - Perl scripts missing exec permission 2015-12-11 16:36:08 +00:00
thirdparty Bug 21180: Allow Talking Tech outbound script to limit based on patron home library branchcode 2019-10-16 23:58:27 +00:00
CONFIGURE.gmail Bug 5251 : Enhancement: [3.2] (Resubmission) Adding code to support using gmail as an SMTP server 2011-04-08 14:01:15 +12:00
advance_notices.pl Bug 17969: Refactor the way <<items.content>> is generated 2017-08-30 15:06:25 -03:00
automatic_item_modification_by_age.pl Bug 11023: Automatic item modification by age (Was Toggle "new" status") 2016-03-02 22:56:31 +00:00
automatic_renewals.pl Bug 15494: Update display of renewal errors 2018-11-07 21:39:38 +00:00
backup.sh Bug 9235 - Hardcoded values in cronjobs/backup.sh 2012-12-21 07:20:50 -05:00
batch_anonymise.pl Bug 16966: move parameters to hashref 2017-03-03 17:20:05 +00:00
build_browser_and_cloud.pl Bug 19040: Refactor GetMarcBiblio parameters 2017-08-25 10:23:42 -03:00
cart_to_shelf.pl Bug 13889: Add information about cron jobs to system log 2015-05-04 11:11:14 -03:00
check-url-quick.pl Bug 21122: Fix check-url-quick when utf8 characters in URL's 2018-08-02 10:21:43 -03:00
check-url.pl Bug 19040: Refactor GetMarcBiblio parameters 2017-08-25 10:23:42 -03:00
cleanup_database.pl Bug 20402: only output if verbose flag is set 2018-05-09 12:47:43 -03:00
cloud-kw.pl Bug 14383: misc: Fix some typos in comments and documentation 2015-06-22 17:34:45 -03:00
cloud-sample.conf
…
create_koc_db.pl Bug 9978: (followup) Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:43 -03:00
crontab.example Bug 21235: Remove table services_throttle 2018-09-07 15:09:39 +00:00
delete_expired_opac_registrations.pl Bug 16907: Koha::Patrons - Move DelMember to ->delete 2016-10-21 16:20:41 +00:00
delete_items.pl Bug 14504: (followup) Make deletion conditional on --commit 2016-08-26 12:07:27 +00:00
delete_patrons.pl Bug 20915: Use date --iso-8601 instead of date +%Y-%m-%d 2018-09-26 16:43:22 +00:00
delete_records_via_leader.pl Bug 19712: (follow-up) Add missing use Pod::Usage 2018-04-06 14:50:58 -03:00
edi_cron.pl Bug 17141: Call config method to retrieve logdir 2016-09-02 15:49:12 +00:00
fines.pl Bug 20727: (QA follow-up) Remove a few use statements again 2018-06-22 16:10:10 +00:00
gather_print_notices.pl Bug 21560: (follow-up) move use at the top 2019-03-19 09:36:51 +00:00
import_webservice_batch.pl Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
j2a.pl Bug 15742 [QA Followup] - Tidy script 2016-02-23 21:19:08 +00:00
longoverdue.pl Bug 19974: Make MarkLostItemsAsReturned multiple 2018-04-20 11:57:31 -03:00
membership_expiry.pl Bug 17762: Send lang to GetPreparedLetter 2017-05-09 20:56:41 +00:00
merge_authorities.pl Bug 9988: Refactor the cron script 2017-04-13 08:53:47 -04:00
notice_unprocessed_suggestions.pl Bug 19304: Move C4::Members::GetNoticeEmailAddress to Koha::Patron->notice_email_address 2018-01-02 11:46:40 -03:00
overdue_notices.pl Bug 20537: Added checks to remove warning from overdue_notices.pl 2019-05-30 21:38:19 +01:00
printoverdues.sh Bug 10127 : Printoverdues.sh should tar only pdf files 2013-07-16 15:47:13 +00:00
process_message_queue.pl Bug 21322: process_message_queue.pl --type should take an argument 2018-10-03 17:34:43 +00:00
purge_suggestions.pl Bug 16280: purge_suggestions.pl: Cron job log should tell number of days used 2018-11-05 14:41:05 +00:00
reconcile_balances.pl Bug 21915: Add a cli script to reconcile balances 2019-01-10 16:18:59 +00:00
remove_temporary_edifiles.pl Bug 7736: Support Ordering via Edifact EDI messages 2016-04-01 20:03:17 +00:00
runreport.pl Bug 22323: cronjob runreport.pl CSV add encoding 2019-02-25 15:32:04 +00:00
serialsUpdate.pl Bug 14960: Remove C4::Dates from files in misc/cronjobs 2015-11-17 15:36:43 -03:00
share_usage_with_koha_community.pl Bug 18066: Hea V2 2017-03-23 00:10:46 +00:00
sitemap.pl Bug 16751: What is sitemaper? 2016-06-24 13:19:06 +00:00
staticfines.pl Bug 14960: Simplify the date management in staticfines 2015-11-17 15:36:51 -03:00
stockrotation.pl Bug 22566: (QA follow-up) Fix pod complaint 2019-07-25 20:31:53 +00:00
update_totalissues.pl Bug 24527: misc/cronjobs/update_totalissues.pl problem with multiple items 2020-04-14 14:36:34 +12:00