misc/migration/3.10.9_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 02 Jul 2013 17:07:34 +0200
changeset 9460 a2a0bc984863
parent 8694 d901c36bcfce
child 11178 b3d3e23be27b
permissions -rw-r--r--
[config] cleanup/refactor server sources file values handling * kill former `sources` method, misnamed since we've only the system source configuration in the sources file (and some default admin account information) * introduce new system_source_config and default_admin_config properties to access to the two information in this file Then use one or the other when appropriate

import sys

if confirm('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 progress
    from cubicweb.server.session import hooks_control
    rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"')
    title = "%i entities to fix" % len(rset)
    nbops = rset.rowcount
    enabled = interactive_mode
    with progress(title=title, nbops=nbops, size=30, enabled=enabled) as pb:
        for i,  row in enumerate(rset):
            with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
                data = {'eid': row[0], 'cwuri': row[1].replace(u'/eid', u'')}
                rql('SET X cwuri %(cwuri)s WHERE X eid %(eid)s', data)
            if not i % 100: # commit every 100 entities to limit memory consumption
                pb.text = "%i committed" % i
                commit(ask_confirm=False)
            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