[1759] | 1 | """Catalog tool columns updater setup handlers. |
---|
| 2 | """ |
---|
| 3 | from zope.component import adapts |
---|
| 4 | from zope.component import queryUtility |
---|
| 5 | |
---|
[1760] | 6 | from Products.ZCatalog.interfaces import IZCatalog |
---|
[1759] | 7 | from Products.GenericSetup.interfaces import ISetupEnviron |
---|
[1760] | 8 | from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter |
---|
[1759] | 9 | |
---|
[1760] | 10 | from quintagroup.catalogupdater.interfaces import ICatalogUpdater |
---|
[1759] | 11 | |
---|
| 12 | |
---|
[1760] | 13 | class CatalogUpdaterXMLAdapter(ZCatalogXMLAdapter): |
---|
| 14 | """XML im- and exporter for ZCatalog with |
---|
| 15 | support of columns updates |
---|
[1759] | 16 | """ |
---|
| 17 | |
---|
[1760] | 18 | adapts(IZCatalog, ISetupEnviron) |
---|
[1759] | 19 | |
---|
[1760] | 20 | def _initColumns(self, node): |
---|
| 21 | super(CatalogUpdaterXMLAdapter, self)._initColumns(node) |
---|
| 22 | import pdb;pdb.set_trace() |
---|
| 23 | updatecols = [] |
---|
[1759] | 24 | for child in node.childNodes: |
---|
| 25 | if child.nodeName != 'column': |
---|
| 26 | continue |
---|
[1760] | 27 | col = str(child.getAttribute('value')) |
---|
| 28 | if child.hasAttribute('update'): |
---|
| 29 | # Add the column to update list if it is there |
---|
| 30 | if col in self.context.schema()[:]: |
---|
| 31 | updatecols.append(col) |
---|
| 32 | continue |
---|
[1759] | 33 | |
---|
| 34 | # Update columns in catalog |
---|
[1760] | 35 | if len(updatecols) > 0: |
---|
[1759] | 36 | catalog = self.context |
---|
| 37 | |
---|
| 38 | self._logger.info('Updating %s columns for %s Catalog.' % ( |
---|
[1760] | 39 | updatecols, '/'.join(catalog.getPhysicalPaht())) ) |
---|
[1759] | 40 | |
---|
| 41 | cu = queryUtility(ICatalogUpdater, name='catalog_updater') |
---|
[1760] | 42 | cu.updateMetadata4All(catalog, updatecols) |
---|