]> git.parisson.com Git - telemeta-data.git/commitdiff
migration: started implementing collections:publisher mapper
authorolivier <olivier@3bf09e05-f825-4182-b9bc-eedd7160adf0>
Fri, 24 Apr 2009 18:52:00 +0000 (18:52 +0000)
committerolivier <olivier@3bf09e05-f825-4182-b9bc-eedd7160adf0>
Fri, 24 Apr 2009 18:52:00 +0000 (18:52 +0000)
git-svn-id: http://svn.parisson.org/svn/crem@88 3bf09e05-f825-4182-b9bc-eedd7160adf0

trunk/import/migration/tasks/collections.py

index 6dd97c5e5e74be551efeda3684076560cc79bc6e..5cae1a3d3014dc35a7f44aa08fff188d5e783ec4 100644 (file)
@@ -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
+"""