diff --git a/opengever/maintenance/scripts/repository_migration.py b/opengever/maintenance/scripts/repository_migration.py index 2a8665c8..e8f0092a 100644 --- a/opengever/maintenance/scripts/repository_migration.py +++ b/opengever/maintenance/scripts/repository_migration.py @@ -507,7 +507,27 @@ def is_complete(self): return complete -class RepositoryExcelAnalyser(object): +class MigratorBase(object): + + def guid_to_object(self, guid): + results = self.catalog.unrestrictedSearchResults(bundle_guid=guid) + if len(results) == 0: + # This should never happen. Object with a guid should have been created. + logger.warning( + u"Couldn't find object with GUID %s in catalog" % guid) + return + + if len(results) > 1: + # Ambiguous GUID - this should never happen + logger.warning( + u"Ambiguous GUID! Found more than one result in catalog " + u"for GUID %s " % guid) + return + + return results[0].getObject() + + +class RepositoryExcelAnalyser(MigratorBase): def __init__(self, mapping_path, output_directory): self.number_changes = {} @@ -882,9 +902,6 @@ def get_uuid_for_position(self, position): return None - def guid_to_object(self, guid): - return self.catalog(bundle_guid=guid)[0].getObject() - def extract_permissions(self, row): permissions = {'block_inheritance': False} @@ -977,7 +994,7 @@ def insert_value_rows(self, sheet, rows): cell.value = attr -class RepositoryMigrator(object): +class RepositoryMigrator(MigratorBase): def __init__(self, operations_list, dry_run=False): self.operations_list = operations_list @@ -1226,23 +1243,6 @@ def reindex(self): # make sure that the model is up to date. TaskSqlSyncer(obj, None).sync() - def guid_to_object(self, guid): - results = self.catalog.unrestrictedSearchResults(bundle_guid=guid) - if len(results) == 0: - # This should never happen. Object with a guid should have been created. - logger.warning( - u"Couldn't find object with GUID %s in catalog" % guid) - return - - if len(results) > 1: - # Ambiguous GUID - this should never happen - logger.warning( - u"Ambiguous GUID! Found more than one result in catalog " - u"for GUID %s " % guid) - return - - return results[0].getObject() - def validate(self): """This steps make sure that the repository system has been correctly migrated."""