Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: field "group_order" on the DB wrong when create a new survey [bug and solution]

field "group_order" on the DB wrong when create a new survey [bug and solution] 1 Jahr 2 Wochen her #105272

  • emimarz
  • emimarzs Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 24
  • Dank erhalten: 5
  • Karma: 1
The bug is:
create a survey
create a group (group1)
create N questions on group1

create a survey (S2)
create a group (group2) on S2
create a question (QN1) on group2

QN1 have the field "group_order" on the database with the value N+1
But why? if is another survey

application/helpers/common_helper.php
Line 810
/**
* getMaxGroupOrder($surveyid) queries the database for the maximum sortorder of a group and returns the next higher one.
*
* @param mixed $surveyid
*/
function getMaxGroupOrder($surveyid)
{
$s_lang = Survey::model()->findByPk($surveyid)->language;

//$max_sql = "SELECT max( group_order ) AS max FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}'" ;
$query = Groups::model()->find(array('order' => 'group_order desc')); //here, not filter by survey and languague

$current_max = !is_null($query) ? $query->group_order : '';

if($current_max!="")
{
return ++$current_max ;
}
else return "0" ;
}

Change to

/**
* getMaxGroupOrder($surveyid) queries the database for the maximum sortorder of a group and returns the next higher one.
*
* @param mixed $surveyid
*/
function getMaxGroupOrder($surveyid)
{
$s_lang = Survey::model()->findByPk($surveyid)->language;

$query = Groups::model()->findAllByAttributes(array('sid' => $surveyid, 'language' => $s_lang), array('order' => 'group_order desc'));

$current_max = !is_null($query) ? $query->group_order : '';

if($current_max!="")
{
return ++$current_max ;
}
else return "0" ;
}

Maybe is not mandatory but if you use that field of the database to do something you got some error

Kindest regards
Emiliano
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Ladezeit der Seite: 0.126 Sekunden
Donation Image