add_manufacturers_to_dictionnaries.patch

orthagh, 05/12/2014 09:16 AM

Download (18 KB)

View differences:

inc/computertype.class.php
38 38
/// Class ComputerType
39 39
class ComputerType extends CommonDropdown {
40 40

  
41

  
41
   var $additional_fields_for_dictionnary = array('manufacturer');
42 42

  
43 43
   static function getTypeName($nb=0) {
44 44
      return _n('Computer type', 'Computer types', $nb);
inc/monitortype.class.php
38 38
/// Class MonitorType
39 39
class MonitorType extends CommonDropdown {
40 40

  
41
   var $additional_fields_for_dictionnary = array('manufacturer');
41 42

  
42 43
   static function getTypeName($nb=0) {
43 44
      return _n('Monitor type', 'Monitor types', $nb);
inc/networkequipmenttype.class.php
38 38
/// Class NetworkEquipementType
39 39
class NetworkEquipmentType extends CommonDropdown {
40 40

  
41
   var $additional_fields_for_dictionnary = array('manufacturer');
41 42

  
42 43
   static function getTypeName($nb=0) {
43 44
      return _n('Networking equipment type', 'Networking equipment types', $nb);
inc/peripheraltype.class.php
38 38
/// Class PeripheralType
39 39
class PeripheralType extends CommonDropdown {
40 40

  
41
   var $additional_fields_for_dictionnary = array('manufacturer');
41 42

  
42 43
   static function getTypeName($nb=0) {
43 44
      return _n('Devices type', 'Devices types', $nb);
inc/phonetype.class.php
38 38
/// Class PhoneType
39 39
class PhoneType extends CommonDropdown {
40 40

  
41
   var $additional_fields_for_dictionnary = array('manufacturer');
41 42

  
42 43
   static function getTypeName($nb=0) {
43 44
      return _n('Phone type', 'Phone types', $nb);
inc/printertype.class.php
38 38
/// Class PrinterType
39 39
class PrinterType extends CommonDropdown {
40 40

  
41
   var $additional_fields_for_dictionnary = array('manufacturer');
41 42

  
42 43
   static function getTypeName($nb=0) {
43 44
      return _n('Printer type', 'Printer types', $nb);
inc/rule.class.php
1397 1397
            unset($output["_no_rule_matches"]);
1398 1398
            $refoutput = $output;
1399 1399
            $output = $this->executeActions($output, $params);
1400

  
1401 1400
            $this->updateOnlyCriteria($options, $refoutput, $output);
1402 1401
            //Hook
1403 1402
            $hook_params["sub_type"] = $this->getType();
inc/ruledictionnarycomputermodel.class.php
72 72

  
73 73
      $actions                          = array();
74 74
      $actions['name']['name']          = __('Model');
75
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
76 76

  
77 77
      return $actions;
78 78
   }
inc/ruledictionnarycomputertype.class.php
54 54
      $criterias['name']['name']  = __('Type');
55 55
      $criterias['name']['table'] = 'glpi_computertypes';
56 56

  
57
      $criterias['manufacturer']['field'] = 'manufacturer';
58
      $criterias['manufacturer']['name']  = __('Manufacturer');
59
      $criterias['manufacturer']['table'] = 'glpi_manufacturers';
60

  
57 61
      return $criterias;
58 62
   }
59 63

  
......
65 69

  
66 70
      $actions                          = array();
67 71
      $actions['name']['name']          = __('Type');
68
      $actions['name']['force_actions'] = array('append_regex_result', 'assign','regex_result');
72
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
69 73

  
70 74
      return $actions;
71 75
   }
inc/ruledictionnarydropdowncollection.class.php
53 53
      global $DB;
54 54

  
55 55
      // Model check : need to check using manufacturer extra data so specific function
56
      if (strpos($this->item_table,'models')) {
57
         return $this->replayRulesOnExistingDBForModel($offset, $maxtime);
56
      if (strpos($this->item_table,'models') || strpos($this->item_table,'types')) {
57
         return $this->replayRulesOnExistingDBWithManufacturer($offset, $maxtime);
58 58
      }
59 59

  
60 60
      if (isCommandLine()) {
......
129 129
    *
130 130
    * @return -1 on completion else current offset
131 131
   **/
132
   function replayRulesOnExistingDBForModel($offset=0, $maxtime=0) {
132
   function replayRulesOnExistingDBWithManufacturer($offset=0, $maxtime=0) {
133 133
      global $DB;
134 134

  
135 135
      if (isCommandLine()) {
136 136
         printf(__('Replay rules on existing database started on %s')."\n", date("r"));
137 137
      }
138 138

  
139
      // Model check : need to check using manufacturer extra data
140
      if (strpos($this->item_table,'models') === false) {
139
      // Model or type check : need to check using manufacturer extra data
140
      if (strpos($this->item_table,'models') !== false) {
141
         $type = "models";
142
      } elseif (strpos($this->item_table,'types') !== false) {
143
         $type = "types";
144
      } else {
141 145
         _e('Error replaying rules');
142 146
         return false;
143 147
      }
144 148

  
145
      $model_table = getPlural(str_replace('models', '', $this->item_table));
146
      $model_field = getForeignKeyFieldForTable($this->item_table);
149
      $table = getPlural(str_replace($type, '', $this->item_table));
150
      $field = getForeignKeyFieldForTable($this->item_table);
147 151

  
148 152
      // Need to give manufacturer from item table
149 153
      $Sql = "SELECT DISTINCT `glpi_manufacturers`.`id` AS idmanu,
......
152 156
                     `".$this->item_table."`.`name` AS name,
153 157
                     `".$this->item_table."`.`comment`
154 158
              FROM `".$this->item_table."`,
155
                   `$model_table`
159
                   `$table`
156 160
              LEFT JOIN `glpi_manufacturers`
157
                  ON (`$model_table`.`manufacturers_id` = `glpi_manufacturers`.`id`)
158
              WHERE `$model_table`.`$model_field` = `".$this->item_table."`.`id`";
161
                  ON (`$table`.`manufacturers_id` = `glpi_manufacturers`.`id`)
162
              WHERE `$table`.`$field` = `".$this->item_table."`.`id`";
159 163

  
160 164
      if ($offset) {
161 165
         $Sql .= " LIMIT ".intval($offset).",999999999";
......
193 197

  
194 198
            if ($data['id'] != $ID) {
195 199
               $tocheck[$data["id"]][] = $ID;
196
               $sql                    = "UPDATE `$model_table`
197
                                          SET `$model_field` = '$ID'
198
                                          WHERE `$model_field` = '".$data['id']."'";
200
               $sql                    = "UPDATE `$table`
201
                                          SET `$field` = '$ID'
202
                                          WHERE `$field` = '".$data['id']."'";
199 203

  
200 204
               if (empty($data['idmanu'])) {
201 205
                  $sql .= " AND (`manufacturers_id` IS NULL
......
217 221

  
218 222
         foreach ($tocheck AS $ID => $tab) {
219 223
            $sql              = "SELECT COUNT(*)
220
                                 FROM `$model_table`
221
                                 WHERE `$model_field` = '$ID'";
224
                                 FROM `$table`
225
                                 WHERE `$field` = '$ID'";
222 226
            $result           = $DB->query($sql);
223 227
            $deletecartmodel  = false;
224 228

  
inc/ruledictionnarymonitormodel.class.php
72 72

  
73 73
      $actions                          = array();
74 74
      $actions['name']['name']          = __('Model');
75
      $actions['name']['force_actions'] = array('append_regex_result', 'assign','regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
76 76

  
77 77
      return $actions;
78 78
   }
inc/ruledictionnarymonitortype.class.php
57 57
      $criterias['name']['name']  = __('Type');
58 58
      $criterias['name']['table'] = 'glpi_monitortypes';
59 59

  
60
      $criterias['manufacturer']['field'] = 'manufacturer';
61
      $criterias['manufacturer']['name']  = __('Manufacturer');
62
      $criterias['manufacturer']['table'] = 'glpi_manufacturers';
63

  
60 64
      return $criterias;
61 65
   }
62 66

  
......
68 72

  
69 73
      $actions                          = array();
70 74
      $actions['name']['name']          = __('Type');
71
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
72 76

  
73 77
      return $actions;
74 78
   }
inc/ruledictionnarynetworkequipmentmodel.class.php
71 71

  
72 72
      $actions                          = array();
73 73
      $actions['name']['name']          = __('Model');
74
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
74
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
75 75

  
76 76
      return $actions;
77 77
   }
inc/ruledictionnarynetworkequipmenttype.class.php
57 57
      $criterias['name']['name']  = __('Type');
58 58
      $criterias['name']['table'] = 'glpi_networkequipmenttypes';
59 59

  
60
      $criterias['manufacturer']['field'] = 'manufacturer';
61
      $criterias['manufacturer']['name']  = __('Manufacturer');
62
      $criterias['manufacturer']['table'] = 'glpi_manufacturers';
63

  
60 64
      return $criterias;
61 65
   }
62 66

  
......
68 72

  
69 73
      $actions                          = array();
70 74
      $actions['name']['name']          = __('Type');
71
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
72 76

  
73 77
      return $actions;
74 78
   }
inc/ruledictionnaryperipheralmodel.class.php
72 72

  
73 73
      $actions                          = array();
74 74
      $actions['name']['name']          = __('Model');
75
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
76 76

  
77 77
      return $actions;
78 78
   }
inc/ruledictionnaryperipheraltype.class.php
57 57
      $criterias['name']['name']  = __('Type');
58 58
      $criterias['name']['table'] = 'glpi_peripheraltypes';
59 59

  
60
      $criterias['manufacturer']['field'] = 'manufacturer';
61
      $criterias['manufacturer']['name']  = __('Manufacturer');
62
      $criterias['manufacturer']['table'] = 'glpi_manufacturers';
63

  
60 64
      return $criterias;
61 65
   }
62 66

  
......
68 72

  
69 73
      $actions                          = array();
70 74
      $actions['name']['name']          = __('Type');
71
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
72 76

  
73 77
      return $actions;
74 78
   }
inc/ruledictionnaryphonemodel.class.php
72 72

  
73 73
      $actions                          = array();
74 74
      $actions['name']['name']          = __('Model');
75
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
76 76

  
77 77
      return $actions;
78 78
   }
inc/ruledictionnaryphonetype.class.php
57 57
      $criterias['name']['name']  = __('Type');
58 58
      $criterias['name']['table'] = 'glpi_phonetypes';
59 59

  
60
      $criterias['manufacturer']['field'] = 'manufacturer';
61
      $criterias['manufacturer']['name']  = __('Manufacturer');
62
      $criterias['manufacturer']['table'] = 'glpi_manufacturers';
63

  
60 64
      return $criterias;
61 65
   }
62 66

  
......
68 72

  
69 73
      $actions                          = array();
70 74
      $actions['name']['name']          = __('Type');
71
      $actions['name']['force_actions'] = array('append_regex_result', 'assign', 'regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
72 76

  
73 77
      return $actions;
74 78
   }
inc/ruledictionnaryprintermodel.class.php
72 72

  
73 73
      $actions                          = array();
74 74
      $actions['name']['name']          = __('Model');
75
      $actions['name']['force_actions'] = array('assign', 'regex_result', 'append_regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
76 76
      return $actions;
77 77
   }
78 78

  
inc/ruledictionnaryprintertype.class.php
57 57
      $criterias['name']['name']  = __('Type');
58 58
      $criterias['name']['table'] = 'glpi_printertypes';
59 59

  
60
      $criterias['manufacturer']['field'] = 'manufacturer';
61
      $criterias['manufacturer']['name']  = __('Manufacturer');
62
      $criterias['manufacturer']['table'] = 'glpi_manufacturers';
63

  
60 64
      return $criterias;
61 65
   }
62 66

  
......
68 72

  
69 73
      $actions                          = array();
70 74
      $actions['name']['name']          = __('Type');
71
      $actions['name']['force_actions'] = array('assign', 'regex_result', 'append_regex_result');
75
      $actions['name']['force_actions'] = array('assign','regex_result','append_regex_result');
72 76

  
73 77
      return $actions;
74 78
   }
plugins/remove.txt
1
Vous pouvez effacer ce fichier sans dommages.
2

  
3
You can safely remove this file.
scripts/compute_dictionnary.php
50 50
include ('../inc/includes.php');
51 51

  
52 52
// No debug mode
53
$_SESSION['glpi_use_mode'] == NORMAL_MODE;
53
$_SESSION['glpi_use_mode'] == Session::NORMAL_MODE;
54 54

  
55 55
if (isset($_GET["dictionnary"])) {
56 56
   $rulecollection = RuleCollection::getClassByType($_GET["dictionnary"]);