else:
raise e
-class CollectionsEnumMigrator(DataMigrator):
+class CollectionsEnumMapper(DataMigrator):
"""Map simple enumerations into the collections table"""
implements(IDataMigrator)
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
+"""