Skip to content

Commit 066811c

Browse files
committed
feat: adds new fork migration strategy
1 parent a0b4f81 commit 066811c

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

cms/djangoapps/modulestore_migrator/api.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from openedx.core.types.user import AuthUser
1212

1313
from . import tasks
14-
from .data import RepeatHandlingStrategy
1514
from .models import ModulestoreSource
1615

1716
__all__ = (
@@ -35,9 +34,6 @@ def start_migration_to_library(
3534
"""
3635
Import a course or legacy library into a V2 library (or, a collection within a V2 library).
3736
"""
38-
# Can raise NotImplementedError for the Fork strategy
39-
assert RepeatHandlingStrategy(repeat_handling_strategy).is_implemented()
40-
4137
source, _ = ModulestoreSource.objects.get_or_create(key=source_key)
4238
target_library = get_library(target_library_key)
4339
# get_library ensures that the library is connected to a learning package.

cms/djangoapps/modulestore_migrator/data.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,3 @@ def default(cls) -> RepeatHandlingStrategy:
7070
Returns the default repeat handling strategy.
7171
"""
7272
return cls.Skip
73-
74-
def is_implemented(self) -> bool:
75-
"""
76-
Returns True if the repeat handling strategy is implemented.
77-
"""
78-
if self == self.Fork:
79-
raise NotImplementedError("Forking is not implemented yet.")
80-
81-
return True

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ def should_update_strategy(self) -> bool:
132132
"""
133133
return self.repeat_handling_strategy is RepeatHandlingStrategy.Update
134134

135+
@property
136+
def should_fork_strategy(self) -> bool:
137+
"""
138+
Determines whether the repeat handling strategy should fork the entity.
139+
"""
140+
return self.repeat_handling_strategy is RepeatHandlingStrategy.Fork
141+
135142

136143
@shared_task(base=_MigrationTask, bind=True)
137144
# Note: The decorator @set_code_owner_attribute cannot be used here because the UserTaskMixin
@@ -601,8 +608,9 @@ def _get_distinct_target_container_key(
601608
Returns:
602609
LibraryContainerLocator: The target container key.
603610
"""
604-
# Check if we already processed this block
605-
if context.is_already_migrated(source_key):
611+
# Check if we already processed this block and we are not forking. If we are forking, we will
612+
# want a new target key.
613+
if context.is_already_migrated(source_key) and not context.should_fork_strategy:
606614
existing_version = context.get_existing_target(source_key)
607615

608616
return LibraryContainerLocator(
@@ -646,8 +654,9 @@ def _get_distinct_target_usage_key(
646654
Raises:
647655
ValueError: If source_key is invalid
648656
"""
649-
# Check if we already processed this block
650-
if context.is_already_migrated(source_key):
657+
# Check if we already processed this block and we are not forking. If we are forking, we will
658+
# want a new target key.
659+
if context.is_already_migrated(source_key) and not context.should_fork_strategy:
651660
log.debug(f"Block {source_key} already exists, reusing existing target")
652661
existing_target = context.get_existing_target(source_key)
653662
block_id = existing_target.component.local_key

0 commit comments

Comments
 (0)