Sha256: 82981951d81d3d2f10d4c44355b5a8f5d90adb286c1252357a7f7e9946c0a404

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

# Define a namespace for the task
namespace :import do
  desc 'Imports the legacy user data into the Devise Admin table'
  task admins: :environment do
    CHARS = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + (1..9).to_a + ['`', '~', '!', '@', '#', '$', '%', '^', '&', '*']
    password = CHARS.sort_by { rand }.join[0...15]

    LegacyUser.all.each do |legacy|
      u = User.find_or_create_by(legacy.email)
      u.update_attributes(
        first_name: legacy.name.split(' ')[0],
        last_name: legacy.name.split(' ')[1],
        password: password,
        password_confirmation: password,
        admin: legacy.admin,
        designer: legacy.designer,
        content_editor: legacy.content_editor,
        notes: legacy.notes, 
        site_id: legacy.site_id
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trusty-cms-3.9.7 lib/tasks/upgrade_to_devise.rake
trusty-cms-3.9.6 lib/tasks/upgrade_to_devise.rake