31
31
from openedx_events .learning .data import CourseNotificationData
32
32
from openedx_events .learning .signals import COURSE_NOTIFICATION_REQUESTED
33
33
from pytz import UTC
34
+ from xblock .core import XBlock
34
35
from xblock .fields import Scope
35
36
36
37
from cms .djangoapps .contentstore .toggles import (
@@ -2371,7 +2372,7 @@ def get_xblock_render_context(request, block):
2371
2372
return ""
2372
2373
2373
2374
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 ):
2375
2376
"""
2376
2377
Create or update upstream->downstream link in database for given xblock.
2377
2378
"""
@@ -2387,9 +2388,32 @@ def create_or_update_xblock_upstream_link(xblock, course_key: str | CourseKey, c
2387
2388
lib_component ,
2388
2389
upstream_usage_key = xblock .upstream ,
2389
2390
upstream_context_key = str (upstream_usage_key .context_key ),
2390
- downstream_context_key = course_key ,
2391
+ downstream_context_key = str ( xblock . context_key ) ,
2391
2392
downstream_usage_key = xblock .usage_key ,
2392
2393
version_synced = xblock .upstream_version ,
2393
2394
version_declined = xblock .upstream_version_declined ,
2394
2395
created = created ,
2395
2396
)
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