Koha-clms/C4
Jonathan Druart 979bc2e6fa Bug 18966: Do not deal with duplicate issue_id on checkin
Koha suffers of big bugs due to its history: When data are deleted, they are moved to another tables.
For instance issues and old_issues: when a checkin is done, it is moved to the old_issues table.
That leads to a main problem that is described on https://wiki.koha-community.org/wiki/DBMS_auto_increment_fix

However we tried first to fix the problem (for issues/old_issues) at code level on bug 18242.
The goal was to prevent data lost.
Data lost may happens in this case:
Check an item out (issue_id = 1)
Check an item in (issue_id = 1)
Restart MySQL (reset auto increment for issue_id to 1)
Check an item out (issue_id = 1)
Check an item in => BOOM, the issue_id is a PK in old_issues and the move fails.
Before bug 18242 the data were lost, we inserted the value into old_issues, which fails silently (because of RaiseError set to 0 in Koha::Database), then delete the row from issues.
That has been fixed using a transaction.

This patch introduced a regression we tried to fix on bug 18651 comment 0, the patron was charged even if the checkin was rejected.
A good way to fix that would have been to LOCK the tables:
1- Start a transaction
2- LOCK the table to make sure nobody will read id and avoid race conditions
3- Move the content from one table to the other, dealing with ids
4- UNLOCK the table
5- Commit the transaction
But there were problems using LOCK and DBIx::Class (See commit 905572910b - Do no LOCK/UNLOCK the table).

Finally the solution implemented is not acceptable for several reasons:
- batch checkins may fail
- issue_id will always stay out of sync (between issues and old_issues)
See 18651 comment 66.

