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 1e1bd01b authored by vermeul's avatar vermeul
Browse files

hashtag bugfixes

parent 19ee392d
......@@ -614,7 +614,7 @@ EOT;
public static function del_category($dbw, $category_name) {
if (substr($category_name, 0) == '#') {
if (substr($category_name, 0, 1) == '#') {
# we go a hashtag, which should be unique.
$dbw->delete(
'yata_category',
......@@ -638,14 +638,16 @@ EOT;
private static function split_cat_argstring($arg_string) {
$args = array();
# split by comma, but only if next element is one of the keys (name, description, parent)
# name='xxx', description='blabla', hashtag='#blabla', parent='parent/category'
# splits argumentlist above and returns a dictionary instead.
$keyvals = preg_split('/\s*\,\s*(?=(name|hashtag|description|parent))/', $arg_string);
foreach($keyvals as $keyval) {
list($key, $value) = preg_split('/\s*\=\s*/', $keyval);
# remove ay leading and trailing " or '
# in the value
$value = preg_replace('/^(\'|\")/', '', $value);
$value = preg_replace('/(\'|\")$/', '', $value);
$value = preg_replace('/^\s*(\'|\")/', '', $value);
$value = preg_replace('/(\'|\")\s*$/', '', $value);
$value = preg_replace('/\s*$/', '', $value);
$args[$key] = $value;
}
return $args;
......@@ -726,26 +728,27 @@ EOT;
public static function get_category($dbr, $category) {
$category = trim($category);
$selection = array(
'id' => 'c.id',
'name' => 'c.name',
'hashtag' => 'c.hashtag',
'description' => 'c.description',
'parent_name' => "''",
'parent_id' => 'c.parent_id'
);
# we received a hashtag: use that.
if (substr($category, 0) == '#') {
if (substr($category, 0,1) == '#') {
$row = $dbr->selectRow(
array(c=>'yata_category'),
array(
id => 'c.id',
name => 'c.name',
hashtag => 'c.hashtag',
description => 'c.description',
parent_name => "''",
parent_id => 'c.parent_id'
),
array('c' =>'yata_category'),
$selection,
array(
hashtag => $category,
'c.hashtag' => $category,
)
);
return $row;
}
# get parent and child category: parent_cat/child_cat
list($parent_cat, $child_cat) = preg_split('/\s*\/\s*/', $category);
......@@ -753,15 +756,8 @@ EOT;
if (is_null($child_cat)) {
# search for a top category (no parent)
$row = $dbr->selectRow(
array(c=>'yata_category'),
array(
'id' => 'c.id',
'name' => 'c.name',
'hashtag' => 'c.hashtag',
'description' => 'c.description',
'parent_name' => "''",
'parent_id' => 'c.parent_id'
),
array('c' =>'yata_category'),
$selection,
array(
'name' => $parent_cat,
'parent_id' => null
......@@ -772,22 +768,17 @@ EOT;
else {
# search for category where parent matches
# by self-joining table via parent_id
$selection['parent_name'] = 'pc.name';
$row = $dbr->selectRow(
array('pc'=>'yata_category', 'cc'=>'yata_category'),
array(
'id' => 'cc.id',
'name' => 'cc.name',
'description' => 'cc.description',
'parent_name' => 'pc.name',
'parent_id' => 'cc.parent_id'
),
array('pc'=>'yata_category', 'c'=>'yata_category'),
$selection,
array(
'cc.name' => $child_cat,
'c.name' => $child_cat,
'pc.name' => $parent_cat,
),
__METHOD__,
array(),
array( 'pc' => array( 'INNER JOIN', array ( 'cc.parent_id = pc.id' ) ) )
array( 'pc' => array( 'INNER JOIN', array ( 'c.parent_id = pc.id' ) ) )
);
return $row;
}
......@@ -957,6 +948,7 @@ EOT;
$cat_strs = preg_split("/\s*\,\s*/", $category, -1, PREG_SPLIT_NO_EMPTY);
$cats = array();
foreach($cat_strs as $cat_str) {
# we got a category id, which consists only of numbers
if ( preg_match("/^\s*\d*\s*$/", $cat_str) ) {
$cat = self::get_category_and_parent_for_id($dbw, $cat_str);
}
......@@ -967,7 +959,7 @@ EOT;
array_push($cats, $cat);
}
else {
throw new Exception("could not find category: $cat_str");
throw new Exception("no such category: $cat_str");
}
}
# we encountered an id: replace it with a unique one,
......
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