Add support for legacy urls, turn them into redirects to messageid
authorMagnus Hagander <magnus@hagander.net>
Wed, 3 Oct 2012 16:15:45 +0000 (18:15 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 3 Oct 2012 16:15:45 +0000 (18:15 +0200)
django/archives/mailarchives/views.py
django/archives/urls.py
loader/legacy/scan_old_archives.py
loader/sql/schema.sql

index 15b9a43fed06b0d2d55aea41d2c8b96e351a1920..ae885ea327345a656f7e2e07dd2c41f61af1fd59 100644 (file)
@@ -1,5 +1,6 @@
 from django.template import RequestContext
 from django.http import HttpResponse, HttpResponseForbidden, Http404
+from django.http import HttpResponsePermanentRedirect
 from django.shortcuts import render_to_response, get_object_or_404
 from django.db import connection
 from django.db.models import Q
@@ -382,3 +383,18 @@ def web_sync_timestamp(request):
        r = HttpResponse(s, mimetype='text/plain')
        r['Content-Length'] = len(s)
        return r
+
+@cache(hours=8)
+def legacy(request, listname, year, month, msgnum):
+       curs = connection.cursor()
+       curs.execute("SELECT msgid FROM legacymap WHERE listid=(SELECT listid FROM lists WHERE listname=%(list)s) AND year=%(year)s AND month=%(month)s AND msgnum=%(msgnum)s", {
+                       'list': listname,
+                       'year': year,
+                       'month': month,
+                       'msgnum': msgnum,
+                       })
+       r = curs.fetchall()
+       if len(r) != 1:
+               print "Meh, not found!"
+               raise Http404('Message does not exist')
+       return HttpResponsePermanentRedirect('/message-id/%s' % r[0][0])
index 14b01cdc280afd51a528af25978c8f4feeb96906..62d082c349ca6041cceef17c03c5799a48aa53fb 100644 (file)
@@ -32,6 +32,9 @@ urlpatterns = patterns('',
 
     (r'^message-id/attachment/(\d+)/.*$', 'archives.mailarchives.views.attachment'),
 
+    # Legacy forwarding from old archives site
+    (r'^message-id/legacy/([\w-]+)/(\d+)-(\d+)/msg(\d+).php$', 'archives.mailarchives.views.legacy'),
+
     # Normally served by the webserver, but needed for development installs
     (r'^media/(.*)$', 'django.views.static.serve', {
                        'document_root': '../media',
index 0ad18be3cd8c57f3ba85fca83a5d827274fe7d9a..e4ebc918cd2d3d51f87dde67f4f39973199120f2 100755 (executable)
@@ -2,7 +2,7 @@
 
 # Scan the old archives, including all subdirs, and generate
 # a mapping table on the format:
-# <listname>;<year>;<month>;num;<messageid>
+# <listid>;<year>;<month>;num;<messageid>
 
 # Used to map from the old site
 
index 645146ba78503392d2ffc25165adf40a3e7e32d6..8b9c1abe28c4ad383d3a43e145adc50afe54b384 100644 (file)
@@ -127,4 +127,13 @@ CREATE TRIGGER messages_fti_trigger
  FOR EACH ROW EXECUTE PROCEDURE messages_fti_trigger_func();
 CREATE INDEX messages_fti_idx ON messages USING gin(fti);
 
+CREATE TABLE legacymap(
+       listid int not null,
+       year int not null,
+       month int not null,
+       msgnum int not null,
+       msgid text not null,
+CONSTRAINT legacymap_pk PRIMARY KEY (listid, year, month, msgnum)
+);
+
 \echo Dont forget to commit!