How do I prevent values of custom registry entries to be overwritten on reinstall of my package?

别等时光非礼了梦想. 提交于 2019-12-11 03:49:09

问题


My package introduces registry entries. Changes by site administrator should not be overwritten on reinstall of the package.

Many ways to Rome. I chose ftw.upgrade. I like the declarative way of the upgrade step syntax. Its possible to use an upgrade directory for generic setup xml-Files like propertiestool.xml. No need to define handler python code. The upgrade works well. The admin can upgrade from control panel and in my case the new property is added. Insomma: For a new property just these have to be added: an upgrade-step declaration for source and destination version and directory where to find the properties.xml. Thumb up! –


回答1:


You can pilot what to do when installing a Plone add-on by providing an Extension/install.py file with a install method inside:

def install(portal, reinstall=False):
    if not reinstall:
        setup_tool = portal.portal_setup
        setup_tool.runAllImportStepsFromProfile('profile-your.pfile:default')

This way you are driving what Plone should do when installing.

If you need it: the same if for uninstall:

def uninstall(portal, reinstall=False):
    if not reinstall:
        setup_tool = portal.portal_setup
        setup_tool.runAllImportStepsFromProfile('profile-example.gs:uninstall')

This way you can prevent the uninstall step to be run when reinstalling.

Warning: as Mathias suggested using quickinstaller -> reinstall feature is bad.

Warning: this will not probably work anymore on Plone 5 (there's open discussion about this).




回答2:


I think what you describe is one of the problems upcoming with the increasing complexity of Plone's stack, and one of the reasons, why it is not recommended to execute a re-install anymore, but to provide a profile for each version of the Add-On, via upgrade-steps (as Mathias mentioned). That increases dev-time significantly and results in even more conflicts, of my experience. Here are the refering docs: http://docs.plone.org/develop/addons/components/genericsetup.html#add-upgrade-step

Elizabeth Leddy once wrote an Add-On to ease that pain and I can confirm it does: https://github.com/ampsport/amp.ezupgrade

And the great guys from FTW, too, I never used it, but looks promising: https://pypi.python.org/pypi/ftw.upgrade

Neither used this one, even claims to have some extra goodies, like cleanup broken OFS objects and R. Patterson's on it: https://github.com/collective/collective.upgrade

As we're here, the first good doc I could find about it ~ 1.5 years ago, comes from Uwosh, of course: http://www.uwosh.edu/ploneprojects/docs/how-tos/how-to-use-generic-setup-upgrade-steps

Another solution can be, to check, if it's an initial- or re-install, and set the properties programatically via a Python-script, conveniently called 'setuphandlers.py', like described in this answer: How to check, if my product is already installed, when installing it? That way one can still trigger re-installs without blowing it all up.

Lastly, a lot of the GS-xml-files understand the purge-property, setting it to False, will not overwrite the whole file, just your given props. This might, or not, apply to your case, you can find samples in the above referenced official doc.



来源:https://stackoverflow.com/questions/30499063/how-do-i-prevent-values-of-custom-registry-entries-to-be-overwritten-on-reinstal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!