-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up old -fs targets in Makefile.
Use instance-local.yaml instead to override for example the data storage layer of the backend from relstoraeg to file/blobstorage.
- Loading branch information
Showing
4 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
backend/instance-filestorage.yaml → backend/instance-local.yaml.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Run this from the backend directory with: | ||
# bin/zconsole run instance/etc/zope.conf scripts/catalog_clear_rebuild.py | ||
# or with extra options: --site=nl | ||
|
||
from plone import api | ||
from zope.component import getUtility | ||
from zope.component.hooks import setSite | ||
|
||
import argparse | ||
import sys | ||
import transaction | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--site", | ||
default="", | ||
dest="site", | ||
help="Single site id to work on. Default is to work on all.", | ||
) | ||
# sys.argv will be something like: | ||
# ['.../parts/instance/bin/interpreter', '-c', | ||
# 'scripts/fix_related_items_and_intids.py', '--site=nl'] | ||
# Ignore the first three. | ||
options = parser.parse_args(args=sys.argv[3:]) | ||
|
||
# 'app' is the Zope root. | ||
# Get Plone Sites to work on. | ||
if options.site: | ||
# Get single Plone Site. | ||
plones = [getattr(app, options.site)] | ||
else: | ||
# Get all Plone Sites. | ||
plones = [ | ||
obj | ||
for obj in app.objectValues() # noqa | ||
if getattr(obj, "portal_type", "") == "Plone Site" | ||
] | ||
|
||
|
||
def commit(note): | ||
print(note) | ||
# Commit transaction and add note. | ||
tr = transaction.get() | ||
tr.note(note) | ||
transaction.commit() | ||
|
||
|
||
for site in plones: | ||
print("") | ||
print("Handling Plone Site %s." % site.id) | ||
setSite(site) | ||
catalog = api.portal.get_tool(name="portal_catalog") | ||
catalog.manage_catalogRebuild() | ||
print("Catalog is rebuilt, now doing a search to empty the indexing queue. This may take long.") | ||
catalog.unrestrictedSearchResults(SearchableText="Maro 1:3") | ||
note = ( | ||
"Cleared and rebuilt the catalog for %s." % site.id | ||
) | ||
commit(note) | ||
print("Done.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Run this with: | ||
# bin/zconsole run instance/etc/zope.conf scripts/purge_image_scales.py | ||
# | ||
# Add --dry-run to change nothing and only get a report. | ||
|
||
import sys | ||
import transaction | ||
from Products.CMFCore.utils import getToolByName | ||
from plone.scale.storage import AnnotationStorage | ||
from zope.component.hooks import setSite | ||
|
||
# Keep scales of at most X days older than their context: | ||
DAYS = -1 | ||
# Commit after these many changes: | ||
LIMIT = 1000 | ||
|
||
if '--dry-run' in sys.argv: | ||
dry_run = True | ||
print('Dry run selected, will not commit changes.') | ||
else: | ||
dry_run = False | ||
|
||
# Get all Plone Sites. 'app' is the Zope root. | ||
plones = [obj for obj in app.objectValues() | ||
if getattr(obj, 'portal_type', '') == 'Plone Site'] | ||
|
||
|
||
def commit(note): | ||
print(note) | ||
if dry_run: | ||
print('Dry run selected, not committing.') | ||
return | ||
# Commit transaction and add note. | ||
tr = transaction.get() | ||
tr.note(note) | ||
transaction.commit() | ||
|
||
|
||
for site in plones: | ||
print('') | ||
print('Handling Plone Site %s.' % site.id) | ||
setSite(site) | ||
catalog = getToolByName(site, 'portal_catalog') | ||
count = 0 | ||
purged = 0 | ||
for brain in catalog.getAllBrains(): | ||
try: | ||
obj = brain.getObject() | ||
except: | ||
continue | ||
savepoint = transaction.savepoint() | ||
ann = AnnotationStorage(obj) | ||
try: | ||
ann.storage | ||
except TypeError: | ||
# This happens when the context cannot be annotated, for | ||
# example for a plone.app.discussion comment. | ||
continue | ||
# We want to remove all scales that are X days older than the | ||
# last modification date of the object. | ||
final_date = obj.modified() - DAYS | ||
changed = False | ||
to_delete = [] | ||
for key, value in ann.items(): | ||
if value['modified'] < final_date.millis(): | ||
to_delete.append(key) | ||
for key in to_delete: | ||
# This may easily give an error, as it tries to remove | ||
# two keys: del ann[key] | ||
del ann.storage[key] | ||
purged += 1 | ||
changed = True | ||
if not changed: | ||
# This avoids adding an empty annotation for items that | ||
# will never store scales. | ||
savepoint.rollback() | ||
else: | ||
count += 1 | ||
if count % LIMIT == 0: | ||
note = ('Purged %d outdated image scales for %d items in ' | ||
'Plone Site %s.' % (purged, count, site.id)) | ||
commit(note) | ||
|
||
note = ('Finished purging %d outdated image scales for %d items in ' | ||
'Plone Site %s.' % (purged, count, site.id)) | ||
commit(note) | ||
|
||
print('Done.') |