You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EDIT_SUMMARY='Replace missing tag with tax tag (senior synonym of), see %github1124'ANTCATBOT=User.find_by!(name: 'AntCatBot')# For activities and PaperTrail.RequestStore.store[:current_request_uuid]=SecureRandom.uuidPaperTrail.request.whodunnit=ANTCATBOT.iddefreplace_missing_with_relevant_historyhistory_itemputs"ID: #{history_item.id}"old_taxt=history_item.taxt.duphelper=QuickAndDirtyFixes::ReplaceMissingTags.new(old_taxt)ifhelper.can_be_quick_fixed?puts"can be quick-fixed".bluereturnendnormalized_name=helper.target_for_replacement[:normalized_name]name_parts=normalized_name.splitifname_parts.size != 2puts"must be a hardcoded species name".bluereturnendgenus_name,epithet=name_partspossible_subspecies=possible_subspecies_instead_of_species(history_item,genus_name,epithet)casepossible_subspecies.sizewhen0puts"found no subspecies".redreturnwhen1# Ok!elseputs"found more than 1 subspecies".redreturnendreplace_with_taxon=possible_subspecies.firstunlesshas_junior_synonym_of_tax_item?(replace_with_taxon,history_item)puts"has no relevant item".redreturnendnew_taxt=old_taxt.sub(/\{missing[0-9]? #{normalized_name}\}/,"{tax #{replace_with_taxon.id}}")puts"old_taxt: #{old_taxt}".yellowputs"new_taxt: #{new_taxt}".greenputshistory_item.update!taxt: new_taxthistory_item.create_activity:update,ANTCATBOT,edit_summary: "Replace missing tag with tax tag (senior synonym of), #{normalized_name} --> #{replace_with_taxon.name_cache}, see %github1124"enddefpossible_subspecies_instead_of_specieshistory_item,genus_name,epithetSubspecies.joins(:name).where(current_taxon: history_item.taxon).where("names.name LIKE ?","#{genus_name} %").where("names.epithet = ?",epithet)enddefhas_junior_synonym_of_tax_item?replace_with_taxon,history_itemreplace_with_taxon.history_items.where("taxt LIKE ?","Junior synonym of {tax #{history_item.taxon.id}}%").exists?enditems=TaxonHistoryItem.where('taxt REGEXP ?',"^Senior synonym of #{Taxt::MISSING_TAG_START}2");nilitems.eachdo |item|
replace_missing_with_relevant_historyitemend;nilActivity.execute_script_activityUser.find_by!(name: 'Fredrik Palmkron'),EDIT_SUMMARY
Script
Output
The text was updated successfully, but these errors were encountered: