Skip to content

Commit

Permalink
fixup! [REF] module_auto_update: Step 3, backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Mar 20, 2018
1 parent 9490a96 commit 8c2b50c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
27 changes: 16 additions & 11 deletions module_auto_update/migrations/9.0.2.0.0/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Tecnativa - Jairo Llopis
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import openupgradelib

import logging
from psycopg2 import IntegrityError
from openerp.addons.module_auto_update.models.module_deprecated import \
PARAM_DEPRECATED

import wdb; wdb.set_trace() # TODO DELETE!
# TODO Remove when deprecated features are removed; see README's known issues
@openupgradelib.migrate(no_version=True, use_env=True)
def migrate(env):
_logger = logging.getLogger(__name__)


def migrate(cr, version):
"""Autoenable deprecated behavior."""
# Check if deprecation parameter existed
deprecated = env["ir.config_parameter"].get_param(PARAM_DEPRECATED)
if deprecated is False:
# If not, enable deprecated features now, to avoid breaking behavior
env["ir.config_parameter"].set_param(PARAM_DEPRECATED, "1")
try:
cr.execute(
"INSERT INTO ir_config_parameter (key, value) VALUES (%s, '1')",
(PARAM_DEPRECATED,)
)
_logger.warn("Deprecated features have been autoenabled, see "
"addon's README to know how to upgrade to the new "
"supported autoupdate mechanism.")
except IntegrityError:
_logger.info("Deprecated features setting exists, not autoenabling")
8 changes: 4 additions & 4 deletions module_auto_update/models/module_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def _compute_checksum_installed(self):
rec.checksum_installed = saved_checksums.get(rec.name, False)

def _inverse_checksum_installed(self):
saved_checksums = self._get_saved_checksums()
checksums = self._get_saved_checksums()
for rec in self:
saved_checksums[rec.name] = rec.checksum_installed
self._save_installed_checksums()
checksums[rec.name] = rec.checksum_installed
self._save_checksums(checksums)

@api.multi
def _store_checksum_installed(self, vals):
"""Store the right installed checksum, if addon is installed."""
if self.env["base.module.upgrade"]._module_auto_update_deprecated():
if not self.env["base.module.upgrade"]._autoupdate_deprecated():
# Skip if deprecated features are disabled
return
if 'checksum_installed' not in vals:
Expand Down
19 changes: 15 additions & 4 deletions module_auto_update/wizards/module_upgrade_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging

from openerp import api, models

from ..models.module_deprecated import PARAM_DEPRECATED

_logger = logging.getLogger(__name__)


class ModuleUpgrade(models.TransientModel):
_inherit = 'base.module.upgrade'

@api.model
def _module_auto_update_deprecated(self):
def _autoupdate_deprecated(self):
"""Know if we should enable deprecated features."""
deprecated = (
self.env["ir.config_parameter"].get_param(PARAM_DEPRECATED))
Expand All @@ -28,7 +32,7 @@ def _module_auto_update_deprecated(self):
@api.model
def get_module_list(self):
"""Set modules to upgrade searching by their dir checksum."""
if self._module_auto_update_deprecated():
if self._autoupdate_deprecated():
Module = self.env["ir.module.module"]
installed_modules = Module.search([('state', '=', 'installed')])
upgradeable_modules = installed_modules.filtered(
Expand All @@ -40,7 +44,14 @@ def get_module_list(self):
@api.multi
def upgrade_module(self):
"""Make a fully automated addon upgrade."""
if self._module_auto_update_deprecated():
if self._autoupdate_deprecated():
_logger.warning(
"You are possibly using an unsupported upgrade system; "
"set '%s' system parameter to '0' and start calling "
"`env['ir.module.module'].upgrade_changed_checksum()` from "
"now on to get rid of this message. See module's README for "
"further information on the matter."
)
# Compute updates by checksum when called in @api.model fashion
self.env.cr.autocommit(True) # Avoid transaction lock
if not self:
Expand All @@ -51,7 +62,7 @@ def upgrade_module(self):
in Module.search_read([], ["name", "state"])}
# Perform upgrades, possibly in a limited graph that excludes me
result = super(ModuleUpgrade, self).upgrade_module()
if self._module_auto_update_deprecated():
if self._autoupdate_deprecated():
self.env.cr.autocommit(False)
# Reload environments, anything may have changed
self.env.clear()
Expand Down

0 comments on commit 8c2b50c

Please sign in to comment.