Fix custom field order renumbering to keep at multiples of 10.

This commit is contained in:
Nathan Gray 2015-06-18 16:48:16 +00:00
parent 5449825beb
commit a602dd3e86
2 changed files with 45 additions and 1 deletions

View File

@ -432,7 +432,10 @@ class customfields
}
// Include type-specific value help
$content['options'] = lang(self::$type_option_help);
foreach(self::$type_option_help as $key => $value)
{
$content['options'][$key] = lang($value);
}
$content['statustext'] = $content['options'][$content['cf_type']];
$content['attributes'] = self::$type_attribute_flags;

View File

@ -365,6 +365,37 @@ class egw_customfields implements IteratorAggregate
{
$op = $cf['id'] ? 'update' : 'insert';
// Check to see if field order needs to be re-done
$update = array();
if($cf['id'])
{
$cfs = egw_customfields::get($cf['app'], true);
$old = $cfs[$cf['id']];
if($old['order'] != $cf['order'])
{
uasort($cfs, function($a1, $a2){
return $a1['order'] - $a2['order'];
});
$n = 0;
foreach($cfs as $old_cf)
{
$n += 10;
if($old_cf['order'] != $n)
{
$old_cf['order'] = $n;
if($old_cf['name'] != $cf['name'])
{
$update[] = $old_cf;
}
else
{
$cf['order'] = $n;
}
}
}
}
}
self::$db->$op(self::TABLE, array(
'cf_label' => $cf['label'],
'cf_type' => $cf['type'],
@ -383,6 +414,16 @@ class egw_customfields implements IteratorAggregate
'cf_app' => $cf['app'],
), __LINE__, __FILE__);
foreach($update as $old_cf)
{
self::$db->$op(self::TABLE, array(
'cf_order' => $old_cf['order'],
), array(
'cf_name' => $old_cf['name'],
'cf_app' => $old_cf['app'],
), __LINE__, __FILE__);
}
self::invalidate_cache($cf['app']);
}