From c2673b97d7a68748b861b3fa50370466e541b564 Mon Sep 17 00:00:00 2001 From: Anthony Muschang Date: Thu, 11 Dec 2014 23:04:24 +0100 Subject: [PATCH] [CHG] Migration to 8.0 [CHG] database_cleanup: move description to README.rst --- database_cleanup/README.rst | 15 +++++++++++++++ database_cleanup/__openerp__.py | 18 ------------------ database_cleanup/model/purge_models.py | 8 ++++++++ 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 database_cleanup/README.rst diff --git a/database_cleanup/README.rst b/database_cleanup/README.rst new file mode 100644 index 000000000..6456ff195 --- /dev/null +++ b/database_cleanup/README.rst @@ -0,0 +1,15 @@ +Clean your OpenERP database from remnants of modules, models, columns and +tables left by uninstalled modules (prior to 7.0) or a homebrew database +upgrade to a new major version of OpenERP. + +After installation of this module, go to the Settings menu -> Technical -> +Database cleanup. Go through the modules, models, columns and tables +entries under this menu (in that order) and find out if there is orphaned data +in your database. You can either delete entries by line, or sweep all entries +in one big step (if you are *really* confident). + +Caution! This module is potentially harmful and can *easily* destroy the +integrity of your data. Do not use if you are not entirely comfortable +with the technical details of the OpenERP data model of *all* the modules +that have ever been installed on your database, and do not purge any module, +model, column or table if you do not know exactly what you are doing. diff --git a/database_cleanup/__openerp__.py b/database_cleanup/__openerp__.py index 12c723365..ab839f57f 100644 --- a/database_cleanup/__openerp__.py +++ b/database_cleanup/__openerp__.py @@ -34,22 +34,4 @@ 'view/purge_data.xml', 'view/menu.xml', ], - 'description': """\ -Clean your OpenERP database from remnants of modules, models, columns and -tables left by uninstalled modules (prior to 7.0) or a homebrew database -upgrade to a new major version of OpenERP. - -After installation of this module, go to the Settings menu -> Technical -> -Database cleanup. Go through the modules, models, columns and tables -entries under this menu (in that order) and find out if there is orphaned data -in your database. You can either delete entries by line, or sweep all entries -in one big step (if you are *really* confident). - -Caution! This module is potentially harmful and can *easily* destroy the -integrity of your data. Do not use if you are not entirely comfortable -with the technical details of the OpenERP data model of *all* the modules -that have ever been installed on your database, and do not purge any module, -model, column or table if you do not know exactly what you are doing. -""", - } diff --git a/database_cleanup/model/purge_models.py b/database_cleanup/model/purge_models.py index a6342afd3..1aff2dc3d 100644 --- a/database_cleanup/model/purge_models.py +++ b/database_cleanup/model/purge_models.py @@ -52,6 +52,7 @@ class CleanupPurgeLineModel(orm.TransientModel): attachment_pool = self.pool['ir.attachment'] constraint_pool = self.pool['ir.model.constraint'] fields_pool = self.pool['ir.model.fields'] + relation_pool = self.pool['ir.model.relation'] local_context = (context or {}).copy() local_context.update({ @@ -86,8 +87,15 @@ class CleanupPurgeLineModel(orm.TransientModel): # cannot be instantiated fields_pool.unlink(cr, uid, [relation], context=local_context) + except KeyError: + pass except AttributeError: pass + relation_ids = relation_pool.search( + cr, uid, [('model', '=', line.name)], context=context) + for relation in relation_ids: + relation_pool.unlink(cr, uid, [relation], + context=local_context) model_pool.unlink(cr, uid, [row[0]], context=local_context) line.write({'purged': True}) cr.commit()