|
1 """execute this script if you've migration to file >= 1.9.0 with cubicweb <= 3.9.2 |
|
2 |
|
3 FYI, this migration occurred : |
|
4 * on our intranet on July 07 2010 |
|
5 * on our extranet on July 16 2010 |
|
6 """ |
|
7 from __future__ import print_function |
|
8 |
|
9 try: |
|
10 backupinstance, = __args__ |
|
11 except ValueError: |
|
12 print('USAGE: cubicweb-ctl shell <instance> repair_file_1-9_migration.py -- <backup instance id>') |
|
13 print() |
|
14 print('you should restored the backup on a new instance, accessible through pyro') |
|
15 |
|
16 from cubicweb import cwconfig, dbapi |
|
17 from cubicweb.server.session import hooks_control |
|
18 |
|
19 defaultadmin = repo.config.default_admin_config |
|
20 backupcfg = cwconfig.instance_configuration(backupinstance) |
|
21 backupcfg.repairing = True |
|
22 backuprepo, backupcnx = dbapi.in_memory_repo_cnx(backupcfg, defaultadmin['login'], |
|
23 password=defaultadmin['password'], |
|
24 host='localhost') |
|
25 backupcu = backupcnx.cursor() |
|
26 |
|
27 with hooks_control(session, session.HOOKS_DENY_ALL): |
|
28 rql('SET X is Y WHERE X is File, Y name "File", NOT X is Y') |
|
29 rql('SET X is_instance_of Y WHERE X is File, Y name "File", NOT X is_instance_of Y') |
|
30 for rtype, in backupcu.execute('DISTINCT Any RTN WHERE X relation_type RT, RT name RTN,' |
|
31 'X from_entity Y, Y name "Image", X is CWRelation, ' |
|
32 'EXISTS(XX is CWRelation, XX relation_type RT, ' |
|
33 'XX from_entity YY, YY name "File")'): |
|
34 if rtype in ('is', 'is_instance_of'): |
|
35 continue |
|
36 print(rtype) |
|
37 for feid, xeid in backupcu.execute('Any F,X WHERE F %s X, F is IN (File,Image)' % rtype): |
|
38 print('restoring relation %s between file %s and %s' % (rtype, feid, xeid), end=' ') |
|
39 print(rql('SET F %s X WHERE F eid %%(f)s, X eid %%(x)s, NOT F %s X' % (rtype, rtype), |
|
40 {'f': feid, 'x': xeid})) |
|
41 |
|
42 for rtype, in backupcu.execute('DISTINCT Any RTN WHERE X relation_type RT, RT name RTN,' |
|
43 'X to_entity Y, Y name "Image", X is CWRelation, ' |
|
44 'EXISTS(XX is CWRelation, XX relation_type RT, ' |
|
45 'XX to_entity YY, YY name "File")'): |
|
46 print(rtype) |
|
47 for feid, xeid in backupcu.execute('Any F,X WHERE X %s F, F is IN (File,Image)' % rtype): |
|
48 print('restoring relation %s between %s and file %s' % (rtype, xeid, feid), end=' ') |
|
49 print(rql('SET X %s F WHERE F eid %%(f)s, X eid %%(x)s, NOT X %s F' % (rtype, rtype), |
|
50 {'f': feid, 'x': xeid})) |
|
51 |
|
52 commit() |