Skip to content

Commit

Permalink
fix: Add --fix-paths option to ./manage.py cms fix-tree (#7744)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 14, 2024
1 parent fc18e26 commit 40fa8d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions cms/management/commands/subcommands/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ def get_descendants(root):


class FixTreeCommand(SubcommandsCommand):
help_string = 'Repairing Materialized Path Tree for Pages'
help_string = 'Repairing Materialized Path Tree for Pages and Plugins'
command_name = 'fix-tree'

def add_arguments(self, parser):
parser.add_argument(
'--fix-paths',
action='store_true',
default=False,
help='Fix paths for pages and plugins - takes a long time',
)

def handle(self, *args, **options):
"""
Repairs the tree
"""
fix_paths = options.get('fix_paths', False)
self.stdout.write('fixing page tree')
TreeNode.fix_tree()
TreeNode.fix_tree(fix_paths=fix_paths)

root_nodes = TreeNode.objects.filter(parent__isnull=True)

Expand All @@ -54,7 +63,7 @@ def handle(self, *args, **options):
self._update_descendants_tree(root)

self.stdout.write('fixing plugin tree')
CMSPlugin.fix_tree()
CMSPlugin.fix_tree(fix_paths=fix_paths)
self.stdout.write('all done')

def _update_descendants_tree(self, root):
Expand Down
4 changes: 2 additions & 2 deletions cms/models/pluginmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ def copy_plugin(self, target_placeholder, target_language, parent_cache, no_sign
return new_plugin

@classmethod
def fix_tree(cls, destructive=False):
def fix_tree(cls, **kwargs):
"""
Fixes the plugin tree by first calling treebeard fix_tree and the
recalculating the correct position property for each plugin.
"""
from cms.utils.plugins import reorder_plugins

super().fix_tree(destructive)
super().fix_tree(**kwargs)
for placeholder in Placeholder.objects.all():
for language, __ in settings.LANGUAGES:
order = CMSPlugin.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'Django>=3.2',
'django-classy-tags>=0.7.2',
'django-formtools>=2.1',
'django-treebeard>=4.3',
'django-treebeard>=4.3,!=4.5',
'django-sekizai>=0.7',
'djangocms-admin-style>=1.2',
'packaging',
Expand Down

0 comments on commit 40fa8d9

Please sign in to comment.