Skip to content

Commit 93a322c

Browse files
wfehrfsbraun
andauthored
added another custom-function-point to run after cleanup is completed (#29)
Co-authored-by: Fabian Braun <[email protected]>
1 parent 731ca76 commit 93a322c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ If you have a custom user model, you should designate a "migration user" by spec
8181
CMS_MIGRATION_USER_ID = <user id>
8282
```
8383

84-
If you want to adjust data to get the migration running in your project, there are 2 function-points available:
84+
If you want to adjust data to get the migration running in your project, there are 3 function-points available:
8585

8686
```
87-
CMS_MIGRATION_PROCESS_MIGRATION_PREPARATION = "mymodule.myfunction2"
88-
CMS_MIGRATION_PROCESS_PAGE_REFERENCES = "mymodule.myfunction"
87+
CMS_MIGRATION_PROCESS_MIGRATION_PREPARATION = "mymodule.myfunction"
88+
CMS_MIGRATION_PROCESS_PAGE_REFERENCES = "mymodule.myfunction2"
89+
CMS_MIGRATION_PROCESS_POST_CLEANUP = "mymodule.myfunction3"
8990
```
9091

91-
The latter function is supplied with parameters `page` and `replacement_page`.
92+
`_PROCESS_PAGE_REFERENCES` is supplied with parameters `page` and `replacement_page`.
9293

9394
## Running
9495
Simply run the following command to run the data migration.

djangocms_4_migration/management/commands/migration_cleanup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ def _get_page_contents(page):
170170
return PageContent._base_manager.filter(page=page)
171171

172172

173+
def _post_cleanup():
174+
custom_function = getattr(settings, "CMS_MIGRATION_PROCESS_POST_CLEANUP", None)
175+
if custom_function:
176+
module, function = custom_function.rsplit(".", 1)
177+
getattr(
178+
__import__(module, fromlist=[""]),
179+
function,
180+
)()
181+
182+
173183
class Command(BaseCommand):
174184
help = "Run after migrations are applied"
175185

@@ -224,4 +234,6 @@ def handle(self, *args, **options):
224234
for url in page.urls.filter(language=language).order_by("pk")[1:]:
225235
url.delete()
226236

237+
_post_cleanup()
238+
227239
logger.info("Stats: %s", str(stats))

0 commit comments

Comments
 (0)