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
780738d7
Commit
780738d7
authored
8 years ago
by
Mateus Rambo Strey
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix-import-stages' into 'master'
Fix import stages See merge request !326
parents
5e24eca3
6da03b76
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
db/seeds/educational_stages.rb
+2
-1
2 additions, 1 deletion
db/seeds/educational_stages.rb
lib/tasks/import/educational_stage.rake
+30
-13
30 additions, 13 deletions
lib/tasks/import/educational_stage.rake
with
32 additions
and
14 deletions
db/seeds/educational_stages.rb
+
2
−
1
View file @
780738d7
EducationalStage
.
create
(
name:
'Educação Infatil'
)
EducationalStage
.
create
(
name:
'Educação Infa
n
til'
)
EducationalStage
.
create
(
name:
'Ensino Fundamental'
)
EducationalStage
.
create
(
name:
'Ensino Fundamental'
)
EducationalStage
.
create
(
name:
'Ensino Médio'
)
EducationalStage
.
create
(
name:
'Ensino Médio'
)
EducationalStage
.
create
(
name:
'Ensino Superior'
)
EducationalStage
.
create
(
name:
'Outros'
)
EducationalStage
.
create
(
name:
'Outros'
)
This diff is collapsed.
Click to expand it.
lib/tasks/import/educational_stage.rake
+
30
−
13
View file @
780738d7
require
'rainbow'
require
'rainbow'
require
'logger'
require
'logger'
namespace
:import
do
namespace
:import
do
...
@@ -7,27 +7,40 @@ namespace :import do
...
@@ -7,27 +7,40 @@ namespace :import do
task
:educational_stage
,
[
:log
]
=>
[
:environment
]
do
|
t
,
args
|
task
:educational_stage
,
[
:log
]
=>
[
:environment
]
do
|
t
,
args
|
logger
=
Logger
.
new
(
STDOUT
)
logger
=
Logger
.
new
(
STDOUT
)
educational_relations
=
[]
educational_relations
=
{}
tags
=
[]
high_stages
=
[
'Edução Superior'
,
'Ensino Terciário'
,
'Ensino Superior'
]
EducationalStage
.
all
.
each
do
|
educational
|
logger
.
info
(
"Creating relations of
#{
educational
.
name
}
"
)
EducationalStage
.
all
.
each
do
|
educational
|
logger
.
info
(
"Creating relations of
#{
educational
.
name
}
"
)
if
educational
.
name
==
'Ensino Superior'
high_stages
.
select
{
|
stage
|
tag_exists?
(
stage
)
}.
each
do
|
stage
|
tags
<<
Tag
.
find_by_name
(
stage
)
end
elsif
educational
.
name
==
'Outros'
tags
=
Tag
.
where
.
not
(
name:
EducationalStage
.
all
.
select
{
|
educational
|
educational
.
name
!=
'Outros'
}.
map
(
&
:name
)
+
high_stages
)
else
if
tag_exists?
(
educational
.
name
)
if
tag_exists?
(
educational
.
name
)
tag
=
Tag
.
find_by_name
(
educational
.
name
)
tags
<<
Tag
.
find_by_name
(
educational
.
name
)
else
tag
=
Tag
.
create
(
name:
educational
.
name
)
end
end
end
tags
.
each
do
|
tag
|
tag
.
taggings
.
each
do
|
tagging
|
tag
.
taggings
.
each
do
|
tagging
|
educational_relation
=
StageRelation
.
new
(
educational_stage:
educational
,
stageable_id:
tagging
.
taggable_id
,
stageable_type:
tagging
.
taggable_type
)
next
if
stage_relation_exists?
(
educational
,
tagging
.
taggable_id
,
tagging
.
taggable_type
)
educational_relations
<<
educational_relation
educational_relation
=
StageRelation
.
new
(
educational_stage:
educational
,
stageable_id:
tagging
.
taggable_id
,
stageable_type:
tagging
.
taggable_type
)
educational_relations
[[
educational
,
tagging
.
taggable_id
,
tagging
.
taggable_type
]]
=
educational_relation
end
end
end
end
StageRelation
.
import
educational_relations
tags
=
[]
end
end
StageRelation
.
import
educational_relations
.
values
end
private
private
...
@@ -35,4 +48,8 @@ namespace :import do
...
@@ -35,4 +48,8 @@ namespace :import do
Tag
.
where
(
name:
name
).
exists?
Tag
.
where
(
name:
name
).
exists?
end
end
def
stage_relation_exists?
(
educational
,
id
,
type
)
StageRelation
.
where
(
educational_stage:
educational
,
stageable_id:
id
,
stageable_type:
type
).
exists?
end
end
end
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