1 | """Catalog tool columns updater setup handlers. |
---|
2 | """ |
---|
3 | from zope.component import adapts |
---|
4 | from zope.component import queryUtility |
---|
5 | |
---|
6 | from Products.CMFCore.utils import getToolByName |
---|
7 | from Products.GenericSetup.utils import importObjects |
---|
8 | from Products.GenericSetup.utils import XMLAdapterBase |
---|
9 | from Products.GenericSetup.interfaces import ISetupEnviron |
---|
10 | |
---|
11 | from quintagroup.catalogupdater.interfaces import IUpdatableCatalog |
---|
12 | |
---|
13 | |
---|
14 | class CatalogUpdaterXMLAdapter(XMLAdapterBase): |
---|
15 | """XML Catalog columns updater for CatalogTool. |
---|
16 | """ |
---|
17 | |
---|
18 | adapts(IUpdatableCatalog, ISetupEnviron) |
---|
19 | |
---|
20 | _LOGGER_ID = 'catalogupdater' |
---|
21 | |
---|
22 | name = 'catalogupdater' |
---|
23 | |
---|
24 | def _exportNode(self): |
---|
25 | """Export the object as a DOM node. |
---|
26 | """ |
---|
27 | return '' |
---|
28 | |
---|
29 | def _importNode(self, node): |
---|
30 | """Import the object from the DOM node. |
---|
31 | """ |
---|
32 | self._updateColumns(node) |
---|
33 | self._logger.info('Catalog columns updated.') |
---|
34 | |
---|
35 | |
---|
36 | def _updateColumns(self, node): |
---|
37 | columns = [] |
---|
38 | for child in node.childNodes: |
---|
39 | if child.nodeName != 'column': |
---|
40 | continue |
---|
41 | col = str(child.getAttribute('value')).strip() |
---|
42 | columns.append(col) |
---|
43 | |
---|
44 | # Update columns in catalog |
---|
45 | if len(columns) > 0: |
---|
46 | |
---|
47 | catalog = self.context |
---|
48 | |
---|
49 | self._logger.info('Updating %s columns for %s Catalog.' % ( |
---|
50 | columns, '/'.join(catalog.getPhysicalPaht())) ) |
---|
51 | |
---|
52 | cu = queryUtility(ICatalogUpdater, name='catalog_updater') |
---|
53 | cu.updateMetadata4All(catalog, columns) |
---|
54 | |
---|
55 | |
---|
56 | def updateCatalogColumns(context): |
---|
57 | """Update catalog columns with catalog_updater tool. |
---|
58 | """ |
---|
59 | site = context.getSite() |
---|
60 | tool = getToolByName(site, 'portal_catalog') |
---|
61 | |
---|
62 | importObjects(tool, '', context) |
---|