184 if fix: |
184 if fix: |
185 cnx.system_sql('DELETE FROM entities WHERE eid=%s;' % eid) |
185 cnx.system_sql('DELETE FROM entities WHERE eid=%s;' % eid) |
186 notify_fixed(fix) |
186 notify_fixed(fix) |
187 # source in entities, but no relation cw_source |
187 # source in entities, but no relation cw_source |
188 # XXX this (get_versions) requires a second connection to the db when we already have one open |
188 # XXX this (get_versions) requires a second connection to the db when we already have one open |
189 applcwversion = cnx.repo.get_versions().get('cubicweb') |
189 cursor = cnx.system_sql('SELECT e.eid FROM entities as e, cw_CWSource as s ' |
190 if applcwversion >= (3, 13, 1): # entities.asource appeared in 3.13.1 |
190 'WHERE NOT EXISTS(SELECT 1 FROM cw_source_relation as cs ' |
191 cursor = cnx.system_sql('SELECT e.eid FROM entities as e, cw_CWSource as s ' |
191 ' WHERE cs.eid_from=e.eid) ' |
192 'WHERE s.cw_name=e.asource AND ' |
192 'ORDER BY e.eid') |
193 'NOT EXISTS(SELECT 1 FROM cw_source_relation as cs ' |
193 msg = (' Entity with eid %s is missing relation cw_source (autofix will create the relation)\n') |
194 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid) ' |
194 for row in cursor.fetchall(): |
195 'ORDER BY e.eid') |
195 sys.stderr.write(msg % row[0]) |
196 msg = (' Entity with eid %s refers to source in entities table, ' |
196 if fix: |
197 'but is missing relation cw_source (autofix will create the relation)\n') |
197 cnx.system_sql('INSERT INTO cw_source_relation (eid_from, eid_to) ' |
198 for row in cursor.fetchall(): |
198 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWSource as s ' |
199 sys.stderr.write(msg % row[0]) |
199 "WHERE s.cw_name='system' AND NOT EXISTS(SELECT 1 FROM cw_source_relation as cs " |
200 if fix: |
200 ' WHERE cs.eid_from=e.eid)') |
201 cnx.system_sql('INSERT INTO cw_source_relation (eid_from, eid_to) ' |
201 notify_fixed(True) |
202 'SELECT e.eid, s.cw_eid FROM entities as e, cw_CWSource as s ' |
|
203 'WHERE s.cw_name=e.asource AND NOT EXISTS(SELECT 1 FROM cw_source_relation as cs ' |
|
204 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid)') |
|
205 notify_fixed(True) |
|
206 # inconsistencies for 'is' |
202 # inconsistencies for 'is' |
207 msg = ' %s #%s is missing relation "is" (autofix will create the relation)\n' |
203 msg = ' %s #%s is missing relation "is" (autofix will create the relation)\n' |
208 cursor = cnx.system_sql('SELECT e.type, e.eid FROM entities as e, cw_CWEType as s ' |
204 cursor = cnx.system_sql('SELECT e.type, e.eid FROM entities as e, cw_CWEType as s ' |
209 'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_relation as cs ' |
205 'WHERE s.cw_name=e.type AND NOT EXISTS(SELECT 1 FROM is_relation as cs ' |
210 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid) ' |
206 ' WHERE cs.eid_from=e.eid AND cs.eid_to=s.cw_eid) ' |