misc/migration/3.10.9_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 18 Feb 2011 17:11:00 +0100
changeset 7023 50defc197448
parent 6955 a6c32edabc8d
child 7026 2c65dd2cbfff
permissions -rw-r--r--
Added tag cubicweb-debian-version-3.11.0-1 for changeset 8daabda9f571

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)