Skip to content

Commit 0a239e6

Browse files
committed
feat: WIP
1 parent 82f816e commit 0a239e6

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

cms/djangoapps/contentstore/tasks.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1459,13 +1459,16 @@ def create_or_update_upstream_links(
14591459
if replace:
14601460
PublishableEntityLink.objects.filter(downstream_context_key=course_key).delete()
14611461
try:
1462-
xblocks = store.get_items(course_key, settings={"upstream": lambda x: x is not None})
1462+
linked_xblocks = store.get_items(course_key, settings={"upstream": lambda x: x is not None})
1463+
lc_xblocks = store.get_items(course_key, block_type="library_content", depth=2)
14631464
except ItemNotFoundError:
14641465
LOGGER.exception(f'Could not find items for given course: {course_key}')
14651466
course_status.update_status(LearningContextLinksStatusChoices.FAILED)
14661467
return
1467-
for xblock in xblocks:
1468+
for xblock in linked_xblocks:
14681469
create_or_update_xblock_upstream_link(xblock, course_key_str, created)
1470+
for lc in lc_xblocks:
1471+
create_or_update_legacy_library_content_children_upstream_links(lc, created)
14691472
course_status.update_status(LearningContextLinksStatusChoices.COMPLETED)
14701473

14711474

cms/djangoapps/contentstore/utils.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from openedx_events.learning.data import CourseNotificationData
3232
from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED
3333
from pytz import UTC
34+
from xblock.core import XBlock
3435
from xblock.fields import Scope
3536

3637
from cms.djangoapps.contentstore.toggles import (
@@ -2371,7 +2372,7 @@ def get_xblock_render_context(request, block):
23712372
return ""
23722373

23732374

2374-
def create_or_update_xblock_upstream_link(xblock, course_key: str | CourseKey, created: datetime | None = None):
2375+
def create_or_update_xblock_upstream_link(xblock: XBlock, created: datetime | None = None):
23752376
"""
23762377
Create or update upstream->downstream link in database for given xblock.
23772378
"""
@@ -2387,9 +2388,32 @@ def create_or_update_xblock_upstream_link(xblock, course_key: str | CourseKey, c
23872388
lib_component,
23882389
upstream_usage_key=xblock.upstream,
23892390
upstream_context_key=str(upstream_usage_key.context_key),
2390-
downstream_context_key=course_key,
2391+
downstream_context_key=str(xblock.context_key),
23912392
downstream_usage_key=xblock.usage_key,
23922393
version_synced=xblock.upstream_version,
23932394
version_declined=xblock.upstream_version_declined,
23942395
created=created,
23952396
)
2397+
2398+
2399+
def create_or_update_children_upstream_links(lc_block: LegacyLibraryContentBlock, created: datetime | None = None):
2400+
"""
2401+
Given an LLC XBlock, save its upstream info for each of its children which don't already have links in the database.
2402+
"""
2403+
for child in xblock.children:
2404+
upstream_usage_key = get_migrated_library_block_usage_key(lc_block.usage_key, child.usage_key) # @@TODO
2405+
try:
2406+
lib_component = get_component_from_usage_key(upstream_usage_key)
2407+
except ObjectDoesNotExist:
2408+
log.error(f"Library component not found for {upstream_usage_key}")
2409+
lib_component = None
2410+
PublishableEntityLink.update_or_create(
2411+
lib_component,
2412+
upstream_usage_key=str(upstream_usage_key),
2413+
upstream_context_key=str(upstream_usage_key.context_key),
2414+
downstream_context_key=str(child.context_key),
2415+
downstream_usage_key=str(child.usage_key),
2416+
version_synced=2, # @@TODO
2417+
version_declined=1, # @@TODO
2418+
created=created,
2419+
)

0 commit comments

Comments
 (0)