'Reverts an item to its last published version (recursively traversing all of its descendants).
If no published version exists, a VersionConflictError is thrown.
If a published version exists but there is no draft version of this item or any of its descendants, this
method is a no-op.
:raises InvalidVersionError: if no published version exists for the location specified'

def revert_to_published(self, location, user_id):

    if (location.category in DIRECT_ONLY_CATEGORIES):
        return
    draft_course_key = location.course_key.for_branch(ModuleStoreEnum.BranchName.draft)
    with self.bulk_operations(draft_course_key):
        published_course_structure = self._lookup_course(location.course_key.for_branch(ModuleStoreEnum.BranchName.published)).structure
        published_block = self._get_block_from_structure(published_course_structure, BlockKey.from_usage_key(location))
        if (published_block is None):
            raise InvalidVersionError(location)
        draft_course_structure = self._lookup_course(draft_course_key).structure
        new_structure = self.version_structure(draft_course_key, draft_course_structure, user_id)
        self._remove_subtree(BlockKey.from_usage_key(location), new_structure['blocks'])
        def copy_from_published(root_block_id):
            '\n                                                                copies    root_block_id    and    its    descendants    from    published_course_structure    to    new_structure\n                                                                '
            self._update_block_in_structure(new_structure, root_block_id, self._get_block_from_structure(published_course_structure, root_block_id))
            block = self._get_block_from_structure(new_structure, root_block_id)
            original_parent_location = location.course_key.make_usage_key(root_block_id.type, root_block_id.id)
            for child_block_id in block.fields.get('children', []):
                item_location = location.course_key.make_usage_key(child_block_id.type, child_block_id.id)
                self.update_parent_if_moved(item_location, original_parent_location, new_structure, user_id)
                copy_from_published(child_block_id)
        copy_from_published(BlockKey.from_usage_key(location))
        self.update_structure(draft_course_key, new_structure)
        index_entry = self._get_index_if_valid(draft_course_key)
        if (index_entry is not None):
            self._update_head(draft_course_key, index_entry, ModuleStoreEnum.BranchName.draft, new_structure['_id'])
