fix: set created_by automatically on MediaWiki import
- Added imported_by parameter to _run_import and _upsert_exercise - Exercises now automatically get created_by set to importing user - Fixes visibility issue where imported exercises were invisible Related: Wiki import - exercise visibility fix
This commit is contained in:
1 parent
e6ce7e241c
commit
a02df32ce2
1 file changed
+7
-4
@@ -172,6 +172,7 @@ async def execute_import(
|
|||||||
reimport=body.reimport_existing,
|
reimport=body.reimport_existing,
|
||||||
dry_run=body.dry_run,
|
dry_run=body.dry_run,
|
||||||
limit=body.limit,
|
limit=body.limit,
|
||||||
|
imported_by=profile_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -269,6 +270,7 @@ async def _run_import(
|
|||||||
reimport: bool,
|
reimport: bool,
|
||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
limit: Optional[int],
|
limit: Optional[int],
|
||||||
|
imported_by: int,
|
||||||
):
|
):
|
||||||
"""Hintergrund-Task: Importiert alle Seiten einer Kategorie."""
|
"""Hintergrund-Task: Importiert alle Seiten einer Kategorie."""
|
||||||
client = SmwClient()
|
client = SmwClient()
|
||||||
@@ -350,7 +352,7 @@ async def _run_import(
|
|||||||
# Speichern
|
# Speichern
|
||||||
try:
|
try:
|
||||||
if import_type == "exercise":
|
if import_type == "exercise":
|
||||||
local_id = _upsert_exercise(mapped, reimport)
|
local_id = _upsert_exercise(mapped, reimport, imported_by)
|
||||||
elif import_type == "skill":
|
elif import_type == "skill":
|
||||||
local_id = _upsert_skill(mapped, reimport)
|
local_id = _upsert_skill(mapped, reimport)
|
||||||
else:
|
else:
|
||||||
@@ -445,7 +447,7 @@ def _update_log(
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
def _upsert_exercise(mapped: dict, reimport: bool) -> Optional[int]:
|
def _upsert_exercise(mapped: dict, reimport: bool, created_by: int) -> Optional[int]:
|
||||||
"""Legt Übung an oder aktualisiert sie (wenn reimport=True)."""
|
"""Legt Übung an oder aktualisiert sie (wenn reimport=True)."""
|
||||||
import json as _json
|
import json as _json
|
||||||
|
|
||||||
@@ -486,8 +488,8 @@ def _upsert_exercise(mapped: dict, reimport: bool) -> Optional[int]:
|
|||||||
"""INSERT INTO exercises
|
"""INSERT INTO exercises
|
||||||
(title, summary, goal, execution, preparation, trainer_notes,
|
(title, summary, goal, execution, preparation, trainer_notes,
|
||||||
duration_min, duration_max, group_size_min, group_size_max,
|
duration_min, duration_max, group_size_min, group_size_max,
|
||||||
equipment, visibility, status, import_source, import_id)
|
equipment, visibility, status, import_source, import_id, created_by)
|
||||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||||
RETURNING id""",
|
RETURNING id""",
|
||||||
(
|
(
|
||||||
mapped.get("title"), mapped.get("summary"), mapped.get("goal"),
|
mapped.get("title"), mapped.get("summary"), mapped.get("goal"),
|
||||||
@@ -499,6 +501,7 @@ def _upsert_exercise(mapped: dict, reimport: bool) -> Optional[int]:
|
|||||||
mapped.get("status", "draft"),
|
mapped.get("status", "draft"),
|
||||||
"mediawiki",
|
"mediawiki",
|
||||||
mapped.get("import_id"),
|
mapped.get("import_id"),
|
||||||
|
created_by,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
ex_id = cur.fetchone()['id']
|
ex_id = cur.fetchone()['id']
|
||||||
|
|||||||
Reference in new issue
Block a user