331 if fix: |
331 if fix: |
332 session.system_sql("UPDATE %s SET %s=%%(v)s WHERE %s=%s ;" |
332 session.system_sql("UPDATE %s SET %s=%%(v)s WHERE %s=%s ;" |
333 % (table, column, eidcolumn, eid), |
333 % (table, column, eidcolumn, eid), |
334 {'v': default}) |
334 {'v': default}) |
335 notify_fixed(fix) |
335 notify_fixed(fix) |
336 cursor = session.system_sql('SELECT MIN(%s) FROM %sCWUser;' % (eidcolumn, |
|
337 SQL_PREFIX)) |
|
338 default_user_eid = cursor.fetchone()[0] |
|
339 assert default_user_eid is not None, 'no user defined !' |
|
340 for rel, default in ( ('owned_by', default_user_eid), ): |
|
341 cursor = session.system_sql("SELECT eid, type FROM entities " |
|
342 "WHERE source='system' AND NOT EXISTS " |
|
343 "(SELECT 1 FROM %s_relation WHERE eid_from=eid);" |
|
344 % rel) |
|
345 for eid, etype in cursor.fetchall(): |
|
346 msg = ' %s with eid %s has no %s relation' |
|
347 print >> sys.stderr, msg % (etype, eid, rel), |
|
348 if fix: |
|
349 session.system_sql('INSERT INTO %s_relation VALUES (%s, %s) ;' |
|
350 % (rel, eid, default)) |
|
351 notify_fixed(fix) |
|
352 |
336 |
353 |
337 |
354 def check(repo, cnx, checks, reindex, fix, withpb=True): |
338 def check(repo, cnx, checks, reindex, fix, withpb=True): |
355 """check integrity of instance's repository, |
339 """check integrity of instance's repository, |
356 using given user and password to locally connect to the repository |
340 using given user and password to locally connect to the repository |