Skip to content

Commit

Permalink
Add upgrade profile and sample blob solution
Browse files Browse the repository at this point in the history
  • Loading branch information
miknevinas committed Oct 4, 2024
1 parent c645b36 commit e4e2e6d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
50 changes: 50 additions & 0 deletions castle/cms/browser/content/fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
from zope.event import notify
from zope.interface import implementer
from zope.lifecycleevent import ObjectModifiedEvent
from zope.component.hooks import getSite
from plone.app.contenttypes.interfaces import IDocument
from zope.annotation.interfaces import IAnnotations
from persistent.mapping import PersistentMapping
from plone.namedfile.file import NamedBlobImage
from ZODB.POSException import POSKeyError
from re import sub

from plone.app.content.browser.vocabulary import (
Expand Down Expand Up @@ -190,6 +196,50 @@ def __call__(self):
except CopyError:
return self.copy_error()

# XXX: Experimental code block
# Can be removed in lieu of installing "experimental.gracefulblobmissing" package,
# which ignores missing blob errors

site = getSite()
for path in paste_data.get('paths'):
print(path)

try:
obj = site.restrictedTraverse(path.strip('/'), None)
print(obj)
if obj is None:
logger.error("Object not found: '{}'".format(path))
return
except Exception as e:
logger.error("Error retrieving object: {}".format(e))
return

if IDocument.providedBy(obj):
annotations = IAnnotations(obj)

# The ANNOTATIONS_KEY_PREFIX ignores tiles with images/blobs
for key in annotations.keys():
data = annotations[key]

# PersistentMapping tiles contain the blobs we want
if isinstance(data, PersistentMapping):
for item in data.values():
if isinstance(item, dict) and isinstance(item.get('data'), NamedBlobImage):
blobfile = item.get('data')
blob = blobfile._blob
try:
# Check blob, opening may not be best approach
f = blob.open('r')
f.close()
except POSKeyError:
# Broken blob reference
# XXX: Call save() on blob or reassign to generic fallback blob
path_on_disk = blob._p_blob_committed
pass

# XXX: end of block


tasks.paste_items.delay(
self.request.form['folder'], paste_data['op'],
paste_data['mdatas'])
Expand Down
15 changes: 15 additions & 0 deletions castle/cms/profiles/3017/registry/resources.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone">

<records prefix="plone.bundles/plone"
interface='Products.CMFPlone.interfaces.IBundleRegistry'>
<value key="last_compilation">2024-09-24 00:00:00</value>
</records>

<records prefix="plone.bundles/plone-logged-in"
interface='Products.CMFPlone.interfaces.IBundleRegistry'>
<value key="last_compilation">2024-09-24 00:00:00</value>
</records>

</registry>
2 changes: 1 addition & 1 deletion castle/cms/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>3016</version>
<version>3017</version>
<dependencies>
<dependency>profile-plone.app.querystring:default</dependency>
<dependency>profile-plone.app.mosaic:default</dependency>
Expand Down
16 changes: 16 additions & 0 deletions castle/cms/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,20 @@
profile="castle.cms:default"
/>

<genericsetup:registerProfile
name="3017"
title="CastleCMS upgrade to 3017 profile"
directory="profiles/3017"
description=""
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<genericsetup:upgradeStep
title="Upgrade CastleCMS to 3.0.17"
description="3017 - Recompile resources for paste async button"
source="*"
destination="3017"
handler=".upgrades.upgrade_3017"
profile="castle.cms:default"
/>

</configure>
1 change: 1 addition & 0 deletions castle/cms/upgrades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ def upgrade_3011(site, logger=CASTLE_LOGGER):
upgrade_3014 = default_upgrade_factory('3014')
upgrade_3015 = default_upgrade_factory('3015')
upgrade_3016 = default_upgrade_factory('3016')
upgrade_3017 = default_upgrade_factory('3017')
1 change: 1 addition & 0 deletions travis.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ eggs +=
Pillow
Products.PloneKeywordManager
plone.app.robotframework
experimental.gracefulblobmissing

zcml =
castle.cms-overrides
Expand Down
1 change: 1 addition & 0 deletions versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ z3c.jbot = 0.7.2
castle.theme = 1.0.6
Products.PloneKeywordManager = 2.2.1
wildcard.hps = 1.4.0
experimental.gracefulblobmissing = 2.0


# dependency pins
Expand Down

0 comments on commit e4e2e6d

Please sign in to comment.