Created task to migrate institutions to users

parent 67c65535
......@@ -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 = '#{}' and email like ''").first
if user.blank?
user = User.create(, description: institution.description, email: "institution#{}", password: "123mudar", password_confirmation: "123mudar")
user.roles << Role.where(name: "publisher")
user.avatar = institution.avatar
institution.learning_objects.update(publisher: user)
institution.collections.update(publisher: user)
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