[IMP] ir.model.data: remove obsolete _unlink() and unlink_mark, and their references
Now all deletions in ir.model.data are automatically handled by ORM during the regular call to orm.unlink(). No need for any manual care. bzr revid: odo@openerp.com-20110531092426-ehvzf3dw6urqsdov
This commit is contained in:
@@ -581,7 +581,6 @@ class ir_model_data(osv.osv):
|
||||
def __init__(self, pool, cr):
|
||||
osv.osv.__init__(self, pool, cr)
|
||||
self.doinit = True
|
||||
self.unlink_mark = {}
|
||||
|
||||
# also stored in pool to avoid being discarded along with this osv instance
|
||||
if getattr(pool, 'model_data_reference_ids', None) is None:
|
||||
@@ -727,11 +726,12 @@ class ir_model_data(osv.osv):
|
||||
table.replace('.', '_'))] = (table, inherit_id)
|
||||
return res_id
|
||||
|
||||
def _unlink(self, cr, uid, model, res_ids):
|
||||
for res_id in res_ids:
|
||||
self.unlink_mark[(model, res_id)] = False
|
||||
cr.execute('delete from ir_model_data where res_id=%s and model=%s', (res_id, model))
|
||||
return True
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
ref_ids = self.browse(cr, uid, ids, context=context)
|
||||
for ref_id in ref_ids:
|
||||
self._get_id.clear_cache(cr.dbname, uid, ref_id.module, ref_id.name)
|
||||
self.get_object_reference.clear_cache(cr.dbname, uid, ref_id.module, ref_id.name)
|
||||
super(ir_model_data,self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
def ir_set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=None, xml_id=False):
|
||||
if type(models[0])==type([]) or type(models[0])==type(()):
|
||||
@@ -765,9 +765,10 @@ class ir_model_data(osv.osv):
|
||||
module_in = ",".join(["%s"] * len(modules))
|
||||
cr.execute('select id,name,model,res_id,module from ir_model_data where module IN (' + module_in + ') and noupdate=%s', modules + [False])
|
||||
wkf_todo = []
|
||||
to_unlink = []
|
||||
for (id, name, model, res_id,module) in cr.fetchall():
|
||||
if (module,name) not in self.loads:
|
||||
self.unlink_mark[(model,res_id)] = id
|
||||
to_unlink.append((model,res_id))
|
||||
if model=='workflow.activity':
|
||||
cr.execute('select res_type,res_id from wkf_instance where id IN (select inst_id from wkf_workitem where act_id=%s)', (res_id,))
|
||||
wkf_todo.extend(cr.fetchall())
|
||||
@@ -780,36 +781,19 @@ class ir_model_data(osv.osv):
|
||||
|
||||
cr.commit()
|
||||
if not config.get('import_partial'):
|
||||
for (model, res_id) in self.unlink_mark.keys():
|
||||
for (model, res_id) in to_unlink:
|
||||
if self.pool.get(model):
|
||||
self.__logger.info('Deleting %s@%s', res_id, model)
|
||||
try:
|
||||
self.pool.get(model).unlink(cr, uid, [res_id])
|
||||
if id:
|
||||
ids = self.search(cr, uid, [('res_id','=',res_id),
|
||||
('model','=',model)])
|
||||
self.__logger.debug('=> Deleting %s: %s',
|
||||
self._name, ids)
|
||||
if len(ids) > 1 and \
|
||||
self.__logger.isEnabledFor(logging.WARNING):
|
||||
self.__logger.warn(
|
||||
'Got %d %s for (%s, %d): %s',
|
||||
len(ids), self._name, model, res_id,
|
||||
map(itemgetter('module','name'),
|
||||
self.read(cr, uid, ids,
|
||||
['name', 'module'])))
|
||||
self.unlink(cr, uid, ids)
|
||||
cr.execute(
|
||||
'DELETE FROM ir_values WHERE value=%s',
|
||||
('%s,%s'%(model, res_id),))
|
||||
cr.commit()
|
||||
except Exception:
|
||||
cr.rollback()
|
||||
self.__logger.warn(
|
||||
'Could not delete id: %d of model %s\nThere '
|
||||
'should be some relation that points to this '
|
||||
'resource\nYou should manually fix this and '
|
||||
'restart with --update=module', res_id, model)
|
||||
'Could not delete obsolete record with id: %d of model %s\n'
|
||||
'There should be some relation that points to this resource\n'
|
||||
'You should manually fix this and restart with --update=module',
|
||||
res_id, model)
|
||||
return True
|
||||
ir_model_data()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user