580
580
def __init__(self, pool, cr):
581
581
osv.osv.__init__(self, pool, cr)
582
582
self.doinit = True
583
self.unlink_mark = {}
585
584
# also stored in pool to avoid being discarded along with this osv instance
586
585
if getattr(pool, 'model_data_reference_ids', None) is None:
631
def unlink(self, cr, uid, ids, context=None):
632
""" Regular unlink method, but make sure to clear the caches. """
633
ref_ids = self.browse(cr, uid, ids, context=context)
634
for ref_id in ref_ids:
635
self._get_id.clear_cache(cr.dbname, uid, ref_id.module, ref_id.name)
636
self.get_object_reference.clear_cache(cr.dbname, uid, ref_id.module, ref_id.name)
637
return super(ir_model_data,self).unlink(cr, uid, ids, context=context)
632
639
def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False, context=None):
633
640
model_obj = self.pool.get(model)
719
726
table.replace('.', '_'))] = (table, inherit_id)
722
def _unlink(self, cr, uid, model, res_ids):
723
for res_id in res_ids:
724
self.unlink_mark[(model, res_id)] = False
725
cr.execute('delete from ir_model_data where res_id=%s and model=%s', (res_id, model))
728
729
def ir_set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=None, xml_id=False):
729
730
if type(models[0])==type([]) or type(models[0])==type(()):
730
731
model,res_id = models[0]
754
755
def _process_end(self, cr, uid, modules):
756
""" Clear records removed from updated module data.
758
This method is called at the end of the module loading process.
759
It is meant to removed records that are no longer present in the
760
updated data. Such records are recognised as the one with an xml id
761
and a module in ir_model_data and noupdate set to false, but not
762
present in self.loads.
757
767
modules = list(modules)
758
768
module_in = ",".join(["%s"] * len(modules))
759
769
cr.execute('select id,name,model,res_id,module from ir_model_data where module IN (' + module_in + ') and noupdate=%s', modules + [False])
761
772
for (id, name, model, res_id,module) in cr.fetchall():
762
773
if (module,name) not in self.loads:
763
self.unlink_mark[(model,res_id)] = id
774
to_unlink.append((model,res_id))
764
775
if model=='workflow.activity':
765
776
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,))
766
777
wkf_todo.extend(cr.fetchall())
775
786
if not config.get('import_partial'):
776
for (model, res_id) in self.unlink_mark.keys():
787
for (model, res_id) in to_unlink:
777
788
if self.pool.get(model):
778
789
self.__logger.info('Deleting %s@%s', res_id, model)
780
791
self.pool.get(model).unlink(cr, uid, [res_id])
782
ids = self.search(cr, uid, [('res_id','=',res_id),
783
('model','=',model)])
784
self.__logger.debug('=> Deleting %s: %s',
786
if len(ids) > 1 and \
787
self.__logger.isEnabledFor(logging.WARNING):
789
'Got %d %s for (%s, %d): %s',
790
len(ids), self._name, model, res_id,
791
map(itemgetter('module','name'),
792
self.read(cr, uid, ids,
793
['name', 'module'])))
794
self.unlink(cr, uid, ids)
796
'DELETE FROM ir_values WHERE value=%s',
797
('%s,%s'%(model, res_id),))
799
793
except Exception:
801
795
self.__logger.warn(
802
'Could not delete id: %d of model %s\nThere '
803
'should be some relation that points to this '
804
'resource\nYou should manually fix this and '
805
'restart with --update=module', res_id, model)
796
'Could not delete obsolete record with id: %d of model %s\n'
797
'There should be some relation that points to this resource\n'
798
'You should manually fix this and restart with --update=module',