Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
osuny
Admin
Commits
76dddb28
Unverified
Commit
76dddb28
authored
3 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
ensure callback is reset
parent
731f7da5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/models/communication/website/imported/website.rb
+43
-37
43 additions, 37 deletions
app/models/communication/website/imported/website.rb
with
43 additions
and
37 deletions
app/models/communication/website/imported/website.rb
+
43
−
37
View file @
76dddb28
...
...
@@ -52,49 +52,55 @@ class Communication::Website::Imported::Website < ApplicationRecord
end
def
sync_pages
Communication
::
Website
::
Page
.
skip_callback
(
:save
,
:after
,
:publish_to_github
)
wordpress
.
pages
.
each
do
|
data
|
page
=
pages
.
where
(
university:
university
,
identifier:
data
[
'id'
]).
first_or_initialize
page
.
data
=
data
page
.
save
end
# The order will treat parents before children
pages
.
order
(
:url
).
find_each
do
|
page
|
next
if
page
.
parent
.
blank?
parent
=
pages
.
where
(
identifier:
page
.
parent
).
first
next
if
parent
.
nil?
generated_page
=
page
.
page
generated_page
.
parent
=
parent
.
page
generated_page
.
save
end
# Batch update all changes (1 query only, good for github API limits)
github
=
Github
.
with_site
website
if
github
.
valid?
website
.
pages
.
find_each
do
|
page
|
github
.
add_to_batch
path:
page
.
github_path_generated
,
previous_path:
page
.
github_path
,
data:
page
.
to_jekyll
begin
Communication
::
Website
::
Page
.
skip_callback
(
:save
,
:after
,
:publish_to_github
)
wordpress
.
pages
.
each
do
|
data
|
page
=
pages
.
where
(
university:
university
,
identifier:
data
[
'id'
]).
first_or_initialize
page
.
data
=
data
page
.
save
end
# The order will treat parents before children
pages
.
order
(
:url
).
find_each
do
|
page
|
next
if
page
.
parent
.
blank?
parent
=
pages
.
where
(
identifier:
page
.
parent
).
first
next
if
parent
.
nil?
generated_page
=
page
.
page
generated_page
.
parent
=
parent
.
page
generated_page
.
save
end
github
.
commit_batch
'[Page] Batch update from import'
# Batch update all changes (1 query only, good for github API limits)
github
=
Github
.
with_site
website
if
github
.
valid?
website
.
pages
.
find_each
do
|
page
|
github
.
add_to_batch
path:
page
.
github_path_generated
,
previous_path:
page
.
github_path
,
data:
page
.
to_jekyll
end
github
.
commit_batch
'[Page] Batch update from import'
end
ensure
Communication
::
Website
::
Page
.
set_callback
(
:save
,
:after
,
:publish_to_github
)
end
Communication
::
Website
::
Page
.
set_callback
(
:save
,
:after
,
:publish_to_github
)
end
def
sync_posts
Communication
::
Website
::
Post
.
skip_callback
(
:save
,
:after
,
:publish_to_github
)
github
=
Github
.
with_site
website
wordpress
.
posts
.
each
do
|
data
|
post
=
posts
.
where
(
university:
university
,
identifier:
data
[
'id'
]).
first_or_initialize
post
.
data
=
data
post
.
save
generated_post
=
post
.
post
if
github
.
valid?
github
.
add_to_batch
path:
generated_post
.
github_path_generated
,
previous_path:
generated_post
.
github_path
,
data:
generated_post
.
to_jekyll
begin
Communication
::
Website
::
Post
.
skip_callback
(
:save
,
:after
,
:publish_to_github
)
github
=
Github
.
with_site
website
wordpress
.
posts
.
each
do
|
data
|
post
=
posts
.
where
(
university:
university
,
identifier:
data
[
'id'
]).
first_or_initialize
post
.
data
=
data
post
.
save
generated_post
=
post
.
post
if
github
.
valid?
github
.
add_to_batch
path:
generated_post
.
github_path_generated
,
previous_path:
generated_post
.
github_path
,
data:
generated_post
.
to_jekyll
end
end
github
.
commit_batch
'[Post] Batch update from import'
if
github
.
valid?
ensure
Communication
::
Website
::
Post
.
set_callback
(
:save
,
:after
,
:publish_to_github
)
end
github
.
commit_batch
'[Post] Batch update from import'
if
github
.
valid?
Communication
::
Website
::
Post
.
set_callback
(
:save
,
:after
,
:publish_to_github
)
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