1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-26 20:54:21 +01:00

Usage of the rails logger instead of printing to standard output

This commit is contained in:
Sylvain 2022-07-26 17:27:33 +02:00
parent eaaf3b9a73
commit bb7eec924c
24 changed files with 80 additions and 82 deletions

View File

@ -6,6 +6,7 @@
- Refactored and documented the availability-slot-reservation data model - Refactored and documented the availability-slot-reservation data model
- Display bookers names to connected users now apply to all resources - Display bookers names to connected users now apply to all resources
- Updated rails locales files - Updated rails locales files
- Usage of the rails logger instead of printing to standard output
- Fix a bug: prevent same slot booking feature ignores canceled reservations - Fix a bug: prevent same slot booking feature ignores canceled reservations
- Fix a bug: wrong currency on invoices files - Fix a bug: wrong currency on invoices files
- Fix a bug: unable to reserve if user's subscription plan is disabled - Fix a bug: unable to reserve if user's subscription plan is disabled

View File

@ -14,7 +14,7 @@ class SocialBotController < ActionController::Base
@training = Training.friendly.find(Regexp.last_match(3).to_s) @training = Training.friendly.find(Regexp.last_match(3).to_s)
render :training, status: :ok render :training, status: :ok
else else
puts "unknown bot request : #{request.original_url}" Rails.logger.warn "unknown bot request : #{request.original_url}"
end end
end end
end end

View File

@ -25,7 +25,7 @@ class NotificationsMailer < NotifyWith::NotificationsMailer
send(notification.notification_type) send(notification.notification_type)
rescue StandardError => e rescue StandardError => e
STDERR.puts "[NotificationsMailer] notification cannot be sent: #{e}" Rails.logger.error "[NotificationsMailer] notification cannot be sent: #{e}"
end end
def helpers def helpers

View File

@ -74,7 +74,7 @@ class Availability < ApplicationRecord
.joins(:slots) .joins(:slots)
.where('slots.availability_id = ?', id) .where('slots.availability_id = ?', id)
else else
STDERR.puts "[safe_destroy] Availability with unknown type #{available_type}" Rails.logger.warn "[safe_destroy] Availability with unknown type #{available_type}"
reservations = [] reservations = []
end end
if reservations.size.zero? if reservations.size.zero?
@ -107,7 +107,7 @@ class Availability < ApplicationRecord
when 'space' when 'space'
spaces.map(&:name).join(' - ') spaces.map(&:name).join(' - ')
else else
STDERR.puts "[title] Availability with unknown type #{available_type}" Rails.logger.warn "[title] Availability with unknown type #{available_type}"
'???' '???'
end end
end end

View File

@ -175,8 +175,9 @@ class Invoice < PaymentDocument
return unless Setting.get('invoicing_module') return unless Setting.get('invoicing_module')
unless Rails.env.test? unless Rails.env.test?
puts "Creating an InvoiceWorker job to generate the following invoice: id(#{id}), main_item.object_id(#{main_item.object_id}), " \ Rails.logger.info "Creating an InvoiceWorker job to generate the following invoice: id(#{id}), " \
"main_item.object_type(#{main_item.object_type}), user_id(#{invoicing_profile.user_id})" "main_item.object_id(#{main_item.object_id}), " \
"main_item.object_type(#{main_item.object_type}), user_id(#{invoicing_profile.user_id})"
end end
InvoiceWorker.perform_async(id, user&.subscription&.expired_at) InvoiceWorker.perform_async(id, user&.subscription&.expired_at)
end end
@ -185,9 +186,7 @@ class Invoice < PaymentDocument
return if Rails.env.test? return if Rails.env.test?
return unless changed? return unless changed?
puts "WARNING: Invoice update triggered [ id: #{id}, reference: #{reference} ]" Rails.logger.warn "Invoice update triggered [ id: #{id}, reference: #{reference} ]\n" \
puts '---------- changes ----------' "---------- changes ----------#{changes}\n---------------------------------"
puts changes
puts '---------------------------------'
end end
end end

View File

@ -50,9 +50,7 @@ class InvoiceItem < Footprintable
return if Rails.env.test? return if Rails.env.test?
return unless changed? return unless changed?
puts "WARNING: InvoiceItem update triggered [ id: #{id}, invoice reference: #{invoice.reference} ]" Rails.logger.warn "InvoiceItem update triggered [ id: #{id}, invoice reference: #{invoice.reference} ]\n" \
puts '---------- changes ----------' "---------- changes ----------\n#{changes}\n---------------------------------"
puts changes
puts '---------------------------------'
end end
end end

View File

@ -100,8 +100,9 @@ class PaymentSchedule < PaymentDocument
return unless Setting.get('invoicing_module') return unless Setting.get('invoicing_module')
unless Rails.env.test? unless Rails.env.test?
puts "Creating an PaymentScheduleWorker job to generate the following payment schedule: id(#{id}), main_object.object_id(#{main_object.object_id}), " \ Rails.logger.info "Creating an PaymentScheduleWorker job to generate the following payment schedule: id(#{id}), " \
"main_object.object_type(#{main_object.object_type}), user_id(#{invoicing_profile.user_id})" "main_object.object_id(#{main_object.object_id}), " \
"main_object.object_type(#{main_object.object_type}), user_id(#{invoicing_profile.user_id})"
end end
PaymentScheduleWorker.perform_async(id) PaymentScheduleWorker.perform_async(id)
end end

View File

@ -122,7 +122,7 @@ class Plan < ApplicationRecord
if !stat_type.nil? && !stat_subtype.nil? if !stat_type.nil? && !stat_subtype.nil?
StatisticTypeSubType.create!(statistic_type: stat_type, statistic_sub_type: stat_subtype) StatisticTypeSubType.create!(statistic_type: stat_type, statistic_sub_type: stat_subtype)
else else
puts 'ERROR: Unable to create the statistics association for the new plan. ' \ Rails.logger.error 'Unable to create the statistics association for the new plan. ' \
'Possible causes: the type or the subtype were not created successfully.' 'Possible causes: the type or the subtype were not created successfully.'
end end
end end

View File

@ -29,7 +29,7 @@ class PDF::Invoice < Prawn::Document
begin begin
image StringIO.new(Base64.decode64(img_b64)), fit: [415, 40] image StringIO.new(Base64.decode64(img_b64)), fit: [415, 40]
rescue StandardError => e rescue StandardError => e
puts "Unable to decode invoice logo from base64: #{e}" Rails.logger.error "Unable to decode invoice logo from base64: #{e}"
end end
move_down 20 move_down 20
# the following line is a special comment to workaround RubyMine inspection problem # the following line is a special comment to workaround RubyMine inspection problem
@ -120,7 +120,7 @@ class PDF::Invoice < Prawn::Document
when 'StatisticProfilePrepaidPack' when 'StatisticProfilePrepaidPack'
object = I18n.t('invoices.prepaid_pack') object = I18n.t('invoices.prepaid_pack')
else else
puts "ERROR : specified main_item.object_type type (#{invoice.main_item.object_type}) is unknown" Rails.logger.error "specified main_item.object_type type (#{invoice.main_item.object_type}) is unknown"
end end
end end
text I18n.t('invoices.object') + ' ' + object text I18n.t('invoices.object') + ' ' + object
@ -233,12 +233,14 @@ class PDF::Invoice < Prawn::Document
# total verification # total verification
total = invoice.total / 100.00 total = invoice.total / 100.00
puts "ERROR: totals are NOT equals => expected: #{total}, computed: #{total_calc}" if total_calc != total Rails.logger.error "totals are NOT equals => expected: #{total}, computed: #{total_calc}" if total_calc != total
# TVA # TVA
vat_service = VatHistoryService.new vat_service = VatHistoryService.new
vat_rate_group = vat_service.invoice_vat(invoice) vat_rate_group = vat_service.invoice_vat(invoice)
if total_vat != 0 if total_vat.zero?
data += [[I18n.t('invoices.total_amount'), number_to_currency(total)]]
else
data += [[I18n.t('invoices.total_including_all_taxes'), number_to_currency(total)]] data += [[I18n.t('invoices.total_including_all_taxes'), number_to_currency(total)]]
vat_rate_group.each do |_type, rate| vat_rate_group.each do |_type, rate|
data += [[I18n.t('invoices.including_VAT_RATE', RATE: rate[:vat_rate], AMOUNT: number_to_currency(rate[:amount] / 100.00)), number_to_currency(rate[:total_vat] / 100.00)]] data += [[I18n.t('invoices.including_VAT_RATE', RATE: rate[:vat_rate], AMOUNT: number_to_currency(rate[:amount] / 100.00)), number_to_currency(rate[:total_vat] / 100.00)]]
@ -247,13 +249,11 @@ class PDF::Invoice < Prawn::Document
data += [[I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total)]] data += [[I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total)]]
# checking the round number # checking the round number
rounded = sprintf('%.2f', total_vat / 100.00).to_f + sprintf('%.2f', total_ht / 100.00).to_f rounded = sprintf('%.2f', total_vat / 100.00).to_f + sprintf('%.2f', total_ht / 100.00)
if rounded != sprintf('%.2f', total_calc).to_f if rounded != sprintf('%.2f', total_calc)
puts 'ERROR: rounding the numbers cause an invoice inconsistency. ' \ Rails.logger.error 'rounding the numbers cause an invoice inconsistency. ' \
"Total expected: #{sprintf('%.2f', total_calc)}, total computed: #{rounded}" "Total expected: #{sprintf('%.2f', total_calc)}, total computed: #{rounded}"
end end
else
data += [[I18n.t('invoices.total_amount'), number_to_currency(total)]]
end end
# display table # display table
@ -305,7 +305,7 @@ class PDF::Invoice < Prawn::Document
when 'none' when 'none'
payment_verbose = I18n.t('invoices.no_refund') payment_verbose = I18n.t('invoices.no_refund')
else else
puts "ERROR : specified refunding method (#{payment_verbose}) is unknown" Rails.logger.error "specified refunding method (#{payment_verbose}) is unknown"
end end
payment_verbose += ' ' + I18n.t('invoices.for_an_amount_of_AMOUNT', AMOUNT: number_to_currency(total)) payment_verbose += ' ' + I18n.t('invoices.for_an_amount_of_AMOUNT', AMOUNT: number_to_currency(total))
else else

View File

@ -32,7 +32,7 @@ class PDF::PaymentSchedule < Prawn::Document
begin begin
image StringIO.new(Base64.decode64(img_b64)), fit: [415, 40] image StringIO.new(Base64.decode64(img_b64)), fit: [415, 40]
rescue StandardError => e rescue StandardError => e
puts "Unable to decode invoice logo from base64: #{e}" Rails.logger.error "Unable to decode invoice logo from base64: #{e}"
end end
move_down 20 move_down 20
font('Open-Sans', size: 10) do font('Open-Sans', size: 10) do

View File

@ -135,7 +135,7 @@ class CartService
plan: plan_info[:plan], plan: plan_info[:plan],
new_subscription: plan_info[:new_subscription]) new_subscription: plan_info[:new_subscription])
else else
STDERR.puts "WARNING: the reservable #{reservable} is not implemented" Rails.logger.warn "the reservable #{reservable} is not implemented"
raise NotImplementedError raise NotImplementedError
end end
end end
@ -172,7 +172,7 @@ class CartService
plan: plan, plan: plan,
new_subscription: true) new_subscription: true)
else else
STDERR.puts "WARNING: the reservable #{reservable} is not implemented" Rails.logger.warn "WARNING: the reservable #{reservable} is not implemented"
raise NotImplementedError raise NotImplementedError
end end
end end

View File

@ -51,19 +51,18 @@ class FootprintService
return saved if Rails.env.test? return saved if Rails.env.test?
if saved.nil? if saved.nil?
puts "Debug data not found for #{klass} [ id: #{item.id} ]" Rails.logger.debug { "Debug data not found for #{klass} [ id: #{item.id} ]" }
else else
puts "Debug footprint for #{klass} [ id: #{item.id} ]" Rails.logger.debug do
puts '-----------------------------------------' "Debug footprint for #{klass} [ id: #{item.id} ]\n" \
puts "columns: [ #{columns.join(', ')} ]" "-----------------------------------------\ncolumns: [ #{columns.join(', ')} ]\n" \
puts "current: #{current}" "current: #{current}\n saved: #{saved.format_data(item.id)}\n" \
puts " saved: #{saved.format_data(item.id)}" '-----------------------------------------'
puts '-----------------------------------------' end
item.footprint_children.map(&:debug_footprint) item.footprint_children.map(&:debug_footprint)
end end
others = FootprintDebug.where('klass = ? AND data LIKE ? AND id != ?', klass, "#{item.id}%", saved&.id) others = FootprintDebug.where('klass = ? AND data LIKE ? AND id != ?', klass, "#{item.id}%", saved&.id)
puts "other possible matches IDs: #{others.map(&:id)}" Rails.logger.debug { "other possible matches IDs: #{others.map(&:id)}\n-----------------------------------------" }
puts '-----------------------------------------'
end end
private private

