File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+ desc 'Fix hyc_download_stats work_id mismatch'
3
+ task fix_hyc_download_stats_work_id_mismatch : :environment do
4
+ puts 'Starting to fix hyc_download_stats work_id mismatches...'
5
+ # Retrieve where work_id is equal to fileset_id
6
+ download_stats = HycDownloadStat . where ( 'work_id = fileset_id' )
7
+ initial_count = download_stats . count
8
+
9
+ updated = 0
10
+ download_stats . each do |download_stat |
11
+ # Retrieve the work data for the fileset id
12
+ work_data = WorkUtilsHelper . fetch_work_data_by_fileset_id ( download_stat . fileset_id )
13
+
14
+ begin
15
+ # Update the download stat with the work id
16
+ download_stat . update! ( work_id : work_data [ :work_id ] || 'Unknown' )
17
+ updated += 1
18
+ rescue StandardError => e
19
+ # Log any errors encountered during the update
20
+ puts "Failed to update HycDownloadStat ID #{ download_stat . id } : #{ e . message } "
21
+ end
22
+ end
23
+ puts 'Completed fixing hyc_download_stats work_id mismatches.'
24
+ puts "Successfully updated #{ updated } records out of #{ initial_count } attempted."
25
+ end
You can’t perform that action at this time.
0 commit comments