我正在尝试过滤 eZPublish 提取。
我有一个具有对象关系属性的类。我的过滤器允许获取由对象关系属性过滤的此类的对象。
我已经开始使用增强的对象关系过滤扩展(http://projects.ez.no/index.php/enhanced_object_relation_filter),但这个只适用于“AND”条件,我想要“OR”。
我能够编辑文件以添加“或”逻辑,这就是我得到的:
<?php
class EORExtendedFilter
{
function CreateSqlParts( $params )
{
$db =& eZDB::instance();
$tables = array();
$joins = array();
// foreach filtered attribute, we add a join the relation table and filter
// on the attribute ID + object ID
foreach( $params as $param )
{
if ( !is_array( $param ) )
continue;
if ( !is_numeric( $param[0] ) )
{
$classAttributeId = eZContentObjectTreeNode::classAttributeIDByIdentifier( $param[0] );
}
else
{
$classAttributeId = $param[0];
}
// multiple objects ids
if ( is_array($param[1]) )
{
foreach( $param[1] as $objectId )
{
$join = array(); // 'OR' logic
if ( is_numeric( $objectId ) )
{
$tableName = 'eor_link_' . $objectId;
$tables[] = 'ezcontentobject_link ' . $tableName;
$join[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
$join[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
$join[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
$join[] = $tableName . '.to_contentobject_id = ' . $objectId;
}
// 'OR' logic
$joins[] = $join;
}
}
// single object id
else
{
$objectId = $param[1];
$tableName = 'eor_link_' . $objectId;
$tables[] = 'ezcontentobject_link ' . $tableName;
$joins[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
$joins[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
$joins[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
$joins[] = $tableName . '.to_contentobject_id = ' . $objectId;
}
}
if ( !count( $tables ) or !count( $joins ) )
{
$tables = $joins = '';
}
else
{
$tables = "\n, " . implode( "\n, ", $tables );
// 'OR' logic
if ( is_array($param[1]) )
{
$andClauses = array();
foreach ($joins as $attr)
{
$andClauses[] = implode( " AND\n ", $attr );
}
$joins = implode( " OR\n ", $andClauses ) . " AND\n ";
}
else
{
$joins = implode( " AND\n ", $joins ) . " AND\n ";
}
}
return array( 'tables' => $tables, 'joins' => $joins );
}
}
这个扩展的属性过滤器产生这个字符串:
eor_link_126.from_contentobject_id = ezcontentobject.id AND eor_link_126.from_contentobject_version = ezcontentobject.current_version AND eor_link_126.contentclassattribute_id = 537和eor_link_126.to_contentobject_id = 126 OR(eor_link_127.from_contentobject_id = ezcontentobject.id AND eor_link_127.from_contentobject_version = ezcontentobject.current_version AND eor_link_127.contentclassattribute_id = 537 AND eor_link_127.to_contentobject_id = 127 AND
我知道它遗漏了一些括号,所以我编辑了字符串以直接在 phpMyAdmin 中对其进行测试。这是查询:
SELECT DISTINCT
ezcontentobject.*,
ezcontentobject_tree.*,
ezcontentclass.serialized_name_list as class_serialized_name_list,
ezcontentclass.identifier as class_identifier,
ezcontentclass.is_container as is_container
, ezcontentobject_name.name as name, ezcontentobject_name.real_translation
, a0.sort_key_int
FROM
ezcontentobject_tree,
ezcontentobject,ezcontentclass
, ezcontentobject_name
, ezcontentobject_attribute a0
, ezcontentobject_link eor_link_126
, ezcontentobject_link eor_link_127
WHERE
ezcontentobject_tree.parent_node_id = 1443 and
((eor_link_126.from_contentobject_id = ezcontentobject.id AND
eor_link_126.from_contentobject_version = ezcontentobject.current_version AND
eor_link_126.contentclassattribute_id = 537 AND
eor_link_126.to_contentobject_id = 126) OR
(eor_link_127.from_contentobject_id = ezcontentobject.id AND
eor_link_127.from_contentobject_version = ezcontentobject.current_version AND
eor_link_127.contentclassattribute_id = 537 AND
eor_link_127.to_contentobject_id = 127)) AND
a0.contentobject_id = ezcontentobject.id AND
a0.contentclassattribute_id = 191 AND
a0.version = ezcontentobject_name.content_version AND
( a0.language_id & ezcontentobject.language_mask > 0 AND
( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 1 )
+ ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 2 ) )
<
( a0.language_id & 1 )
+ ( ( a0.language_id & 2 ) )
)
AND
ezcontentclass.version=0 AND
ezcontentobject_tree.contentobject_id = ezcontentobject.id AND
ezcontentclass.id = ezcontentobject.contentclass_id AND
ezcontentobject.contentclass_id IN ( 17 ) AND
ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and
( ezcontentobject_name.language_id & ezcontentobject.language_mask > 0 AND
( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 1 )
+ ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 2 ) )
<
( ezcontentobject_name.language_id & 1 )
+ ( ( ezcontentobject_name.language_id & 2 ) )
)
AND ezcontentobject_tree.is_invisible = 0
AND
ezcontentobject.language_mask & 3 > 0
ORDER BY a0.sort_key_int DESC
LIMIT 0, 10
问题是,当我执行上面的查询时,没有返回任何内容,因为查询永远不会停止。CPU 达到 100%,我必须重新启动 mysql,这意味着它不是语法问题。
这是查询的解释:
如果有人对此有任何线索,那将非常有帮助。