View File

@ -62,7 +62,7 @@ class VatExportService
vat_total = [] vat_total = []
service = VatHistoryService.new service = VatHistoryService.new
invoices.each do |i| invoices.each do |i|
puts "processing invoice #{i.id}..." unless Rails.env.test? Rails.logger.info "processing invoice #{i.id}..." unless Rails.env.test?
vat_total.push service.invoice_vat(i) vat_total.push service.invoice_vat(i)
end end
@ -83,7 +83,7 @@ class VatExportService
when 'amount' when 'amount'
row << format_number(amount / 100.0) row << format_number(amount / 100.0)
else else
puts "Unsupported column: #{column}" Rails.logger.warn "Unsupported column: #{column}"
end end
row << separator row << separator
end end

View File

@ -8,7 +8,7 @@ class PeriodStatisticsWorker
# @param period {String|Integer} date string or number of days until current date # @param period {String|Integer} date string or number of days until current date
def perform(period) def perform(period)
days = date_to_days(period) days = date_to_days(period)
puts "\n==> generating statistics for the last #{days} days <==\n" Rails.logger.info "\n==> generating statistics for the last #{days} days <==\n"
if days.zero? if days.zero?
StatisticService.new.generate_statistic(start_date: DateTime.current.beginning_of_day, end_date: DateTime.current.end_of_day) StatisticService.new.generate_statistic(start_date: DateTime.current.beginning_of_day, end_date: DateTime.current.end_of_day)
else else

View File

@ -30,18 +30,12 @@ class StripeWorker
cpn = Stripe::Coupon.retrieve(coupon_code, api_key: Setting.get('stripe_secret_key')) cpn = Stripe::Coupon.retrieve(coupon_code, api_key: Setting.get('stripe_secret_key'))
cpn.delete cpn.delete
rescue Stripe::InvalidRequestError => e rescue Stripe::InvalidRequestError => e
STDERR.puts "WARNING: Unable to delete the coupon on Stripe: #{e}" warn "WARNING: Unable to delete the coupon on Stripe: #{e}"
end end
def create_or_update_stp_product(class_name, id) def create_or_update_stp_product(class_name, id)
object = class_name.constantize.find(id) object = class_name.constantize.find(id)
if !object.payment_gateway_object.nil? if object.payment_gateway_object.nil?
Stripe::Product.update(
object.payment_gateway_object.gateway_object_id,
{ name: object.name },
{ api_key: Setting.get('stripe_secret_key') }
)
else
product = Stripe::Product.create( product = Stripe::Product.create(
{ {
name: object.name, name: object.name,
@ -54,12 +48,18 @@ class StripeWorker
pgo = PaymentGatewayObject.new(item: object) pgo = PaymentGatewayObject.new(item: object)
pgo.gateway_object = product pgo.gateway_object = product
pgo.save! pgo.save!
puts "Stripe product was created for the #{class_name} \##{id}" Rails.logger.info "Stripe product was created for the #{class_name} \##{id}"
else
Stripe::Product.update(
object.payment_gateway_object.gateway_object_id,
{ name: object.name },
{ api_key: Setting.get('stripe_secret_key') }
)
end end
rescue Stripe::InvalidRequestError rescue Stripe::InvalidRequestError
obj_id = object.payment_gateway_object.gateway_object_id obj_id = object.payment_gateway_object.gateway_object_id
STDERR.puts "WARNING: saved payment_gateway_object#id (#{obj_id}) does not match on Stripe, recreating..." Rails.logger.warn "WARNING: saved payment_gateway_object#id (#{obj_id}) does not match on Stripe, recreating..."
product = Stripe::Product.create( product = Stripe::Product.create(
{ {
name: object.name, name: object.name,
@ -72,6 +72,6 @@ class StripeWorker
pgo = PaymentGatewayObject.new(item: object) pgo = PaymentGatewayObject.new(item: object)
pgo.gateway_object = product pgo.gateway_object = product
pgo.save! pgo.save!
puts "Stripe product was created for the #{class_name} \##{id}" Rails.logger.info "Stripe product was created for the #{class_name} \##{id}"
end end
end end

View File

@ -7,10 +7,10 @@ class SyncObjectsOnStripeWorker
sidekiq_options lock: :until_executed, on_conflict: :reject, queue: :stripe sidekiq_options lock: :until_executed, on_conflict: :reject, queue: :stripe
def perform(notify_user_id = nil) def perform(notify_user_id = nil)
logger.debug 'We create all non-existing customers on stripe. This may take a while...' Rails.logger.info 'We create all non-existing customers on stripe. This may take a while...'
total = User.online_payers.count total = User.online_payers.count
User.online_payers.each_with_index do |member, index| User.online_payers.each_with_index do |member, index|
logger.debug "#{index} / #{total}" Rails.logger.info "#{index} / #{total}"
begin begin
stp_customer = member.payment_gateway_object&.gateway_object&.retrieve stp_customer = member.payment_gateway_object&.gateway_object&.retrieve
StripeWorker.new.create_stripe_customer(member.id) if stp_customer.nil? || stp_customer[:deleted] StripeWorker.new.create_stripe_customer(member.id) if stp_customer.nil? || stp_customer[:deleted]
@ -18,37 +18,37 @@ class SyncObjectsOnStripeWorker
begin begin
StripeWorker.new.create_stripe_customer(member.id) StripeWorker.new.create_stripe_customer(member.id)
rescue Stripe::InvalidRequestError => e rescue Stripe::InvalidRequestError => e
puts "Unable to create the customer #{member.id} do to a Stripe error: #{e}" Rails.logger.error "Unable to create the customer #{member.id} do to a Stripe error: #{e}"
end end
end end
end end
logger.debug 'We create all non-existing coupons on stripe. This may take a while...' Rails.logger.info 'We create all non-existing coupons on stripe. This may take a while...'
total = Coupon.all.count total = Coupon.all.count
Coupon.all.each_with_index do |coupon, index| Coupon.all.each_with_index do |coupon, index|
logger.debug "#{index} / #{total}" Rails.logger.info "#{index} / #{total}"
Stripe::Coupon.retrieve(coupon.code, api_key: Setting.get('stripe_secret_key')) Stripe::Coupon.retrieve(coupon.code, api_key: Setting.get('stripe_secret_key'))
rescue Stripe::InvalidRequestError rescue Stripe::InvalidRequestError
begin begin
Stripe::Service.new.create_coupon(coupon.id) Stripe::Service.new.create_coupon(coupon.id)
rescue Stripe::InvalidRequestError => e rescue Stripe::InvalidRequestError => e
logger.warn "Unable to create coupon #{coupon.code} on stripe: #{e}" Rails.logger.error "Unable to create coupon #{coupon.code} on stripe: #{e}"
end end
end end
w = StripeWorker.new w = StripeWorker.new
[Machine, Training, Space, Plan].each do |klass| [Machine, Training, Space, Plan].each do |klass|
logger.debug "We create all non-existing #{klass} on stripe. This may take a while..." Rails.logger.info "We create all non-existing #{klass} on stripe. This may take a while..."
total = klass.all.count total = klass.all.count
klass.all.each_with_index do |item, index| klass.all.each_with_index do |item, index|
logger.debug "#{index} / #{total}" Rails.logger.info "#{index} / #{total}"
w.perform(:create_or_update_stp_product, klass.name, item.id) w.perform(:create_or_update_stp_product, klass.name, item.id)
end end
end end
logger.debug 'Sync is done' Rails.logger.info 'Sync is done'
return unless notify_user_id return unless notify_user_id
logger.debug "Notify user #{notify_user_id}" Rails.logger.info "Notify user #{notify_user_id}"
user = User.find(notify_user_id) user = User.find(notify_user_id)
NotificationCenter.call type: :notify_admin_objects_stripe_sync, NotificationCenter.call type: :notify_admin_objects_stripe_sync,
receiver: user, receiver: user,

View File

@ -4,7 +4,7 @@ class MigrateProfileToInvoicingProfile < ActiveRecord::Migration[4.2]
def up def up
User.all.each do |u| User.all.each do |u|
p = u.profile p = u.profile
puts "WARNING: User #{u.id} has no profile" and next unless p Rails.logger.warn "User #{u.id} has no profile" and next unless p
ip = InvoicingProfile.create!( ip = InvoicingProfile.create!(
user: u, user: u,

View File

@ -4,7 +4,7 @@ class MigrateProfileToStatisticProfile < ActiveRecord::Migration[4.2]
def up def up
User.all.each do |u| User.all.each do |u|
p = u.profile p = u.profile
puts "WARNING: User #{u.id} has no profile" and next unless p Rails.logger.warn "User #{u.id} has no profile" and next unless p
StatisticProfile.create!( StatisticProfile.create!(
user: u, user: u,
@ -20,7 +20,7 @@ class MigrateProfileToStatisticProfile < ActiveRecord::Migration[4.2]
def down def down
StatisticProfile.all.each do |sp| StatisticProfile.all.each do |sp|
p = sp.user.profile p = sp.user.profile
puts "WARNING: User #{sp.user_id} has no profile" and next unless p Rails.logger.warn "User #{sp.user_id} has no profile" and next unless p
p.update_attributes( p.update_attributes(
gender: sp.gender, gender: sp.gender,

View File

@ -12,7 +12,7 @@ class MigrateInvoiceToInvoicingProfile < ActiveRecord::Migration[4.2]
# remove and save periods in memory # remove and save periods in memory
periods = Integrity::ArchiveHelper.backup_and_remove_periods periods = Integrity::ArchiveHelper.backup_and_remove_periods
# migrate invoices # migrate invoices
puts 'Migrating invoices. This may take a while...' Rails.logger.info 'Migrating invoices. This may take a while...'
Invoice.order(:id).all.each do |i| Invoice.order(:id).all.each do |i|
user = User.find(i.user_id) user = User.find(i.user_id)
operator = User.find_by(id: i.operator_id) operator = User.find_by(id: i.operator_id)

View File

@ -73,7 +73,7 @@ class AddObjectToInvoiceItem < ActiveRecord::Migration[5.2]
Invoice.reset_column_information Invoice.reset_column_information
# chain records # chain records
puts 'Chaining all record. This may take a while...' Rails.logger.info 'Chaining all record. This may take a while...'
InvoiceItem.order(:id).all.each(&:chain_record) InvoiceItem.order(:id).all.each(&:chain_record)
Invoice.order(:id).all.each(&:chain_record) Invoice.order(:id).all.each(&:chain_record)
@ -121,7 +121,7 @@ class AddObjectToInvoiceItem < ActiveRecord::Migration[5.2]
Invoice.reset_column_information Invoice.reset_column_information
# chain records # chain records
puts 'Chaining all record. This may take a while...' Rails.logger.info 'Chaining all record. This may take a while...'
InvoiceItem.order(:id).all.each(&:chain_record) InvoiceItem.order(:id).all.each(&:chain_record)
Invoice.order(:id).all.each(&:chain_record) Invoice.order(:id).all.each(&:chain_record)

View File

@ -48,7 +48,7 @@ class CreatePaymentScheduleObjects < ActiveRecord::Migration[5.2]
PaymentSchedule.reset_column_information PaymentSchedule.reset_column_information
# chain records # chain records
puts 'Chaining all record. This may take a while...' Rails.logger.info 'Chaining all record. This may take a while...'
PaymentScheduleItem.order(:id).all.each(&:chain_record) PaymentScheduleItem.order(:id).all.each(&:chain_record)
PaymentSchedule.order(:id).all.each(&:chain_record) PaymentSchedule.order(:id).all.each(&:chain_record)
end end
@ -87,7 +87,7 @@ class CreatePaymentScheduleObjects < ActiveRecord::Migration[5.2]
PaymentSchedule.reset_column_information PaymentSchedule.reset_column_information
# chain records # chain records
puts 'Chaining all record. This may take a while...' Rails.logger.info 'Chaining all record. This may take a while...'
PaymentScheduleItem.order(:id).all.each(&:chain_record) PaymentScheduleItem.order(:id).all.each(&:chain_record)
PaymentSchedule.order(:id).all.each(&:chain_record) PaymentSchedule.order(:id).all.each(&:chain_record)
end end

View File

@ -18,7 +18,7 @@ class MigratePaymentSchedulePaymentMethodCheck < ActiveRecord::Migration[5.2]
end end
# chain all records # chain all records
puts 'Chaining all record. This may take a while...' Rails.logger.info 'Chaining all record. This may take a while...'
PaymentSchedule.order(:id).find_each(&:chain_record) PaymentSchedule.order(:id).find_each(&:chain_record)
# re-create all archives from the memory dump # re-create all archives from the memory dump

View File

@ -11,7 +11,7 @@ class Integrity::ArchiveHelper
def check_footprints def check_footprints
if AccountingPeriod.count.positive? if AccountingPeriod.count.positive?
last_period = AccountingPeriod.order(start_at: :desc).first last_period = AccountingPeriod.order(start_at: :desc).first
puts "Checking invoices footprints from #{last_period.end_at}. This may take a while..." Rails.logger.info "Checking invoices footprints from #{last_period.end_at}. This may take a while..."
Invoice.where('created_at > ?', last_period.end_at).order(:id).each do |i| Invoice.where('created_at > ?', last_period.end_at).order(:id).each do |i|
next if i.check_footprint next if i.check_footprint
@ -19,7 +19,7 @@ class Integrity::ArchiveHelper
raise "Invalid footprint for invoice #{i.id}" raise "Invalid footprint for invoice #{i.id}"
end end
else else
puts 'Checking all invoices footprints. This may take a while...' Rails.logger.info 'Checking all invoices footprints. This may take a while...'
Invoice.order(:id).all.each do |i| Invoice.order(:id).all.each do |i|
next if i.check_footprint next if i.check_footprint
@ -34,7 +34,7 @@ class Integrity::ArchiveHelper
range_periods = get_periods(range_start: range_start, range_end: range_end) range_periods = get_periods(range_start: range_start, range_end: range_end)
return [] unless range_periods.count.positive? return [] unless range_periods.count.positive?
puts 'Removing accounting archives...' Rails.logger.info 'Removing accounting archives...'
# 1. remove protection for AccountingPeriods # 1. remove protection for AccountingPeriods
execute("DROP RULE IF EXISTS accounting_periods_del_protect ON #{AccountingPeriod.arel_table.name};") execute("DROP RULE IF EXISTS accounting_periods_del_protect ON #{AccountingPeriod.arel_table.name};")
# 2. backup AccountingPeriods in memory # 2. backup AccountingPeriods in memory
@ -58,7 +58,7 @@ class Integrity::ArchiveHelper
return unless periods.size.positive? return unless periods.size.positive?
# 1. recreate AccountingPeriods # 1. recreate AccountingPeriods
puts 'Recreating accounting archives. This may take a while...' Rails.logger.info 'Recreating accounting archives. This may take a while...'
periods.each do |p| periods.each do |p|
AccountingPeriod.create!( AccountingPeriod.create!(
start_at: p[:start_at], start_at: p[:start_at],

View File

@ -6,7 +6,7 @@ namespace :fablab do
desc 'switch the active authentication provider' desc 'switch the active authentication provider'
task :switch_provider, [:provider] => :environment do |_task, args| task :switch_provider, [:provider] => :environment do |_task, args|
providers = AuthProvider.all.inject('') { |str, item| str + item[:name] + ', ' } providers = AuthProvider.all.inject('') { |str, item| "#{str}#{item[:name]}, " }
unless args.provider unless args.provider
puts "\e[0;31mERROR\e[0m: You must pass a provider name to activate. Available providers are: #{providers[0..-3]}" puts "\e[0;31mERROR\e[0m: You must pass a provider name to activate. Available providers are: #{providers[0..-3]}"
next next
@ -32,14 +32,14 @@ namespace :fablab do
AuthProvider.find_by(name: args.provider).update_attribute(:status, 'active') AuthProvider.find_by(name: args.provider).update_attribute(:status, 'active')
# migrate the current users. # migrate the current users.
if AuthProvider.active.providable_type != DatabaseProvider.name if AuthProvider.active.providable_type == DatabaseProvider.name
# Concerns any providers except local database
User.all.each(&:generate_auth_migration_token)
else
User.all.each do |user| User.all.each do |user|
# Concerns local database provider # Concerns local database provider
user.update_attribute(:auth_token, nil) user.update_attribute(:auth_token, nil)
end end
else
# Concerns any providers except local database
User.all.each(&:generate_auth_migration_token)
end end
# ask the user to restart the application # ask the user to restart the application