Skip to content

Commit

Permalink
Extract guid_to_object to base class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklaus Johner committed Jan 31, 2022
1 parent 22884c8 commit 58c49da
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions opengever/maintenance/scripts/repository_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 58c49da

Please sign in to comment.