|
1 import sys |
|
2 |
|
3 if confirm('fix some corrupted entities noticed on several instances?'): |
|
4 rql('DELETE CWConstraint X WHERE NOT E constrained_by X') |
|
5 rql('SET X is_instance_of Y WHERE X is Y, NOT X is_instance_of Y') |
|
6 commit() |
|
7 |
|
8 if confirm('fix existing cwuri?'): |
|
9 from logilab.common.shellutils import progress |
|
10 from cubicweb.server.session import hooks_control |
|
11 rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"') |
|
12 title = "%i entities to fix" % len(rset) |
|
13 nbops = rset.rowcount |
|
14 enabled = interactive_mode |
|
15 with progress(title=title, nbops=nbops, size=30, enabled=enabled) as pb: |
|
16 for i, row in enumerate(rset): |
|
17 with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'): |
|
18 data = {'eid': row[0], 'cwuri': row[1].replace(u'/eid', u'')} |
|
19 rql('SET X cwuri %(cwuri)s WHERE X eid %(eid)s', data) |
|
20 if not i % 100: # commit every 100 entities to limit memory consumption |
|
21 pb.text = "%i committed" % i |
|
22 commit(ask_confirm=False) |
|
23 pb.update() |
|
24 commit(ask_confirm=False) |
|
25 |
|
26 try: |
|
27 from cubicweb import devtools |
|
28 option_group_changed('anonymous-user', 'main', 'web') |
|
29 option_group_changed('anonymous-password', 'main', 'web') |
|
30 except ImportError: |
|
31 # cubicweb-dev unavailable, nothing needed |
|
32 pass |