[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones. stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Feb 2011 18:05:39 +0100
branchstable
changeset 6955 a6c32edabc8d
parent 6954 f9a84d54ebf3
child 6956 b172c383dbce
child 6965 343c79c3f04a
[entity, metadata] huuum, use resolvable url as cwuri... And fix existing ones.
hooks/metadata.py
misc/migration/3.10.9_Any.py
--- a/hooks/metadata.py	Wed Feb 09 18:04:04 2011 +0100
+++ b/hooks/metadata.py	Wed Feb 09 18:05:39 2011 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -44,7 +44,7 @@
         edited.setdefault('creation_date', timestamp)
         edited.setdefault('modification_date', timestamp)
         if not self._cw.get_shared_data('do-not-insert-cwuri'):
-            cwuri = u'%seid/%s' % (self._cw.base_url(), self.entity.eid)
+            cwuri = u'%s%s' % (self._cw.base_url(), self.entity.eid)
             edited.setdefault('cwuri', cwuri)
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/migration/3.10.9_Any.py	Wed Feb 09 18:05:39 2011 +0100
@@ -0,0 +1,12 @@
+if confirm('fix existing cwuri?'):
+    from logilab.common.shellutils import ProgressBar
+    from cubicweb.server.session import hooks_control
+    rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"')
+    pb = ProgressBar(nbops=rset.rowcount, size=70)
+    with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
+        for i,  e in enumerate(rset.entities()):
+            e.set_attributes(cwuri=e.cwuri.replace('/eid', ''))
+            if i % 100: # commit every 100 entities to limit memory consumption
+                commit(ask_confirm=False)
+            pb.update()
+    commit(ask_confirm=False)