8778: Avoid using place objects during database upgrade
This commit is contained in:
parent
ee1c98b8a0
commit
2c81ff26dc
@ -44,10 +44,6 @@ _ = glocale.translation.gettext
|
|||||||
from gramps.gen.constfunc import handle2internal
|
from gramps.gen.constfunc import handle2internal
|
||||||
from gramps.gen.lib.markertype import MarkerType
|
from gramps.gen.lib.markertype import MarkerType
|
||||||
from gramps.gen.lib.nameorigintype import NameOriginType
|
from gramps.gen.lib.nameorigintype import NameOriginType
|
||||||
from gramps.gen.lib.place import Place
|
|
||||||
from gramps.gen.lib.placeref import PlaceRef
|
|
||||||
from gramps.gen.lib.placetype import PlaceType
|
|
||||||
from gramps.gen.lib.placename import PlaceName
|
|
||||||
from gramps.gen.lib.eventtype import EventType
|
from gramps.gen.lib.eventtype import EventType
|
||||||
from gramps.gen.lib.tag import Tag
|
from gramps.gen.lib.tag import Tag
|
||||||
from gramps.gen.utils.file import create_checksum
|
from gramps.gen.utils.file import create_checksum
|
||||||
@ -96,14 +92,10 @@ def gramps_upgrade_18(self):
|
|||||||
for handle in self.place_map.keys():
|
for handle in self.place_map.keys():
|
||||||
place = self.place_map[handle]
|
place = self.place_map[handle]
|
||||||
new_place = list(place)
|
new_place = list(place)
|
||||||
name = PlaceName()
|
new_place[6] = (new_place[6], None, '')
|
||||||
name.set_value(new_place[6])
|
|
||||||
new_place[6] = name.serialize()
|
|
||||||
alt_names = []
|
alt_names = []
|
||||||
for name in new_place[7]:
|
for name in new_place[7]:
|
||||||
alt_name = PlaceName()
|
alt_names.append((name, None, ''))
|
||||||
alt_name.set_value(name)
|
|
||||||
alt_names.append(alt_name.serialize())
|
|
||||||
new_place[7] = alt_names
|
new_place[7] = alt_names
|
||||||
new_place = tuple(new_place)
|
new_place = tuple(new_place)
|
||||||
with BSDDBTxn(self.env, self.place_map) as txn:
|
with BSDDBTxn(self.env, self.place_map) as txn:
|
||||||
@ -205,15 +197,13 @@ def gramps_upgrade_17(self):
|
|||||||
n -= 1
|
n -= 1
|
||||||
|
|
||||||
if parent_handle is not None:
|
if parent_handle is not None:
|
||||||
placeref = PlaceRef()
|
placeref_list = [(handle2internal(parent_handle), None)]
|
||||||
placeref.ref = handle2internal(parent_handle)
|
|
||||||
placeref_list = [placeref.serialize()]
|
|
||||||
else:
|
else:
|
||||||
placeref_list = []
|
placeref_list = []
|
||||||
|
|
||||||
type_num = 7 - level if name else PlaceType.UNKNOWN
|
type_num = 7 - level if name else -1
|
||||||
new_place = new_place[:5] + [placeref_list, name, [],
|
new_place = new_place[:5] + [placeref_list, name, [],
|
||||||
PlaceType(type_num).serialize(), zip_code] + \
|
(type_num, ''), zip_code] + \
|
||||||
new_place[6:12] + [[]] + new_place[12:]
|
new_place[6:12] + [[]] + new_place[12:]
|
||||||
new_place = tuple(new_place)
|
new_place = tuple(new_place)
|
||||||
with BSDDBTxn(self.env, self.place_map) as txn:
|
with BSDDBTxn(self.env, self.place_map) as txn:
|
||||||
@ -336,21 +326,19 @@ def get_location(loc):
|
|||||||
|
|
||||||
def add_place(self, name, level, parent, title):
|
def add_place(self, name, level, parent, title):
|
||||||
handle = create_id()
|
handle = create_id()
|
||||||
place = Place()
|
|
||||||
place.handle = handle
|
|
||||||
self.max_id += 1
|
self.max_id += 1
|
||||||
place.gramps_id = self.place_prefix % self.max_id
|
gid = self.place_prefix % self.max_id
|
||||||
place.set_name(name)
|
placetype = (7-level, '')
|
||||||
place.set_title(title)
|
|
||||||
place.set_type(PlaceType(7-level))
|
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
placeref = PlaceRef()
|
placeref_list = [(handle2internal(parent), None)]
|
||||||
placeref.ref = handle2internal(parent)
|
else:
|
||||||
place.set_placeref_list([placeref])
|
placeref_list = []
|
||||||
|
place = (handle, gid, title, '', '', placeref_list, name, [], placetype,
|
||||||
|
'', [], [], [], [], [], 0, [], False)
|
||||||
with BSDDBTxn(self.env, self.place_map) as txn:
|
with BSDDBTxn(self.env, self.place_map) as txn:
|
||||||
if isinstance(handle, str):
|
if isinstance(handle, str):
|
||||||
handle = handle.encode('utf-8')
|
handle = handle.encode('utf-8')
|
||||||
txn.put(handle, place.serialize())
|
txn.put(handle, place)
|
||||||
return handle
|
return handle
|
||||||
|
|
||||||
def upgrade_datamap_17(datamap):
|
def upgrade_datamap_17(datamap):
|
||||||
|
Loading…
Reference in New Issue
Block a user