Le Thu, 1 Nov 2012 12:33:29 +0100 David DURIEUX <d.duri...@siprossii.com> a écrit:
>Bonjour, > >je viens de m'apercevoir d'un comportement qui ne devrait pas être >comme ça (enfin je pense). > >Avec fusion, je veux créer un composant mémoire avec ces infos : > > [designation] => rdram - rimm (single-bit ecc) > [frequence] => 400 > [devicememorytypes_id] => 4 > >j'utilise la fonction d'import comme ça : >$deviceMemory = new deviceMemory(); >$deviceMemory->import($input); > >Si j'ai déjà un composant avec : > [designation] => rdram - rimm (single-bit ecc) > [frequence] => 400 > [devicememorytypes_id] => 13 > >Il ne va pas me créé car la fonction import dit que le nom >(designation) est la même. Or le type peux être différent (RDRAM, DRAM, >DDR3...) et donc ça pose problème. > >La solution pour corriger ceci serait de définir dans chaque classe >devicexx (xx = Processor, Memory...) une fonction qui liste les champs >servant à la comparaison dans la fonction import(). > >Qu'en pensez-vous? > Puisqu'il n'y a pas d'objections (votre honneur ^^), voici le patch > >Cordialement, >-- >David DURIEUX >Tel : +33 (0)4.82.53.30.53 >Mail : d.duri...@siprossii.com >Site Web : http://www.siprossii.com/ > >SIPROSSII >Les Lafôrets >69430 Beaujeu >FRANCE > >_______________________________________________ >Glpi-dev mailing list >Glpi-dev@gna.org >https://mail.gna.org/listinfo/glpi-dev
Index: inc/devicecase.class.php =================================================================== --- inc/devicecase.class.php (revision 19619) +++ inc/devicecase.class.php (working copy) @@ -108,5 +108,14 @@ break; } } + + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'manufacturers_id', 'devicecasetypes_id'); + } } ?> Index: inc/devicegraphiccard.class.php =================================================================== --- inc/devicegraphiccard.class.php (revision 19619) +++ inc/devicegraphiccard.class.php (working copy) @@ -120,4 +120,13 @@ } } } + + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'manufacturers_id', 'interfacetypes_id'); + } ?> \ No newline at end of file Index: inc/devicedrive.class.php =================================================================== --- inc/devicedrive.class.php (revision 19619) +++ inc/devicedrive.class.php (working copy) @@ -139,5 +139,14 @@ InterfaceType::getHTMLTableCellsForItem($row, $this, NULL, $options); } } + + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'manufacturers_id', 'interfacetypes_id'); + } } ?> \ No newline at end of file Index: inc/devicememory.class.php =================================================================== --- inc/devicememory.class.php (revision 19619) +++ inc/devicememory.class.php (working copy) @@ -140,5 +140,14 @@ break; } } + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'devicememorytypes_id', 'manufacturers_id'); + } + } ?> \ No newline at end of file Index: inc/devicemotherboard.class.php =================================================================== --- inc/devicemotherboard.class.php (revision 19619) +++ inc/devicemotherboard.class.php (working copy) @@ -108,5 +108,14 @@ break; } } + + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'manufacturers_id', 'chipset'); + } } ?> \ No newline at end of file Index: inc/deviceharddrive.class.php =================================================================== --- inc/deviceharddrive.class.php (revision 19619) +++ inc/deviceharddrive.class.php (working copy) @@ -143,6 +143,14 @@ break; } } - + + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'manufacturers_id', 'interfacetypes_id'); + } } ?> \ No newline at end of file Index: inc/commondevice.class.php =================================================================== --- inc/commondevice.class.php (revision 19619) +++ inc/commondevice.class.php (working copy) @@ -214,9 +214,18 @@ if (!isset($input['designation']) || empty($input['designation'])) { return 0; } + $where = array(); + $a_criteria = $this->getImportCriteria(); + foreach ($a_criteria as $criteria) { + if (isset($input[$criteria])) { + $where[] = "`".$criteria."`='".$input[$criteria]."'"; + + } + } + $query = "SELECT `id` FROM `".$this->getTable()."` - WHERE `designation` = '" . $input['designation'] . "'"; + WHERE ". implode(" AND ", $where); $result = $DB->query($query); if ($DB->numrows($result) > 0) { @@ -225,6 +234,15 @@ } return $this->add($input); } + + + + /* + * Criteria used for import function + */ + function getImportCriteria() { + return array('designation', 'manufacturers_id'); + } } ?> \ No newline at end of file
_______________________________________________ Glpi-dev mailing list Glpi-dev@gna.org https://mail.gna.org/listinfo/glpi-dev