Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
rp
Commits
a4f81d0c
Commit
a4f81d0c
authored
Apr 03, 2019
by
Okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
One SQL request to rule them all and, in the darkness, to bind them.
parent
22703fed
Pipeline
#2542
passed with stages
in 2 minutes and 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
apps/core/management/commands/import_old_rp.py
apps/core/management/commands/import_old_rp.py
+22
-21
No files found.
apps/core/management/commands/import_old_rp.py
View file @
a4f81d0c
...
...
@@ -38,31 +38,29 @@ class Command(BaseCommand):
password
=
options
[
'password'
][
0
],
db
=
'site'
)
c
=
db
.
cursor
(
DictCursor
)
# First, let's get the data from presse table
presse
=
c
.
execute
(
"SELECT * FROM presse"
)
# First, let's get the data from presse table.
# We're also grouping a lot of queries
presse
=
c
.
execute
(
"""SELECT *, nr.body as body, GROUP_CONCAT(t.name, ',') as tags
FROM presse p
JOIN node n
ON n.nid = p.nid
JOIN node_revisions nr
ON nr.vid = n.vid
JOIN term_node tn
ON tn.nid = p.nid
JOIN term_data t
ON t.tid = tn.tid
GROUP BY n.nid"""
)
print
(
"Importing 0/{} from previous database
\r
"
.
format
(
presse
)
)
print
(
"Importing 0/{} from previous database
"
.
format
(
presse
),
end
=
'
\r
'
)
# And here we go
done
=
0
errors
=
0
for
item
in
c
.
fetchall
():
done
+=
1
print
(
"Importing {}/{} from previous database - {} errors
\r
"
.
format
(
done
,
presse
,
errors
))
c
.
execute
(
"SELECT nid, vid FROM node WHERE nid=%s"
,
(
item
[
'nid'
],))
node
=
c
.
fetchone
()
if
node
is
None
:
continue
c
.
execute
(
"SELECT body FROM node_revisions WHERE vid=%s"
,
(
node
[
'vid'
],))
revision
=
c
.
fetchone
()
if
revision
is
None
:
errors
+=
1
continue
# Récupérons l'article si il existe en base
print
(
"Importing {}/{} from previous database ({} errors for now)"
.
format
(
done
,
presse
,
errors
),
end
=
'
\r
'
)
# Fetch the article, or creates it
article
=
Article
.
add_new_url
(
url
=
item
[
'url'
])
if
item
[
'lang'
]
!=
""
:
article
.
lang
=
item
[
'lang'
]
...
...
@@ -74,7 +72,7 @@ class Command(BaseCommand):
if
website
:
article
.
website
=
website
.
group
(
1
)
#
Augmentons le score si nécessaire
#
Raise the score if needed
if
item
[
'note'
]
>
0
:
article
.
und_score_up
=
item
[
'note'
]
if
item
[
'note'
]
<
0
:
...
...
@@ -82,9 +80,12 @@ class Command(BaseCommand):
article
.
save
()
article
.
refresh_from_db
()
# Insert tags
article
.
tags
.
add
(
item
[
'tags'
].
lower
())
# Publish or draft as needed
if
item
[
'published'
]
>=
1
:
# Let's get the extracts
article
.
extracts
=
revision
[
'body'
]
article
.
extracts
=
item
[
'body'
]
try
:
article
.
fetch_content
()
article
.
fetch_image
()
...
...
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