Skip to content

Commit

Permalink
add 2 custom sql checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed May 14, 2020
1 parent ed3d2bd commit 660d74d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
7 changes: 7 additions & 0 deletions doc/changelogs/changelog-0.21.0-to-0.22.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
changelog from version 0.21.0 to 0.22.0

. added one custom SQL check for ezflow blocks

. added one custom SQL check for contents which are descendants of themselves

. changed the sorting order of the list of custom SQL checks
7 changes: 5 additions & 2 deletions doc/todo
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

. allow cli scripts to connect to a different database: done for checkschema.php... is it useful for the others?

. start planning for the "bundle" version: load all field defs from services, use built-in validations etc...

. separate checks on data structure from checks on data

. add a return code to the cli script so that it can be easily used by monitoring systems (nagios etc)

. start planning for the "bundle" version: load all field defs from services, use built-in validations etc...

# database checking

. check coherence of data_type string between ezcoa and ezcca

. review SQL for ezflow_blocks_with_invalid_zones: can it be made more similar to leftover_ezflow_blocks (and viceversa?)

. allow FKs of a table with itself (eg. for node and eztags parents)

. verify if there are more FKs than the ones we know about / some of the current ones to tweak
Expand Down
2 changes: 1 addition & 1 deletion extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<software>
<metadata>
<name>eZ DB Integrity extension</name>
<version>0.21.0</version>
<version>0.22.0</version>
<copyright>Copyright (C) 2014-2020 Gaetano Giunta</copyright>
<license>GNU General Public License v2.0</license>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion ezinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static function info()
{
return array(
'Name' => "<a href=\"http://projects.ez.no/ezdbintegrity\">eZ DB Integrity extension</a>",
'Version' => "0.21.0",
'Version' => "0.22.0",
'Copyright' => "Copyright (C) 2014-2020 Gaetano Giunta",
'License' => "GNU General Public License v2.0"
);
Expand Down
29 changes: 19 additions & 10 deletions settings/ezdbintegrity.ini
Original file line number Diff line number Diff line change
Expand Up @@ -271,33 +271,42 @@ ezx_mbpaex[]=contentobject_id::ezcontentobject::id

[CustomQueries]
sections_with_same_identifier[sql]=SELECT identifier, COUNT(*) AS identical_identifiers FROM ezsection GROUP BY identifier HAVING COUNT(*) > 1

classes_with_same_identifier[sql]=SELECT identifier, COUNT(*) AS identical_identifiers FROM ezcontentclass WHERE version = 0 GROUP BY identifier HAVING COUNT(*) > 1
classes_with_double_attributes[sql]=SELECT contentclass_id, identifier, COUNT(*) AS identical_identifiers FROM ezcontentclass_attribute WHERE version = 0 GROUP BY identifier, contentclass_id HAVING COUNT(*) > 1
urlaliases_without_nodes[sql]=SELECT parent, text_md5, action FROM ezurlalias_ml LEFT JOIN ezcontentobject_tree ON substr(action, 8) = node_id WHERE action_type = 'eznode' AND is_original = 1 AND node_id is null
nodes_without_urlaliases[sql]=SELECT node_id FROM ezcontentobject_tree LEFT JOIN ezurlalias_ml ON node_id = substr(action, 8) WHERE depth > 0 AND action_type = 'eznode' AND is_original = 1 AND ezurlalias_ml.id IS NULL

objects_with_many_published_versions[sql]=SELECT contentobject_id, count(*) FROM ezcontentobject_version WHERE status = 1 GROUP BY contentobject_id HAVING COUNT(*) > 1
objects_with_many_states_in_one_group[sql]=SELECT l.contentobject_id, s.group_id, count(*) as count FROM ezcobj_state s, ezcobj_state_link l WHERE l.contentobject_state_id = s.id GROUP BY s.group_id, l.contentobject_id HAVING count(*) > 1
objects_with_wrong_number_of_states_assigned[sql]=SELECT contentobject_id, count(*) as states FROM ezcobj_state_link l GROUP BY l.contentobject_id HAVING count(*) != (SELECT count(*) FROM ezcobj_state_group)
nodes_with_wrong_depth[sql]=SELECT c.node_id FROM ezcontentobject_tree c, ezcontentobject_tree p WHERE c.parent_node_id = p.node_id AND c.depth != ( p.depth + 1 ) AND c.node_id != 1
objects_with_multiple_main_nodes[sql]=SELECT id, COUNT(DISTINCT main_node_id) FROM ezcontentobject o, ezcontentobject_tree n WHERE o.id = n.contentobject_id GROUP BY id, main_node_id HAVING COUNT(DISTINCT main_node_id) > 1
objects_multilocated_under_a_node[sql]=SELECT parent_node_id, contentobject_id, COUNT(*) FROM ezcontentobject_tree GROUP BY parent_node_id, contentobject_id HAVING COUNT(*) > 1 ORDER BY parent_node_id, contentobject_id
# @todo we should really check using AND on languages table
objects_without_languages[sql]= SELECT id FROM ezcontentobject WHERE language_mask = 0
object_versions_without_languages[sql]= SELECT id FROM ezcontentobject_version WHERE language_mask = 0
objects_versions_with_bad_attribute_count[sql]=select * from ( select count(*) as objattributes, contentobject_id, version, language_code, contentclass_id as contentclass_id_o from ezcontentobject_attribute coa, ezcontentobject co where coa.contentobject_id = co.id group by version, contentobject_id, contentclass_id, language_code ) q1, ( select count(*) as classattributes, contentclass_id from ezcontentclass_attribute cca, ezcontentclass cc where cca.contentclass_id = cc.id and cca.version = cc.version and cc.version = 0 group by cc.id, cc.version ) q2 where q1.contentclass_id_o = q2.contentclass_id and q1.objattributes <> q2.classattributes
# for the one below, do we need to account as well for version states 2 and 4 ?
#draft_objects_with_no_draft_versions[sql]=SELECT * FROM ezcontentobject WHERE status = 0 AND id NOT IN ( SELECT contentobject_id FROM ezcontentobject_version WHERE status IN (0, 5) )

objects_with_multiple_main_nodes[sql]=SELECT id, COUNT(DISTINCT main_node_id) FROM ezcontentobject o, ezcontentobject_tree n WHERE o.id = n.contentobject_id GROUP BY id, main_node_id HAVING COUNT(DISTINCT main_node_id) > 1
objects_without_a_main_node[sql]=SELECT id FROM ezcontentobject WHERE status = 1 AND id NOT IN (SELECT contentobject_id FROM ezcontentobject_tree WHERE main_node_id = node_id)
objects_multilocated_under_a_node[sql]=SELECT parent_node_id, contentobject_id, COUNT(*) FROM ezcontentobject_tree GROUP BY parent_node_id, contentobject_id HAVING COUNT(*) > 1 ORDER BY parent_node_id, contentobject_id
objects_descendants_of_themselves[sql]=SELECT t1.node_id as node_id_1, t2.node_id as node_id_2, o.id as obj_id FROM ezcontentobject o, ezcontentobject_tree t1, ezcontentobject_tree t2 WHERE o.id = t1.contentobject_id AND o.id = t2.contentobject_id AND t1.node_id != t2.node_id AND t2.path_string like concat('%/',t1.node_id,'/_%')
children_of_non_container_parents[sql]=SELECT pclass.identifier as parent_class, count(*) as children FROM ezcontentobject_tree child, ezcontentobject_tree parent, ezcontentobject pobj, ezcontentclass pclass WHERE (pclass.is_container != 1 or pclass.is_container is null) AND child.parent_node_id = parent.node_id AND parent.contentobject_id = pobj.id AND pobj.contentclass_id = pclass.id GROUP BY pclass.id ORDER BY pclass.identifier
related_nodes_with_different_objects[sql]=SELECT main_node_id, COUNT(DISTINCT contentobject_id) FROM ezcontentobject_tree GROUP BY main_node_id HAVING COUNT(DISTINCT contentobject_id) > 1
visible_but_hidden_nodes[sql]=SELECT node_id, is_hidden, is_invisible FROM ezcontentobject_tree WHERE is_hidden=1 AND is_invisible=0
objects_versions_with_bad_attribute_count[sql]=select * from ( select count(*) as objattributes, contentobject_id, version, language_code, contentclass_id as contentclass_id_o from ezcontentobject_attribute coa, ezcontentobject co where coa.contentobject_id = co.id group by version, contentobject_id, contentclass_id, language_code ) q1, ( select count(*) as classattributes, contentclass_id from ezcontentclass_attribute cca, ezcontentclass cc where cca.contentclass_id = cc.id and cca.version = cc.version and cc.version = 0 group by cc.id, cc.version ) q2 where q1.contentclass_id_o = q2.contentclass_id and q1.objattributes <> q2.classattributes
# nb: the following query can create a huge temp table!
ezflow_blocks_with_invalid_zones[sql]=SELECT * FROM ezm_block WHERE zone_id NOT IN ( SELECT DISTINCT ( SUBSTRING( a.data_text, LOCATE( '<zone id="id_', a.data_text ) +13, 32 ) ) AS existing_zone_id FROM ezcontentobject_attribute a, ezcontentobject_version v WHERE a.version = v.version AND a.contentobject_id = v.contentobject_id AND a.data_type_string = 'ezpage' )
nodes_with_wrong_path[sql]=SELECT c.node_id, c.path_string, p.path_string as parent_path_string FROM ezcontentobject_tree c, ezcontentobject_tree p WHERE c.parent_node_id = p.node_id AND c.path_string NOT REGEXP CONCAT('^', p.path_string, c.node_id, '/$') AND c.node_id <> 1
# for the one below, do we need to account as well for version states 2 and 4 ?
#draft_objects_with_no_draft_versions[sql]=SELECT * FROM ezcontentobject WHERE status = 0 AND id NOT IN ( SELECT contentobject_id FROM ezcontentobject_version WHERE status IN (0, 5) )
nodes_with_wrong_depth[sql]=SELECT c.node_id FROM ezcontentobject_tree c, ezcontentobject_tree p WHERE c.parent_node_id = p.node_id AND c.depth != ( p.depth + 1 ) AND c.node_id != 1

urlaliases_without_nodes[sql]=SELECT parent, text_md5, action FROM ezurlalias_ml LEFT JOIN ezcontentobject_tree ON substr(action, 8) = node_id WHERE action_type = 'eznode' AND is_original = 1 AND node_id is null
nodes_without_urlaliases[sql]=SELECT node_id FROM ezcontentobject_tree LEFT JOIN ezurlalias_ml ON node_id = substr(action, 8) WHERE depth > 0 AND action_type = 'eznode' AND is_original = 1 AND ezurlalias_ml.id IS NULL

policy_limitations_for_missing_subtrees[sql]= SELECT p.role_id, p.id as policy_id, p.module_name, p.function_name, l.identifier, v.value FROM ezpolicy_limitation_value v JOIN ezpolicy_limitation l ON v.limitation_id = l.id JOIN ezpolicy p ON l.policy_id = p.id LEFT JOIN ezcontentobject_tree n ON v.value = n.path_string WHERE l.identifier = 'Subtree' AND n.node_id IS NULL ORDER BY p.role_id, p.module_name, p.function_name, p.id, v.value
policy_limitations_for_missing_locations[sql]=SELECT p.role_id, p.id as policy_id, p.module_name, p.function_name, l.identifier, v.value FROM ezpolicy_limitation_value v JOIN ezpolicy_limitation l ON v.limitation_id = l.id JOIN ezpolicy p ON l.policy_id = p.id LEFT JOIN ezcontentobject_tree n ON v.value = n.node_id WHERE l.identifier = 'Node' AND n.node_id IS NULL ORDER BY p.role_id, p.module_name, p.function_name, p.id, v.value
policy_limitations_for_missing_classes[sql]= SELECT p.role_id, p.id as policy_id, p.module_name, p.function_name, l.identifier, v.value FROM ezpolicy_limitation_value v JOIN ezpolicy_limitation l ON v.limitation_id = l.id JOIN ezpolicy p ON l.policy_id = p.id LEFT JOIN ezcontentclass c ON v.value = c.id WHERE l.identifier IN ('Class', 'ParentClass') AND c.id IS NULL ORDER BY p.role_id, p.module_name, p.function_name, p.id, v.value
policy_limitations_for_missing_sections[sql]= SELECT p.role_id, p.id as policy_id, p.module_name, p.function_name, l.identifier, v.value FROM ezpolicy_limitation_value v JOIN ezpolicy_limitation l ON v.limitation_id = l.id JOIN ezpolicy p ON l.policy_id = p.id LEFT JOIN ezsection s ON v.value = s.id WHERE l.identifier IN ('Section', 'NewSection') AND s.id IS NULL ORDER BY p.role_id, p.module_name, p.function_name, p.id, v.value
policy_limitations_for_missing_states[sql]= SELECT p.role_id, p.id as policy_id, p.module_name, p.function_name, l.identifier, v.value FROM ezpolicy_limitation_value v JOIN ezpolicy_limitation l ON v.limitation_id = l.id JOIN ezpolicy p ON l.policy_id = p.id LEFT JOIN ezcobj_state s ON v.value = s.id WHERE l.identifier IN ('State', 'NewState') AND s.id IS NULL ORDER BY p.role_id, p.module_name, p.function_name, p.id, v.value

# @todo: ezcontentobject_link where contentclassattribute_id = 0 and relation_type = 8 (and vice-versa)

# nb: the following 2 queries assume there are no other datatypes besides 'ezpage' which are linked to data in ezm_block table
# nb: the following query can create a huge temp table!
ezflow_blocks_with_invalid_zones[sql]=SELECT * FROM ezm_block WHERE zone_id NOT IN ( SELECT DISTINCT( SUBSTRING( a.data_text, LOCATE( '<zone id="id_', a.data_text ) +13, 32 ) ) AS existing_zone_id FROM ezcontentobject_attribute a, ezcontentobject_version v WHERE a.version = v.version AND a.contentobject_id = v.contentobject_id AND a.data_type_string = 'ezpage' )
leftover_ezflow_blocks[sql]=SELECT * FROM ezm_block WHERE id NOT IN (SELECT DISTINCT(b.id) FROM ezm_block b, ezcontentobject_attribute a WHERE a.data_text like concat('%', b.id, '%') AND a.contentclassattribute_id IN (SELECT id from ezcontentclass_attribute WHERE data_type_string = 'ezpage'))

0 comments on commit 660d74d

Please sign in to comment.