• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sleede / fab-manager / #106

pending completion
#106

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 6.0.0

704 of 704 new or added lines in 168 files covered. (100.0%)

7919 of 13474 relevant lines covered (58.77%)

15.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.3
/lib/tasks/fablab/maintenance.rake
1
# frozen_string_literal: true
2

3
# Maintenance tasks
4
namespace :fablab do
1✔
5
  namespace :maintenance do
1✔
6
    desc 'Regenerate the invoices (invoices & avoirs) PDF'
1✔
7
    task :regenerate_invoices, %i[year month end] => :environment do |_task, args|
1✔
8
      start_date, end_date = dates_from_args(args)
×
9
      puts "-> Start regenerate the invoices PDF between #{I18n.l start_date, format: :long} and " \
×
10
           "#{I18n.l end_date - 1.minute, format: :long}"
11
      invoices = Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: start_date, end_date: end_date)
×
12
                        .order(created_at: :asc)
13
      invoices.each(&:regenerate_invoice_pdf)
×
14
      puts '-> Done'
×
15
    end
16

17
    task :regenerate_schedules, %i[year month end] => :environment do |_task, args|
1✔
18
      start_date, end_date = dates_from_args(args)
×
19
      puts "-> Start regenerate the payment schedules PDF between #{I18n.l start_date, format: :long} and " \
×
20
           "#{I18n.l end_date - 1.minute, format: :long}"
21
      schedules = PaymentSchedule.where('created_at >= :start_date AND created_at < :end_date', start_date: start_date, end_date: end_date)
×
22
                                 .order(created_at: :asc)
23
      schedules.each(&:regenerate_pdf)
×
24
      puts '-> Done'
×
25
    end
26

27
    desc 'recreate every versions of images'
1✔
28
    task build_images_versions: :environment do
1✔
29
      Project.find_each do |project|
×
30
        project.project_image.attachment.recreate_versions! if project.project_image.present? && project.project_image.attachment.present?
×
31
      end
32
      ProjectStepImage.find_each do |project_step_image|
×
33
        project_step_image.attachment.recreate_versions! if project_step_image.present? && project_step_image.attachment.present?
×
34
      end
35
      Machine.find_each do |machine|
×
36
        machine.machine_image.attachment.recreate_versions! if machine.machine_image.present?
×
37
      end
38
      Event.find_each do |event|
×
39
        event.event_image.attachment.recreate_versions! if event.event_image.present?
×
40
      end
41
    end
42

43
    desc 'generate current code checksum'
1✔
44
    task checksum: :environment do
1✔
45
      require 'integrity/checksum'
×
46
      puts Integrity::Checksum.code
×
47
    end
48

49
    desc 'delete users with accounts marked with is_active=false'
1✔
50
    task delete_inactive_users: :environment do
1✔
51
      count = User.where(is_active: false).count
×
52
      if count.positive?
×
53
        print "WARNING: You are about to delete #{count} users. Are you sure? (y/n) "
×
54
        confirm = $stdin.gets.chomp
×
55
        next unless confirm == 'y'
×
56

57
        User.where(is_active: false).map(&:destroy!)
×
58
      else
59
        puts 'No inactive users to delete'
×
60
      end
61
    end
62

63
    desc '(re)build customization stylesheet'
1✔
64
    task rebuild_stylesheet: :environment do
1✔
65
      Stylesheet.build_theme!
×
66
    end
67

68
    desc 'migration notifications from Fab-manager v1'
1✔
69
    task migrate_v1_notifications: :environment do
1✔
70
      Notification.where(notification_type_id: 4).each do |n|
×
71
        n.notification_type_id = 11
×
72
        n.save!
×
73
      end
74
    end
75

76
    desc 'get the version'
1✔
77
    task version: :environment do
1✔
78
      require 'version'
×
79
      puts Version.current
×
80
    end
81

82
    desc 'clean the cron workers'
1✔
83
    task clean_workers: :environment do
1✔
84
      Sidekiq::Cron::Job.destroy_all!
×
85
      Sidekiq::Queue.new('system').clear
×
86
      Sidekiq::Queue.new('default').clear
×
87
      Sidekiq::DeadSet.new.clear
×
88
    end
89

90
    desc 'save the footprint original data'
1✔
91
    task save_footprint_data: :environment do
1✔
92
      [Invoice, InvoiceItem, HistoryValue, PaymentSchedule, PaymentScheduleItem, PaymentScheduleObject].each do |klass|
×
93
        next if klass == PaymentScheduleObject && !ActiveRecord::Base.connection.table_exists?(PaymentScheduleObject.arel_table)
×
94

95
        order = klass == HistoryValue ? :created_at : :id
×
96
        previous = nil
×
97
        klass.order(order).find_each do |item|
×
98
          created = ChainedElement.create!(
×
99
            element: item,
100
            previous: previous
101
          )
102
          previous = created
×
103
        end
104
      end
105
    end
106

107
    desc 'regenerate statistics'
1✔
108
    task :regenerate_statistics, %i[year month] => :environment do |_task, args|
1✔
109
      exit unless Setting.get('statistics_module')
×
110

111
      yesterday = 1.day.ago
×
112
      year = args.year || yesterday.year
×
113
      month = args.month || yesterday.month
×
114
      start_date = Time.zone.local(year.to_i, month.to_i, 1)
×
115
      end_date = yesterday.end_of_day
×
116
      puts "-> Start regenerate statistics between #{I18n.l start_date, format: :long} and " \
×
117
           "#{I18n.l end_date, format: :long}"
118
      Statistics::BuilderService.generate_statistic(
×
119
        start_date: start_date,
120
        end_date: end_date
121
      )
122
      puts '-> Done'
×
123
    end
124

125
    desc 'Regenerate the invoices (invoices & avoirs) reference'
1✔
126
    task :regenerate_invoices_reference, %i[year month end] => :environment do |_task, args|
1✔
127
      start_date, end_date = dates_from_args(args)
×
128
      puts "-> Start regenerate the invoices reference between #{I18n.l start_date, format: :long} and " \
×
129
           "#{I18n.l end_date - 1.minute, format: :long}"
130
      invoices = Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: start_date, end_date: end_date)
×
131
                        .order(created_at: :asc)
132
      invoices.each(&:update_reference)
×
133
      puts '-> Done'
×
134
    end
135

136
    desc 'Regenerate accounting lines'
1✔
137
    task :regenerate_accounting_lines, %i[year month end] => :environment do |_task, args|
1✔
138
      start_date, end_date = dates_from_args(args)
×
139
      puts "-> Start regenerate the accounting lines between #{I18n.l start_date, format: :long} and " \
×
140
           "#{I18n.l end_date - 1.minute, format: :long}"
141
      AccountingLine.where(date: start_date.beginning_of_day..end_date.end_of_day).delete_all
×
142
      Accounting::AccountingService.new.build(start_date.beginning_of_day, end_date.end_of_day)
×
143
      puts '-> Done'
×
144
    end
145

146
    desc 'Remove ghost availabilities and slots'
1✔
147
    task clean_availabilities: :environment do
1✔
148
      Availability.where(available_type: 'unknown').destroy_all
×
149
    end
150

151
    def dates_from_args(args)
1✔
152
      year = args.year || Time.current.year
×
153
      month = args.month || Time.current.month
×
154
      start_date = Time.zone.local(year.to_i, month.to_i, 1)
×
155
      end_date = args.end == 'today' ? Time.current.end_of_day : start_date.next_month
×
156
      [start_date, end_date]
×
157
    end
158
  end
159
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc