Last change
on this file since 17394 was
15754,
checked in by uli, 5 years ago
|
Add a collection of helper scripts.
These will not work through-the-web. Use them from the debug shell.
|
File size:
1.3 KB
|
Line | |
---|
1 | """ |
---|
2 | This is a collection of arbitrary scripts for mainly maintenance purposes. |
---|
3 | |
---|
4 | The scripts are not callable via web interface. |
---|
5 | |
---|
6 | Use them (for instance) like so:: |
---|
7 | |
---|
8 | $ ./bin/kofa-debug |
---|
9 | >>> from waeup.kofa.scripts import add_field_index |
---|
10 | >>> add_field_index(root['aaue'], 'things_catalog', 'new_id') |
---|
11 | |
---|
12 | Use at your own risk. |
---|
13 | |
---|
14 | """ |
---|
15 | from zope.catalog.field import FieldIndex |
---|
16 | from zope.catalog.interfaces import ICatalog |
---|
17 | from zope.component import getUtility |
---|
18 | from waeup.kofa.utils.helpers import reindex_cat |
---|
19 | import transaction |
---|
20 | |
---|
21 | |
---|
22 | def get_catalog(app, catalog_name): |
---|
23 | return getUtility(ICatalog, name=catalog_name, context=app) |
---|
24 | |
---|
25 | |
---|
26 | def add_field_index(app, catalog_name, field_name): |
---|
27 | """Add a catalog FieldIndex. |
---|
28 | |
---|
29 | This can become cumbersome through the web API as _all_ objects stored in |
---|
30 | ZODB will then be indexed and pulled into memory - might become a problem |
---|
31 | with large databases. This CLI runs faster. You should make sure, that not |
---|
32 | much traffic is on the site when running the script. |
---|
33 | """ |
---|
34 | cat = get_catalog(app, catalog_name) |
---|
35 | if field_name in cat.keys(): |
---|
36 | # index exists already |
---|
37 | return False |
---|
38 | cat[field_name] = FieldIndex(field_name=field_name) |
---|
39 | transaction.commit() |
---|
40 | reindex_cat(cat) |
---|
41 | transaction.commit() |
---|
42 | return True |
---|
Note: See
TracBrowser for help on using the repository browser.