Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
PortalMEC
portalmec
Commits
d017ad27
Commit
d017ad27
authored
Dec 07, 2018
by
Israel Barreto Sant'Anna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created task to migrate institutions to users
parent
67c65535
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
app/models/institution.rb
app/models/institution.rb
+2
-2
lib/tasks/import/institutions.rake
lib/tasks/import/institutions.rake
+20
-0
No files found.
app/models/institution.rb
View file @
d017ad27
...
...
@@ -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'
]
...
...
lib/tasks/import/institutions.rake
View file @
d017ad27
...
...
@@ -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
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment