From 3396345cb01fa463ccf22672afd77673d5f6496c Mon Sep 17 00:00:00 2001 From: psc Date: Tue, 12 Apr 2011 08:07:01 +0000 Subject: [PATCH] Apply patch for #5863 - Add a new function get_configured_packages and move logic, which gets debconf configuration for all configured packages from LDAP, to this function. - In object initialisation and PrepareForCopyPaste function use get_configured_packages instead of duplicating the functionality at two places. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@20704 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../fai/admin/fai/class_faiPackage.inc | 151 +++++++----------- 1 file changed, 61 insertions(+), 90 deletions(-) diff --git a/trunk/gosa-plugins/fai/admin/fai/class_faiPackage.inc b/trunk/gosa-plugins/fai/admin/fai/class_faiPackage.inc index 3cf8cc46d..796b72da7 100644 --- a/trunk/gosa-plugins/fai/admin/fai/class_faiPackage.inc +++ b/trunk/gosa-plugins/fai/admin/fai/class_faiPackage.inc @@ -81,56 +81,8 @@ class faiPackage extends plugin ksort($this->usedPackages); } - /* Fetch all package configurations from ldap - */ - $PackageFilter = ""; - foreach($this->usedPackages as $name => $value){ - $PackageFilter .= "(FAIpackage=".$name.")"; - } - /* Also fetch d-i */ - $PackageFilter .= "(FAIpackage=d-i)"; - - $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))"; - - /* Search for configuration objects */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType", - "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); - - /* Walk through configurations and append them to our list of ConfiguredPackages - */ - while($attr = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$attr['FAIstate'][0])){ - continue; - } - } - - $tmp =array(); - $tmp['Name'] = $attr['FAIvariable'][0]; - $tmp['Type'] = $attr['FAIvariableType'][0]; - $tmp['Save'] = TRUE; - - if (isset($attr['FAIvariableContent'][0])){ - if(!in_array($attr['FAIvariableType'],array("multiselect"))){ - $tmp['Value'] = $attr['FAIvariableContent'][0]; - }else{ - $content = array(); - unset($attr['FAIvariableContent']['count']); - foreach($attr['FAIvariableContent'] as $attr){ - $tmp['Value'][] = $attr; - } - } - $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; - } - else { - $tmp['Value'] = ""; - $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; - } - } + /* Fetch package configurations from LDAP */ + $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $this->dn); $this->FAIdebianSection = array(); if(isset($this->attrs['FAIdebianSection'])){ @@ -167,6 +119,64 @@ class faiPackage extends plugin $this->list= $this->genPkgs(TRUE); } + function get_configured_packages($packages, $base) + { + /* Fetch all package configurations from ldap + */ + $PackageFilter = ""; + foreach($packages as $name => $value){ + $PackageFilter .= "(FAIpackage=".$name.")"; + } + /* Also fetch d-i */ + $PackageFilter .= "(FAIpackage=d-i)"; + + $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))"; + + /* Search for configuration objects */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($base); + $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType", + "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); + + $configured_packages = array(); + + /* Walk through configurations and append them to our list of ConfiguredPackages + */ + while($attr = $ldap->fetch()){ + + /* Skip objects, that are tagged as removed */ + if(isset($object['FAIstate'][0])){ + if(preg_match("/removed$/",$attr['FAIstate'][0])){ + continue; + } + } + + $tmp =array(); + $tmp['Name'] = $attr['FAIvariable'][0]; + $tmp['Type'] = $attr['FAIvariableType'][0]; + $tmp['Save'] = TRUE; + + if (isset($attr['FAIvariableContent'][0])){ + if(!in_array($attr['FAIvariableType'],array("multiselect"))){ + $tmp['Value'] = $attr['FAIvariableContent'][0]; + }else{ + $content = array(); + unset($attr['FAIvariableContent']['count']); + foreach($attr['FAIvariableContent'] as $attr){ + $tmp['Value'][] = $attr; + } + } + $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; + } + else { + $tmp['Value'] = ""; + $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; + } + } + + return $configured_packages; + } + function execute() { @@ -826,47 +836,8 @@ class faiPackage extends plugin $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i]; } } + $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $source['dn']); - /* Create one filter with all package names, - instead of calling $ldap->search for every single package - */ - $PackageFilter = ""; - foreach($this->usedPackages as $name){ - $PackageFilter .= "(FAIpackage=".$name.")"; - } - - /* Search for configuration objects */ - $ldap = $this->config->get_ldap_link(); - $ldap->cd($source['dn']); - $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate")); - - /* Walk through configurations and append them to our list of ConfiguredPackages */ - while($attr = $ldap->fetch()){ - - /* Skip objects, that are tagged as removed */ - if(isset($object['FAIstate'][0])){ - if(preg_match("/removed$/",$attr['FAIstate'][0])){ - continue; - } - } - - $tmp =array(); - $tmp['Name'] = $attr['FAIvariable'][0]; - $tmp['Type'] = $attr['FAIvariableType'][0]; - - if (isset($attr['FAIvariableContent'][0])){ - if(!in_array($attr['FAIvariableType'],array("multiselect"))){ - $tmp['Value'] = $attr['FAIvariableContent'][0]; - }else{ - $content = array(); - unset($attr['FAIvariableContent']['count']); - foreach($attr['FAIvariableContent'] as $attr){ - $tmp['Value'][] = $attr; - } - } - $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp; - } - } } -- 2.30.2