From 5e1a3e836c71272fe58bdbf1532955e822542c1a Mon Sep 17 00:00:00 2001 From: olivier Date: Fri, 24 Apr 2009 18:52:00 +0000 Subject: [PATCH] migration: started implementing collections:publisher mapper git-svn-id: http://svn.parisson.org/svn/crem@88 3bf09e05-f825-4182-b9bc-eedd7160adf0 --- trunk/import/migration/tasks/collections.py | 47 ++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/trunk/import/migration/tasks/collections.py b/trunk/import/migration/tasks/collections.py index 6dd97c5..5cae1a3 100644 --- a/trunk/import/migration/tasks/collections.py +++ b/trunk/import/migration/tasks/collections.py @@ -116,7 +116,7 @@ class CollectionsCopyMigrator(DataMigrator): else: raise e -class CollectionsEnumMigrator(DataMigrator): +class CollectionsEnumMapper(DataMigrator): """Map simple enumerations into the collections table""" implements(IDataMigrator) @@ -304,3 +304,48 @@ class CollectionsCodeConverter(DataMigrator): self.stats['remaining'] = self.stats['total'] - self.stats['removed'] self.stats['unmatched'] = self.stats['total'] - self.stats['matched'] + +class CollectionsPublishersMapper(DataMigrator): + """Map publishers and publisher collections into the collections table""" + + implements(IDataMigrator) + + def get_name(self): + return "collections:publisher" + + def process(self): + pass + +""" + self.target_cursor.execute("SELECT COUNT(*) FROM media_collections") + self.stats = { + 'total': self.target_cursor.fetchone()[0], + 'with_publisher': 0, + 'with_collection': 0 + } + + self.target_cursor.execute("UPDATE media_collections SET publisher_id = NULL") + + query = "UPDATE media_collections AS c \n" \ + "SET publisher_id = \n" \ + " (SELECT p.id FROM publishers AS p INNER JOIN %s.Support AS s \n" \ + " ON p.value = s.Editeur WHERE s.Cote = c.old_code) \n" + + self.target_cursor.execute(query % (self.src_db_name, )) + self.stats['with_publisher'] += self.target_cursor.rowcount + offset += limit + + self.target_cursor.execute("UPDATE media_collections SET publisher_collection_id = NULL") + + query = "UPDATE media_collections AS c \n" \ + "SET publisher_collection_id = \n" \ + " (SELECT p.id FROM publisher_collections AS p INNER JOIN %s.Support AS s \n" \ + " ON p.value = s.Collect_Serie WHERE s.Cote = c.old_code AND c.publisher_id = p.publisher_id)" \ + "LIMIT %d, %d" + + offset = 0 + while offset < self.stats['total']: + self.target_cursor.execute(query % (self.src_db_name, offset, limit)) + self.stats['with_collection'] += self.target_cursor.rowcount + offset += limit +""" -- 2.39.5