Пример #1
0
 function pre_deleteItem()
 {
     $_SESSION['delete_container'] = true;
     $classname = "PluginFields" . ucfirst(strtolower($this->fields['itemtype'] . preg_replace('/s$/', '', $this->fields['name'])));
     $class_filename = strtolower($this->fields['itemtype'] . preg_replace('/s$/', '', $this->fields['name'])) . ".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 table
     $classname::uninstall();
     //clean session
     unset($_SESSION['delete_container']);
     //remove file
     if (file_exists(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}")) {
         return unlink(GLPI_ROOT . "/plugins/fields/inc/{$class_filename}");
     }
     return true;
 }
Пример #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;
 }