Browse Source

[FIX] really uninstall modules and avoid a crash on cached data

[FIX] don't try to uninstall uninstalled modules

[DEL] weird code

[FIX] actually cleanup where we can
pull/1009/head
Holger Brunn 7 years ago
parent
commit
8d450dfe21
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 18
      database_cleanup/models/purge_models.py
  2. 19
      database_cleanup/models/purge_modules.py

18
database_cleanup/models/purge_models.py

@ -10,11 +10,9 @@ class IrModel(models.Model):
_inherit = 'ir.model'
def _drop_table(self):
# Allow to skip this step during model unlink
# The super method crashes if the model cannot be instantiated
if self.env.context.get('no_drop_table'):
return True
return super(IrModel, self)._drop_table()
"""this function crashes for undefined models"""
existing_model_ids = self.filtered(lambda x: x.model in self.env)
return super(IrModel, existing_model_ids)._drop_table()
@api.depends()
def _inherited_models(self):
@ -28,11 +26,9 @@ class IrModelFields(models.Model):
@api.multi
def _prepare_update(self):
# Allow to skip this step during model unlink
# The super method crashes if the model cannot be instantiated
if self.env.context.get('no_prepare_update'):
return True
return super(IrModelFields, self)._prepare_update()
"""this function crashes for undefined models"""
existing = self.filtered(lambda x: x.model in self.env)
return super(IrModelFields, existing)._prepare_update()
class CleanupPurgeLineModel(models.TransientModel):
@ -50,9 +46,7 @@ class CleanupPurgeLineModel(models.TransientModel):
"""
context_flags = {
MODULE_UNINSTALL_FLAG: True,
'no_drop_table': True,
'purge': True,
'no_prepare_update': True,
}
if self:

19
database_cleanup/models/purge_modules.py

@ -3,7 +3,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.modules.registry import RegistryManager
from odoo.modules.module import get_module_path
from odoo.addons.base.ir.ir_model import MODULE_UNINSTALL_FLAG
@ -41,25 +40,19 @@ class CleanupPurgeLineModule(models.TransientModel):
Uninstall modules upon manual confirmation, then reload
the database.
"""
if self:
objs = self
else:
objs = self.env['cleanup.purge.line.module']\
.browse(self._context.get('active_ids'))
module_names = objs.filtered(lambda x: not x.purged).mapped('name')
module_names = self.filtered(lambda x: not x.purged).mapped('name')
modules = self.env['ir.module.module'].search([
('name', 'in', module_names)
])
if not modules:
return True
self.logger.info('Purging modules %s', ', '.join(module_names))
modules.button_uninstall()
# we need this commit because reloading the registry would roll back
# our changes
self.env.cr.commit() # pylint: disable=invalid-commit
RegistryManager.new(self.env.cr.dbname, update_module=True)
modules.filtered(
lambda x: x.state not in ('uninstallable', 'uninstalled')
).button_immediate_uninstall()
modules.refresh()
modules.unlink()
return objs.write({'purged': True})
return self.write({'purged': True})
class CleanupPurgeWizardModule(models.TransientModel):

Loading…
Cancel
Save