Since the next stable releases are very soon, and we absolutely need to fix this problem, I am suggesting to:
1- Execute the move in a transaction to avoid data lost and reject the checkin if we face IDs dup
=> It will only reject 1 checkin (max is 1 * MySQL restart), no need to deal with race conditions,
2- Display a warning on the checkin page and link to a solution/explanation
3- Communicate as much as we can on the proper fix: Update auto increment values when the DBMS is restarted - https://wiki.koha-community.org/wiki/DBMS_auto_increment_fix
4- Display a warning on the about page for corrupted data (see bug 18931)
5- Write and make available a maintenance script to fix corrupted data (TODO LATER)

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Mason James <mtj@kohaaloha.com>
2017-07-25 11:51:43 +12:00
..
AuthoritiesMarc Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Barcodes Bug 16635: [QA Follow-up] Eliminate some global package vars 2016-06-15 09:07:46 +02:00
Bookseller Bug 10402 follow-up: choose contacts for claims 2014-08-26 11:45:59 -03:00
ClassSortRoutine Bug 16011: $VERSION - Remove use vars qw(); 2016-03-24 17:20:39 +00:00
Creators Bug 18044: Label Batches not displaying 2017-02-16 07:23:50 +13:00
External Bug 16636: [QA Follow-up] Make BakerTaylor plack safe 2016-06-15 09:08:11 +02:00
Form Bug 16259: Replace CGI->param with CGI->multi_param in list context - part 2 2016-05-16 17:28:06 +00:00
Heading Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
ILSDI Bug 16864: Silence warnings in t/db_dependent/ILSDI_Services.t 2016-08-05 09:01:39 +02:00
Installer Bug 18373: Re-add UpgradeBackup.pm 2017-04-30 23:19:56 +12:00
Labels Bug 16011: $VERSION - Remove empty BEGIN block 2016-03-24 17:20:41 +00:00
Linker Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
Members Bug 16443: Make C4::Members::Statistics plack safe 2016-06-15 08:17:23 +02:00
OAI Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
Output Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
Patroncards Bug 18244: Patron card creator does not take in account fields with underscore (B_address etc.) 2017-04-24 11:08:15 +12:00
Reports Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
SIP Bug 12021 - SIP2 checkin should alert on transfer and use CT for return branch 2017-04-30 23:19:59 +12:00
Search Bug 17323: Column search_history.time cannot be null 2016-12-31 15:19:46 +13:00
Serials Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Utils Bug 18094: Only search in searchable patron attributes if searching in standard fields 2017-05-04 02:52:33 +12:00
Accounts.pm Bug 18266: Fix internal error when paying fine for lost item without.. item 2017-04-30 23:19:53 +12:00
Acquisition.pm Bug 14535: Late orders does not show orders with price = 0 2017-04-24 11:08:02 +12:00
Auth.pm Bug 18442: Add a test 2017-05-24 13:45:02 +12:00
Auth_cas_servers.yaml.sample Bug 17065 - Rename C4/Auth_cas_servers.yaml.orig 2016-08-08 16:43:22 +02:00
Auth_with_cas.pm Bug 17481: Fix incorrect merge of bug 11048 (logout redirection for CAS authentication) 2016-12-12 14:54:08 +13:00
Auth_with_ldap.pm Bug 17775 - Add new user with LDAP not works under Plack 2017-02-22 22:12:11 +13:00
Auth_with_shibboleth.pm Bug 16818: External auth redirect broken under Plack 2016-08-05 08:51:45 +02:00
AuthoritiesMarc.pm Bug 17913: [16.11.x] followup 2017-02-24 10:12:30 +13:00
BackgroundJob.pm Bug 16011: $VERSION - Remove empty BEGIN block 2016-03-24 17:20:41 +00:00
Barcodes.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Biblio.pm Bug 17372: Standardize Elasticsearch paths 2016-10-22 13:56:11 +02:00
Bookseller.pm Bug 14535: Update the supplier filter too 2017-04-24 11:08:08 +12:00
Boolean.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Branch.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Breeding.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Budgets.pm Bug 17872: Fix small error in GetBudgetHierarchy and one of its calls 2017-04-30 23:19:55 +12:00
Calendar.pm Bug 15333: Use Koha::Cache to cache exception_holidays instead of a package variable 2016-05-25 22:18:27 +00:00
Category.pm Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
Charset.pm Bug 18152 : fix unimarc label in SetMarcUnicodeFlag 2017-05-24 13:45:02 +12:00
Circulation.pm Bug 18966: Do not deal with duplicate issue_id on checkin 2017-07-25 11:51:43 +12:00
ClassSortRoutine.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
ClassSource.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Context.pm Bug 16813: Allow empty string for OPACBaseURL 2016-08-01 13:31:21 +02:00
Contract.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
CourseReserves.pm Bug 16011: $VERSION - remove use vars $VERSION 2016-03-24 17:20:26 +00:00
Creators.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Debug.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
HTML5Media.pm Bug 17231 - (QA Followup) 2016-09-08 22:21:35 +02:00
Heading.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
HoldsQueue.pm Bug 18001 - LocalHoldsPriority can cause multiple holds queue lines for same hold request 2017-04-30 23:19:57 +12:00
Images.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
ImportBatch.pm Bug 6852: Staged import reports wrong success for items 2016-09-13 09:49:40 +02:00
ImportExportFramework.pm Bug 17389: Clear logs 2016-10-22 14:37:09 +02:00
InstallAuth.pm Bug 18578: Use subdirectory in /tmp for session storage during installation 2017-05-24 15:44:13 +12:00
Installer.pm Bug 17234: Need to separate KEY and FOREIGN KEY checks 2017-01-25 13:19:12 +13:00
ItemCirculationAlertPreference.pm Bug 14828: Use Koha::ItemType[s] everywhere C4::ItemType was used 2016-01-27 20:46:58 +00:00
Items.pm Bug 17512: Improve handling dates in C4::Items 2017-02-23 09:36:21 +13:00
Koha.pm Bug 16716: Replaced wrong GROUP BY with DISTINCT 2016-08-01 13:31:23 +02:00
Labels.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Languages.pm Bug 16770: Remove wrong caching of 3 subroutines in C4::Lancuages 2016-08-01 10:19:58 +02:00
Letters.pm Bug 18457 - process_message_queue.pl will die if a patron has no sms_provider_id set but sms via email is enabled for that patron 2017-05-24 13:45:00 +12:00
Linker.pm Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
Log.pm Bug 16436 [QA Followup] - Use debug instead of info 2016-08-05 07:50:00 +02:00
MarcModificationTemplates.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Matcher.pm Bug 12478: make things using SimpleSearch use the new version 2016-04-26 20:20:07 +00:00
Members.pm Bug 17257: Fix add/edit patrons under MySQL 5.7 2017-05-24 14:26:24 +12:00
Message.pm Bug 9978: Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:38 -03:00
NewsChannels.pm Bug 16550: Can't set opac news expiration date to NULL, it reverts to today 2016-05-23 17:37:48 +00:00
Output.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Overdues.pm Bug 14390: [Follow-up] Only update FU record in UpdateFine 2016-09-08 20:30:12 +02:00
Patroncards.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Print.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Ratings.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Record.pm Bug 15451: Koha::CsvProfiles - Remove the residue 2017-04-30 23:20:01 +12:00
Reports.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Reserves.pm Bug 17995 - HOLDPLACED notice should have access to the reserves table 2017-04-24 11:07:24 +12:00
Review.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Ris.pm Bug 16245: [QA Follow-up] Replace typeofrecord2 by biblevel 2016-10-22 15:14:49 +02:00
RotatingCollections.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
SMS.pm Bug 16011: $VERSION - Remove empty BEGIN block 2016-03-24 17:20:41 +00:00
Scheduler.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Scrubber.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
Search.pm Bug 17821 - due date in intranet search results should use TT date plugin 2017-04-30 23:19:56 +12:00
Serials.pm Bug 14932: Do not call can_edit_subscription with an empty value 2017-04-30 23:19:55 +12:00
Service.pm Bug 7550: [QA Follow-up] Resolve param warning from sco-patron-image 2017-05-24 13:45:03 +12:00
ShelfBrowser.pm Bug 16315 - OPAC Shelfbrowser doesn't display the full title 2016-05-05 18:28:16 +00:00
SocialData.pm Bug 9978: (followup) Replace license header with the correct license (GPLv3+) 2015-04-20 09:59:43 -03:00
Stats.pm Bug 16011: $VERSION - Remove comments 2016-03-24 17:20:29 +00:00
Suggestions.pm Bug 16325: Do not return all suggestions if search for STATUS='' 2016-05-05 20:46:02 +00:00
TTParser.pm Bug 14383: C4: Fix some typos (mostly in comments and documentation) 2015-06-22 17:34:45 -03:00
Tags.pm Bug 16637: Dependency for C4::Tags not listed 2016-06-15 09:09:11 +02:00
Templates.pm Bug 18010: Remove potential exposure from gettemplate 2017-04-04 03:45:23 +12:00
TmplToken.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
TmplTokenType.pm Bug 16011: $VERSION - Remove the $VERSION init 2016-03-24 17:20:28 +00:00
UsageStats.pm Bug 18066: Hea V2 [squashed] 2017-05-24 13:44:59 +12:00
XISBN.pm Bug 12478: make things using SimpleSearch use the new version 2016-04-26 20:20:07 +00:00
XSLT.pm Bug 18089 - All XSLT testing singleBranchMode = 0 fails to show even if install has only 1 branch 2017-02-23 09:36:22 +13:00