@@ -674,7 +674,15 @@ def _import_staged_block(
674674 data = file_data ,
675675 created = now ,
676676 )
677+ < << << << HEAD
677678 paths_to_media [filename ] = media .id
679+ == == == =
680+ content_api .create_component_version_media (
681+ component_version .pk ,
682+ content .id ,
683+ path = filename ,
684+ )
685+ >> >> >> > 847 aa95b85 (refactor : Upgrade to openedx - core 0.44 .0 (for OEP - 68 ) (#38402))
678686
679687 # This will create the first component version and set the OLX/title
680688 # appropriately. It will not publish. Once we get the newly created
@@ -897,21 +905,122 @@ def delete_library_block(
897905 )
898906 raise
899907
908+ << < << < < HEAD
909+ content_api .soft_delete_draft (component .id , deleted_by = user_id )
910+
911+ == == == =
912+ affected_collections = content_api .get_entity_collections (component .learning_package_id , component .entity_ref )
913+ affected_containers = get_containers_contains_item (usage_key )
914+
900915 content_api .soft_delete_draft (component .id , deleted_by = user_id )
901916
917+ send_block_deleted_signal ()
918+
919+ # For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger
920+ # collection indexing asynchronously.
921+ #
922+ # To delete the component on collections
923+ for collection in affected_collections :
924+ # .. event_implemented_name: LIBRARY_COLLECTION_UPDATED
925+ # .. event_type: org.openedx.content_authoring.content_library.collection.updated.v1
926+ LIBRARY_COLLECTION_UPDATED .send_event (
927+ library_collection = LibraryCollectionData (
928+ collection_key = library_collection_locator (
929+ library_key = library_key ,
930+ collection_key = collection .collection_code ,
931+ ),
932+ background = True ,
933+ )
934+ )
935+
936+ # For each container, trigger LIBRARY_CONTAINER_UPDATED signal and set background=True to trigger
937+ # container indexing asynchronously.
938+ #
939+ # To update the components count in containers
940+ for container in affected_containers :
941+ # .. event_implemented_name: LIBRARY_CONTAINER_UPDATED
942+ # .. event_type: org.openedx.content_authoring.content_library.container.updated.v1
943+ LIBRARY_CONTAINER_UPDATED .send_event (
944+ library_container = LibraryContainerData (
945+ container_key = container .container_key ,
946+ background = True ,
947+ )
948+ )
949+
950+ >> >> > >> 847 aa95b85 (refactor : Upgrade to openedx - core 0.44 .0 (for OEP - 68 ) (#38402))
902951
903952def restore_library_block (usage_key : LibraryUsageLocatorV2 , user_id : int | None = None ) - > None :
904953 """
905954 Restore the specified library block.
906955 """
907956 component = get_component_from_usage_key (usage_key )
957+ << < << << HEAD
958+ == == == =
959+ library_key = usage_key .context_key
960+ affected_collections = content_api .get_entity_collections (component .learning_package_id , component .entity_ref )
961+
962+ >> > >> >> 847 aa95b85 (refactor : Upgrade to openedx - core 0.44 .0 (for OEP - 68 ) (#38402))
908963 # Set draft version back to the latest available component version id.
909964 content_api .set_draft_version (
910965 component .id ,
911966 component .versioning .latest .pk ,
912967 set_by = user_id ,
913968 )
914969
970+ << < << << HEAD
971+ == == == =
972+ # .. event_implemented_name: LIBRARY_BLOCK_CREATED
973+ # .. event_type: org.openedx.content_authoring.library_block.created.v1
974+ LIBRARY_BLOCK_CREATED .send_event (
975+ library_block = LibraryBlockData (
976+ library_key = library_key ,
977+ usage_key = usage_key
978+ )
979+ )
980+
981+ # Add tags and collections back to index
982+ # .. event_implemented_name: CONTENT_OBJECT_ASSOCIATIONS_CHANGED
983+ # .. event_type: org.openedx.content_authoring.content.object.associations.changed.v1
984+ CONTENT_OBJECT_ASSOCIATIONS_CHANGED .send_event (
985+ content_object = ContentObjectChangedData (
986+ object_id = str (usage_key ),
987+ changes = ["collections" , "tags" , "units" ],
988+ ),
989+ )
990+
991+ # For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger
992+ # collection indexing asynchronously.
993+ #
994+ # To restore the component in the collections
995+ for collection in affected_collections :
996+ # .. event_implemented_name: LIBRARY_COLLECTION_UPDATED
997+ # .. event_type: org.openedx.content_authoring.content_library.collection.updated.v1
998+ LIBRARY_COLLECTION_UPDATED .send_event (
999+ library_collection = LibraryCollectionData (
1000+ collection_key = library_collection_locator (
1001+ library_key = library_key ,
1002+ collection_key = collection .collection_code ,
1003+ ),
1004+ background = True ,
1005+ )
1006+ )
1007+
1008+ # For each container, trigger LIBRARY_CONTAINER_UPDATED signal and set background=True to trigger
1009+ # container indexing asynchronously.
1010+ #
1011+ # To update the components count in containers
1012+ affected_containers = get_containers_contains_item (usage_key )
1013+ for container in affected_containers :
1014+ # .. event_implemented_name: LIBRARY_CONTAINER_UPDATED
1015+ # .. event_type: org.openedx.content_authoring.content_library.container.updated.v1
1016+ LIBRARY_CONTAINER_UPDATED .send_event (
1017+ library_container = LibraryContainerData (
1018+ container_key = container .container_key ,
1019+ background = True ,
1020+ )
1021+ )
1022+
1023+ >> > >> >> 847 aa95b85 (refactor : Upgrade to openedx - core 0.44 .0 (for OEP - 68 ) (#38402))
9151024
9161025def get_library_block_static_asset_files (usage_key : LibraryUsageLocatorV2 ) - > list [LibraryXBlockStaticFile ]:
9171026 """
@@ -1099,12 +1208,26 @@ def _create_component_for_block(
10991208 component_type = content_api .get_or_create_component_type (
11001209 "xblock.v1" , usage_key .block_type
11011210 )
1211+ << << < << HEAD
11021212 block_olx_media = content_api .get_or_create_text_media (
1213+ == == == =
1214+ component , component_version = content_api .create_component_and_version (
1215+ learning_package .id ,
1216+ component_type = component_type ,
1217+ component_code = usage_key .block_id ,
1218+ title = display_name ,
1219+ created = now ,
1220+ created_by = user_id ,
1221+ can_stand_alone = can_stand_alone ,
1222+ )
1223+ content = content_api .get_or_create_text_media (
1224+ >> >> >> > 847 aa95b85 (refactor : Upgrade to openedx - core 0.44 .0 (for OEP - 68 ) (#38402))
11031225 learning_package .id ,
11041226 get_or_create_olx_media_type (usage_key .block_type ).id ,
11051227 text = xml_text ,
11061228 created = now ,
11071229 )
1230+ << < << << HEAD
11081231 _component , component_version = content_api .create_component_and_version (
11091232 learning_package .id ,
11101233 component_type = component_type ,
@@ -1116,6 +1239,12 @@ def _create_component_for_block(
11161239 media = {
11171240 'block.xml' : block_olx_media
11181241 }
1242+ == == == =
1243+ content_api .create_component_version_media (
1244+ component_version .pk ,
1245+ content .id ,
1246+ path = "block.xml" ,
1247+ >> >> >> > 847 aa95b85 (refactor : Upgrade to openedx - core 0.44 .0 (for OEP - 68 ) (#38402))
11191248 )
11201249
11211250 return component_version
0 commit comments