https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41307

--- Comment #40 from Matt Blenkinsop <[email protected]> ---
Created attachment 210283
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210283&action=edit
Bug 41307: Add a maintenance script to migrate the old counter data

The counter log rows written before Bug 41307 have no report type and
no period, so the data providers summary skips every month harvested
before the upgrade, and the Import logs tab shows those rows without a
report type or a period. Re-harvests before Bug 42217 also left
duplicated rows in erm_usage_mus, which double the yearly totals.

misc/maintenance/erm_migrate_counter_data.pl fixes both. Without
--confirm it is a dry run: it reports what it would change and writes
nothing. --logs and --usage run one part only, --verbose reports each
row.

The script backfills the rows that have no period:
- the report type is the one of the counter file
- the months come from the Reporting_Period header row of the file, or
  from its month columns when the file has no such row. Before Bug 41294
  one harvest covered several months, so such a row becomes one row per
  month, all with the same file, import date, user and status
- every month gets status success: the old code only wrote a log row
  after a file was imported
- the background job is not linked
A row whose file has no reporting period is reported and left without a
period. The script only reads the first 4000 bytes of each file and can
run again without changes.

It then removes the duplicated monthly usage rows, with the identity of
Bug 42217 (every column except usage_count). The newest row is kept: the
harvest path of 42217 keeps the lowest id because it overwrites the
count, but here there is no harvested count, and the newest row holds
the last count the provider sent.

The yearly usage in erm_usage_yus is then rebuilt from the monthly usage,
so its totals follow the cleaned rows. This runs even when no duplicate
is found.

Each part runs in one transaction.

Test plan:
1. On a database with harvests made before this patch, or after
   UPDATE erm_counter_logs SET report_type = NULL, report_year = NULL,
   report_month = NULL; on a few rows, run
   perl misc/maintenance/erm_migrate_counter_data.pl -v
   It lists the rows it would update and add, and changes nothing
2. Run it again with --confirm: it reports the rows updated and added
3. Open the provider, Import logs tab: every old row now shows its report
   type and period; a file that covered several months has one row per
   month, all with the same file name and Download link
4. Open the Summary page: the old months show "Success"
5. Run the script with --confirm again: no counter log is changed
6. Duplicate a row of erm_usage_mus with a different usage_count and run
   the script with --usage --confirm: the older row is removed and the
   yearly total of the title in erm_usage_yus is correct
   again

Assisted-by: Sonnet 5.5 (Anthropic)

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to