Project 'rfhf19/cleanning-portalmec' was moved to 'rfhferreira/cleanning-portalmec'. Please update any links and bookmarks that may still have the old path.
Commit d017ad27 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Created task to migrate institutions to users

parent 67c65535
Showing with 22 additions and 2 deletions
+22 -2
......@@ -37,8 +37,8 @@ class Institution < ApplicationRecord
include Publisher
has_and_belongs_to_many :users
#has_many :learning_objects, as: :publisher
#has_many :collections, as: :owner
has_many :learning_objects, as: :publisher
has_many :collections, as: :owner
has_attached_file :avatar, styles: { medium: '300x300>', thumb: '60x60>' }, default_url: ''
validates_attachment_content_type :avatar, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
......
......@@ -19,6 +19,26 @@
require 'rainbow'
namespace :migrate do
desc "import institutions"
task institutions: :environment do
desc "Create users for each institution and migrate their learning objects"
Institution.all.each do |institution|
if !institution.learning_objects.blank? || !institution.collections.blank?
user = User.where("name = '#{institution.name}' and email like 'institution%@c3sl.ufpr.br'").first
if user.blank?
user = User.create(name:institution.name, description: institution.description, email: "institution#{institution.id}@c3sl.ufpr.br", password: "123mudar", password_confirmation: "123mudar")
end
user.roles << Role.where(name: "publisher")
user.avatar = institution.avatar
user.save
institution.learning_objects.update(publisher: user)
institution.collections.update(publisher: user)
end
end
end
end
namespace :import do
desc "import institutions"
task :institution, [:log] => [:environment] do |t, args|
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment