author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 30 Jul 2009 18:51:44 +0200 | |
changeset 2575 | e033939d5664 |
parent 2476 | 1294a6bdf3bf |
child 2596 | d02eed70937f |
permissions | -rw-r--r-- |
0 | 1 |
"""Check integrity of a CubicWeb repository. Hum actually only the system database |
2 |
is checked. |
|
3 |
||
4 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
import sys |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
713
diff
changeset
|
12 |
from datetime import datetime |
0 | 13 |
|
14 |
from logilab.common.shellutils import ProgressBar |
|
15 |
||
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
16 |
from cubicweb.server.sqlutils import SQL_PREFIX |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
17 |
|
0 | 18 |
def has_eid(sqlcursor, eid, eids): |
19 |
"""return true if the eid is a valid eid""" |
|
20 |
if eids.has_key(eid): |
|
21 |
return eids[eid] |
|
22 |
sqlcursor.execute('SELECT type, source FROM entities WHERE eid=%s' % eid) |
|
23 |
try: |
|
24 |
etype, source = sqlcursor.fetchone() |
|
25 |
except: |
|
26 |
eids[eid] = False |
|
27 |
return False |
|
28 |
if source and source != 'system': |
|
29 |
# XXX what to do... |
|
30 |
eids[eid] = True |
|
31 |
return True |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
32 |
sqlcursor.execute('SELECT * FROM %s%s WHERE %seid=%s' % (SQL_PREFIX, etype, |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
33 |
SQL_PREFIX, eid)) |
0 | 34 |
result = sqlcursor.fetchall() |
35 |
if len(result) == 0: |
|
36 |
eids[eid] = False |
|
37 |
return False |
|
38 |
elif len(result) > 1: |
|
39 |
msg = ' More than one entity with eid %s exists in source !' |
|
40 |
print >> sys.stderr, msg % eid |
|
41 |
print >> sys.stderr, ' WARNING : Unable to fix this, do it yourself !' |
|
42 |
eids[eid] = True |
|
43 |
return True |
|
44 |
||
45 |
# XXX move to yams? |
|
46 |
def etype_fti_containers(eschema, _done=None): |
|
47 |
if _done is None: |
|
48 |
_done = set() |
|
49 |
_done.add(eschema) |
|
50 |
containers = tuple(eschema.fulltext_containers()) |
|
51 |
if containers: |
|
52 |
for rschema, target in containers: |
|
53 |
if target == 'object': |
|
54 |
targets = rschema.objects(eschema) |
|
55 |
else: |
|
56 |
targets = rschema.subjects(eschema) |
|
57 |
for targeteschema in targets: |
|
58 |
if targeteschema in _done: |
|
59 |
continue |
|
60 |
_done.add(targeteschema) |
|
61 |
for container in etype_fti_containers(targeteschema, _done): |
|
62 |
yield container |
|
63 |
else: |
|
64 |
yield eschema |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
65 |
|
0 | 66 |
def reindex_entities(schema, session): |
67 |
"""reindex all entities in the repository""" |
|
68 |
# deactivate modification_date hook since we don't want them |
|
69 |
# to be updated due to the reindexation |
|
70 |
from cubicweb.server.hooks import (setmtime_before_update_entity, |
|
71 |
uniquecstrcheck_before_modification) |
|
72 |
from cubicweb.server.repository import FTIndexEntityOp |
|
73 |
repo = session.repo |
|
2248
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
74 |
cursor = session.pool['system'] |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
75 |
if not repo.system_source.indexer.has_fti_table(cursor): |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
76 |
from indexer import get_indexer |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
77 |
print 'no text index table' |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
78 |
indexer = get_indexer(repo.system_source.dbdriver) |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
79 |
# XXX indexer.init_fti(cursor) once index 0.7 is out |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
80 |
indexer.init_extensions(cursor) |
cbf043a2134a
try to create fti table if not existant on rebuild-fti
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
81 |
cursor.execute(indexer.sql_init_fti()) |
0 | 82 |
repo.hm.unregister_hook(setmtime_before_update_entity, |
83 |
'before_update_entity', '') |
|
84 |
repo.hm.unregister_hook(uniquecstrcheck_before_modification, |
|
85 |
'before_update_entity', '') |
|
1161
936c311010fc
ensure do_fti is true in reindex_entities
sylvain.thenault@logilab.fr
parents:
381
diff
changeset
|
86 |
repo.do_fti = True # ensure full-text indexation is activated |
0 | 87 |
etypes = set() |
88 |
for eschema in schema.entities(): |
|
89 |
if eschema.is_final(): |
|
90 |
continue |
|
91 |
indexable_attrs = tuple(eschema.indexable_attributes()) # generator |
|
92 |
if not indexable_attrs: |
|
93 |
continue |
|
94 |
for container in etype_fti_containers(eschema): |
|
95 |
etypes.add(container) |
|
96 |
print 'Reindexing entities of type %s' % \ |
|
97 |
', '.join(sorted(str(e) for e in etypes)) |
|
98 |
pb = ProgressBar(len(etypes) + 1) |
|
99 |
# first monkey patch Entity.check to disable validation |
|
713
5adb6d8e5fa7
update imports of "cubicweb.common.entity" and use the new module path "cubicweb.entity"
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
381
diff
changeset
|
100 |
from cubicweb.entity import Entity |
0 | 101 |
_check = Entity.check |
102 |
Entity.check = lambda self, creation=False: True |
|
103 |
# clear fti table first |
|
104 |
session.system_sql('DELETE FROM %s' % session.repo.system_source.dbhelper.fti_table) |
|
105 |
pb.update() |
|
106 |
# reindex entities by generating rql queries which set all indexable |
|
107 |
# attribute to their current value |
|
108 |
for eschema in etypes: |
|
109 |
for entity in session.execute('Any X WHERE X is %s' % eschema).entities(): |
|
110 |
FTIndexEntityOp(session, entity=entity) |
|
111 |
pb.update() |
|
112 |
# restore Entity.check |
|
113 |
Entity.check = _check |
|
114 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
115 |
|
380 | 116 |
def check_schema(schema, session, eids, fix=1): |
0 | 117 |
"""check serialized schema""" |
118 |
print 'Checking serialized schema' |
|
119 |
unique_constraints = ('SizeConstraint', 'FormatConstraint', |
|
120 |
'VocabularyConstraint', 'RQLConstraint', |
|
121 |
'RQLVocabularyConstraint') |
|
122 |
rql = ('Any COUNT(X),RN,EN,ECTN GROUPBY RN,EN,ECTN ORDERBY 1 ' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
123 |
'WHERE X is CWConstraint, R constrained_by X, ' |
0 | 124 |
'R relation_type RT, R from_entity ET, RT name RN, ' |
125 |
'ET name EN, X cstrtype ECT, ECT name ECTN') |
|
126 |
for count, rn, en, cstrname in session.execute(rql): |
|
127 |
if count == 1: |
|
128 |
continue |
|
129 |
if cstrname in unique_constraints: |
|
130 |
print "ERROR: got %s %r constraints on relation %s.%s" % ( |
|
131 |
count, cstrname, en, rn) |
|
132 |
||
133 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
134 |
|
0 | 135 |
def check_text_index(schema, session, eids, fix=1): |
136 |
"""check all entities registered in the text index""" |
|
137 |
print 'Checking text index' |
|
138 |
cursor = session.system_sql('SELECT uid FROM appears;') |
|
139 |
for row in cursor.fetchall(): |
|
140 |
eid = row[0] |
|
141 |
if not has_eid(cursor, eid, eids): |
|
142 |
msg = ' Entity with eid %s exists in the text index but in no source' |
|
143 |
print >> sys.stderr, msg % eid, |
|
144 |
if fix: |
|
145 |
session.system_sql('DELETE FROM appears WHERE uid=%s;' % eid) |
|
146 |
print >> sys.stderr, ' [FIXED]' |
|
147 |
else: |
|
148 |
print >> sys.stderr |
|
149 |
||
150 |
||
151 |
def check_entities(schema, session, eids, fix=1): |
|
152 |
"""check all entities registered in the repo system table""" |
|
153 |
print 'Checking entities system table' |
|
154 |
cursor = session.system_sql('SELECT eid FROM entities;') |
|
155 |
for row in cursor.fetchall(): |
|
156 |
eid = row[0] |
|
157 |
if not has_eid(cursor, eid, eids): |
|
158 |
msg = ' Entity with eid %s exists in the system table but in no source' |
|
159 |
print >> sys.stderr, msg % eid, |
|
160 |
if fix: |
|
161 |
session.system_sql('DELETE FROM entities WHERE eid=%s;' % eid) |
|
162 |
print >> sys.stderr, ' [FIXED]' |
|
163 |
else: |
|
164 |
print >> sys.stderr |
|
165 |
print 'Checking entities tables' |
|
166 |
for eschema in schema.entities(): |
|
167 |
if eschema.is_final(): |
|
168 |
continue |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
169 |
table = SQL_PREFIX + eschema.type |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
170 |
column = SQL_PREFIX + 'eid' |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
171 |
cursor = session.system_sql('SELECT %s FROM %s;' % (column, table)) |
0 | 172 |
for row in cursor.fetchall(): |
173 |
eid = row[0] |
|
174 |
# eids is full since we have fetched everyting from the entities table, |
|
175 |
# no need to call has_eid |
|
176 |
if not eid in eids or not eids[eid]: |
|
177 |
msg = ' Entity with eid %s exists in the %s table but not in the system table' |
|
178 |
print >> sys.stderr, msg % (eid, eschema.type), |
|
179 |
if fix: |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
180 |
session.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid)) |
0 | 181 |
print >> sys.stderr, ' [FIXED]' |
182 |
else: |
|
183 |
print >> sys.stderr |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
184 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
185 |
|
0 | 186 |
def bad_related_msg(rtype, target, eid, fix): |
187 |
msg = ' A relation %s with %s eid %s exists but no such entity in sources' |
|
188 |
print >> sys.stderr, msg % (rtype, target, eid), |
|
189 |
if fix: |
|
190 |
print >> sys.stderr, ' [FIXED]' |
|
191 |
else: |
|
192 |
print >> sys.stderr |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
193 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
194 |
|
0 | 195 |
def check_relations(schema, session, eids, fix=1): |
196 |
"""check all relations registered in the repo system table""" |
|
197 |
print 'Checking relations' |
|
198 |
for rschema in schema.relations(): |
|
199 |
if rschema.is_final(): |
|
200 |
continue |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
201 |
if rschema == 'identity': |
0 | 202 |
continue |
203 |
if rschema.inlined: |
|
204 |
for subjtype in rschema.subjects(): |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
205 |
table = SQL_PREFIX + str(subjtype) |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
206 |
column = SQL_PREFIX + str(rschema) |
380 | 207 |
sql = 'SELECT %s FROM %s WHERE %s IS NOT NULL;' % ( |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
208 |
column, table, column) |
380 | 209 |
cursor = session.system_sql(sql) |
0 | 210 |
for row in cursor.fetchall(): |
211 |
eid = row[0] |
|
212 |
if not has_eid(cursor, eid, eids): |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
213 |
bad_related_msg(rschema, 'object', eid, fix) |
0 | 214 |
if fix: |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
215 |
sql = 'UPDATE %s SET %s = NULL WHERE %seid=%s;' % ( |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
216 |
table, column, SQL_PREFIX, eid) |
381 | 217 |
session.system_sql(sql) |
0 | 218 |
continue |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
219 |
cursor = session.system_sql('SELECT eid_from FROM %s_relation;' % rschema) |
0 | 220 |
for row in cursor.fetchall(): |
221 |
eid = row[0] |
|
222 |
if not has_eid(cursor, eid, eids): |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
223 |
bad_related_msg(rschema, 'subject', eid, fix) |
0 | 224 |
if fix: |
380 | 225 |
sql = 'DELETE FROM %s_relation WHERE eid_from=%s;' % ( |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
226 |
rschema, eid) |
380 | 227 |
session.system_sql(sql) |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
228 |
cursor = session.system_sql('SELECT eid_to FROM %s_relation;' % rschema) |
0 | 229 |
for row in cursor.fetchall(): |
230 |
eid = row[0] |
|
231 |
if not has_eid(cursor, eid, eids): |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
232 |
bad_related_msg(rschema, 'object', eid, fix) |
0 | 233 |
if fix: |
380 | 234 |
sql = 'DELETE FROM %s_relation WHERE eid_to=%s;' % ( |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
235 |
rschema, eid) |
380 | 236 |
session.system_sql(sql) |
0 | 237 |
|
238 |
||
239 |
def check_metadata(schema, session, eids, fix=1): |
|
240 |
"""check entities has required metadata |
|
241 |
||
242 |
FIXME: rewrite using RQL queries ? |
|
243 |
""" |
|
244 |
print 'Checking metadata' |
|
245 |
cursor = session.system_sql("SELECT DISTINCT type FROM entities;") |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
246 |
eidcolumn = SQL_PREFIX + 'eid' |
0 | 247 |
for etype, in cursor.fetchall(): |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
248 |
table = SQL_PREFIX + etype |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
713
diff
changeset
|
249 |
for rel, default in ( ('creation_date', datetime.now()), |
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
713
diff
changeset
|
250 |
('modification_date', datetime.now()), ): |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
251 |
column = SQL_PREFIX + rel |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
252 |
cursor = session.system_sql("SELECT %s FROM %s WHERE %s is NULL" |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
253 |
% (eidcolumn, table, column)) |
0 | 254 |
for eid, in cursor.fetchall(): |
255 |
msg = ' %s with eid %s has no %s' |
|
256 |
print >> sys.stderr, msg % (etype, eid, rel), |
|
257 |
if fix: |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
258 |
session.system_sql("UPDATE %s SET %s=%%(v)s WHERE %s=%s ;" |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
259 |
% (table, column, eidcolumn, eid), |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
260 |
{'v': default}) |
0 | 261 |
print >> sys.stderr, ' [FIXED]' |
262 |
else: |
|
263 |
print >> sys.stderr |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
264 |
cursor = session.system_sql('SELECT MIN(%s) FROM %sCWUser;' % (eidcolumn, |
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
1161
diff
changeset
|
265 |
SQL_PREFIX)) |
0 | 266 |
default_user_eid = cursor.fetchone()[0] |
267 |
assert default_user_eid is not None, 'no user defined !' |
|
268 |
for rel, default in ( ('owned_by', default_user_eid), ): |
|
269 |
cursor = session.system_sql("SELECT eid, type FROM entities " |
|
270 |
"WHERE NOT EXISTS " |
|
271 |
"(SELECT 1 FROM %s_relation WHERE eid_from=eid);" |
|
272 |
% rel) |
|
273 |
for eid, etype in cursor.fetchall(): |
|
274 |
msg = ' %s with eid %s has no %s relation' |
|
275 |
print >> sys.stderr, msg % (etype, eid, rel), |
|
276 |
if fix: |
|
277 |
session.system_sql('INSERT INTO %s_relation VALUES (%s, %s) ;' |
|
278 |
% (rel, eid, default)) |
|
279 |
print >> sys.stderr, ' [FIXED]' |
|
280 |
else: |
|
281 |
print >> sys.stderr |
|
282 |
||
283 |
||
284 |
def check(repo, cnx, checks, reindex, fix): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2248
diff
changeset
|
285 |
"""check integrity of instance's repository, |
0 | 286 |
using given user and password to locally connect to the repository |
287 |
(no running cubicweb server needed) |
|
288 |
""" |
|
289 |
session = repo._get_session(cnx.sessionid, setpool=True) |
|
290 |
# yo, launch checks |
|
291 |
if checks: |
|
292 |
eids_cache = {} |
|
293 |
for check in checks: |
|
294 |
check_func = globals()['check_%s' % check] |
|
295 |
check_func(repo.schema, session, eids_cache, fix=fix) |
|
296 |
if fix: |
|
297 |
cnx.commit() |
|
298 |
else: |
|
299 |
print |
|
300 |
if not fix: |
|
301 |
print 'WARNING: Diagnostic run, nothing has been corrected' |
|
302 |
if reindex: |
|
303 |
cnx.rollback() |
|
304 |
session.set_pool() |
|
305 |
reindex_entities(repo.schema, session) |
|
306 |
cnx.commit() |