@@ -0,0 +1,1169 @@
+# coding=utf-8%0A%0Afrom django.db import connection%0Afrom django.conf import settings%0Afrom django.core.management.base import BaseCommand, CommandError%0Afrom django.contrib.sites.models import Site%0A%0A%0Aclass Command(BaseCommand):%0A  args = '%3Cid_or_name%3E'%0A  help = 'Fix any broken article urls due to wrong root site id'%0A%0A  def handle(self, *args, **options):%0A    id_or_name = args%5B0%5D%0A%0A    try:%0A      site = Site.objects.get(id=int(id_or_name))%0A    except (Site.DoesNotExist, ValueError):%0A      try:%0A        site = Site.objects.get(domain=id_or_name)%0A      except Site.DoesNotExist:%0A        try:%0A          site = Site.objects.get(name=id_or_name)%0A        except Site.DoesNotExist:%0A          raise CommandError('No such site: %25s' %25 id_or_name)%0A%0A    root_site = site.settings.root_site%0A%0A    # Remove any duplicate urls%0A    from begood.models import ArticleUrl%0A    on_new = ArticleUrl.objects.filter(article__sites=site).filter(site=root_site).values_list('article_id', flat=True)%0A    ArticleUrl.objects.filter(article_id__in=on_new).exclude(site=root_site).delete()%0A%0A    # Update all urls to the new root site%0A    ArticleUrl.objects.filter(article__sites=site).update(site=site)%0A%0A

Add a management command to fix broken article urls when changing root site id.