To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 4a944ce8 authored by vermeul's avatar vermeul
Browse files

added better value comparison

parent 962b7d0d
......@@ -103,21 +103,28 @@ class YATA {
elseif( $field === 'user' ) {
$where["u.username"] = $values;
}
# page annotation
elseif( $field === 'page' ) {
$keyvalues=array();
self::extract_keyvalues($values, $keyvalues);
$where[] =
"EXISTS(
SELECT NULL
FROM yata_page_annotation pa
";
// WHERE pa.page_id = ".$wikiPage->getId()
$key_comp_vals = self::extract_query_keyvalues($values);
foreach($key_comp_vals as $key_comp_val){
$where[] =
"EXISTS(
SELECT NULL
FROM yata_page_annotation pa
WHERE pa.page_id = ".$wikiPage->getId()
." AND pa.name = "
.$dbr->addQuotes($key_comp_val[0])
." AND pa.value "
.$key_comp_val[1]
.$dbr->addQuotes($key_comp_val[2])
.")";
}
}
# annotation
elseif( in_array($field, array('wiki_text', 'comment')) ) {
array_push($searches, $field . ': ' . $values);
if ( preg_match( '/[\%_]/', $values ) ) {
$where[] = "$field LIKE (" . $dbr->addQuotes($values).")";
$where[] = "a.$field LIKE (" . $dbr->addQuotes($values).")";
}
else {
$where["a.$field"] = $values;
......@@ -125,12 +132,14 @@ class YATA {
}
}
if ($errors) {
if ($errors) {
foreach( $errors as $error) {
$errstr .= $error . "<br/>";
}
return $errstr;
}
//var_dump($where);
//die();
# fetch the annotation details
......@@ -1093,24 +1102,28 @@ EOT;
return $id;
}
public static function extract_keyvalues($string, &$keyvalues=array()) {
// Match key-value pairs in a given string.
public static function extract_query_keyvalues($string) {
// Match key-value pairs and its comperator in a given search string.
// e.g. key>value, key>=value, key<value, key<=value, key<>value, key=value
// Will match key and values that are:
// within single quotes ' \'.*?(?<!\\\\)\'
// within double quotes " \".*?(?<!\\\\)\"
// with no quotes at all (and no spaces): [^\s]+
// including one of these comperators: = <> >= <=
$key_comp_vals = array();
$re =
'/(?P<key>\'.*?(?<!\\\\)\'|\".*?(?<!\\\\)\"|[^\s]+)'
.'\s*?=\s*?'
.'\s*?(?P<comp>\=|\<\>|\>\=|\<\=)\s*?'
.'(?P<val>\'.*?(?<!\\\\)\'|\".*?(?<!\\\\)\"|[^\s]+)/';
preg_match_all($re, $string, $matches, PREG_SET_ORDER, 0);
foreach($matches as $match) {
# trim keys and values: remove any spaces and quotes
$key = trim($match["key"], " '\"");
$val = trim($match["val"], " '\"");
$keyvalues[$key] = $val;
array_push($key_comp_vals, [$key, $match["comp"], $val]);
}
return $key_comp_vals;
}
# Main function to parse all annotations,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment