Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
d017ad27
Commit
d017ad27
authored
6 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Created task to migrate institutions to users
parent
67c65535
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/institution.rb
+2
-2
2 additions, 2 deletions
app/models/institution.rb
lib/tasks/import/institutions.rake
+20
-0
20 additions, 0 deletions
lib/tasks/import/institutions.rake
with
22 additions
and
2 deletions
app/models/institution.rb
+
2
−
2
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'
]
...
...
This diff is collapsed.
Click to expand it.
lib/tasks/import/institutions.rake
+
20
−
0
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
|
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment