function updateGenericServicesCatalogs($action = 'update')
 {
     global $DB;
     $entity = new Entity();
     $pmServicescatalog = new PluginMonitoringServicescatalog();
     $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
     $pmBusinessrulecomponent = new PluginMonitoringBusinessrule_component();
     $existingSCs = array();
     // Find existing instances of generic services catalog ...
     $a_SCs = $this->find("`name` LIKE '" . $this->getName() . "%'");
     foreach ($a_SCs as $a_SC) {
         // Toolbox::logInFile("pm", "SC : ".$a_SC['id'].", name : ".$a_SC['name'].", generic : ".$a_SC['is_generic']."\n");
         if ($a_SC['name'] == $this->getField('name')) {
             continue;
         }
         $existingSCs[$a_SC['name']] = $a_SC;
     }
     if ($action == 'delete') {
         foreach ($existingSCs as $name => $a_SC) {
             $pmServicescatalog->getFromDB($a_SC['id']);
             $pmServicescatalog->delete($pmServicescatalog->fields);
             // Toolbox::logInFile("pm", "Deleted : ".$a_SC['name']."\n");
             $pmBusinessrulecomponent = new PluginMonitoringBusinessrule_component();
             $pmBusinessrule = new PluginMonitoringBusinessrule();
             // Get business rules groups ...
             $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $a_SC['id'] . "'");
             // Delete business groups components
             foreach ($a_BRgroups as $a_BRgroup) {
                 // Toolbox::logInFile("pm", "a_BRgroup : ".$a_BRgroup['id']."\n");
                 $a_brcomponents = $pmBusinessrulecomponent->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brcomponents as $a_brcomponent) {
                     // Toolbox::logInFile("pm", "a_brcomponent : ".$a_brcomponent['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
             // Delete business groups rules
             foreach ($a_BRgroups as $a_BRgroup) {
                 $a_brs = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brs as $a_br) {
                     // Toolbox::logInFile("pm", "a_br : ".$a_br['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
         }
         return;
     } else {
         foreach ($existingSCs as $name => $a_SC) {
             $pmServicescatalog->getFromDB($a_SC['id']);
             $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
             $pmBusinessrulecomponent = new PluginMonitoringBusinessrule_component();
             $pmBusinessrule = new PluginMonitoringBusinessrule();
             // Get business rules groups ...
             $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $a_SC['id'] . "'");
             // Delete business groups components
             foreach ($a_BRgroups as $a_BRgroup) {
                 // Toolbox::logInFile("pm", "a_BRgroup : ".$a_BRgroup['id']."\n");
                 $a_brcomponents = $pmBusinessrulecomponent->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brcomponents as $a_brcomponent) {
                     // Toolbox::logInFile("pm", "a_brcomponent : ".$a_brcomponent['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
             // Delete business groups rules
             foreach ($a_BRgroups as $a_BRgroup) {
                 $a_brs = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $a_BRgroup['id'] . "'");
                 foreach ($a_brs as $a_br) {
                     // Toolbox::logInFile("pm", "a_br : ".$a_br['id']."\n");
                     $pmBusinessrulecomponent->getFromDB($a_brcomponent['id']);
                     $pmBusinessrulecomponent->delete($pmBusinessrulecomponent->fields);
                 }
             }
         }
     }
     // Find entities concerned ...
     $a_entitiesServices = $this->getGenericServicesEntities();
     foreach ($a_entitiesServices as $idEntity => $a_entityServices) {
         // New entity ... so it must exist a derivated SC !
         $entity->getFromDB($idEntity);
         // Toolbox::logInFile("pm", "Found entity : ".$idEntity." / ".$entity->getName()."\n");
         $scName = $this->getName() . " - " . $entity->getName();
         if (isset($existingSCs[$scName])) {
             // Update SC
             $pmServicescatalog->getFromDB($existingSCs[$scName]['id']);
             $pmServicescatalog->fields = $this->fields;
             unset($pmServicescatalog->fields['id']);
             $pmServicescatalog->fields['id'] = $existingSCs[$scName]['id'];
             $pmServicescatalog->fields['entities_id'] = $idEntity;
             $pmServicescatalog->fields['is_generic'] = 0;
             $pmServicescatalog->fields['name'] = $DB->escape($scName);
             $pmServicescatalog->update($pmServicescatalog->fields);
             /*            // Finish updating if needed ...
                         $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$this->fields['id']."'");
                         foreach ($a_BRgroups as $a_BRgroup) {
                            $pmBusinessrulegroup = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$a_SC['id']."' AND `name`='".$a_BRgroup['name']."'");
                            $pmBusinessrulegroup->fields = $a_BRgroup->fields;
                            unset($pmBusinessrulegroup->fields['id']);
                            $pmBusinessrulegroup->fields['plugin_monitoring_servicescatalogs_id'] = $pmServicescatalog->fields['id'];
                            $pmBusinessrulegroup->update($pmBusinessrulegroup->fields);
                         }
             */
             // Toolbox::logInFile("pm", "Updated : ".$scName."\n");
         } else {
             // Add SC
             $pmServicescatalog = new PluginMonitoringServicescatalog();
             $pmServicescatalog->getEmpty();
             $pmServicescatalog->fields = $this->fields;
             unset($pmServicescatalog->fields['id']);
             $pmServicescatalog->fields['entities_id'] = $idEntity;
             $pmServicescatalog->fields['is_recursive'] = 0;
             $pmServicescatalog->fields['is_generic'] = 0;
             $pmServicescatalog->fields['name'] = $DB->escape($scName);
             $pmServicescatalog->fields['plugin_monitoring_servicescatalogs_id'] = $this->fields['id'];
             $pmServicescatalog->add($pmServicescatalog->fields);
             /*
                         // Finish updating if needed ...
                         $a_BRgroups = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='".$this->fields['id']."'");
                         foreach ($a_BRgroups as $a_BRgroup) {
                            $ref = new PluginMonitoringBusinessrulegroup();
                            $ref->getFromDB($a_BRgroup['id']);
                            $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup();
                            $pmBusinessrulegroup->getEmpty();
                            $pmBusinessrulegroup->fields = $ref->fields;
                            unset($pmBusinessrulegroup->fields['id']);
                            $pmBusinessrulegroup->fields['plugin_monitoring_servicescatalogs_id'] = $pmServicescatalog->fields['id'];
                            $pmBusinessrulegroup->add($pmBusinessrulegroup->fields);
             
                            $a_brcomponents = $pmBusinessrulecomponent->find("`plugin_monitoring_businessrulegroups_id`='".$a_BRgroup['id']."'");
                            foreach ($a_brcomponents as $a_brcomponent) {
                               $ref = new PluginMonitoringBusinessrule_component();
                               $ref->getFromDB($a_brcomponent['id']);
                               $pmBusinessrule_component = new PluginMonitoringBusinessrule_component();
                               $pmBusinessrule_component->getEmpty();
                               $pmBusinessrule_component->fields = $ref->fields;
                               unset($pmBusinessrule_component->fields['id']);
                               $pmBusinessrule_component->fields['plugin_monitoring_businessrulegroups_id'] = $pmBusinessrulegroup->fields['id'];
                               $pmBusinessrule_component->add($pmBusinessrule_component->fields);
                            }
                         }
             */
             // Toolbox::logInFile("pm", "Added : ".$scName."\n");
         }
     }
 }