Commit c5527fff authored by Shane Hathaway's avatar Shane Hathaway

Changed ZCTextIndex to store a lexicon ID rather than a physical path to the

lexicon.  Before this, it was not safe to move, rename, or mount in a
different location a ZCatalog containing a ZCTextIndex.

In general, we need to avoid physical paths when a simple ID will suffice.
parent 0c6de141
...@@ -20,6 +20,7 @@ from types import TupleType ...@@ -20,6 +20,7 @@ from types import TupleType
import ZODB import ZODB
from Persistence import Persistent from Persistence import Persistent
import Acquisition import Acquisition
from Acquisition import aq_base, aq_inner, aq_parent
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from Globals import DTMLFile, InitializeClass from Globals import DTMLFile, InitializeClass
...@@ -81,7 +82,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -81,7 +82,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
'ZCTextIndex Lexicon interface' 'ZCTextIndex Lexicon interface'
% lexicon.getId()) % lexicon.getId())
self.lexicon_path = lexicon.getPhysicalPath() self.lexicon_id = lexicon.getId()
self._v_lexicon = lexicon self._v_lexicon = lexicon
if index_factory is None: if index_factory is None:
...@@ -102,17 +103,25 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -102,17 +103,25 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
def getLexicon(self): def getLexicon(self):
"""Get the lexicon for this index """Get the lexicon for this index
""" """
if hasattr(self, 'lexicon'): if hasattr(aq_base(self), 'lexicon'):
# Fix up old ZCTextIndexes by removing direct lexicon ref # Fix up old ZCTextIndexes by removing direct lexicon ref
# and changing it to a path # and changing it to an ID
lexicon = getattr(self.aq_parent, self.lexicon.getId()) lexicon = getattr(aq_parent(aq_inner(self)), self.lexicon.getId())
self.lexicon_path = lexicon.getPhysicalPath() self.lexicon_id = lexicon.getId()
del self.lexicon del self.lexicon
if getattr(aq_base(self), 'lexicon_path', None):
# Fix up slightly less old ZCTextIndexes by removing
# the physical path and changing it to an ID.
# There's no need to use a physical path, which otherwise
# makes it difficult to move or rename ZCatalogs.
self.lexicon_id = self.lexicon_path[-1]
del self.lexicon_path
try: try:
return self._v_lexicon return self._v_lexicon
except AttributeError: except AttributeError:
lexicon = self.unrestrictedTraverse(self.lexicon_path) lexicon = getattr(aq_parent(aq_inner(self)), self.lexicon_id)
if not ILexicon.isImplementedBy(lexicon): if not ILexicon.isImplementedBy(lexicon):
raise TypeError('Object "%s" is not a ZCTextIndex Lexicon' raise TypeError('Object "%s" is not a ZCTextIndex Lexicon'
% lexicon.getId()) % lexicon.getId())
...@@ -214,13 +223,15 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -214,13 +223,15 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
"""Return indexed attribute name""" """Return indexed attribute name"""
return self._fieldname return self._fieldname
def getLexiconPath(self): def getLexiconURL(self):
"""Return the path of the lexicon used by the index""" """Return the url of the lexicon used by the index"""
try: try:
self.getLexicon() # Make sure the path is set lex = self.getLexicon()
return '/'.join(self.lexicon_path) except (KeyError, AttributeError):
except KeyError: return None
return else:
return lex.absolute_url()
InitializeClass(ZCTextIndex) InitializeClass(ZCTextIndex)
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
</p> </p>
<p class="form-help"> <p class="form-help">
ZCTextIndex Lexicon used: ZCTextIndex Lexicon used:
<dtml-if getLexiconPath> <dtml-if getLexiconURL>
<a href="<dtml-var getLexiconPath>/manage_main" <a href="<dtml-var getLexiconURL>/manage_main"
><dtml-var getLexiconPath></a> ><dtml-var getLexiconURL></a>
<dtml-else> <dtml-else>
<em>(Lexicon Not Found)</em> <em>(Lexicon Not Found)</em>
</dtml-if> </dtml-if>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment