Skip to content

Commit

Permalink
Update the Plone Site FTI if it is not a dexterity one
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Feb 14, 2021
1 parent 2c82ffb commit 699e6f9
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 9 deletions.
27 changes: 23 additions & 4 deletions plone/app/upgrade/v60/alphas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from plone.app.upgrade.utils import loadMigrationProfile
from plone.dexterity.fti import DexterityFTI
from Products.CMFCore.utils import getToolByName
from ZODB.broken import Broken
from zope.component.hooks import getSite

import logging
Expand All @@ -14,7 +17,6 @@ def to60alpha1(context):

def remove_temp_folder(context):
"""Remove temp_folder from Zope root if broken."""
from ZODB.broken import Broken

app = context.unrestrictedTraverse("/")
broken_id = "temp_folder"
Expand All @@ -37,6 +39,19 @@ def remove_temp_folder(context):
logger.info("Removed %s from Zope root _mount_points.", broken_id)


def change_plone_site_fti(context):
pt = getToolByName(context, "portal_types")
fti = pt.getTypeInfo("Plone Site")

if isinstance(fti, DexterityFTI):
# We assume the fti has been already fixed ...
return

# ... otherwise we fix it
del pt["Plone Site"]
loadMigrationProfile(context, "profile-plone.app.upgrade.v60:to_dx_site_root")


def make_site_dx(context):
"""Make the Plone Site a dexterity container"""
portal = getSite()
Expand All @@ -52,9 +67,13 @@ def make_site_dx(context):
logger.info("Migrating object %r", obj_id)
# Load the content object ...
obj = portal.__dict__.pop(obj_id)
# ...and insert it into the btree.
# Use _setOb so we don't reindex stuff: the paths stay the same.
portal._setOb(obj_id, obj)
if not isinstance(obj, Broken) and obj_id not in (
"portal_quickinstaller",
"portal_form_controller",
):
# ...and insert it into the btree.
# Use _setOb so we don't reindex stuff: the paths stay the same.
portal._setOb(obj_id, obj)

delattr(portal, "_objects")
portal._p_changed = True
15 changes: 10 additions & 5 deletions plone/app/upgrade/v60/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
destination="6000"
profile="Products.CMFPlone:plone">

<gs:upgradeStep
title="Be sure that the Plone Site FTI is a dexterity one"
handler=".alphas.change_plone_site_fti"
/>

<gs:upgradeStep
title="Make the Plone Site a dexterity container"
handler=".alphas.make_site_dx"
/>

<gs:upgradeStep
title="Run to60alpha1 upgrade profile."
description=""
Expand All @@ -22,11 +32,6 @@
handler=".alphas.remove_temp_folder"
/>

<gs:upgradeStep
title="Make the Plone Site a dexterity container"
handler=".alphas.make_site_dx"
/>

</gs:upgradeSteps>


Expand Down
12 changes: 12 additions & 0 deletions plone/app/upgrade/v60/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<!--
This is special, we want to reread the profile to create the FTI only if the old FTI
is not already a Dexterity one
-->
<genericsetup:registerProfile
name="to_dx_site_root"
title="Upgrade profile to change the FTI for the Plone Site object a dexterity one"
directory="profiles/to_dx_site_root"
for="Products.CMFPlone.interfaces.IMigratingPloneSiteRoot"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

</configure>
4 changes: 4 additions & 0 deletions plone/app/upgrade/v60/profiles/to_dx_site_root/types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<object name="portal_types" meta_type="Plone Types Tool">
<object name="Plone Site" meta_type="Dexterity FTI" />
</object>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0"?>
<object
i18n:domain="plone"
meta_type="Dexterity FTI"
name="Plone Site"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">

<!-- Basic properties -->
<property
i18n:translate=""
name="title">Plone Site</property>
<property
i18n:translate=""
name="description"></property>

<property name="allow_discussion">False</property>
<property name="factory">manage_addSite</property>
<property name="icon_expr"></property>
<property name="link_target"></property>

<!-- Hierarchy control -->
<property name="allowed_content_types"/>
<property name="filter_content_types">False</property>
<property name="global_allow">False</property>

<!-- Schema, class and security -->
<property name="add_permission">cmf.AddPortalContent</property>
<property name="klass">Products.CMFPlone.Portal.PloneSite</property>
<property name="model_file">plone.app.contenttypes.schema:folder.xml</property>
<property name="model_source"></property>
<property name="schema"></property>

<!-- Enabled behaviors -->
<property name="behaviors" purge="false">
<element value="plone.dublincore" />
<element value="plone.richtext" />
<element value="plone.relateditems" />
<element value="plone.locking" />
<element value="plone.allowdiscussion" />
<element value="plone.excludefromnavigation" />
<element value="plone.tableofcontents" />
</property>

<!-- View information -->
<property name="add_view_expr">string:${folder_url}/addPlone Site</property>
<property name="default_view">listing_view</property>
<property name="default_view_fallback">False</property>
<property name="immediate_view">view</property>
<property name="view_methods">
<element value="album_view"/>
<element value="event_listing"/>
<element value="full_view"/>
<element value="listing_view"/>
<element value="summary_view"/>
<element value="tabular_view"/>
</property>

<!-- Method aliases -->
<alias from="(Default)" to="(dynamic view)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
<alias from="view" to="(selected layout)"/>
<action title="View" action_id="view" category="object" condition_expr=""
url_expr="string:${object_url}" visible="True"
i18n:attributes="title">
<permission value="View"/>
</action>
<action
action_id="edit"
category="object"
condition_expr="not:object/@@plone_lock_info/is_locked_for_current_user|python:True"
i18n:attributes="title"
title="Edit"
url_expr="string:${object_url}/edit"
visible="True">
<permission value="Modify portal content"/>
</action>

</object>

0 comments on commit 699e6f9

Please sign in to comment.