misc/migration/3.10.9_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Mar 2011 17:55:15 +0100
branchstable
changeset 7054 c8f12ab250b7
parent 7050 3f2857704444
child 7104 62c880e5d980
permissions -rw-r--r--
Add a "closed" property on session This will simplify check and allow nicer error thatn the current "no _tx_data" attribute error.

from __future__ import with_statement
import sys

# fix some corrupted entities noticed on several instances
rql('DELETE CWConstraint X WHERE NOT E constrained_by X')
rql('SET X is_instance_of Y WHERE X is Y, NOT X is_instance_of Y')
commit()

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/%"')
    if sys.stdout.isatty():
        pb = ProgressBar(nbops=rset.rowcount, size=70)
    else:
        pb = None
    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)
            if pb is not None:
                pb.update()
    commit(ask_confirm=False)

try:
    from cubicweb import devtools
    option_group_changed('anonymous-user', 'main', 'web')
    option_group_changed('anonymous-password', 'main', 'web')
except ImportError:
    # cubicweb-dev unavailable, nothing needed
    pass