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..ef0bef066 100644 --- a/database_cleanup/__openerp__.py +++ b/database_cleanup/__openerp__.py @@ -21,8 +21,8 @@ { 'name': 'Database cleanup', - 'version': '0.1', - 'author': 'Therp BV', + 'version': '8.0.0.1.0', + 'author': "Therp BV,Odoo Community Association (OCA)", 'depends': ['base'], 'license': 'AGPL-3', 'category': 'Tools', @@ -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_columns.py b/database_cleanup/model/purge_columns.py index 60b56ccc8..abcf1d2d4 100644 --- a/database_cleanup/model/purge_columns.py +++ b/database_cleanup/model/purge_columns.py @@ -96,8 +96,9 @@ class CleanupPurgeWizardColumn(orm.TransientModel): columns = list(set([ column for model_pool in model_pools for column in model_pool._columns - if not (isinstance(model_pool._columns[column], fields.function) - and not model_pool._columns[column].store) + if not (isinstance(model_pool._columns[column], + fields.function) and + not model_pool._columns[column].store) ])) columns += orm.MAGIC_COLUMNS columns += self.blacklist.get(model_pools[0]._table, []) 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() diff --git a/database_cleanup/model/purge_tables.py b/database_cleanup/model/purge_tables.py index 8d9c86544..50bf3d8e6 100644 --- a/database_cleanup/model/purge_tables.py +++ b/database_cleanup/model/purge_tables.py @@ -110,9 +110,9 @@ class CleanupPurgeWizardTable(orm.TransientModel): known_tables += [ column._sql_names(model_pool)[0] for column in model_pool._columns.values() - if column._type == 'many2many' - # unstored function fields of type m2m don't have _rel - and hasattr(column, '_rel') + if (column._type == 'many2many' and + hasattr(column, '_rel')) # unstored function fields of + # type m2m don't have _rel ] # Cannot pass table names as a psycopg argument diff --git a/database_cleanup/static/src/img/icon.png b/database_cleanup/static/description/icon.png similarity index 100% rename from database_cleanup/static/src/img/icon.png rename to database_cleanup/static/description/icon.png