'Fixes the plugin tree by first calling treebeard fix_tree and the
recalculating the correct position property for each plugin.'

@classmethod
def fix_tree(cls, destructive=False):

    from cms.utils.plugins import reorder_plugins
    super(CMSPlugin, cls).fix_tree(destructive)
    for placeholder in Placeholder.objects.all():
        for (language, __) in settings.LANGUAGES:
            order = CMSPlugin.objects.filter(placeholder_id=placeholder.pk, language=language, parent_id__isnull=True).order_by('position', 'path').values_list('pk', flat=True)
            reorder_plugins(placeholder, None, language, order)
            for plugin in CMSPlugin.objects.filter(placeholder_id=placeholder.pk, language=language).order_by('depth', 'path'):
                order = CMSPlugin.objects.filter(parent_id=plugin.pk).order_by('position', 'path').values_list('pk', flat=True)
                reorder_plugins(placeholder, plugin.pk, language, order)
