def upgrade(self, toVersion="0.3.7"): from config import VERSION toVersion = VERSION current_version = getattr(self, "__current_version", "0.5") if toVersion >= "0.3.5" and current_version < "0.3.5": _changeQuesCatalog(self) if toVersion >= "0.3.6" and current_version < "0.3.6": _publicQuesToDraft(self) if toVersion >= "0.3.7" and current_version < "0.3.7": _changeTestsCatalog(self) if toVersion >= "0.5" and current_version < "0.5": _fixWorkflow(self) _replaceACL(self) if toVersion >= "0.6" and current_version < "0.6": _addGroupsCatalog(self) if toVersion >= "0.6.1" and current_version < "0.6.1": # added status field for tests and changed catalog accordingly _testsStatusToPrivate(self) _changeTestsCatalog(self) _updateConf(self) self.__current_version = toVersion return "Migrated from %s to %s" % (current_version, toVersion) def _testsStatusToPrivate(self): tests = self.tests.objectValues() for test in tests: test.setStatus('private') test.reindex_object() def _replaceACL(self): from Products.PluggableAuthService.Extensions.upgrade import _replaceUserFolder, replace_acl_users replace_acl_users(self) self._setupPAS() def _fixWorkflow(self): errn = 0 for x in self.questions.objectValues(): state = 'draft' try: state = x.workflow_history['qtauthor_workflow'][-1]['review_state'] except AttributeError: print ">>", x errn += 1 x.setStatus(state) print "error:", errn def _changeQuesCatalog(self): cat_ques = self._getOb('cat_ques') cat_ques.delIndex('fulltext') class attrs: doc_attr = 'getId, getTitle, getQuestion, getKeywordsTuple, getAuthor' lexicon_id = 'lexicon' index_type = 'Cosine Measure' cat_ques.addIndex('fulltext', 'ZCTextIndex', attrs()) ques_objs = self.questions.objectValues() for ques in ques_objs: try: ques.reindex_object() except UnicodeDecodeError: print ques, 'unicodeerror' def _publicQuesToDraft(self): ques_objs = self.questions.objectValues() for ques in ques_objs: if ques.getStatus() == 'public': ques.changeStatus('to_draft') try: ques.reindex_object() except UnicodeDecodeError: print ques, 'unicodeerror' def _changeTestsCatalog(self): self._delObject('cat_tests') from Products.ZCatalog.ZCatalog import ZCatalog catalog_tests = ZCatalog('zcatalog', 'ZCatalog for tests') class largs: def __init__(self, **kw): self.__dict__.update(kw) from Products.ZCTextIndex.ZCTextIndex import manage_addLexicon manage_addLexicon(catalog_tests, 'lexicon', elements=[ largs(group= 'Stop Words', name= " Don't remove stop words" ), largs(group= 'Word Splitter' , name= "QTAuthor Unicode Whitespace splitter" ), ] ) class attrs: doc_attr = 'getId, getTitle, getDescription, getKeywordsTuple, getUser, getAuthor' lexicon_id = 'lexicon' index_type = 'Cosine Measure' catalog_tests.addIndex('fulltext', 'ZCTextIndex', attrs()) catalog_tests.addIndex('getTitle', 'FieldIndex') catalog_tests.addIndex('getDescription', 'FieldIndex') catalog_tests.addIndex('getKeywords', 'KeywordIndex') catalog_tests.addIndex('getLanguage', 'FieldIndex') catalog_tests.addIndex('getDifficulty', 'FieldIndex') catalog_tests.addIndex('getLicence', 'FieldIndex') catalog_tests.addIndex('getUser', 'FieldIndex') catalog_tests.addIndex('getAuthor', 'FieldIndex') catalog_tests.addIndex('getStatus', 'FieldIndex') catalog_tests.addIndex('getLastChange', 'FieldIndex') catalog_tests.addIndex('getQuestions', 'KeywordIndex') catalog_tests.addIndex('getErased', 'FieldIndex') catalog_tests.addColumn('getId') catalog_tests.addColumn('getTitle') catalog_tests.addColumn('getKeywords') catalog_tests.addColumn('getLanguage') catalog_tests.addColumn('getDifficulty') catalog_tests.addColumn('getLicence') catalog_tests.addColumn('getUser') catalog_tests.addColumn('getAuthor') catalog_tests.addColumn('getStatus') catalog_tests.addColumn('getNumQuestions') catalog_tests.addColumn('getLastChange') catalog_tests.addColumn('getQuestions') catalog_tests.addColumn('getErased') self._setObject('cat_tests', catalog_tests) tests_objs = self.tests.objectValues() for test in tests_objs: test.index_object() def _addGroupsCatalog(self): # setup catalog for groups from Products.ZCatalog.ZCatalog import ZCatalog from Products.ZCTextIndex.ZCTextIndex import manage_addLexicon class largs: def __init__(self, **kw): self.__dict__.update(kw) catalog_groups = ZCatalog('zcatalog', 'ZCatalog for groups') manage_addLexicon(catalog_groups, 'lexicon', elements=[ largs(group= 'Stop Words', name= " Don't remove stop words" ), largs(group= 'Word Splitter' , name= "QTAuthor Unicode Whitespace splitter" ), ] ) class attrs: doc_attr = 'getId, getTitle, getDescription, getUser' lexicon_id = 'lexicon' index_type = 'Cosine Measure' catalog_groups.addIndex('fulltext', 'ZCTextIndex', attrs()) catalog_groups.addIndex('getTitle', 'FieldIndex') catalog_groups.addIndex('getUser', 'FieldIndex') catalog_groups.addIndex('getMembers', 'KeywordIndex') catalog_groups.addIndex('getTests', 'KeywordIndex') catalog_groups.addColumn('getId') catalog_groups.addColumn('getTitle') catalog_groups.addColumn('getDescription') catalog_groups.addColumn('getUser') catalog_groups.addColumn('getMembers') catalog_groups.addColumn('getTests') self._setObject('cat_groups', catalog_groups) groups_objs = self.groups.objectValues() for group in groups_objs: print "group: ", group group.default_catalog = 'cat_groups' group.index_object() def _updateConf(self): self.configuration.reload()