Beispiel #1
0
 function pre_deleteItem()
 {
     global $DB;
     //TODO: remove labels translations
     //remove field in container table
     if ($this->fields['type'] !== "header" && !isset($_SESSION['uninstall_fields']) && !isset($_SESSION['delete_container'])) {
         if ($this->fields['type'] === "dropdown") {
             $oldname = $this->fields['name'];
             $this->fields['name'] = getForeignKeyFieldForItemType(PluginFieldsDropdown::getClassname($this->fields['name']));
         }
         $container_obj = new PluginFieldsContainer();
         $container_obj->getFromDB($this->fields['plugin_fields_containers_id']);
         foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) {
             $classname = "PluginFields" . ucfirst(strtolower($itemtype . preg_replace('/s$/', '', $container_obj->fields['name'])));
             $classname::removeField($this->fields['name']);
         }
         $classname::removeField($this->fields['name']);
     }
     //delete label translations
     $translation_obj = new PluginFieldsLabelTranslation();
     $translations = $translation_obj->find("plugin_fields_itemtype = '" . self::getType() . "' AND plugin_fields_items_id = " . $this->fields['id']);
     foreach ($translations as $translation_id => $translation) {
         $translation_obj->delete(['id' => $translation_id]);
     }
     if (isset($oldname)) {
         $this->fields['name'] = $oldname;
     }
     if ($this->fields['type'] === "dropdown") {
         return PluginFieldsDropdown::destroy($this->fields['name']);
     }
     return true;
 }
Beispiel #2
0
 function pre_deleteItem()
 {
     $_SESSION['delete_container'] = true;
     foreach (json_decode($this->fields['itemtypes']) as $itemtype) {
         $classname = "PluginFields" . ucfirst(strtolower($itemtype . preg_replace('/s$/', '', $this->fields['name'])));
         $class_filename = strtolower($itemtype . preg_replace('/s$/', '', $this->fields['name'])) . ".class.php";
         $injection_filename = strtolower($itemtype . preg_replace('/s$/', '', $this->fields['name'])) . "injection.class.php";
         //delete fields
         $field_obj = new PluginFieldsField();
         $fields = $field_obj->find("plugin_fields_containers_id = " . $this->fields['id']);
         foreach ($fields as $fields_id => $field) {
             $field_obj->delete(array('id' => $fields_id));
         }
         //delete profiles
         $profile_obj = new PluginFieldsProfile();
         $profiles = $profile_obj->find("plugin_fields_containers_id = " . $this->fields['id']);
         foreach ($profiles as $profiles_id => $profile) {
             $profile_obj->delete(array('id' => $profiles_id));
         }
         //delete label translations
         $translation_obj = new PluginFieldsLabelTranslation();
         $translations = $translation_obj->find("plugin_fields_itemtype = '" . self::getType() . "' AND plugin_fields_items_id = " . $this->fields['id']);
         foreach ($translations as $translation_id => $translation) {
             $translation_obj->delete(['id' => $translation_id]);
         }
         //delete table
         if (class_exists($classname)) {
             $classname::uninstall();
         } else {
             //class does not exists; try to remove any existing table
             $tablename = "glpi_plugin_fields_" . strtolower($itemtype . getPlural(preg_replace('/s$/', '', $this->fields['name'])));
             $DB->query("DROP TABLE IF EXISTS `{$tablename}`");
         }
         //clean session
         unset($_SESSION['delete_container']);
         //remove file
         if (file_exists(PLUGINFIELDS_CLASS_PATH . "/{$class_filename}")) {
             unlink(PLUGINFIELDS_CLASS_PATH . "/{$class_filename}");
         }
         if (file_exists(PLUGINFIELDS_CLASS_PATH . "/{$injection_filename}")) {
             unlink(PLUGINFIELDS_CLASS_PATH . "/{$injection_filename}");
         }
     }
     return true;
 }