From: hickert Date: Fri, 9 Apr 2010 15:19:12 +0000 (+0000) Subject: Updated macro stuff X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=07eb010efeb6a7596b611ca97e422660555e0c24;p=gosa.git Updated macro stuff -Do not allow to write duplicate entries into the database. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17570 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/gofon/gofon/macro/class_gofonMacro.inc b/gosa-plugins/gofon/gofon/macro/class_gofonMacro.inc index 725df304a..d5571e073 100644 --- a/gosa-plugins/gofon/gofon/macro/class_gofonMacro.inc +++ b/gosa-plugins/gofon/gofon/macro/class_gofonMacro.inc @@ -255,6 +255,9 @@ class macro extends plugin " VALUES "; $a_contentLines = preg_split("/\n/",$this->goFonMacroContent); + + // Keep all macro priorities to avoid duplicates! + $priorities = array(); foreach($a_contentLines as $i_linenum => $s_linestr){ /* Remove the 'exten => ' string in front of the macro content line @@ -278,23 +281,28 @@ class macro extends plugin */ $tmp = explode(",", $s_linestr,3); - // No priority given ... somehow - if(count($tmp) == 2){ - $tmp = array($tmp[0],"1",$tmp[1]); - } - /* Check if there is an application given */ - if($tmp[2] == ""){ + if(!isset($tmp[2]) || $tmp[2] == ""){ return(sprintf(_("Application missing in line %s!"),$i_linenum)); } - if($tmp[1] == ""){ + if(!isset($tmp[1]) || $tmp[1] == ""){ return(sprintf(_("Priority missing in line %s!"),$i_linenum)); } /* Check if there is an extension given */ - if($tmp[0] == ""){ + if(!isset($tmp[0]) || $tmp[0] == ""){ return(sprintf(_("Extension missing in line %s!"),$i_linenum)); } + // Table 'extensions' has a primary key over the following fields + // 'context', 'exten' and 'priority' - + // Ensure that we do not write duplicates here. + $du = $context.$tmp[0].$tmp[1]; + if(!isset($priorities[$du])){ + $priorities[$du] = 1; + }else{ + return(sprintf(_("Duplicate combination of 'extension' and 'priority' in line %s!"),$i_linenum)); + } + /* Create extension entry for current line * and add this line to an array that will be inserted * to each database.