|
| 1 | +from Acquisition import aq_inner |
| 2 | +from Acquisition import aq_parent |
| 3 | +from Products.CMFCore.utils import getToolByName |
| 4 | +from bika.lims import api |
| 5 | +from bika.lims import logger |
| 6 | +from bika.lims.config import PROJECTNAME as product |
| 7 | +from bika.lims.upgrade import upgradestep |
| 8 | +from bika.lims.upgrade.utils import UpgradeUtils |
| 9 | + |
| 10 | +version = '1.1.4' |
| 11 | +profile = 'profile-{0}:default'.format(product) |
| 12 | + |
| 13 | + |
| 14 | +@upgradestep(product, version) |
| 15 | +def upgrade(tool): |
| 16 | + portal = aq_parent(aq_inner(tool)) |
| 17 | + setup = portal.portal_setup |
| 18 | + ut = UpgradeUtils(portal) |
| 19 | + ver_from = ut.getInstalledVersion(product) |
| 20 | + |
| 21 | + if ut.isOlderVersion(product, version): |
| 22 | + logger.info("Skipping upgrade of {0}: {1} > {2}".format( |
| 23 | + product, ver_from, version)) |
| 24 | + # The currently installed version is more recent than the target |
| 25 | + # version of this upgradestep |
| 26 | + return True |
| 27 | + |
| 28 | + logger.info("Upgrading {0}: {1} -> {2}".format(product, ver_from, version)) |
| 29 | + |
| 30 | + # Add inactive_state workflow for Reflex Rules |
| 31 | + setup.runImportStepFromProfile(profile, 'workflow') |
| 32 | + update_reflexrules_workflow_state(portal) |
| 33 | + |
| 34 | + logger.info("{0} upgraded to version {1}".format(product, version)) |
| 35 | + return True |
| 36 | + |
| 37 | + |
| 38 | +def update_reflexrules_workflow_state(portal): |
| 39 | + """ |
| 40 | + Updates Reflex Rules' inactive_state, otherwise they don't have it by |
| 41 | + default. |
| 42 | + :param portal: Portal object |
| 43 | + :return: None |
| 44 | + """ |
| 45 | + wf_tool = getToolByName(portal, 'portal_workflow') |
| 46 | + logger.info("Updating Reflex Rules' 'inactive_state's...") |
| 47 | + wf = wf_tool.getWorkflowById("bika_inactive_workflow") |
| 48 | + uc = api.get_tool('portal_catalog') |
| 49 | + r_rules = uc(portal_type='ReflexRule') |
| 50 | + for rr in r_rules: |
| 51 | + obj = rr.getObject() |
| 52 | + wf.updateRoleMappingsFor(obj) |
| 53 | + obj.reindexObject() |
| 54 | + logger.info("Reflex Rules' 'inactive_state's were updated.") |
0 commit comments